This commit is contained in:
Zef Hemel
2022-10-24 13:51:26 +02:00
parent 2d9240ee25
commit 01aea4768b
11 changed files with 178 additions and 66 deletions
+19 -10
View File
@@ -85,17 +85,26 @@ export class HttpServer {
this.system.addHook(namespaceHook);
// The space
this.spacePrimitives = new AssetBundlePlugSpacePrimitives(
new EventedSpacePrimitives(
new PlugSpacePrimitives(
new DiskSpacePrimitives(options.pagesPath),
namespaceHook,
try {
this.spacePrimitives = new AssetBundlePlugSpacePrimitives(
new EventedSpacePrimitives(
new PlugSpacePrimitives(
new DiskSpacePrimitives(options.pagesPath),
namespaceHook,
),
this.eventHook,
),
this.eventHook,
),
this.assetBundle,
);
this.space = new Space(this.spacePrimitives);
this.assetBundle,
);
this.space = new Space(this.spacePrimitives);
} catch (e: any) {
if (e instanceof Deno.errors.NotFound) {
console.error("Pages folder", options.pagesPath, "not found");
} else {
console.error(e.message);
}
Deno.exit(1);
}
// The database used for persistence (SQLite)
this.db = new AsyncSQLite(path.join(options.pagesPath, "data.db"));
-45
View File
@@ -1,45 +0,0 @@
import { Command } from "https://deno.land/x/cliffy@v0.25.2/command/command.ts";
import * as path from "https://deno.land/std@0.158.0/path/mod.ts";
import { HttpServer } from "./http_server.ts";
import assetBundle from "../dist/asset_bundle.json" assert { type: "json" };
import { AssetBundle, AssetJson } from "../plugos/asset_bundle/bundle.ts";
await new Command()
.name("silverbullet")
.description("Markdown as a platform")
// Main command
.arguments("<folder:string>")
.option("-p, --port <port:number>", "Port to listen on")
.option("--password <password:string>", "Password for basic authentication")
.action((options, folder) => {
const pagesPath = path.resolve(Deno.cwd(), folder);
const port = options.port || 3000;
console.log("Pages folder:", pagesPath);
const httpServer = new HttpServer({
port: port,
pagesPath: pagesPath,
assetBundle: new AssetBundle(assetBundle as AssetJson),
password: options.password,
});
httpServer.start().catch((e) => {
console.error(e);
});
})
// Upgrade command
.command("upgrade", "Upgrade Silver Bullet")
.action(async () => {
console.log("Attempting upgrade...");
const p = Deno.run({
cmd: ["deno", "cache", "--reload", Deno.mainModule],
});
const exitCode = await p.status();
if (exitCode.success) {
console.log("Upgrade succeeded");
} else {
console.error("Upgrade failed");
}
})
.parse(Deno.args);
-5
View File
@@ -1,5 +0,0 @@
export function safeRun(fn: () => Promise<void>) {
fn().catch((e) => {
console.error(e);
});
}