1
0
silverbullet/packages/server/server.ts

50 lines
1.2 KiB
TypeScript
Raw Normal View History

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