toolaby 1.4.1 → 1.4.2

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.
Files changed (3) hide show
  1. package/bin.mjs +11 -3
  2. package/lib/project.js +16 -27
  3. package/package.json +1 -1
package/bin.mjs CHANGED
@@ -32,9 +32,9 @@ import { homedir } from 'node:os';
32
32
  import { spawn } from 'node:child_process';
33
33
  import { createHmac, randomBytes } from 'node:crypto';
34
34
  import { wireManifest, WORKER_LINES } from './lib/manifest.js';
35
- import { detectProject, CODE_FILES, filesToWrite, BUILD_COPY_NOTE } from './lib/project.js';
35
+ import { detectProject, CODE_FILES, filesToWrite, STALE_FILES, BUILD_COPY_NOTE } from './lib/project.js';
36
36
 
37
- const VERSION = '1.4.1';
37
+ const VERSION = '1.4.2';
38
38
  const CLIENT_ID = 'toolaby-cli';
39
39
  const argv = process.argv.slice(2);
40
40
  // `--version` and `--help` are commands of their own; every other command is the first bare word.
@@ -212,7 +212,13 @@ async function wire() {
212
212
  const present = targets.filter((f) => existsSync(join(dir, f)));
213
213
  if (present.length && !flag('--force')) fail(`${present.join(', ')} already in ${dir}; add --force to replace them.`);
214
214
  const write = (rel, content) => { mkdirSync(dirname(join(dir, rel)), { recursive: true }); writeFileSync(join(dir, rel), content); };
215
+ // A command older than the Wall asks for files the Wall no longer hands out: said, with the way to the current one, rather than a crash.
216
+ const missing = targets.map((p) => p.split('/').pop()).filter((name) => typeof plan.files[name] !== 'string');
217
+ if (missing.length) fail(`This command (${VERSION}) is older than the Wall at ${wall}: it expects ${missing.join(', ')}, which the Wall no longer hands out.\n Update it: npm install -g toolaby@latest — or run the Wall's own copy: npx --yes ${wall}/toolaby.tgz ${command} ${slug}`);
215
218
  for (const path of targets) write(path, plan.files[path.split('/').pop()].replaceAll('__APP_POPUP__', appPopup ?? ''));
219
+ // What an earlier wiring wrote and this one does not, wherever it put them: taken away, so nothing stale is shipped.
220
+ const removed = [];
221
+ for (const at of new Set([project.codeDir, project.popupDir, 'public/', 'src/public/'])) for (const f of STALE_FILES) { const p = join(dir, `${at}${f}`); if (existsSync(p)) { unlinkSync(p); removed.push(`${at}${f}`); } }
216
222
  const did = [];
217
223
  let ownWorker = null;
218
224
  if (wiring) {
@@ -223,12 +229,14 @@ async function wire() {
223
229
  } else if (project.createWorker) {
224
230
  write(project.createWorker.file, project.createWorker.content);
225
231
  did.push(`a background entry, ${project.createWorker.file} (it starts the platform)`);
226
- } else if (project.worker) {
232
+ } else if (project.worker && !project.extraFiles) {
233
+ // A framework with its own extension point (WXT's module) starts the platform in the background itself.
227
234
  ownWorker = { file: project.worker, classic: false };
228
235
  }
229
236
 
230
237
  out(`\n ${plan.name} → ${dir}${project.kind === 'plain' ? '' : ` (${project.label})`} · ${side}${side === 'Test' ? ' (the tk_test_ key; `--live` for the store build)' : ''}\n`);
231
238
  out(` Written: ${targets.join(', ')}${did.length ? `,\n ${did.join(',\n ')}` : ''}.\n`);
239
+ if (removed.length) out(` Removed: ${removed.join(', ')} — earlier files, now inside toolaby.js.\n`);
232
240
  for (const sn of project.snippets) out(` Add to ${sn.file} — yours to paste, the manifest being generated:\n\n${sn.code.split('\n').map((l) => ` ${l}`).join('\n')}\n`);
233
241
  if (ownWorker) out(` Your background, ${ownWorker.file}: add${ownWorker.classic ? ' — after giving "background" a "type": "module" in manifest.json (importScripts() is not available in a module worker)' : ''}:\n\n${project.workerLines.trimEnd().split('\n').map((l) => ` ${l}`).join('\n')}\n`);
234
242
  if (project.built) out(` ${BUILD_COPY_NOTE}\n`);
package/lib/project.js CHANGED
@@ -1,18 +1,20 @@
1
1
  // Generated from wall/src/packages/wiring/project.ts by wall/scripts/pack-create.mjs — edit there.
2
2
  /** What to tell a developer whose build ships the extension — the Wire button, the command and the Set up page all say it in these words. */
3
- export const BUILD_COPY_NOTE = 'A build ships this extension: make sure it copies the platform\'s files to its output — toolaby.js, toolaby.config.js, toolaby-client.module.js, paywall.js, paywall.css and toolaby-popup.* — the way it copies your popup.html.';
4
- /** Always written, where the build imports from: the client, its config and types, and the panel a popup of the developer's own can draw. */
5
- export const CODE_FILES = ['toolaby.config.js', 'toolaby.js', 'toolaby-client.module.js', 'toolaby.d.ts', 'paywall.js', 'paywall.css'];
3
+ export const BUILD_COPY_NOTE = 'A build ships this extension: make sure it copies the platform\'s files to its output — toolaby.js, toolaby.config.js and toolaby-popup.html — the way it copies your popup.html.';
4
+ /** Always written, where the build imports from: the platform as one file (the client and the popup UI), its config, its types. */
5
+ export const CODE_FILES = ['toolaby.config.js', 'toolaby.js', 'toolaby.d.ts'];
6
6
  /** Beside the client when the build generates the manifest: the fragment it spreads in, derived from the key (boilerplate/toolaby.manifest.js). */
7
7
  export const MANIFEST_HELPER = ['toolaby.manifest.js', 'toolaby.manifest.d.ts'];
8
- /** The Wall's popup, where the build copies files as they are; it imports the panel beside it, so the panel goes there too when that is elsewhere. */
9
- export const POPUP_FILES = ['toolaby-popup.html', 'toolaby-popup.js', 'toolaby-popup.css'];
10
- export const PANEL_FILES = ['paywall.js', 'paywall.css'];
8
+ /** The Wall's popup: a shell, and the line that mounts it from toolaby.js beside it (an extension page may not run a script inline). */
9
+ export const POPUP_FILES = ['toolaby-popup.html', 'toolaby-popup.js'];
10
+ /** What earlier wirings wrote and this one does not: an upgrade takes them away, wherever a wiring put them. */
11
+ export const STALE_FILES = ['toolaby-client.module.js', 'paywall.js', 'paywall.css', 'toolaby-popup.css', 'toolaby-account.js'];
11
12
  /** Every file a wiring writes, with its path: the code files, and — with a popup to stand in front of — the Wall's popup and, beside it, the panel. */
12
13
  export const filesToWrite = (p, appPopup) => [
13
14
  ...CODE_FILES.map((f) => `${p.codeDir}${f}`),
14
15
  ...(p.manifestFile ? [] : MANIFEST_HELPER.map((f) => `${p.codeDir}${f}`)),
15
- ...(appPopup ? [...POPUP_FILES, ...(p.popupDir !== p.codeDir ? PANEL_FILES : [])].map((f) => `${p.popupDir}${f}`) : []),
16
+ ...(appPopup ? POPUP_FILES.map((f) => `${p.popupDir}${f}`) : []),
17
+ ...(p.extraFiles ?? []).map((f) => f.to),
16
18
  ];
17
19
  /** The import of toolaby.js from a file at `from`, both relative to the root. */
18
20
  export function importPath(from, codeDir = '') {
@@ -37,32 +39,19 @@ export function detectProject(o) {
37
39
  const appPopup = popup ? 'popup.html' : null;
38
40
  const workerFile = worker ?? `${src}entrypoints/background.ts`;
39
41
  const workerLines = `import { toolaby } from '${importPath(workerFile)}';\n\nexport default defineBackground(() => {\n toolaby.startBackground();\n});\n`;
40
- const code = [
41
- `// wxt.config.ts — the Wall's needs in the manifest come from toolaby.config.js${appPopup ? ', and its popup goes in front of yours' : ''}`,
42
- `import { manifest as toolaby } from './toolaby.manifest.js';`,
43
- ``,
44
- `export default defineConfig({`,
45
- ` manifest: { ...toolaby }, // the extension's id, the storage permission, the Wall's address`,
46
- ...(appPopup ? [
47
- ` hooks: {`,
48
- ` // WXT names your popup entrypoint after merging the manifest above; the hook runs after that.`,
49
- ` 'build:manifestGenerated': (_, manifest) => {`,
50
- ` manifest.action = { ...manifest.action, default_popup: 'toolaby-popup.html' };`,
51
- ` },`,
52
- ` },`,
53
- ] : []),
54
- `});`,
55
- ].join('\n');
42
+ // WXT's extension point: a module in modules/, loaded by WXT itself. It merges the manifest, puts the Wall's popup in
43
+ // front, and starts the platform in the background — yours, or its own when there is none. Nothing to paste.
56
44
  return {
57
- kind: 'wxt', label: 'WXT', codeDir: '', popupDir: `${src}public/`, manifestFile: null, wrapper: true, appPopup, worker, built: false, foundManifest: null,
58
- createWorker: worker ? null : { file: workerFile, content: workerLines },
59
- workerLines, snippets: [{ file: first(has, ['wxt.config.ts', 'wxt.config.js', 'wxt.config.mts', 'wxt.config.mjs']) ?? 'wxt.config.ts', language: 'ts', code }],
45
+ kind: 'wxt', label: 'WXT', codeDir: '', popupDir: '', manifestFile: null, wrapper: true, appPopup, worker, built: false, foundManifest: null,
46
+ createWorker: null,
47
+ workerLines, snippets: [],
48
+ extraFiles: [{ from: 'toolaby.wxt.ts', to: 'modules/toolaby.wxt.ts' }, { from: 'toolaby.background.js', to: 'toolaby.background.js' }],
60
49
  };
61
50
  }
62
51
  if (plasmo) {
63
52
  // Plasmo builds only the pages its own manifest names (popup.tsx → popup.html, from .plasmo/), and its manifest
64
53
  // override replaces `action` whole: a page of ours in front of the popup would leave the popup unbuilt. So no
65
- // wrapper here — the gate goes in the popup's code, one call, and the panel is a function away (paywall.js).
54
+ // wrapper here — the gate goes in the popup's code, one call, and the panel is a function away (toolaby.js).
66
55
  const src = has('src') && !first(has, ['popup.tsx', 'popup.html', 'background.ts', 'background.js']) ? 'src/' : '';
67
56
  const worker = first(has, [`${src}background.ts`, `${src}background.js`, `${src}background/index.ts`, `${src}background/index.js`]);
68
57
  const workerFile = worker ?? `${src}background.ts`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "toolaby",
3
- "version": "1.4.1",
3
+ "version": "1.4.2",
4
4
  "description": "The Toolaby command line: sign in once, then wire any Chrome extension to your tool on the Wall — sign-in, the Free plan, licences and subscriptions — or start a new one.",
5
5
  "type": "module",
6
6
  "bin": {