@stacksjs/buddy 0.70.67 → 0.70.69
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/dist/commands/extension.js +48 -0
- package/dist/lazy-commands.js +1 -0
- package/package.json +1 -1
|
@@ -20,6 +20,54 @@ export function extension(buddy) {
|
|
|
20
20
|
log.success(`Built ${config.name} ${v} for ${(config.targets ?? ["chrome", "firefox"]).join(", ")}`);
|
|
21
21
|
}
|
|
22
22
|
});
|
|
23
|
+
buddy.command("extension:init", "Scaffold a browser extension (config/extension.ts + starter background/content/pages)").option("--name <name>", "Extension display name").action(async (options) => {
|
|
24
|
+
const { existsSync } = await import("node:fs"), { mkdir, writeFile } = await import("node:fs/promises"), { dirname, join } = await import("node:path"), cwd = process.cwd(), name = options.name ?? "My Extension", write = async (rel, content) => {
|
|
25
|
+
const abs = join(cwd, rel);
|
|
26
|
+
if (existsSync(abs)) {
|
|
27
|
+
log.info(`skip (exists): ${rel}`);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
await mkdir(dirname(abs), { recursive: !0 });
|
|
31
|
+
await writeFile(abs, content);
|
|
32
|
+
log.success(`created ${rel}`);
|
|
33
|
+
};
|
|
34
|
+
await write("config/extension.ts", `import { defineExtension } from '@stacksjs/browser-extension'
|
|
35
|
+
|
|
36
|
+
export default defineExtension({
|
|
37
|
+
name: ${JSON.stringify(name)},
|
|
38
|
+
description: 'A browser extension built with Stacks.',
|
|
39
|
+
targets: ['chrome', 'firefox'],
|
|
40
|
+
background: 'src/background/index.ts',
|
|
41
|
+
content: [
|
|
42
|
+
{ entry: 'src/content/index.ts', matches: ['<all_urls>'], runAt: 'document_start' },
|
|
43
|
+
],
|
|
44
|
+
pages: {
|
|
45
|
+
popup: { template: 'pages/popup.stx', script: 'src/ui/popup.ts' },
|
|
46
|
+
},
|
|
47
|
+
icons: { 16: 'icons/icon-16.png', 48: 'icons/icon-48.png', 128: 'icons/icon-128.png' },
|
|
48
|
+
public: 'public',
|
|
49
|
+
manifest: {
|
|
50
|
+
permissions: ['storage', 'tabs'],
|
|
51
|
+
},
|
|
52
|
+
})
|
|
53
|
+
`);
|
|
54
|
+
await write("src/background/index.ts", `// Background service worker (MV3).
|
|
55
|
+
console.log('[${name}] background ready')
|
|
56
|
+
`);
|
|
57
|
+
await write("src/content/index.ts", `// Content script \u2014 runs on matched pages.
|
|
58
|
+
console.log('[${name}] content script loaded')
|
|
59
|
+
`);
|
|
60
|
+
await write("src/ui/popup.ts", `// Popup script.
|
|
61
|
+
console.log('[${name}] popup')
|
|
62
|
+
`);
|
|
63
|
+
await write("pages/popup.stx", `<div class="popup">
|
|
64
|
+
<h1>${name}</h1>
|
|
65
|
+
<p>Edit pages/popup.stx to build your popup.</p>
|
|
66
|
+
<script src="/popup.js"></script>
|
|
67
|
+
</div>
|
|
68
|
+
`);
|
|
69
|
+
log.info("Next: add icons under public/icons, then `buddy extension:build`.");
|
|
70
|
+
});
|
|
23
71
|
buddy.command("extension:package", "Build + zip the browser extension into store-ready archives").option("--target <target>", "Package a single target (chrome | firefox); omit to package all").option("--version <version>", "Override the extension version (defaults to package.json)").action(async (options) => {
|
|
24
72
|
const { packageExtension } = await import("@stacksjs/browser-extension"), { config, version } = await load(), v = options.version ?? version, targets = options.target ? [options.target] : config.targets ?? ["chrome", "firefox"];
|
|
25
73
|
for (const target of targets) {
|
package/dist/lazy-commands.js
CHANGED
|
@@ -19,6 +19,7 @@ const commandRegistry = {
|
|
|
19
19
|
domains: { path: "./commands/domains.js", exportName: "domains" },
|
|
20
20
|
email: { path: "./commands/email.js", exportName: "email" },
|
|
21
21
|
env: { path: "./commands/env.js", exportName: "env" },
|
|
22
|
+
"extension:init": { path: "./commands/extension.js", exportName: "extension" },
|
|
22
23
|
"extension:build": { path: "./commands/extension.js", exportName: "extension" },
|
|
23
24
|
"extension:package": { path: "./commands/extension.js", exportName: "extension" },
|
|
24
25
|
"dashboard:install": { path: "./commands/features.js", exportName: "features" },
|