silverbullet/packages/server/server.ts

50 lines
1.2 KiB
TypeScript
Raw Normal View History

2022-05-04 22:26:52 +08:00
#!/usr/bin/env node --enable-source-maps
2022-04-25 16:33:38 +08:00
import { nodeModulesDir } from "@plugos/plugos/environments/node_sandbox";
2022-04-25 17:24:13 +08:00
import { preloadModules } from "@silverbulletmd/common/preload_modules";
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";
let args = yargs(hideBin(process.argv))
2022-04-01 23:32:03 +08:00
.option("port", {
type: "number",
default: 3000,
})
2022-04-30 00:54:27 +08:00
.option("token", {
type: "string",
})
2022-04-01 23:32:03 +08:00
.parse();
2022-03-27 15:55:29 +08:00
if (!args._.length) {
2022-05-04 22:26:52 +08:00
console.error(
"Usage: silverbullet [--port 3000] [--token mysecrettoken] <path-to-pages>"
);
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;
const port = args.port;
2022-04-26 01:46:08 +08:00
const webappDistDir = realpathSync(
`${nodeModulesDir}/node_modules/@silverbulletmd/web/dist`
);
console.log("Webapp dist dir", webappDistDir);
2022-04-27 01:04:36 +08:00
const plugDistDir = realpathSync(
`${nodeModulesDir}/node_modules/@silverbulletmd/plugs/dist`
);
console.log("Builtin plug dist dir", plugDistDir);
2022-04-30 00:54:27 +08:00
const expressServer = new ExpressServer({
port: port,
pagesPath: pagesPath,
preloadedModules: preloadModules,
distDir: webappDistDir,
builtinPlugDir: plugDistDir,
token: args.token,
});
2022-04-25 00:06:34 +08:00
expressServer.start().catch((e) => {
console.error(e);
});