2022-03-27 07:55:29 +00:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
2022-03-20 08:56:28 +00:00
|
|
|
import yargs from "yargs";
|
2022-04-01 15:32:03 +00:00
|
|
|
import { hideBin } from "yargs/helpers";
|
|
|
|
import { ExpressServer } from "./api_server";
|
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 path from "path";
|
|
|
|
import { realpath } from "fs/promises";
|
|
|
|
import { realpathSync } from "fs";
|
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,
|
|
|
|
})
|
|
|
|
.parse();
|
2022-03-20 08:56:28 +00:00
|
|
|
|
2022-03-27 07:55:29 +00:00
|
|
|
if (!args._.length) {
|
2022-04-01 15:32:03 +00:00
|
|
|
console.error("Usage: silverbullet <path-to-pages>");
|
|
|
|
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`
|
|
|
|
);
|
|
|
|
console.log("Webapp dist dir", webappDistDir);
|
2022-03-20 08:56:28 +00:00
|
|
|
|
2022-04-25 09:24:13 +00:00
|
|
|
const expressServer = new ExpressServer(
|
|
|
|
port,
|
|
|
|
pagesPath,
|
|
|
|
webappDistDir,
|
|
|
|
preloadModules
|
|
|
|
);
|
2022-04-24 16:06:34 +00:00
|
|
|
expressServer.start().catch((e) => {
|
|
|
|
console.error(e);
|
|
|
|
});
|