2022-05-04 22:31:11 +08:00
|
|
|
#!/usr/bin/env -S node --enable-source-maps
|
2022-10-06 21:14:21 +08:00
|
|
|
import * as flags from "https://deno.land/std@0.158.0/flags/mod.ts";
|
|
|
|
import * as path from "https://deno.land/std@0.158.0/path/mod.ts";
|
|
|
|
import { ExpressServer } from "./express_server.ts";
|
2022-04-27 02:31:31 +08:00
|
|
|
|
2022-10-09 02:33:49 +08:00
|
|
|
const args = flags.parse(Deno.args, {
|
|
|
|
string: ["port", "password", "builtins"],
|
|
|
|
alias: { p: "port" },
|
|
|
|
default: {
|
|
|
|
port: "3000",
|
|
|
|
builtins: new URL("./../plugs/dist/", import.meta.url).toString(),
|
|
|
|
},
|
|
|
|
});
|
2022-03-20 16:56:28 +08:00
|
|
|
|
2022-03-27 15:55:29 +08:00
|
|
|
if (!args._.length) {
|
2022-05-04 22:26:52 +08:00
|
|
|
console.error(
|
2022-10-06 21:14:21 +08:00
|
|
|
"Usage: silverbullet [--port 3000] [--password mysecretpassword] <path-to-pages>",
|
2022-05-04 22:26:52 +08:00
|
|
|
);
|
2022-10-06 21:14:21 +08:00
|
|
|
Deno.exit(1);
|
2022-03-27 15:55:29 +08:00
|
|
|
}
|
|
|
|
|
2022-10-06 21:14:21 +08:00
|
|
|
const pagesPath = path.resolve(Deno.cwd(), args._[0] as string);
|
2022-10-09 02:33:49 +08:00
|
|
|
const port = +args.port;
|
2022-10-07 22:27:47 +08:00
|
|
|
|
2022-10-08 22:47:55 +08:00
|
|
|
import assetBundle from "../dist/web_bundle.json" assert { type: "json" };
|
2022-10-07 22:27:47 +08:00
|
|
|
|
2022-10-09 02:33:49 +08:00
|
|
|
const plugDistUrl = args.builtins;
|
2022-10-06 21:14:21 +08:00
|
|
|
console.log("Pages dir", pagesPath);
|
2022-10-09 02:33:49 +08:00
|
|
|
console.log("Plugs url", plugDistUrl);
|
2022-03-20 16:56:28 +08:00
|
|
|
|
2022-04-30 00:54:27 +08:00
|
|
|
const expressServer = new ExpressServer({
|
|
|
|
port: port,
|
|
|
|
pagesPath: pagesPath,
|
2022-10-07 22:27:47 +08:00
|
|
|
assetBundle: assetBundle,
|
2022-10-09 02:33:49 +08:00
|
|
|
builtinPlugUrl: new URL(plugDistUrl),
|
2022-06-28 20:14:15 +08:00
|
|
|
password: args.password,
|
2022-04-30 00:54:27 +08:00
|
|
|
});
|
2022-04-25 00:06:34 +08:00
|
|
|
expressServer.start().catch((e) => {
|
|
|
|
console.error(e);
|
|
|
|
});
|