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