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
+29
View File
@@ -0,0 +1,29 @@
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 Silver Bullet again.",
);
}
+26
View File
@@ -0,0 +1,26 @@
import { path } from "../server/deps.ts";
import { HttpServer } from "../server/http_server.ts";
import assetBundle from "../dist/asset_bundle.json" assert { type: "json" };
import { AssetBundle, AssetJson } from "../plugos/asset_bundle/bundle.ts";
export function serveCommand(options: any, folder: string) {
const pagesPath = path.resolve(Deno.cwd(), folder);
const port = options.port || 3000;
console.log(
"Going to start Silver Bullet on port",
port,
"serving pages from",
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);
});
}
+39
View File
@@ -0,0 +1,39 @@
import { version } from "../version.ts";
export async function upgradeCommand() {
console.log(
"Now going to attempt an upgrade, this may involve downloading the Internet (but there may be cool spinners). Prepare!",
);
const p = Deno.run({
cmd: ["deno", "cache", "--reload", Deno.mainModule],
});
const exitCode = await p.status();
if (!exitCode.success) {
console.error("Something went wrong there...");
Deno.exit(1);
}
console.log(
"So, that's done. Now let's see if this actually did anything...",
);
const vp = Deno.run({
cmd: ["deno", "run", "-A", "--unstable", Deno.mainModule, "version"],
stdout: "piped",
});
const versionStatus = await vp.status();
if (!versionStatus.success) {
console.error("Could not run version command, something is wrong.");
Deno.exit(1);
}
const rawVersion = await vp.output();
const newVersion = new TextDecoder().decode(rawVersion).trim();
if (newVersion === version) {
console.log(
`Nope. I hate to tell you this, but it looks like we're stilling running ${newVersion}.\nThis was a bit of a futile exercise. Let's try again soon some time.`,
);
} else {
console.log(
`Congrats, we've upgraded you from ${version} to ${newVersion}. Seems like quite bump, enjoy! https://silverbullet.md/changelog/ may give you more hints on what's new.`,
);
}
}
+5
View File
@@ -0,0 +1,5 @@
import { version } from "../version.ts";
export function versionCommand() {
console.log(version);
}