diff --git a/deno.json b/deno.json index 07271cf..7e4f591 100644 --- a/deno.json +++ b/deno.json @@ -26,11 +26,14 @@ "exclude": ["dist", "examples"] }, "tasks": { - "build": "(cd examples/preact && deno run -A ../../source/main.ts build)", + "build": "deno task build:preact && deno task build:barebones", + "build:barebones": "(cd examples/barebones && deno run -A ../../source/main.ts internal-dev-only-build)", + "build:preact": "(cd examples/preact && deno run -A ../../source/main.ts internal-dev-only-build)", "check": "deno check source/main.ts && deno check source/mod.ts", - "dev": "(cd examples/preact && deno run -A ../../source/main.ts build -w)", - "test": "deno task test:source && deno task build && deno task test:examples && deno publish --dry-run --allow-dirty", - "test:examples": "(cd examples/preact && deno task test)", + "dev:barebones": "(cd examples/barebones && deno run -A ../../source/main.ts internal-dev-only-build -w)", + "dev:preact": "(cd examples/preact && deno run -A ../../source/main.ts internal-dev-only-build -w)", + "test": "deno task test:source && deno task build && deno task test:preact && deno publish --dry-run --allow-dirty", + "test:preact": "(cd examples/preact && deno task test)", "test:source": "deno fmt && deno lint && deno task check && deno test source" }, "test": { diff --git a/examples/barebones/.gitignore b/examples/barebones/.gitignore new file mode 100644 index 0000000..f016002 --- /dev/null +++ b/examples/barebones/.gitignore @@ -0,0 +1,8 @@ +# build files +dist + +# misc +._* +.DS_Store +.env +.Trashes diff --git a/examples/barebones/README.md b/examples/barebones/README.md new file mode 100644 index 0000000..67704e6 --- /dev/null +++ b/examples/barebones/README.md @@ -0,0 +1,6 @@ +# Barebones + +The bare minimum needed for a chrome extension + +Note: Since is also used for internal dev. In your own app, the +`internal-dev-only` tasks can be removed. diff --git a/examples/barebones/deno.json b/examples/barebones/deno.json new file mode 100644 index 0000000..570662d --- /dev/null +++ b/examples/barebones/deno.json @@ -0,0 +1,9 @@ +{ + "tasks": { + "dev": "bext --watch", + "build": "bext", + "internal-dev-only-install": "deno install --name=bext-internal -Agf ../../source/main.ts", + "internal-dev-only-dev": "bext-internal --watch", + "internal-dev-only-build": "bext-internal" + } +} diff --git a/examples/barebones/source/content_script.js b/examples/barebones/source/content_script.js new file mode 100644 index 0000000..7879ec9 --- /dev/null +++ b/examples/barebones/source/content_script.js @@ -0,0 +1 @@ +globalThis.alert('Running Barebones Browser Extension') diff --git a/examples/barebones/source/manifest.json b/examples/barebones/source/manifest.json new file mode 100644 index 0000000..9de4a6b --- /dev/null +++ b/examples/barebones/source/manifest.json @@ -0,0 +1,23 @@ +{ + "manifest_version": 3, + "name": "Barebones Browser Extension", + "description": "A browser Extension", + "version": "0.0.1", + "content_scripts": [ + { + "matches": [ + "*://*/*" + ], + "js": [ + "content_script.js" + ], + "run_at": "document_end" + } + ], + "permissions": [], + "applications": { + "gecko": { + "id": "browser-extension@my-extension-id-email.com" + } + } +} diff --git a/examples/preact/README.md b/examples/preact/README.md index b77ff71..5434eab 100644 --- a/examples/preact/README.md +++ b/examples/preact/README.md @@ -2,6 +2,8 @@ A Preact-Rendered Chrome/Firefox extension built with Bext. +Note: Since is also used for internal dev. In your own app, the `browser` dependency should point to `jsr:@bpev/bext`. Also, the `internal-dev-only` tasks can be removed. + Uses: - `background.ts` logs url to extension console for each new tab update diff --git a/examples/preact/deno.json b/examples/preact/deno.json index 52e6002..c21b94e 100644 --- a/examples/preact/deno.json +++ b/examples/preact/deno.json @@ -29,11 +29,10 @@ }, "tasks": { - "install": "deno install --name=bext-internal -Agf ../../source/main.ts", - "dev": "bext-internal --watch", - "build": "bext-internal", - "build:chrome": "bext-internal chrome", - "build:firefox": "bext-internal firefox", + "dev": "bext --watch", + "build": "bext", + "build:chrome": "bext chrome", + "build:firefox": "bext firefox", "test": "deno task check && deno task test:unit && deno lint", "test:unit": "deno test -A source", "test:unit:update": "deno test -A -- --update source", @@ -41,6 +40,9 @@ "check:background": "deno check source/background.ts", "check:content_script": "deno check source/content_script.ts", "check:options": "deno check source/options.tsx", - "check:popup": "deno check source/popup.tsx" + "check:popup": "deno check source/popup.tsx", + "bext-internal-dev-only-install": "deno install --name=bext-internal -Agf ../../source/main.ts", + "bext-internal-dev-only-dev": "bext-internal --watch", + "bext-internal-dev-only-build": "bext-internal" } } diff --git a/examples/preact/source/content_script.ts b/examples/preact/source/content_script.ts index 9a547e0..54f8e9c 100644 --- a/examples/preact/source/content_script.ts +++ b/examples/preact/source/content_script.ts @@ -5,7 +5,7 @@ /// -globalThis.alert('Running Sample Browser Extension') +globalThis.alert('Running Preact Browser Extension') Array.prototype.forEach.call( document.getElementsByTagName('*'), diff --git a/examples/preact/source/manifest.json b/examples/preact/source/manifest.json index 1485688..008dcc5 100644 --- a/examples/preact/source/manifest.json +++ b/examples/preact/source/manifest.json @@ -1,6 +1,6 @@ { "manifest_version": 3, - "name": "Browser Extension", + "name": "Preact Browser Extension", "description": "A browser Extension", "version": "0.0.1", "background": { diff --git a/examples/preact/static/icons/128.png b/examples/preact/static/icons/128.png index fff0aaa..82b1093 100644 Binary files a/examples/preact/static/icons/128.png and b/examples/preact/static/icons/128.png differ diff --git a/examples/preact/static/icons/256.png b/examples/preact/static/icons/256.png index 083c5b0..d1b928a 100644 Binary files a/examples/preact/static/icons/256.png and b/examples/preact/static/icons/256.png differ diff --git a/examples/preact/static/icons/32.png b/examples/preact/static/icons/32.png index ab3b741..eff2e88 100644 Binary files a/examples/preact/static/icons/32.png and b/examples/preact/static/icons/32.png differ diff --git a/examples/preact/static/icons/48.png b/examples/preact/static/icons/48.png index 487c024..0aa9f4d 100644 Binary files a/examples/preact/static/icons/48.png and b/examples/preact/static/icons/48.png differ diff --git a/examples/preact/static/icons/64.png b/examples/preact/static/icons/64.png index 64d51f0..0fd588b 100644 Binary files a/examples/preact/static/icons/64.png and b/examples/preact/static/icons/64.png differ diff --git a/examples/preact/static/options.html b/examples/preact/static/options.html index 1a58bc3..eaac108 100644 --- a/examples/preact/static/options.html +++ b/examples/preact/static/options.html @@ -1,9 +1,9 @@ - Options - - + Options + + diff --git a/examples/preact/static/popup.html b/examples/preact/static/popup.html index 94a1d10..58ecbbe 100644 --- a/examples/preact/static/popup.html +++ b/examples/preact/static/popup.html @@ -1,8 +1,8 @@ - Popup - - + Popup + + diff --git a/examples/preact/static/styles/options.css b/examples/preact/static/styles/options.css index 20d0a05..6773a2b 100644 --- a/examples/preact/static/styles/options.css +++ b/examples/preact/static/styles/options.css @@ -2,7 +2,7 @@ input { margin: 10px; } -button: { +button { margin: 10px; display: block; } diff --git a/examples/preact/static/styles/popup.css b/examples/preact/static/styles/popup.css index e69de29..8b13789 100644 --- a/examples/preact/static/styles/popup.css +++ b/examples/preact/static/styles/popup.css @@ -0,0 +1 @@ + diff --git a/source/main.ts b/source/main.ts index f03de9a..d1aabd0 100644 --- a/source/main.ts +++ b/source/main.ts @@ -22,8 +22,8 @@ import * as esbuild from 'npm:esbuild@^0.23.0' import { denoPlugins } from 'jsr:@luca/esbuild-deno-loader@^0.10.3' import { parseArgs } from 'jsr:@std/cli@^1.0.0' -import { copySync, ensureDir } from 'jsr:@std/fs@^0.229.3' -import { resolve } from 'jsr:@std/path@^1.0.1' +import { copy, ensureDir, exists } from 'jsr:@std/fs@^0.229.3' +import { join, resolve } from 'jsr:@std/path@^1.0.1' interface BrowserManifestSettings { color: string @@ -74,29 +74,47 @@ const browsers: BrowserManifests = { if (args._[0] === 'chrome') delete browsers.firefox if (args._[0] === 'firefox') delete browsers.chrome -const entryPoints = [ - 'options.tsx', - 'content_script.ts', - 'background.ts', - 'popup.tsx', -].map((file) => `${args.source}/${file}`) +const entryNames = [ + 'options', + 'content_script', + 'contentScript', + 'background', + 'popup', +] +const entryPoints: string[] = [] + +await Promise.all(entryNames.map(async (name) => { + const jsPath = `${args.source}/${name}.js` + const jsxPath = `${args.source}/${name}.jsx` + const tsPath = `${args.source}/${name}.ts` + const tsxPath = `${args.source}/${name}.tsx` + if (await exists(jsPath)) entryPoints.push(jsPath) + else if (await exists(jsxPath)) entryPoints.push(jsxPath) + else if (await exists(tsPath)) entryPoints.push(tsPath) + else if (await exists(tsxPath)) entryPoints.push(tsxPath) +})) console.log('\x1b[37mPackager\n========\x1b[0m') console.log(`Using paths: -Source: "${resolve(args.source)}" -Static: "${resolve(args.static)}" +source: "${resolve(args.source)}" +static: "${resolve(args.static)}" output: "${resolve(args.output)}" `) +await ensureDir(resolve(args.output)) + const builds = Object.keys(browsers).map(async (browserId) => { /** Browser-Specific Build Path */ - const outdir = `${args.output}/${browserId}` + const outdir = join(args.output, browserId) + await ensureDir(resolve(outdir)) // Copy JS/HTML/CSS/ICONS - ensureDir(`${outdir}/static`) + if (await exists(args.static)) { + await ensureDir(join(outdir, 'static')) - const options = { overwrite: true } - copySync(args.static, outdir, options) + const options = { overwrite: true } + await copy(args.static, outdir, options) + } const browserManifestSettings = browsers[browserId]