Move plugos-bundle into `silverbullet plug:build` command

pull/109/head
Zef Hemel 2022-10-24 16:06:36 +02:00
parent 01aea4768b
commit ae0aa0639c
6 changed files with 62 additions and 8 deletions

View File

@ -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

27
cmd/plug_bundle.ts Normal file
View File

@ -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();
}

View File

@ -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"

View File

@ -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) {

View File

@ -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:number>", "Port to listen on")
.option("--password <password:string>", "Password for basic authentication")
.action(serveCommand)
// fix
.command("fix", "Fix a broken space")
.arguments("<folder:string>")
.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 <path:string>",
"Folder to put the resulting .plug.json file into",
{ default: "." },
)
.option("--importmap <path:string>", "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);

View File

@ -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
---