From 60ab40005a51d319171bd9ec196f637e47ad776f Mon Sep 17 00:00:00 2001 From: Zef Hemel Date: Tue, 30 Jul 2024 14:04:43 +0200 Subject: [PATCH] Added Grep plug --- .vscode/settings.json | 3 +- build_bundle.ts | 3 +- build_plugs.ts | 1 + build_web.ts | 3 +- cmd/compile.ts | 9 ++++-- cmd/plug_compile.ts | 4 ++- import_map.json => deno.json | 51 ++++++++++++++++++++++++++++++++++ deno.jsonc | 54 ------------------------------------ lib/deps_client.ts | 2 +- lib/deps_server.ts | 2 +- silverbullet.ts | 1 + website/Plugs/Grep.md | 9 ++++++ 12 files changed, 76 insertions(+), 66 deletions(-) rename import_map.json => deno.json (63%) delete mode 100644 deno.jsonc create mode 100644 website/Plugs/Grep.md diff --git a/.vscode/settings.json b/.vscode/settings.json index 621c336b..1ff58e63 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,8 +1,7 @@ { "editor.formatOnSave": true, "deno.enable": true, - "deno.importMap": "import_map.json", - "deno.config": "deno.jsonc", + "deno.config": "deno.json", "deno.unstable": true, "[json]": { "editor.defaultFormatter": "denoland.vscode-deno" diff --git a/build_bundle.ts b/build_bundle.ts index 50e5fa6e..87613efa 100644 --- a/build_bundle.ts +++ b/build_bundle.ts @@ -15,8 +15,7 @@ await esbuild.build({ logLevel: "error", minify: true, plugins: denoPlugins({ - importMapURL: new URL("./import_map.json", import.meta.url) - .toString(), + configPath: new URL("./deno.json", import.meta.url).pathname, }), }); const bundleJs = await Deno.readTextFile("dist/silverbullet.js"); diff --git a/build_plugs.ts b/build_plugs.ts index da82ec80..a3b26619 100644 --- a/build_plugs.ts +++ b/build_plugs.ts @@ -27,6 +27,7 @@ if (import.meta.main) { debug: args.debug, reload: args.reload, info: args.info, + configPath: new URL("deno.json", import.meta.url).pathname, }, ); esbuild.stop(); diff --git a/build_web.ts b/build_web.ts index 1db5189b..be12ffbe 100644 --- a/build_web.ts +++ b/build_web.ts @@ -105,8 +105,7 @@ async function buildCopyBundleAssets() { jsxFragment: "Fragment", jsxImportSource: "https://esm.sh/preact@10.23.1", plugins: denoPlugins({ - importMapURL: new URL("./import_map.json", import.meta.url) - .toString(), + configPath: new URL("./deno.json", import.meta.url).pathname, }), }); diff --git a/cmd/compile.ts b/cmd/compile.ts index a605574e..a72a63b2 100644 --- a/cmd/compile.ts +++ b/cmd/compile.ts @@ -12,6 +12,9 @@ const workerRuntimeUrl = export type CompileOptions = { debug?: boolean; runtimeUrl?: string; + // path to config file + configPath?: string; + // path to import map importMap?: string; // Reload plug import cache reload?: boolean; @@ -103,9 +106,9 @@ setupMessageListener(functionMapping, manifest); treeShaking: true, plugins: [ ...denoPlugins({ - // TODO do this differently - importMapURL: options.importMap || - new URL("../import_map.json", import.meta.url).toString(), + configPath: options.configPath && + path.resolve(Deno.cwd(), options.configPath), + importMapURL: options.importMap, loader: "native", }), ], diff --git a/cmd/plug_compile.ts b/cmd/plug_compile.ts index 9bf9e351..52bb74b4 100644 --- a/cmd/plug_compile.ts +++ b/cmd/plug_compile.ts @@ -2,12 +2,13 @@ import { compileManifests } from "./compile.ts"; import * as esbuild from "esbuild"; export async function plugCompileCommand( - { watch, dist, debug, info, importmap, runtimeUrl }: { + { watch, dist, debug, info, importmap, config, runtimeUrl }: { watch: boolean; dist: string; debug: boolean; info: boolean; importmap?: string; + config?: string; runtimeUrl?: string; }, ...manifestPaths: string[] @@ -23,6 +24,7 @@ export async function plugCompileCommand( importMap: importmap ? new URL(importmap, `file://${Deno.cwd()}/`).toString() : undefined, + configPath: config, }, ); esbuild.stop(); diff --git a/import_map.json b/deno.json similarity index 63% rename from import_map.json rename to deno.json index 016b3d18..4a0ae7a7 100644 --- a/import_map.json +++ b/deno.json @@ -1,4 +1,55 @@ { + "tasks": { + "clean": "rm -rf dist dist_client_bundle dist_plug_bundle website_build", + "deep-clean-mac": "rm -f deno.lock && rm -rf $HOME/Library/Caches/deno && deno task clean", + "install": "deno install -g -f --unstable-kv --unstable-worker-options -A --import-map deno.json silverbullet.ts", + "check": "find . -name '*.ts*' | xargs deno check", + "test": "deno test -A --unstable-kv --unstable-worker-options", + "bench": "deno bench", + "build": "deno run -A build_plugs.ts && deno run -A build_web.ts", + "plugs": "deno run -A build_plugs.ts", + "server": "deno run -A --unstable-kv --unstable-worker-options --check silverbullet.ts", + "generate": "./scripts/generate.sh", + + "watch-web": "deno run -A --check build_web.ts --watch", + "watch-server": "deno run -A --unstable-kv --unstable-worker-options --check --watch silverbullet.ts", + "watch-plugs": "deno run -A --check build_plugs.ts -w", + + "bundle": "deno run -A build_bundle.ts", + + "compile": "deno task bundle && deno compile -A --unstable-kv --unstable-worker-options -o silverbullet dist/silverbullet.js", + "server:dist:linux-x86_64": "deno task bundle && deno compile -A --unstable-kv --unstable-worker-options --target x86_64-unknown-linux-gnu -o silverbullet dist/silverbullet.js && zip silverbullet-server-linux-x86_64.zip silverbullet", + "server:dist:linux-aarch64": "deno task bundle && deno compile -A --unstable-kv --unstable-worker-options --target aarch64-unknown-linux-gnu -o silverbullet dist/silverbullet.js && zip silverbullet-server-linux-aarch64 silverbullet", + "server:dist:darwin-x86_64": "deno task bundle && deno compile -A --unstable-kv --unstable-worker-options --target x86_64-apple-darwin -o silverbullet dist/silverbullet.js && zip silverbullet-server-darwin-x86_64.zip silverbullet", + "server:dist:darwin-aarch64": "deno task bundle && deno compile -A --unstable-kv --unstable-worker-options --target aarch64-apple-darwin -o silverbullet dist/silverbullet.js && zip silverbullet-server-darwin-aarch64.zip silverbullet", + "server:dist:windows-x86_64": "deno task bundle && deno compile -A --unstable-kv --unstable-worker-options --target x86_64-pc-windows-msvc -o silverbullet.exe dist/silverbullet.js && zip silverbullet-server-windows-x86_64.zip silverbullet.exe" + }, + + "compilerOptions": { + "lib": ["dom", "dom.iterable", "dom.asynciterable", "deno.ns"], + "jsx": "react-jsx", + "jsxImportSource": "https://esm.sh/preact@10.23.1" + }, + "lint": { + "exclude": [ + "dist", + "dist_bundle" + ], + "rules": { + "exclude": ["no-explicit-any"] + } + }, + "fmt": { + "exclude": [ + "dist", + "dist_bundle", + "website", + "website_build", + "test_space", + "README.md" + ] + }, + "imports": { "@lezer/common": "https://esm.sh/@lezer/common@1.2.1&target=es2022", "@lezer/lr": "https://esm.sh/@lezer/lr@1.4.1?external=@lezer/common&target=es2022", diff --git a/deno.jsonc b/deno.jsonc deleted file mode 100644 index af3c080c..00000000 --- a/deno.jsonc +++ /dev/null @@ -1,54 +0,0 @@ -{ - "tasks": { - "clean": "rm -rf dist dist_client_bundle dist_plug_bundle website_build", - "deep-clean-mac": "rm -f deno.lock && rm -rf $HOME/Library/Caches/deno && deno task clean", - "install": "deno install -g -f --unstable-kv --unstable-worker-options -A --importmap import_map.json silverbullet.ts", - "check": "find . -name '*.ts*' | xargs deno check", - "test": "deno test -A --unstable-kv --unstable-worker-options", - "build": "deno run -A build_plugs.ts && deno run -A build_web.ts", - "plugs": "deno run -A build_plugs.ts", - "server": "deno run -A --unstable-kv --unstable-worker-options --check silverbullet.ts", - - "watch-web": "deno run -A --check build_web.ts --watch", - "watch-server": "deno run -A --unstable-kv --unstable-worker-options --check --watch silverbullet.ts", - "watch-plugs": "deno run -A --check build_plugs.ts -w", - - "bundle": "deno run -A build_bundle.ts", - // Regenerates some bundle files (checked into the repo) - "generate": "./scripts/generate.sh", - - // Compile - "compile": "deno task bundle && deno compile -A --unstable-kv --unstable-worker-options -o silverbullet dist/silverbullet.js", - "server:dist:linux-x86_64": "deno task bundle && deno compile -A --unstable-kv --unstable-worker-options --target x86_64-unknown-linux-gnu -o silverbullet dist/silverbullet.js && zip silverbullet-server-linux-x86_64.zip silverbullet", - "server:dist:linux-aarch64": "deno task bundle && deno compile -A --unstable-kv --unstable-worker-options --target aarch64-unknown-linux-gnu -o silverbullet dist/silverbullet.js && zip silverbullet-server-linux-aarch64 silverbullet", - "server:dist:darwin-x86_64": "deno task bundle && deno compile -A --unstable-kv --unstable-worker-options --target x86_64-apple-darwin -o silverbullet dist/silverbullet.js && zip silverbullet-server-darwin-x86_64.zip silverbullet", - "server:dist:darwin-aarch64": "deno task bundle && deno compile -A --unstable-kv --unstable-worker-options --target aarch64-apple-darwin -o silverbullet dist/silverbullet.js && zip silverbullet-server-darwin-aarch64.zip silverbullet", - "server:dist:windows-x86_64": "deno task bundle && deno compile -A --unstable-kv --unstable-worker-options --target x86_64-pc-windows-msvc -o silverbullet.exe dist/silverbullet.js && zip silverbullet-server-windows-x86_64.zip silverbullet.exe" - }, - - "compilerOptions": { - "lib": ["dom", "dom.iterable", "dom.asynciterable", "deno.ns"], - "jsx": "react-jsx", - "jsxImportSource": "https://esm.sh/preact@10.23.1" - }, - "importMap": "import_map.json", - "lint": { - "exclude": [ - "dist", - "dist_bundle" - ], - "rules": { - "exclude": ["no-explicit-any"] - } - }, - "fmt": { - "exclude": [ - "dist", - "dist_bundle", - "website", - "website_build", - "test_space", - "README.md" - ] - } -} diff --git a/lib/deps_client.ts b/lib/deps_client.ts index 7a74320f..27054bc3 100644 --- a/lib/deps_client.ts +++ b/lib/deps_client.ts @@ -1,4 +1,4 @@ -// Remember to keep in sync with import_map.json ! +// Remember to keep in sync with deno.json ! // We have to use different deps for client and server as esbuild doesn't // support wildcard exporting. See https://github.com/evanw/esbuild/issues/1420 export { diff --git a/lib/deps_server.ts b/lib/deps_server.ts index d87c42f3..33007965 100644 --- a/lib/deps_server.ts +++ b/lib/deps_server.ts @@ -1,4 +1,4 @@ -// Remember to keep in sync with import_map.json ! +// Remember to keep in sync with deno.json ! // We have to use different deps for client and server as esbuild doesn't // support wildcard exporting. See https://github.com/evanw/esbuild/issues/1420 export { globToRegExp } from "https://deno.land/std@0.165.0/path/glob.ts"; diff --git a/silverbullet.ts b/silverbullet.ts index c43ca7e3..4e4d68ed 100755 --- a/silverbullet.ts +++ b/silverbullet.ts @@ -72,6 +72,7 @@ await new Command() { default: "." }, ) .option("--importmap ", "Path to import map file to use") + .option("-c, --config ", "Path to deno.json file to use") .option("--runtimeUrl ", "URL to worker_runtime.ts to use") .action(plugCompileCommand) // plug:run diff --git a/website/Plugs/Grep.md b/website/Plugs/Grep.md new file mode 100644 index 00000000..fa35d745 --- /dev/null +++ b/website/Plugs/Grep.md @@ -0,0 +1,9 @@ +--- +uri: https://github.com/Maarrk/silverbullet-grep/releases/latest/download/grep.plug.js +repo: https://github.com/Maarrk/silverbullet-grep +author: Marek S. Ɓukasiewicz +tags: plug +--- + +![[!raw.githubusercontent.com/Maarrk/silverbullet-grep/main/README]] +```