@stacksjs/browser-extension 0.70.148 → 0.70.149
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/dist/build.js +2 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/scaffold.d.ts +22 -0
- package/dist/scaffold.js +92 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -11,7 +11,8 @@ packaging owned by the framework.
|
|
|
11
11
|
## Quick start
|
|
12
12
|
|
|
13
13
|
```sh
|
|
14
|
-
buddy extension:init # scaffold
|
|
14
|
+
buddy extension:init # scaffold Chrome + Firefox + Safari, including the Xcode app
|
|
15
|
+
buddy extension:init --target safari --name "My Extension" --bundle-id com.example.MyExtension
|
|
15
16
|
buddy extension:build # build all targets → dist/ (+ dist-firefox/)
|
|
16
17
|
buddy extension:build --target chrome
|
|
17
18
|
buddy extension:build --target safari # → dist-safari/ (browser.* namespace, safari manifest)
|
package/dist/build.js
CHANGED
|
@@ -69,12 +69,12 @@ export async function buildExtension(config, options) {
|
|
|
69
69
|
const pages = pageEntries(config.pages);
|
|
70
70
|
await Promise.all(pages.filter((p) => p.page.script).map((p) => buildScript(p.page.script, `${p.name}.js`, outdir, cwd, minify)));
|
|
71
71
|
if (pages.length) {
|
|
72
|
-
const { default: stxPlugin } = await import("bun-plugin-stx"), result = await Bun.build({
|
|
72
|
+
const { default: stxPlugin } = await import("bun-plugin-stx"), resourcesPartials = resolve(cwd, "resources/partials"), legacyPartials = resolve(cwd, "partials"), partialsDir = existsSync(resourcesPartials) ? resourcesPartials : legacyPartials, result = await Bun.build({
|
|
73
73
|
entrypoints: pages.map((p) => resolve(cwd, p.page.template)),
|
|
74
74
|
outdir,
|
|
75
75
|
minify,
|
|
76
76
|
naming: { entry: "[name].html" },
|
|
77
|
-
plugins: [stxPlugin()]
|
|
77
|
+
plugins: [stxPlugin({ partialsDir })]
|
|
78
78
|
});
|
|
79
79
|
if (!result.success)
|
|
80
80
|
throw Error(`[browser-extension] failed to build pages: ${result.logs.join(`
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { scaffoldSafariApp } from './safari';
|
|
2
|
+
import type { ExtensionConfig, ExtensionTarget, SafariPlatform } from './types';
|
|
3
|
+
export declare function resolveExtensionScaffoldTargets(target?: ExtensionScaffoldTarget): ExtensionTarget[];
|
|
4
|
+
/** Scaffold a complete cross-browser extension, including Safari's container app. */
|
|
5
|
+
export declare function scaffoldExtensionProject(options?: ExtensionProjectScaffoldOptions): Promise<ExtensionProjectScaffoldResult>;
|
|
6
|
+
export declare interface ExtensionProjectScaffoldOptions {
|
|
7
|
+
cwd?: string
|
|
8
|
+
name?: string
|
|
9
|
+
target?: ExtensionScaffoldTarget
|
|
10
|
+
bundleId?: string
|
|
11
|
+
teamId?: string
|
|
12
|
+
platforms?: SafariPlatform[]
|
|
13
|
+
version?: string
|
|
14
|
+
force?: boolean
|
|
15
|
+
}
|
|
16
|
+
export declare interface ExtensionProjectScaffoldResult {
|
|
17
|
+
config: ExtensionConfig
|
|
18
|
+
written: string[]
|
|
19
|
+
skipped: string[]
|
|
20
|
+
safari?: Awaited<ReturnType<typeof scaffoldSafariApp>>
|
|
21
|
+
}
|
|
22
|
+
export type ExtensionScaffoldTarget = ExtensionTarget | 'all';
|
package/dist/scaffold.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { mkdir } from "node:fs/promises";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
import process from "node:process";
|
|
5
|
+
import { scaffoldSafariApp } from "./safari";
|
|
6
|
+
export function resolveExtensionScaffoldTargets(target = "all") {
|
|
7
|
+
return target === "all" ? ["chrome", "firefox", "safari"] : [target];
|
|
8
|
+
}
|
|
9
|
+
function safariAppName(name) {
|
|
10
|
+
return name.replace(/[^A-Za-z0-9]/g, "") || "MyExtension";
|
|
11
|
+
}
|
|
12
|
+
function quotedList(values) {
|
|
13
|
+
return `[${values.map((value) => `'${value}'`).join(", ")}]`;
|
|
14
|
+
}
|
|
15
|
+
function extensionConfigSource(config) {
|
|
16
|
+
const safari = config.targets?.includes("safari") ? `
|
|
17
|
+
safariBundleId: '${config.safariBundleId}',
|
|
18
|
+
safariPlatforms: ${quotedList(config.safariPlatforms ?? ["macos", "ios"])},
|
|
19
|
+
safariAppCategory: 'public.app-category.utilities',${config.safariTeamId ? `
|
|
20
|
+
safariTeamId: '${config.safariTeamId}',` : ""}` : "", firefox = config.targets?.includes("firefox") ? `
|
|
21
|
+
// Replace this before publishing to Mozilla Add-ons.
|
|
22
|
+
geckoId: 'extension@example.com',` : "";
|
|
23
|
+
return `import { defineExtension } from '@stacksjs/browser-extension'
|
|
24
|
+
|
|
25
|
+
export default defineExtension({
|
|
26
|
+
name: ${JSON.stringify(config.name)},
|
|
27
|
+
description: 'A browser extension built with Stacks.',
|
|
28
|
+
targets: ${quotedList(config.targets ?? [])},${firefox}${safari}
|
|
29
|
+
background: 'src/background/index.ts',
|
|
30
|
+
content: [
|
|
31
|
+
{ entry: 'src/content/index.ts', matches: ['<all_urls>'], runAt: 'document_start' },
|
|
32
|
+
],
|
|
33
|
+
pages: {
|
|
34
|
+
popup: { template: 'resources/views/popup.stx', script: 'resources/scripts/popup.ts' },
|
|
35
|
+
},
|
|
36
|
+
public: 'public',
|
|
37
|
+
manifest: {
|
|
38
|
+
permissions: ['storage', 'tabs'],
|
|
39
|
+
},
|
|
40
|
+
})
|
|
41
|
+
`;
|
|
42
|
+
}
|
|
43
|
+
export async function scaffoldExtensionProject(options = {}) {
|
|
44
|
+
const cwd = options.cwd ?? process.cwd(), name = options.name ?? "My Extension", targets = resolveExtensionScaffoldTargets(options.target), appName = safariAppName(name), config = {
|
|
45
|
+
name,
|
|
46
|
+
description: "A browser extension built with Stacks.",
|
|
47
|
+
targets,
|
|
48
|
+
background: "src/background/index.ts",
|
|
49
|
+
content: [{ entry: "src/content/index.ts", matches: ["<all_urls>"], runAt: "document_start" }],
|
|
50
|
+
pages: { popup: { template: "resources/views/popup.stx", script: "resources/scripts/popup.ts" } },
|
|
51
|
+
public: "public",
|
|
52
|
+
manifest: { permissions: ["storage", "tabs"] },
|
|
53
|
+
...targets.includes("firefox") && { geckoId: "extension@example.com" },
|
|
54
|
+
...targets.includes("safari") && {
|
|
55
|
+
safariBundleId: options.bundleId ?? `com.example.${appName}`,
|
|
56
|
+
safariTeamId: options.teamId,
|
|
57
|
+
safariPlatforms: options.platforms ?? ["macos", "ios"],
|
|
58
|
+
safariAppCategory: "public.app-category.utilities"
|
|
59
|
+
}
|
|
60
|
+
}, written = [], skipped = [], write = async (relative, content) => {
|
|
61
|
+
const absolute = join(cwd, relative);
|
|
62
|
+
if (existsSync(absolute) && !options.force) {
|
|
63
|
+
skipped.push(relative);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
await mkdir(dirname(absolute), { recursive: !0 });
|
|
67
|
+
await Bun.write(absolute, content);
|
|
68
|
+
written.push(relative);
|
|
69
|
+
};
|
|
70
|
+
await write("config/extension.ts", extensionConfigSource(config));
|
|
71
|
+
await write("src/background/index.ts", `console.log(${JSON.stringify(`[${name}] background ready`)})
|
|
72
|
+
`);
|
|
73
|
+
await write("src/content/index.ts", `console.log(${JSON.stringify(`[${name}] content script loaded`)})
|
|
74
|
+
`);
|
|
75
|
+
await write("resources/scripts/popup.ts", `console.log(${JSON.stringify(`[${name}] popup ready`)})
|
|
76
|
+
`);
|
|
77
|
+
await write("resources/views/popup.stx", `<main class="popup">
|
|
78
|
+
<h1>${name}</h1>
|
|
79
|
+
<p>Edit resources/views/popup.stx to build your popup.</p>
|
|
80
|
+
<script src="/popup.js"></script>
|
|
81
|
+
</main>
|
|
82
|
+
`);
|
|
83
|
+
await mkdir(join(cwd, "public"), { recursive: !0 });
|
|
84
|
+
const safari = targets.includes("safari") ? await scaffoldSafariApp(config, {
|
|
85
|
+
cwd,
|
|
86
|
+
bundleId: config.safariBundleId,
|
|
87
|
+
teamId: config.safariTeamId,
|
|
88
|
+
version: options.version,
|
|
89
|
+
force: options.force
|
|
90
|
+
}) : void 0;
|
|
91
|
+
return { config, written, skipped, safari };
|
|
92
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stacksjs/browser-extension",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.70.
|
|
4
|
+
"version": "0.70.149",
|
|
5
5
|
"description": "Build MV3 browser extensions (Chrome, Firefox, Safari) the Stacks way — manifest, content/background scripts, DNR rules, packaging, Safari container app, all config-driven.",
|
|
6
6
|
"author": "Chris Breuer",
|
|
7
7
|
"contributors": [
|