@stagepass/cli 2.1.0 → 2.2.1

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 CHANGED
@@ -54,7 +54,7 @@ Linked: https://my-project.sp -> /absolute/path/to/project
54
54
  | `stagepass unlink [domain]` | Remove the site block and `projects.json` entry, reload Caddy. |
55
55
  | `stagepass reload` | Reload Caddy configuration. Migrates legacy Caddyfile blocks if needed. |
56
56
  | `stagepass stop` | Stop background services. Prints a hint when login autostart is enabled. |
57
- | `stagepass doctor` | Read-only diagnostics (Homebrew, Caddy, PHP/php-fpm, dnsmasq, resolver, port 443, Caddyfile, projects, certs, LaunchAgent). Never uses sudo. `--json` available. Exit `1` if any fail. |
57
+ | `stagepass doctor` | Read-only diagnostics (Homebrew, Caddy, PHP/php-fpm, dnsmasq, resolver, port 443, Caddyfile, projects, certs, LaunchAgent, plus the current project's declared modules vs. its live site). Never uses sudo. `--json`, `--skip-site`. Exit `1` if any fail. |
58
58
  | `stagepass certs check` | Read-only Caddy local CA check (validity, System keychain trust, orphans, optional TLS handshake per linked domain). `--json`, `--skip-handshake`. |
59
59
  | `stagepass certs trust` | Run `caddy trust` after interactive confirmation (or `--yes`). |
60
60
  | `stagepass autostart on\|off\|status` | Manage a user LaunchAgent (`io.github.arobertherz.stagepass`) that runs `stagepass daemon` at login. |
@@ -62,7 +62,7 @@ Linked: https://my-project.sp -> /absolute/path/to/project
62
62
  | `stagepass new [name]` | Scaffold a lean Webflow project (TypeScript + SCSS by default). |
63
63
  | `stagepass build` | Run `npm run build` in the current project (forwards exit code). |
64
64
  | `stagepass watch` | Run `npm run watch` in the current project (forwards exit code). |
65
- | `stagepass upgrade` | Bump `@stagepass/*` in the current `package.json` and print Webflow snippets. |
65
+ | `stagepass upgrade` | Bump `@stagepass/*`, sync declared modules, `AGENTS.md`, the Cursor rule and `types`, print Webflow snippets. |
66
66
 
67
67
  All commands support `-v, --verbose` where applicable.
68
68
 
@@ -84,23 +84,56 @@ Scaffold a project with flags for every choice (interactive prompts only on a TT
84
84
  | `--author <name>` | `package.json` author (default: `git config user.name`). |
85
85
  | `--lang ts\|js` | Language (default: `ts`). |
86
86
  | `--styles scss\|css` | Styles (default: `scss`). |
87
- | `--modules` / `--no-modules` | Include `@stagepass/modules` (default: yes). |
87
+ | `--modules` / `--no-modules` | Include `@stagepass/modules` as npm dependency (default: yes; forced on when `--site-modules` lists a module). |
88
+ | `--site <host>` | Live Webflow site (https) to detect the loaded modules from. Stored as the project origin. |
89
+ | `--site-modules <list>` | Modules the site loads: `none`, `all`, or a comma list of `inject`, `cookies`, `maintenance`. Takes precedence over `--site`. |
88
90
  | `--git` / `--no-git` | `git init` (default: yes). |
89
91
  | `--remote <url>` | Set `origin` after git init (rejects URLs with embedded credentials). |
90
92
  | `--install` / `--no-install` | Run `npm install` (default: no). |
91
93
  | `-y, --yes` | Non-interactive; use defaults for omitted flags. |
92
94
  | `--dry-run` | Print the file plan without writing. |
93
95
 
94
- The name must be DNS-safe (lowercase `a-z`, `0-9`, hyphens; 1 to 63 chars; no leading/trailing hyphen). Existing files are never overwritten. Generated projects include `scripts/build.mjs` (content-hashed `dist/` + `manifest.json`), Webflow head/footer snippets (jsDelivr `@2` with `loader/dist/loader.min.js` and optional `modules/dist/{inject,cookies}.min.js`; also document `all` / `maintenance`), and an `AGENTS.md` with safe development rules.
96
+ The name must be DNS-safe (lowercase `a-z`, `0-9`, hyphens; 1 to 63 chars; no leading/trailing hyphen). Existing files are never overwritten. Generated projects include `scripts/build.mjs` (content-hashed `dist/` + `manifest.json`), Webflow head/footer snippets (jsDelivr `@2`, loader plus the declared modules), `stagepass.json`, an `AGENTS.md` with the full `sp` API reference, `.cursor/rules/stagepass.mdc`, and a `.gitignore`. `@stagepass/loader` / `@stagepass/modules` are added as `^2` (same major as the CDN pin `@2`; npm installs the newest published 2.x). Per-module types are written only when the published or installed `@stagepass/modules` ships them (2.2.0 and later); otherwise `types` lists the umbrella `@stagepass/modules`.
97
+
98
+ Interactively, `new` asks for the live site after the styles question, shows the detected modules and asks for confirmation; otherwise it asks for the list directly. Without a TTY (or with `--yes`) it uses `--site-modules`, then `--site` detection, else `[]` with a hint.
99
+
100
+ ### Declared modules (`stagepass.json`)
101
+
102
+ ```json
103
+ { "name": "my-project", "modules": ["cookies"] }
104
+ ```
105
+
106
+ `modules` is `[]` (loader only), a list of `inject`, `cookies`, `maintenance`, or `["all"]`. It must match what your Webflow site loads. From it the CLI generates:
107
+
108
+ - the managed block in `AGENTS.md` (between `<!-- stagepass:begin -->` and `<!-- stagepass:end -->`): loader API always, full sections for declared modules, a "not available; enable by …" line for the others, and the rule never to use undeclared `sp.<module>`;
109
+ - `.cursor/rules/stagepass.mdc` (globs `src/**`) with the same content;
110
+ - `compilerOptions.types` in `tsconfig.json` / `jsconfig.json`: `@stagepass/loader` plus `@stagepass/modules/<module>` for each declared module (`@stagepass/modules` for `all`), so undeclared modules are type errors.
111
+
112
+ The legacy boolean `"modules": true|false` is still read; `upgrade` replaces it with a list (`true` becomes `["all"]` without a TTY).
113
+
114
+ ### Live site detection
115
+
116
+ `new --site`, `upgrade` and `doctor` read the modules from the live site: one public `GET` of the origin, https only, no cookies or auth headers, about 5 s timeout, a size cap, at most 3 redirects (all https). Only `<script src>` attributes are parsed with a regex (HTML comments ignored); nothing is executed. Recognised: `@stagepass/loader` and `@stagepass/modules` `dist/{inject,cookies,maintenance,all}` files on `cdn.jsdelivr.net/npm/` or `unpkg.com/`, any version (`@2`, `@2.0.0`, none). The npm dependency in `package.json` is only a hint.
95
117
 
96
118
  ### `upgrade` options
97
119
 
98
120
  | Option | Behaviour |
99
121
  | :--- | :--- |
100
- | `--version <x>` | Target version (default: this CLI version from its `package.json`). Dist-tags such as `latest` resolve via `npm view`. (Implemented as `--target` internally so it does not collide with `stagepass --version`.) |
101
- | `--dry-run` | Show changes without writing `package.json`. |
122
+ | `--version <x>` | Target loader/modules version, range or dist-tag. It must be published on npm (staged releases are refused until approved). Default: `^<latest published 2.x>` from `npm view`, or `^2` when the registry is not reachable. (Implemented as `--target` internally so it does not collide with `stagepass --version`.) |
123
+ | `--site <host>` | Live site to detect modules from (default: the origin linked in `~/.stagepass/projects.json` for this folder). Stored in `stagepass.json` when given. |
124
+ | `--site-modules <list>` | Set the modules list directly (`none`, `all`, or a comma list). |
125
+ | `--skip-site` | Do not fetch the live site. |
126
+ | `-y, --yes` | Accept the detected or existing list without asking. |
127
+ | `--dry-run` | Print every planned change; write no file. |
128
+
129
+ `upgrade` bumps `@stagepass/*` in `package.json`, then resolves the modules list (`--site-modules`, else live detection, confirmed interactively; if the site is unreachable or no origin is known it asks; without a TTY it keeps the existing list or `[]` and prints a hint). It then syncs the project:
130
+
131
+ - `stagepass.json`: writes the `modules` list.
132
+ - `AGENTS.md`: created if missing, otherwise only the managed block is replaced (or appended when there is none). Your own text stays. Broken markers are left alone with a hint.
133
+ - `.cursor/rules/stagepass.mdc`: created if missing, otherwise only its managed block is refreshed.
134
+ - `tsconfig.json` / `jsconfig.json`: only `compilerOptions.types` changes, the rest of the JSON is preserved. Files with comments, or without a `types` array, are skipped with a hint.
102
135
 
103
- Only `package.json` is modified. `npm install` is printed, not run. Snippets use the major pin `@2` plus an optional exact pin note.
136
+ Every change is printed as `file: action` (unchanged files are not listed; skipped files appear as hints). `npm install` is printed, not run. Snippets use the major pin `@2` plus an optional exact pin note.
104
137
 
105
138
  ### Domain argument (`link` / `unlink`)
106
139
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stagepass/cli",
3
- "version": "2.1.0",
3
+ "version": "2.2.1",
4
4
  "description": "Local Development Orchestrator for Webflow",
5
5
  "type": "module",
6
6
  "main": "bin/index.js",
package/src/cli.js CHANGED
@@ -197,6 +197,7 @@ export function createProgram(deps = {}) {
197
197
  .description('Diagnose the local Stagepass stack (read-only; never uses sudo)')
198
198
  .option('-v, --verbose', 'Show extra detail for ok checks')
199
199
  .option('--json', 'Machine-readable JSON output')
200
+ .option('--skip-site', 'Do not fetch the live site of the current project')
200
201
  .action(async (options) => {
201
202
  const code = await doctor(options);
202
203
  process.exitCode = code;
@@ -257,12 +258,16 @@ export function createProgram(deps = {}) {
257
258
  program
258
259
  .command('upgrade')
259
260
  .description(
260
- 'Bump @stagepass/* in the current package.json and print Webflow snippets'
261
+ 'Bump @stagepass/*, sync modules, AGENTS.md, Cursor rule and types, print Webflow snippets'
261
262
  )
262
- .option('--dry-run', 'Show changes without writing package.json')
263
+ .option('--dry-run', 'Show changes without writing any file')
264
+ .option('--site <host>', 'Live Webflow site to detect loaded modules from (https)')
265
+ .option('--site-modules <list>', 'Modules the site loads: none, all, or inject,cookies,maintenance')
266
+ .option('--skip-site', 'Do not fetch the live site')
267
+ .option('-y, --yes', 'Non-interactive; accept detected or existing modules')
263
268
  .option(
264
269
  '--target <version>',
265
- 'Target version (default: this CLI version; dist-tags use npm view)'
270
+ 'Target version, range or dist-tag; must be published on npm (default: ^<latest published 2.x>, ^2 offline)'
266
271
  )
267
272
  // Public docs use `--version`; rewriteArgvForUpgrade maps it to `--target`
268
273
  // so it does not collide with the root `stagepass --version` handler.
@@ -301,8 +306,10 @@ export function createProgram(deps = {}) {
301
306
  .option('--author <author>', 'Author for package.json (default: git user.name)')
302
307
  .option('--lang <lang>', 'ts or js (default: ts)')
303
308
  .option('--styles <styles>', 'scss or css (default: scss)')
304
- .option('--modules', 'Include @stagepass/modules')
309
+ .option('--modules', 'Include @stagepass/modules (npm, types)')
305
310
  .option('--no-modules', 'Skip @stagepass/modules')
311
+ .option('--site <host>', 'Live Webflow site to detect loaded modules from (https)')
312
+ .option('--site-modules <list>', 'Modules the site loads: none, all, or inject,cookies,maintenance')
306
313
  .option('--git', 'Initialize a git repository')
307
314
  .option('--no-git', 'Do not initialize git')
308
315
  .option('--remote <url>', 'Git remote URL (requires git)')
@@ -10,6 +10,7 @@ import { runDoctor } from '../lib/doctor.js';
10
10
  export async function doctor(options = {}) {
11
11
  const result = await runDoctor({
12
12
  skipHandshake: options.skipHandshake === true,
13
+ skipSite: options.skipSite === true,
13
14
  });
14
15
 
15
16
  if (options.json) {
@@ -3,7 +3,6 @@ import path from 'node:path';
3
3
  import readline from 'node:readline/promises';
4
4
  import { stdin as input, stdout as output } from 'node:process';
5
5
  import chalk from 'chalk';
6
- import { createRequire } from 'module';
7
6
  import { defaultExec } from '../lib/exec.js';
8
7
  import { defaultSpawn } from '../lib/spawn.js';
9
8
  import { validateProjectName } from '../lib/project-name.js';
@@ -18,8 +17,20 @@ import {
18
17
  printWebflowSnippets,
19
18
  } from '../lib/snippets.js';
20
19
 
21
- const require = createRequire(import.meta.url);
22
- const { version: cliVersion } = require('../../package.json');
20
+ import { STAGEPASS_PACKAGES_VERSION } from '../lib/versions.js';
21
+ import { formatModules, normalizeModulesList } from '../lib/project-modules.js';
22
+ import { describeDetection, detectSite, normalizeSiteUrl } from '../lib/site-detect.js';
23
+ import {
24
+ PACKAGES_MAJOR_RANGE,
25
+ fetchPublished,
26
+ installedHasPerModuleTypes,
27
+ rangeHasPerModuleTypes,
28
+ } from '../lib/registry.js';
29
+ import { updateConfigTypes } from '../lib/project-sync.js';
30
+
31
+ const PER_MODULE_TYPES_HINT =
32
+ '@stagepass/modules on npm has no per-module types yet (needs 2.2.0); ' +
33
+ 'types use "@stagepass/modules" for now. Run `stagepass upgrade` once it is published to narrow them.';
23
34
 
24
35
  /**
25
36
  * Resolve a boolean flag that may appear as --foo / --no-foo.
@@ -109,6 +120,37 @@ export async function resolveNewOptions(nameArg, options = {}, deps = {}) {
109
120
  let git = resolveBoolFlag(options, 'git', argv, undefined);
110
121
  let install = resolveBoolFlag(options, 'install', argv, undefined);
111
122
  let remote = options.remote != null ? String(options.remote).trim() : '';
123
+ const log = deps.log || console.log;
124
+ const detect = deps.detectSite || detectSite;
125
+
126
+ /** @type {string[] | undefined} */
127
+ let siteModules;
128
+ if (options.siteModules != null) {
129
+ const parsed = normalizeModulesList(String(options.siteModules));
130
+ if (!parsed.ok) return { ok: false, error: parsed.error };
131
+ siteModules = parsed.modules;
132
+ }
133
+ /** @type {string} */
134
+ let origin = '';
135
+ if (options.site != null && String(options.site).trim() !== '') {
136
+ const check = normalizeSiteUrl(String(options.site));
137
+ if (!check.ok) return { ok: false, error: check.error };
138
+ origin = check.host;
139
+ }
140
+
141
+ /**
142
+ * Detect modules on the live site (public GET, never executed).
143
+ * @returns {Promise<string[] | null>} detected list, or null when unknown
144
+ */
145
+ const detectFromSite = async () => {
146
+ if (!origin) return null;
147
+ log(`Checking live site https://${origin}/ for Stagepass script tags...`);
148
+ const det = await detect(origin);
149
+ log(` ${describeDetection(det)}`);
150
+ if (det.ok && det.loader) return det.list;
151
+ if (det.ok) log(' The page does not load @stagepass/loader yet.');
152
+ return null;
153
+ };
112
154
 
113
155
  if (interactive) {
114
156
  const rl =
@@ -133,8 +175,29 @@ export async function resolveNewOptions(nameArg, options = {}, deps = {}) {
133
175
  const raw = await ask(rl, 'Styles (scss|css)', 'scss');
134
176
  styles = raw === 'css' ? 'css' : 'scss';
135
177
  }
136
- if (modules === undefined) {
137
- modules = await askYesNo(rl, 'Include @stagepass/modules?', true);
178
+ if (siteModules === undefined && modules !== false) {
179
+ if (!origin) {
180
+ const raw = await ask(rl, 'Live Webflow site to check (optional, e.g. my-project.webflow.io)', '');
181
+ if (raw) {
182
+ const check = normalizeSiteUrl(raw);
183
+ if (check.ok) origin = check.host;
184
+ else log(chalk.yellow(` ${check.error} Skipping the live check.`));
185
+ }
186
+ }
187
+ const detected = await detectFromSite();
188
+ if (detected && (await askYesNo(rl, `Use modules detected on the site: ${formatModules(detected)}?`, true))) {
189
+ siteModules = detected;
190
+ }
191
+ while (siteModules === undefined) {
192
+ const raw = await ask(
193
+ rl,
194
+ 'Modules your Webflow site loads (none | all | inject,cookies,maintenance)',
195
+ detected ? formatModules(detected) : 'none'
196
+ );
197
+ const parsed = normalizeModulesList(raw);
198
+ if (parsed.ok) siteModules = parsed.modules;
199
+ else log(chalk.yellow(` ${parsed.error}`));
200
+ }
138
201
  }
139
202
  if (git === undefined) {
140
203
  git = await askYesNo(rl, 'Initialize git repository?', true);
@@ -148,8 +211,29 @@ export async function resolveNewOptions(nameArg, options = {}, deps = {}) {
148
211
  } finally {
149
212
  rl.close();
150
213
  }
214
+ } else if (siteModules === undefined && modules !== false) {
215
+ const detected = await detectFromSite();
216
+ if (detected) {
217
+ siteModules = detected;
218
+ log(`Modules: ${formatModules(detected)} (detected on ${origin}; change "modules" in stagepass.json if needed).`);
219
+ }
151
220
  }
152
221
 
222
+ if (siteModules === undefined) {
223
+ siteModules = [];
224
+ if (!interactive && modules !== false) {
225
+ log(chalk.dim('Modules: none declared. Pass --site <host> or --site-modules <list>, or edit stagepass.json and run stagepass upgrade.'));
226
+ }
227
+ }
228
+ if (modules === false && siteModules.length > 0) {
229
+ return {
230
+ ok: false,
231
+ error: '--no-modules conflicts with declared site modules. Drop --no-modules or pass --site-modules none.',
232
+ };
233
+ }
234
+ // The npm package (types) follows the declared list; keep the legacy default (included).
235
+ if (siteModules.length > 0) modules = true;
236
+
153
237
  // Non-interactive / --yes defaults
154
238
  if (!name) {
155
239
  return { ok: false, error: 'Project name is required (pass [name] or use a TTY).' };
@@ -199,15 +283,46 @@ export async function resolveNewOptions(nameArg, options = {}, deps = {}) {
199
283
  lang,
200
284
  styles,
201
285
  modules,
286
+ siteModules,
287
+ origin: origin || undefined,
202
288
  git,
203
289
  remote: remoteCheck.remote,
204
290
  install,
205
291
  dryRun: options.dryRun === true,
206
- loaderVersion: deps.cliVersion || cliVersion,
292
+ loaderVersion:
293
+ deps.packagesVersion || deps.cliVersion || STAGEPASS_PACKAGES_VERSION,
207
294
  },
208
295
  };
209
296
  }
210
297
 
298
+ /**
299
+ * After `npm install`, align tsconfig/jsconfig types with the installed
300
+ * @stagepass/modules (per-module entries only when it ships them).
301
+ *
302
+ * @param {string} targetDir
303
+ * @param {{ siteModules: string[], perModuleTypes?: boolean }} config
304
+ * @param {typeof fs} fse
305
+ * @param {(msg?: string) => void} log
306
+ */
307
+ async function reconcileInstalledTypes(targetDir, config, fse, log) {
308
+ const installed = await installedHasPerModuleTypes(targetDir, fse);
309
+ if (installed === null || installed === (config.perModuleTypes !== false)) return;
310
+ for (const name of ['tsconfig.json', 'jsconfig.json']) {
311
+ const file = path.join(targetDir, name);
312
+ if (!(await fse.pathExists(file))) continue;
313
+ const raw = await fse.readFile(file, 'utf8');
314
+ const result = updateConfigTypes(raw, config.siteModules, {
315
+ modulesDependency: true,
316
+ perModuleTypes: installed,
317
+ });
318
+ if (result.status === 'updated' && result.content) {
319
+ await fse.writeFile(file, result.content, 'utf8');
320
+ log(chalk.dim(`${name}: types ${result.types.join(', ')} (matches installed @stagepass/modules)`));
321
+ }
322
+ }
323
+ if (!installed) log(chalk.yellow(PER_MODULE_TYPES_HINT));
324
+ }
325
+
211
326
  /**
212
327
  * Scaffold a new Stagepass project.
213
328
  *
@@ -247,9 +362,33 @@ export async function createNew(nameArg, options = {}, deps = {}) {
247
362
  ) {
248
363
  throw new Error(`Template path escapes templates root: ${rel}`);
249
364
  }
250
- return fse.readFile(abs, 'utf8');
365
+ try {
366
+ return await fse.readFile(abs, 'utf8');
367
+ } catch (err) {
368
+ if (err && err.code === 'ENOENT') {
369
+ throw new Error(
370
+ `Template "${rel}" is missing from the @stagepass/cli install (${templatesRootResolved}). ` +
371
+ 'Reinstall the CLI (npm install -g @stagepass/cli) and try again. Nothing was written.'
372
+ );
373
+ }
374
+ throw err;
375
+ }
251
376
  };
252
377
 
378
+ // Single-module types (`@stagepass/modules/cookies`) exist since modules
379
+ // 2.2.0. Only use them when a published release in range ships them;
380
+ // otherwise (or offline) fall back to the umbrella types so tsc passes.
381
+ const singleModuleTypes =
382
+ config.modules === true &&
383
+ config.siteModules.length > 0 &&
384
+ !config.siteModules.includes('all');
385
+ if (singleModuleTypes && !config.dryRun) {
386
+ const published = await (deps.fetchPublished || fetchPublished)('@stagepass/modules', { exec });
387
+ config.perModuleTypes =
388
+ rangeHasPerModuleTypes(published ? published.versions : null, PACKAGES_MAJOR_RANGE) === true;
389
+ if (!config.perModuleTypes) log(chalk.yellow(PER_MODULE_TYPES_HINT));
390
+ }
391
+
253
392
  let files;
254
393
  try {
255
394
  files = await planScaffoldFiles(config, { readTemplate });
@@ -337,6 +476,9 @@ export async function createNew(nameArg, options = {}, deps = {}) {
337
476
  error(chalk.red(`npm install exited with code ${result.code}`));
338
477
  return typeof result.code === 'number' ? result.code : 1;
339
478
  }
479
+ if (singleModuleTypes) {
480
+ await reconcileInstalledTypes(targetDir, config, fse, log);
481
+ }
340
482
  } catch (err) {
341
483
  error(
342
484
  chalk.red(
@@ -353,11 +495,12 @@ export async function createNew(nameArg, options = {}, deps = {}) {
353
495
  log(` cd ${path.relative(cwd, targetDir) || '.'} && npm install`);
354
496
  }
355
497
  log(' npm run build');
356
- log(` stagepass link ${config.name} --origin my-project.webflow.io`);
498
+ log(` stagepass link ${config.name} --origin ${config.origin || 'my-project.webflow.io'}`);
499
+ log(chalk.dim(`Declared modules (stagepass.json): ${formatModules(config.siteModules)}`));
357
500
 
358
501
  const snippets = buildWebflowSnippets({
359
502
  version: config.loaderVersion,
360
- modules: config.modules,
503
+ moduleList: config.siteModules,
361
504
  });
362
505
  printWebflowSnippets(snippets, log);
363
506