SilverBullet pivot to become an offline-first PWA (#403)

This commit is contained in:
Zef Hemel
2023-05-23 20:53:53 +02:00
committed by GitHub
parent b256269897
commit 5f484bed57
389 changed files with 4484 additions and 291129 deletions
-29
View File
@@ -1,29 +0,0 @@
import { path } from "../server/deps.ts";
export async function fixCommand(_options: any, folder: string) {
folder = path.resolve(Deno.cwd(), folder);
console.log("Now going to attempt to fix", folder);
console.log(`First, we'll purge the ${folder}/_plug folder...`);
try {
await Deno.remove(path.join(folder, "_plug"), { recursive: true });
} catch (e: any) {
if (e instanceof Deno.errors.NotFound) {
console.log("No _plug folder found, nothing to do here.");
} else {
console.error("Something went wrong:", e);
}
}
console.log("And now we'll delete data.db");
try {
await Deno.remove(path.join(folder, "data.db"));
} catch (e: any) {
if (e instanceof Deno.errors.NotFound) {
console.log("No data.db found, nothing to do here.");
} else {
console.error("Something went wrong:", e);
}
}
console.log(
"Alright then, that should be it. Try running SilverBullet again.",
);
}
-33
View File
@@ -1,33 +0,0 @@
import { SpaceSystem } from "../server/space_system.ts";
import assetBundle from "../dist/asset_bundle.json" assert { type: "json" };
import { path } from "../plugos/deps.ts";
import { AssetBundle, AssetJson } from "../plugos/asset_bundle/bundle.ts";
export async function invokeFunction(
options: any,
pagesPath: string,
functionName: string,
...args: string[]
) {
console.log("Going to invoke funciton", functionName, "with args", args);
const spaceSystem = new SpaceSystem(
new AssetBundle(assetBundle as AssetJson),
pagesPath,
path.join(pagesPath, options.db),
);
await spaceSystem.start();
const [plugName, funcName] = functionName.split(".");
const plug = spaceSystem.system.loadedPlugs.get(plugName);
if (!plug) {
console.error("Plug not found", plugName);
Deno.exit(1);
}
await plug.invoke(funcName, args);
Deno.exit(0);
}
+7 -5
View File
@@ -1,25 +1,27 @@
import { bundleRun } from "../plugos/bin/plugos-bundle.ts";
import { esbuild } from "../plugos/compile.ts";
import { compileManifests } from "../plugos/compile.ts";
import { esbuild } from "../plugos/deps.ts";
export async function plugCompileCommand(
{ watch, dist, debug, info, importmap }: {
{ watch, dist, debug, info, importmap, runtimeUrl }: {
watch: boolean;
dist: string;
debug: boolean;
info: boolean;
importmap?: string;
runtimeUrl?: string;
},
...manifestPaths: string[]
) {
await bundleRun(
await compileManifests(
manifestPaths,
dist,
watch,
{
debug: debug,
info: info,
runtimeUrl,
importMap: importmap
? new URL(importmap, `file://${Deno.cwd()}/`)
? new URL(importmap, `file://${Deno.cwd()}/`).toString()
: undefined,
},
);
+43 -15
View File
@@ -1,37 +1,65 @@
import { path } from "../server/deps.ts";
import { HttpServer } from "../server/http_server.ts";
import assetBundle from "../dist/asset_bundle.json" assert { type: "json" };
import clientAssetBundle from "../dist/client_asset_bundle.json" assert {
type: "json",
};
import plugAssetBundle from "../dist/plug_asset_bundle.json" assert {
type: "json",
};
import { AssetBundle, AssetJson } from "../plugos/asset_bundle/bundle.ts";
import { AssetBundlePlugSpacePrimitives } from "../common/spaces/asset_bundle_space_primitives.ts";
import { DiskSpacePrimitives } from "../common/spaces/disk_space_primitives.ts";
import { SpacePrimitives } from "../common/spaces/space_primitives.ts";
import { S3SpacePrimitives } from "../server/spaces/s3_space_primitives.ts";
export function serveCommand(options: any, folder: string) {
const pagesPath = path.resolve(Deno.cwd(), folder);
const hostname = options.hostname || "127.0.0.1";
const port = options.port || 3000;
const bareMode = options.bare;
const maxFileSizeMB = options.maxFileSizeMB || 20;
console.log(
"Going to start SilverBullet binding to",
`${hostname}:${port}`,
);
console.log("Serving pages from", pagesPath);
if (hostname === "127.0.0.1") {
console.log(
`_Note:_ SilverBullet will only be available locally (via http://localhost:${port}), to allow outside connections, pass --host 0.0.0.0 as a flag.`,
`NOTE: SilverBullet will only be available locally (via http://localhost:${port}).
To allow outside connections, pass -L 0.0.0.0 as a flag, and put a TLS terminator on top.`,
);
}
let spacePrimitives: SpacePrimitives | undefined;
if (folder === "s3://") {
spacePrimitives = new AssetBundlePlugSpacePrimitives(
new S3SpacePrimitives({
accessKey: Deno.env.get("AWS_ACCESS_KEY_ID")!,
secretKey: Deno.env.get("AWS_SECRET_ACCESS_KEY")!,
endPoint: Deno.env.get("AWS_ENDPOINT")!,
region: Deno.env.get("AWS_REGION")!,
bucket: Deno.env.get("AWS_BUCKET")!,
}),
new AssetBundle(plugAssetBundle as AssetJson),
);
console.log("Running in S3 mode");
} else {
folder = path.resolve(Deno.cwd(), folder);
spacePrimitives = new AssetBundlePlugSpacePrimitives(
new DiskSpacePrimitives(folder, {
maxFileSizeMB: options.maxFileSizeMB,
}),
new AssetBundle(plugAssetBundle as AssetJson),
);
}
console.log("Serving pages from", folder);
const httpServer = new HttpServer({
const httpServer = new HttpServer(spacePrimitives, {
hostname,
port: port,
pagesPath: pagesPath,
dbPath: path.join(pagesPath, options.db),
assetBundle: new AssetBundle(assetBundle as AssetJson),
pagesPath: folder,
clientAssetBundle: new AssetBundle(clientAssetBundle as AssetJson),
user: options.user,
bareMode,
});
httpServer.start().catch((e) => {
console.error("HTTP Server error", e);
Deno.exit(1);
keyFile: options.key,
certFile: options.cert,
maxFileSizeMB: +maxFileSizeMB,
});
httpServer.start().catch(console.error);
}