diff --git a/build_plugs.sh b/build_plugs.sh index b882f5c..cf52890 100755 --- a/build_plugs.sh +++ b/build_plugs.sh @@ -1,3 +1,3 @@ #!/bin/sh -deno run -A --unstable plugos/bin/plugos-bundle.ts --dist dist_bundle/_plug $@ --exclude=https://esm.sh/handlebars,https://deno.land/std/encoding/yaml.ts,https://esm.sh/@lezer/lr plugs/*/*.plug.yaml +deno run -A --unstable silverbullet.ts plug:build $@ --dist dist_bundle/_plug plugs/*/*.plug.yaml diff --git a/cmd/plug_bundle.ts b/cmd/plug_bundle.ts new file mode 100644 index 0000000..07d7fd6 --- /dev/null +++ b/cmd/plug_bundle.ts @@ -0,0 +1,27 @@ +import { bundleRun } from "../plugos/bin/plugos-bundle.ts"; +import { esbuild } from "../plugos/compile.ts"; + +export async function plugBundleCommand( + { watch, dist, debug, info, importmap }: { + watch: boolean; + dist: string; + debug: boolean; + info: boolean; + importmap?: string; + }, + ...manifestPaths: string[] +) { + await bundleRun( + manifestPaths, + dist, + watch, + { + debug: debug, + info: info, + importMap: importmap + ? new URL(importmap, `file://${Deno.cwd()}/`) + : undefined, + }, + ); + esbuild.stop(); +} diff --git a/deno.jsonc b/deno.jsonc index 61b14d7..9d5ed91 100644 --- a/deno.jsonc +++ b/deno.jsonc @@ -1,13 +1,13 @@ { "tasks": { "clean": "rm -rf dist dist_bundle", - "install": "deno install -f -A --unstable plugos/bin/plugos-bundle.ts && deno install -f -A --unstable silverbullet.ts", + "install": "deno install -f -A --unstable 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 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", + "watch-plugs": "./build_plugs.sh -w", "bundle": "deno bundle --importmap import_map.json silverbullet.ts dist/silverbullet.js", // Regenerates some bundle files (checked into the repo) "generate": "deno run -A plugos/gen.ts" diff --git a/plugos/bin/plugos-bundle.ts b/plugos/bin/plugos-bundle.ts index 1c3acb7..860ba61 100755 --- a/plugos/bin/plugos-bundle.ts +++ b/plugos/bin/plugos-bundle.ts @@ -1,4 +1,5 @@ -#!/usr/bin/env deno +// The recommended way to use this for now is through `silverbullet bundle:build` until +// we fork out PlugOS as a whole import { Manifest } from "../types.ts"; import { YAML } from "../../common/deps.ts"; @@ -111,7 +112,7 @@ async function buildManifest( return { generatedManifest, outPath }; } -async function bundleRun( +export async function bundleRun( manifestFiles: string[], dist: string, watch: boolean, @@ -145,6 +146,7 @@ async function bundleRun( await buildAll(); if (watch) { + console.log("Watching for changes..."); const watcher = Deno.watchFs(manifestFiles.map((p) => path.dirname(p))); for await (const event of watcher) { if (event.paths.length > 0) { diff --git a/silverbullet.ts b/silverbullet.ts index a427225..2f92087 100755 --- a/silverbullet.ts +++ b/silverbullet.ts @@ -6,6 +6,7 @@ import { upgradeCommand } from "./cmd/upgrade.ts"; import { versionCommand } from "./cmd/version.ts"; import { fixCommand } from "./cmd/fix.ts"; import { serveCommand } from "./cmd/server.ts"; +import { plugBundleCommand } from "./cmd/plug_bundle.ts"; await new Command() .name("silverbullet") @@ -20,11 +21,29 @@ await new Command() .option("-p, --port ", "Port to listen on") .option("--password ", "Password for basic authentication") .action(serveCommand) + // fix .command("fix", "Fix a broken space") .arguments("") .action(fixCommand) + // plug:bundle + .command("plug:build", "Bundle (compile) one or more plug manifests") + .arguments("<...name.plug.yaml:string>") + .option("--debug", "Do not minifiy code", { default: false }) + .option("--info", "Print out size info per function", { default: false }) + .option("--watch, -w [type:boolean]", "Watch for changes and rebuild", { + default: false, + }) + .option( + "--dist ", + "Folder to put the resulting .plug.json file into", + { default: "." }, + ) + .option("--importmap ", "Path to import map file to use") + .action(plugBundleCommand) + // upgrade .command("upgrade", "Upgrade Silver Bullet") .action(upgradeCommand) + // version .command("version", "Get current version") .action(versionCommand) .parse(Deno.args); diff --git a/website/CHANGELOG.md b/website/CHANGELOG.md index ad2e45c..8aaf8fa 100644 --- a/website/CHANGELOG.md +++ b/website/CHANGELOG.md @@ -18,9 +18,15 @@ 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). +- `silverbullet` now has sub-commands. It defaults to just running the server + (when passed a path to a directory), but you can also run + `silverbullet --help` to see the available commands. Commands currently + available: + - `silverbullet upgrade` to perform a self upgrade + - `silverbullet fix` to attempt to solve any issues with your space (deletes + your `_plug` directory and `data.db` file) + - `silverbullet plug:build` replaces the old `plugos-bundle` command. + - `silverbullet version` prints the current version ---