Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
8 changes: 8 additions & 0 deletions examples/barebones/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# build files
dist

# misc
._*
.DS_Store
.env
.Trashes
6 changes: 6 additions & 0 deletions examples/barebones/README.md
Original file line number Diff line number Diff line change
@@ -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.
9 changes: 9 additions & 0 deletions examples/barebones/deno.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
1 change: 1 addition & 0 deletions examples/barebones/source/content_script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
globalThis.alert('Running Barebones Browser Extension')
23 changes: 23 additions & 0 deletions examples/barebones/source/manifest.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
2 changes: 2 additions & 0 deletions examples/preact/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 8 additions & 6 deletions examples/preact/deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,20 @@
},

"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",
"check": "deno task check:background && deno task check:content_script && deno task check:options && deno task check:popup",
"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"
}
}
2 changes: 1 addition & 1 deletion examples/preact/source/content_script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

/// <reference lib="dom" />

globalThis.alert('Running Sample Browser Extension')
globalThis.alert('Running Preact Browser Extension')

Array.prototype.forEach.call(
document.getElementsByTagName('*'),
Expand Down
2 changes: 1 addition & 1 deletion examples/preact/source/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"manifest_version": 3,
"name": "Browser Extension",
"name": "Preact Browser Extension",
"description": "A browser Extension",
"version": "0.0.1",
"background": {
Expand Down
Binary file modified examples/preact/static/icons/128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/preact/static/icons/256.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/preact/static/icons/32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/preact/static/icons/48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/preact/static/icons/64.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions examples/preact/static/options.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>Options</title>
<meta charset="utf-8" />
<link rel="stylesheet" href="styles/options.css" />
<title>Options</title>
<meta charset="utf-8" />
<link rel="stylesheet" href="styles/options.css" />
</head>

<body>
Expand Down
6 changes: 3 additions & 3 deletions examples/preact/static/popup.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<html lang="en">
<head>
<title>Popup</title>
<meta charset="utf-8" />
<link rel="stylesheet" href="styles/popup.css" />
<title>Popup</title>
<meta charset="utf-8" />
<link rel="stylesheet" href="styles/popup.css" />
</head>

<body>
Expand Down
2 changes: 1 addition & 1 deletion examples/preact/static/styles/options.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ input {
margin: 10px;
}

button: {
button {
margin: 10px;
display: block;
}
1 change: 1 addition & 0 deletions examples/preact/static/styles/popup.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

46 changes: 32 additions & 14 deletions source/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]

Expand Down
Loading