-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
413 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,4 +21,4 @@ | |
"hydrator", | ||
"mononykus" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { assert } from "https://deno.land/[email protected]/testing/asserts.ts"; | ||
import { assert } from "jsr:@std/testing/asserts"; | ||
import { build } from "./build.ts"; | ||
|
||
const base = "mononykus/"; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,11 @@ | ||
import * as esbuild from "https://deno.land/x/[email protected]/mod.js"; | ||
import { svelte_components } from "./esbuild_plugins/svelte_components.ts"; | ||
import { denoPlugins } from "jsr:@luca/esbuild-deno-loader@^0.10.3"; | ||
import { parseArgs } from "jsr:@std/[email protected]/parse-args"; | ||
import { copy, ensureDir, walk } from "jsr:@std/[email protected]"; | ||
import { globToRegExp, normalize } from "jsr:@std/[email protected]"; | ||
import * as esbuild from "npm:[email protected]"; | ||
import { build_routes } from "./esbuild_plugins/build_routes.ts"; | ||
import { ensureDir } from "https://deno.land/[email protected]/fs/ensure_dir.ts"; | ||
import { parse } from "https://deno.land/[email protected]/flags/mod.ts"; | ||
import { serve } from "https://deno.land/[email protected]/http/server.ts"; | ||
import { walk } from "https://deno.land/[email protected]/fs/walk.ts"; | ||
import { svelte_components } from "./esbuild_plugins/svelte_components.ts"; | ||
import { create_handler } from "./server.ts"; | ||
import { globToRegExp } from "https://deno.land/[email protected]/path/glob.ts"; | ||
import { copy } from "https://deno.land/[email protected]/fs/copy.ts"; | ||
import { normalize } from "https://deno.land/[email protected]/path/mod.ts"; | ||
import { denoPlugins } from "https://deno.land/x/[email protected]/mod.ts"; | ||
|
||
const slashify = (path: string) => normalize(path + "/"); | ||
|
||
|
@@ -20,7 +16,7 @@ type Options = { | |
minify: boolean; | ||
}; | ||
|
||
const flags = parse(Deno.args, { | ||
const flags = parseArgs(Deno.args, { | ||
string: ["site_dir", "out_dir", "base"], | ||
boolean: ["minify", "watch"], | ||
default: { | ||
|
@@ -56,7 +52,7 @@ export const get_svelte_files = async ({ | |
}: { | ||
site_dir: Options["site_dir"]; | ||
dir: "routes/" | "components/"; | ||
}) => { | ||
}): Promise<string[]> => { | ||
const glob = (glob: string) => globToRegExp(glob, { globstar: true }); | ||
const files: string[] = []; | ||
for await ( | ||
|
@@ -82,7 +78,7 @@ export const rebuild = async ({ | |
out_dir, | ||
site_dir, | ||
minify, | ||
}: Options) => { | ||
}: Options): Promise<void> => { | ||
const baseESBuildConfig = { | ||
logLevel: "info", | ||
format: "esm", | ||
|
@@ -114,7 +110,7 @@ export const rebuild = async ({ | |
...baseESBuildConfig, | ||
}; | ||
|
||
return Promise.all([ | ||
await Promise.all([ | ||
esbuild.build(routesESBuildConfig), | ||
esbuild.build(islandsESBuildConfig), | ||
copy_assets({ site_dir, out_dir }), | ||
|
@@ -128,7 +124,7 @@ export const build = async ( | |
site_dir: _site_dir = options.site_dir, | ||
minify = options.minify, | ||
}: Partial<Options> = {}, | ||
) => { | ||
): Promise<void> => { | ||
const base = slashify(_base); | ||
const out_dir = slashify(_out_dir); | ||
const site_dir = slashify(_site_dir); | ||
|
@@ -147,7 +143,8 @@ export const watch = async ( | |
site_dir: _site_dir = options.site_dir, | ||
minify = options.minify, | ||
}: Partial<Options> = {}, | ||
) => { | ||
signal: AbortSignal, | ||
): Promise<void> => { | ||
const base = slashify(_base); | ||
const out_dir = slashify(_out_dir); | ||
const site_dir = slashify(_site_dir); | ||
|
@@ -158,7 +155,7 @@ export const watch = async ( | |
|
||
await _rebuild(); | ||
|
||
serve(create_handler({ base, out_dir }), { port: 4507 }); | ||
Deno.serve({ port: 4507, signal }, create_handler({ base, out_dir })); | ||
|
||
const watcher = Deno.watchFs(site_dir); | ||
let timeout; | ||
|
@@ -173,12 +170,15 @@ export const watch = async ( | |
|
||
if (import.meta.main) { | ||
if (flags.watch) { | ||
Deno.addSignalListener("SIGINT", async () => { | ||
console.log("\nShutting down gracefully…"); | ||
const controller = new AbortController(); | ||
const shutdown = async () => { | ||
console.log("\nShutting down gracefully, light as a feather…"); | ||
controller.abort(); | ||
await esbuild.stop(); | ||
}); | ||
}; | ||
|
||
await watch(options); | ||
Deno.addSignalListener("SIGINT", shutdown); | ||
await watch(options, controller.signal).catch(shutdown); | ||
} else { | ||
await build(options); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
import { | ||
basename, | ||
dirname, | ||
normalize as normalise, | ||
resolve, | ||
} from "https://deno.land/[email protected]/path/mod.ts"; | ||
import type { Plugin } from "https://deno.land/x/[email protected]/mod.js"; | ||
import { normalize } from "https://deno.land/[email protected]/path/mod.ts"; | ||
} from "jsr:@std/[email protected]"; | ||
import type { Plugin } from "npm:[email protected]"; | ||
import { compile, VERSION } from "npm:[email protected]/compiler"; | ||
import type { ComponentType } from "npm:[email protected]"; | ||
|
||
|
@@ -89,7 +89,7 @@ export const svelte_components = ( | |
.replace(/(\.island)?\.svelte$/, "") | ||
.replaceAll(/(\.|\W)/g, "_"); | ||
|
||
const module_src = normalize("/" + base_path + path.split(site_dir)[1]) | ||
const module_src = normalise("/" + base_path + path.split(site_dir)[1]) | ||
.replace( | ||
/svelte$/, | ||
"js", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
import { Handler } from "https://deno.land/[email protected]/http/server.ts"; | ||
import { serveDir } from "https://deno.land/[email protected]/http/file_server.ts"; | ||
import { normalize as normalise } from "https://deno.land/[email protected]/path/posix.ts"; | ||
import { serveDir } from "jsr:@std/[email protected]/file-server"; | ||
import { normalize as normalise } from "jsr:@std/[email protected]"; | ||
|
||
interface ServerOptions { | ||
base: string; | ||
|
@@ -9,7 +8,7 @@ interface ServerOptions { | |
|
||
export const create_handler = ( | ||
{ base, out_dir }: ServerOptions, | ||
): Handler => ((req) => { | ||
): Deno.ServeHandler => ((req) => { | ||
const url = new URL(req.url); | ||
|
||
const normalised_base = normalise("/" + base); | ||
|