2022-05-04 22:31:11 +08:00
|
|
|
#!/usr/bin/env -S node --enable-source-maps
|
2022-04-25 16:33:38 +08:00
|
|
|
import { nodeModulesDir } from "@plugos/plugos/environments/node_sandbox";
|
2022-04-26 01:46:08 +08:00
|
|
|
import { realpathSync } from "fs";
|
2022-04-27 02:31:31 +08:00
|
|
|
import yargs from "yargs";
|
|
|
|
import { hideBin } from "yargs/helpers";
|
|
|
|
|
|
|
|
import { ExpressServer } from "./express_server";
|
2022-03-20 16:56:28 +08:00
|
|
|
|
|
|
|
let args = yargs(hideBin(process.argv))
|
2022-04-01 23:32:03 +08:00
|
|
|
.option("port", {
|
|
|
|
type: "number",
|
|
|
|
default: 3000,
|
|
|
|
})
|
2022-06-28 20:14:15 +08:00
|
|
|
.option("password", {
|
2022-04-30 00:54:27 +08:00
|
|
|
type: "string",
|
|
|
|
})
|
2022-04-01 23:32:03 +08:00
|
|
|
.parse();
|
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-06-28 20:14:15 +08:00
|
|
|
"Usage: silverbullet [--port 3000] [--password mysecretpassword] <path-to-pages>"
|
2022-05-04 22:26:52 +08:00
|
|
|
);
|
2022-04-01 23:32:03 +08:00
|
|
|
process.exit(1);
|
2022-03-27 15:55:29 +08:00
|
|
|
}
|
|
|
|
|
2022-03-21 22:21:34 +08:00
|
|
|
const pagesPath = args._[0] as string;
|
2022-03-20 16:56:28 +08:00
|
|
|
const port = args.port;
|
2022-04-26 01:46:08 +08:00
|
|
|
|
|
|
|
const webappDistDir = realpathSync(
|
|
|
|
`${nodeModulesDir}/node_modules/@silverbulletmd/web/dist`
|
|
|
|
);
|
2022-06-28 20:34:25 +08:00
|
|
|
// console.log("Webapp dist dir", webappDistDir);
|
2022-04-27 01:04:36 +08:00
|
|
|
const plugDistDir = realpathSync(
|
|
|
|
`${nodeModulesDir}/node_modules/@silverbulletmd/plugs/dist`
|
|
|
|
);
|
2022-06-28 20:34:25 +08:00
|
|
|
// console.log("Builtin plug dist dir", plugDistDir);
|
2022-03-20 16:56:28 +08:00
|
|
|
|
2022-04-30 00:54:27 +08:00
|
|
|
const expressServer = new ExpressServer({
|
|
|
|
port: port,
|
|
|
|
pagesPath: pagesPath,
|
|
|
|
distDir: webappDistDir,
|
|
|
|
builtinPlugDir: plugDistDir,
|
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);
|
|
|
|
});
|