1
0

New silverbullet command line structure, allowing for sub-commands

This commit is contained in:
Zef Hemel 2022-10-23 09:06:12 +02:00
parent 110f262e6f
commit 2d9240ee25
6 changed files with 56 additions and 45 deletions

View File

@ -23,7 +23,7 @@ tasks:
init: |
gp sync-await setup
mkdir pages
command: deno task watch-server -- pages
command: deno task watch-server pages
- name: Web watcher
init: gp sync-await setup
command: deno task watch-web

View File

@ -52,8 +52,7 @@ terminal:
deno run -A --unstable https://get.silverbullet.md <pages-path>
However, because this command is not super easy to remember, you may install it
as well:
However, because this command is not super easy to remember, you may install it:
deno install -f --name silverbullet -A --unstable https://get.silverbullet.md
@ -81,7 +80,7 @@ found its killer app.
Simply run this:
deno cache --reload https://get.silverbullet.md
silverbullet upgrade
And restart Silver Bullet. You should be good to go.
@ -113,7 +112,7 @@ You can then run the server in “watch mode” (automatically restarting when y
change source files) with:
```shell
deno task watch-server -- <PATH-TO-YOUR-SPACE>
deno task watch-server <PATH-TO-YOUR-SPACE>
```
After this initial build, it's convenient to run three commands in parallel (in
@ -121,7 +120,7 @@ separate terminals):
```shell
deno task watch-web
deno task watch-server -- <PATH-TO-YOUR-SPACE>
deno task watch-server <PATH-TO-YOUR-SPACE>
deno task watch-plugs
```

View File

@ -1,14 +1,14 @@
{
"tasks": {
"clean": "rm -rf dist dist_bundle",
"install": "deno install -f -A --unstable plugos/bin/plugos-bundle.ts && deno install -f -n silverbullet -A --unstable server/server.ts",
"install": "deno install -f -A --unstable plugos/bin/plugos-bundle.ts && deno install -f -n silverbullet -A --unstable server/silverbullet.ts",
"test": "deno test -A --unstable",
"build": "./build_plugs.sh && deno run -A --unstable --check build.ts",
"watch-web": "deno run -A --unstable --check build.ts --watch",
"watch-server": "deno run -A --unstable --check --watch server/server.ts",
"watch-server": "deno run -A --unstable --check --watch server/silverbullet.ts",
// The only reason to run a shell script is that deno task doesn't support globs yet (e.g. *.plug.yaml)
"watch-plugs": "./build_plugs.sh --watch",
"bundle": "deno bundle --importmap import_map.json server/server.ts dist/silverbullet.js",
"bundle": "deno bundle --importmap import_map.json server/silverbullet.ts dist/silverbullet.js",
"generate": "deno run -A plugos/gen.ts"
},

View File

@ -1,36 +0,0 @@
import * as flags from "https://deno.land/std@0.158.0/flags/mod.ts";
import * as path from "https://deno.land/std@0.158.0/path/mod.ts";
import { HttpServer } from "./http_server.ts";
const args = flags.parse(Deno.args, {
string: ["port", "password", "builtins"],
alias: { p: "port" },
default: {
port: "3000",
},
});
if (!args._.length) {
console.error(
"Usage: silverbullet [--port 3000] [--password mysecretpassword] <path-to-pages>",
);
Deno.exit(1);
}
const pagesPath = path.resolve(Deno.cwd(), args._[0] as string);
const port = +args.port;
import assetBundle from "../dist/asset_bundle.json" assert { type: "json" };
import { AssetBundle, AssetJson } from "../plugos/asset_bundle/bundle.ts";
console.log("Pages folder:", pagesPath);
const httpServer = new HttpServer({
port: port,
pagesPath: pagesPath,
assetBundle: new AssetBundle(assetBundle as AssetJson),
password: args.password,
});
httpServer.start().catch((e) => {
console.error(e);
});

45
server/silverbullet.ts Executable file
View File

@ -0,0 +1,45 @@
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);

View File

@ -18,6 +18,9 @@ release.
results. Search results now also snow a snippet of the page, with the phrase
highlighted.
- Faster page indexing.
- If you have Silver Bullet installed via the `deno install` command, you can
use `silverbullet upgrade` to upgrade to the latest version (from this version
onwards).
---