diff --git a/.gitpod.yml b/.gitpod.yml index d19a2ec..319e9ea 100644 --- a/.gitpod.yml +++ b/.gitpod.yml @@ -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 diff --git a/README.md b/README.md index 8b591bd..3bc778e 100644 --- a/README.md +++ b/README.md @@ -52,8 +52,7 @@ terminal: deno run -A --unstable https://get.silverbullet.md -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 -- +deno task watch-server ``` 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 -- +deno task watch-server deno task watch-plugs ``` diff --git a/deno.jsonc b/deno.jsonc index 235022c..703daa8 100644 --- a/deno.jsonc +++ b/deno.jsonc @@ -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" }, diff --git a/server/server.ts b/server/server.ts deleted file mode 100755 index 8749344..0000000 --- a/server/server.ts +++ /dev/null @@ -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] ", - ); - 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); -}); diff --git a/server/silverbullet.ts b/server/silverbullet.ts new file mode 100755 index 0000000..b3e6aaa --- /dev/null +++ b/server/silverbullet.ts @@ -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("") + .option("-p, --port ", "Port to listen on") + .option("--password ", "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); diff --git a/website/CHANGELOG.md b/website/CHANGELOG.md index 5dbe5d3..ad2e45c 100644 --- a/website/CHANGELOG.md +++ b/website/CHANGELOG.md @@ -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). ---