CLI work
This commit is contained in:
+19
-10
@@ -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"));
|
||||
|
||||
@@ -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);
|
||||
@@ -1,5 +0,0 @@
|
||||
export function safeRun(fn: () => Promise<void>) {
|
||||
fn().catch((e) => {
|
||||
console.error(e);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user