From 8d3688b2fd6308c5f115ebfff4cac40cb3ffe08c Mon Sep 17 00:00:00 2001 From: Krzysztof Kowalczyk Date: Thu, 29 Dec 2022 14:33:40 -0500 Subject: [PATCH] add build_plugs.ts (#229) --- build_plugs.ts | 38 ++++++++++++++++++++++++++++++++++++++ deno.jsonc | 4 ++-- plugos/deps.ts | 1 + 3 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 build_plugs.ts diff --git a/build_plugs.ts b/build_plugs.ts new file mode 100644 index 00000000..3235cbed --- /dev/null +++ b/build_plugs.ts @@ -0,0 +1,38 @@ +import { path, expandGlobSync, flags } from "./plugos/deps.ts"; +import { bundleRun } from "./plugos/bin/plugos-bundle.ts" +import { + esbuild, +} from "./plugos/compile.ts"; + +if (import.meta.main) { + const args = flags.parse(Deno.args, { + boolean: ["debug", "watch", "reload", "info"], + string: ["dist", "importmap"], + alias: { w: "watch" }, + }); + + if (!args.dist) { + args.dist = path.resolve(path.join("dist_bundle", "_plug")); + } + + const manifests : string[] = []; + const pattern : string = path.join("plugs", "*", "*.plug.yaml"); + for (const file of expandGlobSync(pattern)) { + manifests.push(file.path); + } + + await bundleRun( + manifests, + args.dist, + args.watch, + { + debug: args.debug, + reload: args.reload, + info: args.info, + importMap: args.importmap + ? new URL(args.importmap, `file://${Deno.cwd()}/`) + : undefined, + }, + ); + esbuild.stop(); +} diff --git a/deno.jsonc b/deno.jsonc index 63ff6183..e9e943ab 100644 --- a/deno.jsonc +++ b/deno.jsonc @@ -3,11 +3,11 @@ "clean": "rm -rf dist dist_bundle", "install": "deno install -f -A --unstable silverbullet.ts", "test": "deno test -A --unstable", - "build": "./build_plugs.sh && deno run -A --unstable --check build.ts", + "build": "deno run -A --unstable --check build_plugs.ts && 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 -w", + "watch-plugs": "deno run -A --unstable --check build_plugs.ts -w", "bundle": "deno bundle silverbullet.ts dist/silverbullet.js", // Regenerates some bundle files (checked into the repo) // Install lezer-generator with "npm install -g @lezer/generator" diff --git a/plugos/deps.ts b/plugos/deps.ts index aaeae33d..697c5f11 100644 --- a/plugos/deps.ts +++ b/plugos/deps.ts @@ -1,6 +1,7 @@ export { globToRegExp } from "https://deno.land/std@0.165.0/path/glob.ts"; export { walk } from "https://deno.land/std@0.165.0/fs/mod.ts"; export * as path from "https://deno.land/std@0.165.0/path/mod.ts"; +export { expandGlobSync } from "https://deno.land/std@0.165.0/fs/mod.ts"; export { mime } from "https://deno.land/x/mimetypes@v1.0.0/mod.ts"; export { default as cacheDir } from "https://deno.land/x/cache_dir@0.2.0/mod.ts"; export * as flags from "https://deno.land/std@0.165.0/flags/mod.ts";