From 9b4fde2cb9a282f4a4f7c8fa363e6acb77a686bb Mon Sep 17 00:00:00 2001 From: Zef Hemel Date: Sat, 8 Oct 2022 20:33:49 +0200 Subject: [PATCH] Fixes --- deno.json | 2 +- server/express_server.ts | 18 +++++++++++------- server/server.ts | 24 ++++++++++++------------ 3 files changed, 24 insertions(+), 20 deletions(-) diff --git a/deno.json b/deno.json index c00f9b26d..deb626f12 100644 --- a/deno.json +++ b/deno.json @@ -9,7 +9,7 @@ "watch-web": "deno run -A build.ts", "watch-server": "deno run -A --unstable --watch server/server.ts", "plugs": "./build_plugs.sh", - "compile": "deno compile --output silverbullet --importmap import_map.json -A --unstable server/server.ts" + "bundle": "deno bundle --importmap import_map.json server/server.ts dist/silverbullet.js" } } \ No newline at end of file diff --git a/server/express_server.ts b/server/express_server.ts index ed19fd404..a6cdfe423 100644 --- a/server/express_server.ts +++ b/server/express_server.ts @@ -46,7 +46,7 @@ export type ServerOptions = { port: number; pagesPath: string; assetBundle: Record; - builtinPlugDir: string; + builtinPlugUrl: URL; password?: string; }; @@ -60,7 +60,7 @@ export class ExpressServer { private eventHook: EventHook; private db: SQLite; private port: number; - builtinPlugDir: string; + builtinPlugUrl: URL; password?: string; settings: { [key: string]: any } = {}; spacePrimitives: SpacePrimitives; @@ -71,7 +71,7 @@ export class ExpressServer { constructor(options: ServerOptions) { this.port = options.port; this.app = new Application(); - this.builtinPlugDir = options.builtinPlugDir; + this.builtinPlugUrl = options.builtinPlugUrl; this.assetBundle = options.assetBundle; this.password = options.password; @@ -151,11 +151,15 @@ export class ExpressServer { throw new Error(`Invalid plug name: ${plugName}`); } try { - let manifestJson = await Deno.readTextFile( - path.join(this.builtinPlugDir, `${plugName}.plug.json`), + console.log( + "Fetching", + new URL(`${plugName}.plug.json`, this.builtinPlugUrl).toString(), ); - return JSON.parse(manifestJson); - } catch { + return await (await fetch( + new URL(`${plugName}.plug.json`, this.builtinPlugUrl), + )).json(); + } catch (e: any) { + console.error("FEtching builtin", e); throw new Error(`No such builtin: ${plugName}`); } }, diff --git a/server/server.ts b/server/server.ts index 9717dd8de..9bdd3201b 100755 --- a/server/server.ts +++ b/server/server.ts @@ -3,12 +3,14 @@ import * as flags from "https://deno.land/std@0.158.0/flags/mod.ts"; import * as path from "https://deno.land/std@0.158.0/path/mod.ts"; import { ExpressServer } from "./express_server.ts"; -type ServerArgs = { - _: string[]; - port: number; - password: string; -}; -let args: ServerArgs = flags.parse(Deno.args); +const args = flags.parse(Deno.args, { + string: ["port", "password", "builtins"], + alias: { p: "port" }, + default: { + port: "3000", + builtins: new URL("./../plugs/dist/", import.meta.url).toString(), + }, +}); if (!args._.length) { console.error( @@ -18,21 +20,19 @@ if (!args._.length) { } const pagesPath = path.resolve(Deno.cwd(), args._[0] as string); -const port = args.port ? +args.port : 3000; - -// const webappDistDir = new URL("./../../dist", import.meta.url).pathname; -// console.log("Webapp dist dir", webappDistDir); +const port = +args.port; import assetBundle from "../dist/web_bundle.json" assert { type: "json" }; -const plugDistDir = new URL("./../plugs/dist", import.meta.url).pathname; +const plugDistUrl = args.builtins; console.log("Pages dir", pagesPath); +console.log("Plugs url", plugDistUrl); const expressServer = new ExpressServer({ port: port, pagesPath: pagesPath, assetBundle: assetBundle, - builtinPlugDir: plugDistDir, + builtinPlugUrl: new URL(plugDistUrl), password: args.password, }); expressServer.start().catch((e) => {