Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
zefhemel committed Oct 8, 2022
1 parent 5c4b313 commit 9b4fde2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 20 deletions.
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}

18 changes: 11 additions & 7 deletions server/express_server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export type ServerOptions = {
port: number;
pagesPath: string;
assetBundle: Record<string, string>;
builtinPlugDir: string;
builtinPlugUrl: URL;
password?: string;
};

Expand All @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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}`);
}
},
Expand Down
24 changes: 12 additions & 12 deletions server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import * as flags from "https://deno.land/[email protected]/flags/mod.ts";
import * as path from "https://deno.land/[email protected]/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(
Expand All @@ -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) => {
Expand Down

0 comments on commit 9b4fde2

Please sign in to comment.