@stagepass/cli 2.3.1 → 2.4.0
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 +24 -13
- package/package.json +1 -1
- package/src/cli.js +48 -5
- package/src/commands/dev.js +14 -0
- package/src/commands/link.js +11 -1
- package/src/commands/new.js +39 -16
- package/src/commands/npm-run.js +14 -0
- package/src/commands/reload.js +5 -1
- package/src/commands/start.js +1 -1
- package/src/commands/upgrade.js +84 -32
- package/src/lib/build-script-upgrade.js +244 -0
- package/src/lib/caddy-version.js +31 -0
- package/src/lib/caddyfile.js +76 -36
- package/src/lib/doctor-site.js +15 -10
- package/src/lib/doctor.js +30 -29
- package/src/lib/migrate.js +29 -2
- package/src/lib/package-versions.js +1 -1
- package/src/lib/php-runtime.js +249 -0
- package/src/lib/scaffold.js +22 -16
- package/templates/project/README.md.tmpl +8 -6
- package/templates/project/api/README.md.tmpl +172 -5
- package/templates/project/api/action.php +100 -0
- package/templates/project/api/actions/boom.php +21 -0
- package/templates/project/api/actions/contact.php +46 -0
- package/templates/project/api/actions/ping.php +23 -0
- package/templates/project/api/actions.php +59 -0
- package/templates/project/api/env.example +25 -0
- package/templates/project/api/lib/bootstrap.php +44 -0
- package/templates/project/api/lib/config.php +180 -0
- package/templates/project/api/lib/request.php +94 -0
- package/templates/project/api/lib/response.php +97 -0
- package/templates/project/api/lib/security.php +114 -0
- package/templates/project/api/lib/validate.php +69 -0
- package/templates/project/gitignore +4 -0
- package/templates/project/php-private/config.php +24 -0
- package/templates/project/scripts/build.mjs +114 -8
- package/templates/project/examples/php/README.md.tmpl +0 -18
- package/templates/project/examples/php/form.php +0 -105
- package/templates/project/examples/php/proxy.php +0 -171
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@ The CLI sets up and manages the local Stagepass infrastructure (`.sp` domains, C
|
|
|
6
6
|
|
|
7
7
|
## Install
|
|
8
8
|
|
|
9
|
-
Published CLI 2.3.
|
|
9
|
+
Published CLI 2.3.1 requires Node.js **20.17+** (`engines.node`: `>=20.17.0`) on **macOS** with Homebrew, because `@inquirer/prompts@8` requires it. Node 18 is no longer supported; stay on `@stagepass/cli@2.2.7` if you must remain on Node 18. Development and CI use Node 22 or 24.
|
|
10
10
|
|
|
11
11
|
```bash
|
|
12
12
|
npm install -g @stagepass/cli@2
|
|
@@ -21,7 +21,7 @@ npx @stagepass/cli@2 setup
|
|
|
21
21
|
## Requirements
|
|
22
22
|
|
|
23
23
|
- **macOS** (system commands refuse other platforms with exit code 1; this is not a breaking change because those commands never worked off macOS)
|
|
24
|
-
- Published CLI 2.3.
|
|
24
|
+
- Published CLI 2.3.1: Node.js `>=20.17.0`. Use Node 22 or 24 for local development and CI
|
|
25
25
|
- Homebrew
|
|
26
26
|
|
|
27
27
|
`stagepass --version` and `stagepass --help` work on any platform. For tests/CI only, set `STAGEPASS_SKIP_PLATFORM_CHECK=1` to bypass the macOS guard (not for production use).
|
|
@@ -51,12 +51,12 @@ Linked: https://my-project.sp -> /absolute/path/to/project
|
|
|
51
51
|
| Command | Description |
|
|
52
52
|
| :--- | :--- |
|
|
53
53
|
| `stagepass setup` | Install Caddy, PHP, Dnsmasq via Homebrew and configure the local `.sp` resolver (`address=/.sp/127.0.0.1` + `/etc/resolver/sp`). |
|
|
54
|
-
| `stagepass start` | Start Caddy & PHP. Runs `certs check` (offers repair when interactive). No unconditional root warm-up: inspects port 443 without sudo; signals only after confirm (TERM then optional KILL; sudo only if unprivileged kill fails). With autostart installed, bootstraps/kickstarts the LaunchAgent (else direct `caddy start`). Migrates legacy Caddyfile blocks if needed. |
|
|
55
|
-
| `stagepass link [domain]` | Link the current directory to a `.sp` domain, write/update the Caddyfile + `~/.stagepass/projects.json`, reload Caddy. |
|
|
54
|
+
| `stagepass start` | Start Caddy & PHP. Runs `certs check` (offers repair when interactive). No unconditional root warm-up: inspects port 443 without sudo; signals only after confirm (TERM then optional KILL; sudo only if unprivileged kill fails). With autostart installed, bootstraps/kickstarts the LaunchAgent (else direct `caddy start`). Migrates legacy Caddyfile blocks if needed, except when Caddy is known to be older than 2.9 (`brew upgrade caddy`). |
|
|
55
|
+
| `stagepass link [domain]` | Link the current directory to a `.sp` domain, write/update the Caddyfile + `~/.stagepass/projects.json`, reload Caddy. The linked block is v3. On Caddy older than 2.9, other existing blocks are left unchanged and CORS on success responses may be missing (`brew upgrade caddy`). |
|
|
56
56
|
| `stagepass unlink [domain]` | Remove the site block and `projects.json` entry, reload Caddy. |
|
|
57
|
-
| `stagepass reload` | Reload Caddy configuration. Migrates legacy Caddyfile blocks if needed. |
|
|
57
|
+
| `stagepass reload` | Reload Caddy configuration. Migrates legacy Caddyfile blocks if needed, except when Caddy is known to be older than 2.9 (`brew upgrade caddy`). |
|
|
58
58
|
| `stagepass stop` | Stop Caddy & PHP. If autostart is installed/loaded, `launchctl bootout` first (until next login); use `autostart off` to disable permanently. |
|
|
59
|
-
| `stagepass doctor` | Read-only diagnostics (Homebrew, Caddy, PHP/php-fpm, dnsmasq, resolver, port 443, Caddyfile, projects, certs, LaunchAgent, declared modules vs. live site). CDN pin warnings in docs + project files. Never uses sudo. `--json`, `--skip-site`. Exit `1` if any fail. |
|
|
59
|
+
| `stagepass doctor` | Read-only diagnostics (Homebrew, Caddy, PHP/php-fpm, dnsmasq, resolver, port 443, Caddyfile, projects, certs, LaunchAgent, declared modules vs. live site). CDN pin warnings in docs + project files. Reports the Caddy version and warns (does not fail) when it is older than 2.9 (`brew upgrade caddy`); the v3 site block needs 2.9 or newer. Published CLI 2.3.1 fails when a LaunchAgent node or CLI path is missing, and warns on a versioned Homebrew Cellar node path or a daemon version that differs from the CLI (fix hint: `stagepass autostart on`). Never uses sudo. `--json`, `--skip-site`. Exit `1` if any fail. |
|
|
60
60
|
| `stagepass certs check` | Read-only Caddy local CA check (validity, System keychain trust, orphans, optional TLS handshake per linked domain). `--json`, `--skip-handshake`. |
|
|
61
61
|
| `stagepass certs trust` | Run `caddy trust` after interactive confirmation (or `--yes`). |
|
|
62
62
|
| `stagepass certs renew` | Repair failing linked site certs; `--root` moves the CA folder to a backup (double confirm, or `--yes --i-understand-root-renewal`); `--remove-orphans` deletes keychain orphans by SHA-1 after confirm. |
|
|
@@ -77,7 +77,8 @@ All commands support `-v, --verbose` where applicable.
|
|
|
77
77
|
- `certs renew` is opt-in and confirmation-gated. Site repair only deletes `certificates/local/<linked-domain>` after checks fail. `--root` moves the CA folder to a timestamped backup (never deletes; needs two interactive confirmations without `--yes`, or `--yes --i-understand-root-renewal`). `--yes` alone always aborts for `--root` (TTY or not). Do not combine `--root` with `--remove-orphans`; run them as separate commands. Orphans are removed only by SHA-1 via `renew --remove-orphans`.
|
|
78
78
|
- Chrome may require Local Network Access permission for public HTTPS pages that load `https://*.sp` assets.
|
|
79
79
|
- Autostart runs as your user (same privilege model as interactive `caddy start`). `start` kickstarts the agent when present; `stop` bootouts until the next login. If port 443 cannot be bound, `daemon` logs a clear error, may notify, and exits `0` so launchd KeepAlive does not restart-loop. Interactive `start` confirms before signalling any non-caddy listener (name + PID; SIGTERM then optional SIGKILL). Own processes are signalled without elevated rights first; `sudo` only when needed after confirmation. There is no standby `sudo -v`.
|
|
80
|
-
- `stagepass autostart on` records a launchd-safe `PATH` from `brew --prefix` (Apple Silicon `/opt/homebrew`, Intel `/usr/local`) plus `/usr/bin:/bin:/usr/sbin:/sbin`. It does **not** copy your interactive shell environment. `brew` and `caddy` must resolve to shims under that prefix's `bin`/`sbin` (normal Homebrew Cellar symlinks are fine). Missing Homebrew/Caddy aborts **before** writing the plist.
|
|
80
|
+
- `stagepass autostart on` records a launchd-safe `PATH` from `brew --prefix` (Apple Silicon `/opt/homebrew`, Intel `/usr/local`) plus `/usr/bin:/bin:/usr/sbin:/sbin`. It does **not** copy your interactive shell environment. `brew` and `caddy` must resolve to shims under that prefix's `bin`/`sbin` (normal Homebrew Cellar symlinks are fine). Missing Homebrew/Caddy aborts **before** writing the plist. Published CLI 2.3.1 uses the Homebrew `bin/node` shim when the running node is a versioned Cellar path.
|
|
81
|
+
- Published CLI 2.3.1 `stagepass doctor` fails when a LaunchAgent node or CLI path is missing. It warns when that node path is a versioned Homebrew Cellar path, or when the running daemon version differs from the CLI. The fix hint is `stagepass autostart on`.
|
|
81
82
|
- Published CLI requires Node `>=20.17.0`. Node 18 is no longer supported; stay on `@stagepass/cli@2.2.7` if you must remain on Node 18.
|
|
82
83
|
- Manual macOS checklist: [`TESTING-macos.md`](./TESTING-macos.md).
|
|
83
84
|
|
|
@@ -94,7 +95,7 @@ These are different prompts. Grant only the narrow dialog macOS shows. Stagepass
|
|
|
94
95
|
#### Install location and LaunchAgent paths
|
|
95
96
|
|
|
96
97
|
- Prefer a **stable** global install (`npm install -g @stagepass/cli` into the normal npm prefix, or another fixed absolute path). Avoid pointing autostart at a temporary Desktop unpack / ad-hoc test tarball when you can use the published package instead.
|
|
97
|
-
- `autostart on` records **absolute** Node and CLI paths
|
|
98
|
+
- `autostart on` records **absolute** Node and CLI paths plus the validated Homebrew `PATH`. Published CLI 2.3.1 uses the Homebrew `bin/node` shim when the running node is a versioned Cellar path (it does not store that versioned binary). It does not follow later `brew` upgrades automatically.
|
|
98
99
|
- After a Homebrew Node upgrade/cleanup, moving the CLI, or changing the npm prefix, run `stagepass autostart on` again so ProgramArguments stay valid. A brief local outage while the agent reloads is expected.
|
|
99
100
|
- Upgrading the global CLI package does **not** rewrite an existing LaunchAgent that still points at an older test path. Switch deliberately: `stagepass autostart off` then `autostart on` with the stable CLI you want. Do **not** delete a test directory while a loaded agent still references it; disable/refresh the agent first.
|
|
100
101
|
- Development checkouts (`packages/cli`, Desktop test packs) and the published global install are different binaries; compare behaviour with one style at a time.
|
|
@@ -114,8 +115,8 @@ Scaffold a project with flags for every choice (interactive prompts only on a TT
|
|
|
114
115
|
| `--staging <domain>` | Staging hostname (hostname only; same validation as `--origin`). Stored as `origin`. Must match `--site` when both are set. |
|
|
115
116
|
| `--production <domain>` | Optional production hostname. Stored as `production`. When omitted, prints a short hint to add it later via `stagepass link --origin`. |
|
|
116
117
|
| `--site-modules <list>` | Modules the site loads: `none`, `all`, or a comma list of `inject`, `cookies`, `maintenance`. Takes precedence over `--site`. |
|
|
117
|
-
| `--php` / `--no-php` | Enable PHP
|
|
118
|
-
| `--php-examples` / `--no-php-examples` |
|
|
118
|
+
| `--php` / `--no-php` | Enable the PHP boilerplate (`api/`, `.php/config.php`, `php_fastcgi` on link). Default: off. Existing linked projects without `"php"` keep PHP on. |
|
|
119
|
+
| `--php-examples` / `--no-php-examples` | Deprecated. Sample actions ship with `--php` in `api/actions/`. The flags are accepted and do not copy a second sample set. |
|
|
119
120
|
| `--link` / `--no-link` | After scaffolding, run `stagepass link` (macOS only). Default: off; interactive macOS may offer it. |
|
|
120
121
|
| `--git` / `--no-git` | `git init` (default: yes). |
|
|
121
122
|
| `--remote <url>` | Set `origin` after git init (rejects URLs with embedded credentials). |
|
|
@@ -125,7 +126,11 @@ Scaffold a project with flags for every choice (interactive prompts only on a TT
|
|
|
125
126
|
|
|
126
127
|
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/` + SRI `integrity` in `manifest.json`), scripts `build` / `watch` / `dev` (`dev` aliases `watch`), 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`.
|
|
127
128
|
|
|
128
|
-
Interactively (macOS), `new` runs a read-only `doctor` preflight and can offer `stagepass setup` if the local stack looks incomplete (never automatic, never under `--yes` / no-TTY, never sudo by itself). Without a TTY (or with `--yes`) it uses `--site-modules`, then `--site` detection, else `[]` with a hint. Staging / production prompts,
|
|
129
|
+
Interactively (macOS), `new` runs a read-only `doctor` preflight and can offer `stagepass setup` if the local stack looks incomplete (never automatic, never under `--yes` / no-TTY, never sudo by itself). Without a TTY (or with `--yes`) it uses `--site-modules`, then `--site` detection, else `[]` with a hint. The interactive wizard always asks whether to enable PHP unless `--php` / `--no-php` was passed. Staging / production prompts, `--staging` detection, and `link` reading `origin` / `production` from `stagepass.json` are part of this release.
|
|
130
|
+
|
|
131
|
+
### PHP
|
|
132
|
+
|
|
133
|
+
`--php` writes a plain PHP 8.2 boilerplate: `api/action.php` is the only public entry, actions are an allowlist in `api/actions.php`, and `.php/config.php` stays outside that folder. Copy `api/.env.example` to `.env` and set `ALLOWED_ORIGINS` (include `https://<name>.sp`). There is no mail. Caddy already returns 404 for hidden segments such as `/.env`, `/api/.env`, and `/.php/`. `stagepass new` and `doctor` warn when `php` is missing, older than 8.2, or has no `php-fpm` / `php-cgi` (`brew install php` on macOS). `stagepass dev` and `stagepass watch` on a `"php": true` project do the same check and start Homebrew php-fpm (`brew services start php`, and `brew services restart php` only if start fails), the same helper `stagepass start` has used since 2.3. The JS build still runs. `stagepass build` copies `api/` and `.php/config.php` into `dist/` and skips `.env`, `.php/rate-limit/`, logs, pid files, and key, certificate, or database files (`.pem`, `.key`, `.p12`, `.pfx`, `.crt`, `.cer`, `.sqlite`, `.db`). It keeps `.htaccess` and `.env.example`. `stagepass dev` / `watch` serve PHP from the project root, so edits show up on the next request. A longer draft for the website lives in [docs/php.md](https://github.com/arobertherz/stagepass/blob/master/docs/php.md); that page is not live yet.
|
|
129
134
|
|
|
130
135
|
### Declared modules (`stagepass.json`)
|
|
131
136
|
|
|
@@ -158,7 +163,7 @@ Still not recognised: tags without `src`, `data-src` only, other hosts without a
|
|
|
158
163
|
| `--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. |
|
|
159
164
|
| `--site-modules <list>` | Set the modules list directly (`none`, `all`, or a comma list). |
|
|
160
165
|
| `--skip-site` | Do not fetch the live site. |
|
|
161
|
-
| `-y, --yes` | Accept the detected or existing list without asking. |
|
|
166
|
+
| `-y, --yes` | Accept the detected or existing list without asking. With `--yes`, CLI 2.4.0 also replaces an unmodified `scripts/build.mjs`. |
|
|
162
167
|
| `--dry-run` | Print every planned change; write no file. |
|
|
163
168
|
|
|
164
169
|
`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:
|
|
@@ -167,6 +172,7 @@ Still not recognised: tags without `src`, `data-src` only, other hosts without a
|
|
|
167
172
|
- `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.
|
|
168
173
|
- `.cursor/rules/stagepass.mdc`: created if missing, otherwise only its managed block is refreshed.
|
|
169
174
|
- `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.
|
|
175
|
+
- `scripts/build.mjs`: CLI 2.4.0 replaces it when it is still an unmodified scaffold from an earlier CLI (line endings ignored; `src/main.js` / `src/main.ts` and `src/styles.css` / `src/styles.scss` still count). The interactive prompt defaults to yes. Without a TTY, and with `--yes`, the file is replaced. `--dry-run` writes nothing. An edited script is left unchanged and the CLI prints what `stagepass build`, `stagepass watch` and `stagepass dev` do now. A missing script stays missing. Published CLI 2.3.1 does not replace that file.
|
|
170
176
|
|
|
171
177
|
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.
|
|
172
178
|
|
|
@@ -232,7 +238,7 @@ Stagepass reflects `Access-Control-Allow-Origin` for **allowed** browser `Origin
|
|
|
232
238
|
|
|
233
239
|
Webflow staging/live hosts are **not** included by default. Add them per project, e.g. `--origin my-project.webflow.io`. An explicit `--origin *.webflow.io` (or `*.webflow.com`) is accepted but prints a warning (any Webflow user's site would then be allowed).
|
|
234
240
|
|
|
235
|
-
Matching responses also send `Vary: Origin`. Preflight (`OPTIONS`) for allowed origins returns `204` with reflected ACAO, `Access-Control-Allow-Methods: GET, HEAD, POST, OPTIONS`, reflected `Access-Control-Allow-Headers`, `Access-Control-Max-Age: 86400`, and `Access-Control-Allow-Private-Network: true` (Chrome Private Network Access from public HTTPS → loopback).
|
|
241
|
+
Matching responses also send `Vary: Origin`. On HTTP 2xx, Caddy sets a single `Access-Control-Allow-Origin` with a deferred replace, so a PHP app that sends the same header does not produce a second value. Other status codes are not given an ACAO by Caddy. Preflight (`OPTIONS`) for allowed origins returns `204` with reflected ACAO, `Access-Control-Allow-Methods: GET, HEAD, POST, OPTIONS`, reflected `Access-Control-Allow-Headers`, `Access-Control-Max-Age: 86400`, and `Access-Control-Allow-Private-Network: true` (Chrome Private Network Access from public HTTPS → loopback).
|
|
236
242
|
|
|
237
243
|
Non-matching origins get **no** ACAO. Non-allowlisted `OPTIONS` still get `204` without CORS headers.
|
|
238
244
|
|
|
@@ -267,6 +273,8 @@ On `stagepass link`, `reload`, and `start`, legacy Caddyfile blocks (no `# stage
|
|
|
267
273
|
3. **`allowAllOrigins` is enabled** for migrated blocks so existing Webflow / live-domain embedding keeps working
|
|
268
274
|
4. A short notice recommends tightening CORS
|
|
269
275
|
|
|
276
|
+
Blocks already marked `# stagepass-block: v2` are rewritten to the current marker on those same commands. Saved options (`allowAllOrigins`, origins, `php`, `devPort`) stay as they are.
|
|
277
|
+
|
|
270
278
|
Recommended after migration:
|
|
271
279
|
|
|
272
280
|
```bash
|
|
@@ -276,6 +284,8 @@ stagepass link --no-allow-all-origins
|
|
|
276
284
|
|
|
277
285
|
Hand-written content outside `# START:` / `# END:` markers is left untouched. Unparsable legacy blocks are left unchanged with a warning. Migration is idempotent (second run does nothing and creates no new backup).
|
|
278
286
|
|
|
287
|
+
The v3 block needs Caddy 2.9 or newer (`brew upgrade caddy`). Homebrew does not upgrade an existing Caddy when you `brew install caddy`. On a known older Caddy, `link`, `reload`, and `start` do not rewrite existing blocks. `link` still writes that project's block as v3 and warns that CORS on success responses may be missing until you upgrade. If `caddy version` cannot be read, the rewrite stays as before. `stagepass doctor` reports the version and warns below 2.9.
|
|
288
|
+
|
|
279
289
|
## Troubleshooting (CLI)
|
|
280
290
|
|
|
281
291
|
| Symptom | What to check |
|
|
@@ -283,6 +293,7 @@ Hand-written content outside `# START:` / `# END:` markers is left untouched. Un
|
|
|
283
293
|
| Autostart runs at login but `caddy: command not found` / daemon exits | Re-run `stagepass autostart on` so the plist embeds Homebrew `PATH`. Confirm `brew --prefix` and that `which caddy` points at `$prefix/bin/caddy` (Cellar symlink OK). |
|
|
284
294
|
| macOS asks Node for Desktop access | Normal TCC when the CLI/agent reads a project under Desktop. Grant the folder or move the project / use a stable global CLI install. Not the same as browser Local Network or CA trust. |
|
|
285
295
|
| Autostart still runs an old Desktop test binary after `npm i -g` | Global upgrade does not migrate LaunchAgent ProgramArguments. `autostart off` then `on` with the stable CLI; do not remove the old path while the agent still references it. |
|
|
296
|
+
| Login autostart points at a deleted Homebrew Node, or `doctor` warns that the daemon version differs from the CLI | Published CLI 2.3.1. Run `stagepass autostart on`. `doctor` fails on a missing LaunchAgent node or CLI path, and warns on a versioned Cellar node path or a daemon/CLI version mismatch. The fix hint is `stagepass autostart on`. |
|
|
286
297
|
| `stagepass start` spinner floods the terminal (weird ANSI) | Upgrade to a build with the spinner geometry guard. Rare with TTY width `0`. |
|
|
287
298
|
| `start` asks for a password at every boot | There is no unconditional `sudo -v`. Only confirmed conflict resolution may use `sudo kill` / `apachectl`. |
|
|
288
299
|
| Port 443 bind failure under LaunchAgent | Expected when something else owns 443; daemon exits `0` (no restart loop). Free the port or use interactive `stagepass start`. |
|
package/package.json
CHANGED
package/src/cli.js
CHANGED
|
@@ -62,6 +62,35 @@ export function rewriteArgvForUpgrade(argv) {
|
|
|
62
62
|
return out;
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
+
// Suggest subcommands for a top-level unknown option. Strip control chars. Do not run.
|
|
66
|
+
function suggestMisplacedOption(program, errorText) {
|
|
67
|
+
if (!errorText.startsWith("error: unknown option '")) return '';
|
|
68
|
+
const args = (program.args || []).map((s) => String(s).replace(/\p{C}/gu, ''));
|
|
69
|
+
const flag = args[0];
|
|
70
|
+
if (!flag || flag[0] !== '-' || flag === '--') return '';
|
|
71
|
+
const name = flag.split('=')[0];
|
|
72
|
+
const hits = [];
|
|
73
|
+
const walk = (cmd, prefix) => {
|
|
74
|
+
for (const sub of cmd.commands) {
|
|
75
|
+
const path = prefix.concat(sub.name());
|
|
76
|
+
if (sub.options.some((o) => o.long === name || o.short === name)) hits.push(path);
|
|
77
|
+
walk(sub, path);
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
walk(program, []);
|
|
81
|
+
if (!hits.length) return '';
|
|
82
|
+
const bin = program.name();
|
|
83
|
+
hits.sort((a, b) => (a.join(' ') < b.join(' ') ? -1 : a.join(' ') > b.join(' ') ? 1 : 0));
|
|
84
|
+
return hits
|
|
85
|
+
.map((cmdPath) => {
|
|
86
|
+
const rest = args.slice(1);
|
|
87
|
+
const echoed = cmdPath.every((part, i) => rest[i] === part);
|
|
88
|
+
const tail = echoed ? [flag, ...rest.slice(cmdPath.length)] : args;
|
|
89
|
+
return `Did you mean: ${bin} ${cmdPath.join(' ')} ${tail.join(' ')}\n`;
|
|
90
|
+
})
|
|
91
|
+
.join('');
|
|
92
|
+
}
|
|
93
|
+
|
|
65
94
|
/**
|
|
66
95
|
* Build the Commander program (no parse). Injectable handlers for unit tests.
|
|
67
96
|
*
|
|
@@ -294,13 +323,13 @@ export function createProgram(deps = {}) {
|
|
|
294
323
|
program
|
|
295
324
|
.command('upgrade')
|
|
296
325
|
.description(
|
|
297
|
-
'Bump @stagepass/*, sync
|
|
326
|
+
'Bump @stagepass/*, sync project files, replace an unmodified scripts/build.mjs, print Webflow snippets'
|
|
298
327
|
)
|
|
299
328
|
.option('--dry-run', 'Show changes without writing any file')
|
|
300
329
|
.option('--site <host>', 'Live Webflow site to detect loaded modules from (https)')
|
|
301
330
|
.option('--site-modules <list>', 'Modules the site loads: none, all, or inject,cookies,maintenance')
|
|
302
331
|
.option('--skip-site', 'Do not fetch the live site')
|
|
303
|
-
.option('-y, --yes', 'Non-interactive; accept detected or existing modules')
|
|
332
|
+
.option('-y, --yes', 'Non-interactive; accept detected or existing modules and an unmodified scripts/build.mjs')
|
|
304
333
|
.option(
|
|
305
334
|
'--target <version>',
|
|
306
335
|
'Target version, range or dist-tag; must be published on npm (default: ^<latest published 2.x>, ^2 offline)'
|
|
@@ -359,10 +388,10 @@ export function createProgram(deps = {}) {
|
|
|
359
388
|
.option('--staging <domain>', 'Staging hostname written to stagepass.json as origin')
|
|
360
389
|
.option('--production <domain>', 'Optional production hostname written to stagepass.json')
|
|
361
390
|
.option('--site-modules <list>', 'Modules the site loads: none, all, or inject,cookies,maintenance')
|
|
362
|
-
.option('--php', 'Enable PHP (api/ + php_fastcgi on link)')
|
|
391
|
+
.option('--php', 'Enable PHP (api/ boilerplate + php_fastcgi on link)')
|
|
363
392
|
.option('--no-php', 'Disable PHP for this project (default)')
|
|
364
|
-
.option('--php-examples', '
|
|
365
|
-
.option('--no-php-examples', '
|
|
393
|
+
.option('--php-examples', 'Deprecated: sample actions ship with --php under api/actions/')
|
|
394
|
+
.option('--no-php-examples', 'Deprecated no-op (examples are not a separate copy)')
|
|
366
395
|
.option('--link', 'Run stagepass link after scaffolding (macOS)')
|
|
367
396
|
.option('--no-link', 'Do not link after scaffolding (default)')
|
|
368
397
|
.option('--git', 'Initialize a git repository')
|
|
@@ -378,5 +407,19 @@ export function createProgram(deps = {}) {
|
|
|
378
407
|
process.exitCode = code;
|
|
379
408
|
});
|
|
380
409
|
|
|
410
|
+
// Typo suggestions (commander). Root-only writer: subcommands already copied output config.
|
|
411
|
+
const enableSuggest = (cmd) => {
|
|
412
|
+
cmd.showSuggestionAfterError();
|
|
413
|
+
cmd.commands.forEach(enableSuggest);
|
|
414
|
+
};
|
|
415
|
+
enableSuggest(program);
|
|
416
|
+
program.configureOutput({
|
|
417
|
+
outputError(str, write) {
|
|
418
|
+
write(str);
|
|
419
|
+
const hint = suggestMisplacedOption(program, str);
|
|
420
|
+
if (hint) write(hint);
|
|
421
|
+
},
|
|
422
|
+
});
|
|
423
|
+
|
|
381
424
|
return program;
|
|
382
425
|
}
|
package/src/commands/dev.js
CHANGED
|
@@ -20,6 +20,8 @@ import { readStagepassJson } from '../lib/project-sync.js';
|
|
|
20
20
|
import { getCaddyfilePath, getProjectsPath, validateRoot } from '../lib/paths.js';
|
|
21
21
|
import { isPidAlive, isValidDevPort } from '../lib/dev-port.js';
|
|
22
22
|
import { ensureStagepassReady } from '../lib/ensure-running.js';
|
|
23
|
+
import { warnPhpProject } from '../lib/php-runtime.js';
|
|
24
|
+
import { ensurePhpFpm } from '../lib/php-fpm.js';
|
|
23
25
|
import { start as defaultStart } from './start.js';
|
|
24
26
|
|
|
25
27
|
/** Grace before SIGKILL after a forwarded stop signal (overridable in tests). */
|
|
@@ -328,6 +330,18 @@ export async function dev(options = {}, deps = {}) {
|
|
|
328
330
|
|
|
329
331
|
setupDone = true;
|
|
330
332
|
|
|
333
|
+
await warnPhpProject(cwd, {
|
|
334
|
+
fs: fse,
|
|
335
|
+
exec: deps.exec,
|
|
336
|
+
platform: deps.platform,
|
|
337
|
+
pathExists: deps.pathExists,
|
|
338
|
+
resolveCommand: deps.resolveCommand,
|
|
339
|
+
brewPrefix: deps.brewPrefix,
|
|
340
|
+
domain,
|
|
341
|
+
warn: (m) => log(chalk.yellow(m)),
|
|
342
|
+
ensurePhpFpm: deps.ensurePhpFpm || ensurePhpFpm,
|
|
343
|
+
});
|
|
344
|
+
|
|
331
345
|
log(chalk.green(`Live reload on https://${domain}/__stagepass/live (127.0.0.1:${live.port})`));
|
|
332
346
|
if (options.verbose) {
|
|
333
347
|
log(chalk.dim('Running: npm run watch'));
|
package/src/commands/link.js
CHANGED
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
isBroadWebflowWildcard,
|
|
18
18
|
} from '../lib/origins.js';
|
|
19
19
|
import { ensureCaddyfileMigrated } from '../lib/migrate.js';
|
|
20
|
+
import { CADDY_UPGRADE_HINT, readCaddyVersion } from '../lib/caddy-version.js';
|
|
20
21
|
import {
|
|
21
22
|
originsFromStagepassConfig,
|
|
22
23
|
phpFromStagepassConfig,
|
|
@@ -36,6 +37,7 @@ import { isPhpEnabled } from '../lib/caddyfile.js';
|
|
|
36
37
|
* @param {string} [deps.cwd]
|
|
37
38
|
* @param {(msg?: string) => void} [deps.log]
|
|
38
39
|
* @param {(msg?: string) => void} [deps.error]
|
|
40
|
+
* @param {import('../lib/exec.js').ExecFn} [deps.exec]
|
|
39
41
|
*/
|
|
40
42
|
export async function link(domain, options = {}, deps = {}) {
|
|
41
43
|
const log = deps.log || console.log;
|
|
@@ -127,7 +129,15 @@ export async function link(domain, options = {}, deps = {}) {
|
|
|
127
129
|
await fs.ensureDir(caddyDir);
|
|
128
130
|
|
|
129
131
|
spinner.stop();
|
|
130
|
-
|
|
132
|
+
const caddy = await readCaddyVersion(deps.exec);
|
|
133
|
+
await ensureCaddyfileMigrated({ caddyfilePath: caddyFilePath, projectsPath, caddy });
|
|
134
|
+
if (caddy.known && !caddy.ok) {
|
|
135
|
+
log(
|
|
136
|
+
chalk.yellow(
|
|
137
|
+
` This site block is v3 and needs Caddy 2.9 or newer for CORS on success responses. ${CADDY_UPGRADE_HINT}`
|
|
138
|
+
)
|
|
139
|
+
);
|
|
140
|
+
}
|
|
131
141
|
await clearStaleDevPorts(projectsPath);
|
|
132
142
|
spinner.start(`Linking ${chalk.bold(targetDomain)}...`);
|
|
133
143
|
|
package/src/commands/new.js
CHANGED
|
@@ -33,6 +33,7 @@ import {
|
|
|
33
33
|
import { updateConfigTypes } from '../lib/project-sync.js';
|
|
34
34
|
import { validateOriginEntry, isBroadWebflowWildcard } from '../lib/origins.js';
|
|
35
35
|
import { isMacOS } from '../lib/platform.js';
|
|
36
|
+
import { checkPhpRuntime, phpOriginsHint, phpProjectWarning } from '../lib/php-runtime.js';
|
|
36
37
|
import { runDoctor } from '../lib/doctor.js';
|
|
37
38
|
import { setup as defaultSetup } from './setup.js';
|
|
38
39
|
import { link as defaultLink } from './link.js';
|
|
@@ -329,9 +330,6 @@ export async function resolveNewOptions(nameArg, options = {}, deps = {}) {
|
|
|
329
330
|
if (php === undefined) {
|
|
330
331
|
php = await askYesNo(rl, 'Enable PHP for this project?', false);
|
|
331
332
|
}
|
|
332
|
-
if (php && phpExamples === undefined) {
|
|
333
|
-
phpExamples = await askYesNo(rl, 'Include PHP examples under examples/php/?', false);
|
|
334
|
-
}
|
|
335
333
|
if (git === undefined) {
|
|
336
334
|
git = await askYesNo(rl, 'Initialize git repository?', true);
|
|
337
335
|
}
|
|
@@ -341,10 +339,7 @@ export async function resolveNewOptions(nameArg, options = {}, deps = {}) {
|
|
|
341
339
|
if (install === undefined) {
|
|
342
340
|
install = await askYesNo(rl, 'Run npm install now?', false);
|
|
343
341
|
}
|
|
344
|
-
|
|
345
|
-
// Asked after create on macOS only; remember preference here when already decided.
|
|
346
|
-
linkAtEnd = undefined;
|
|
347
|
-
}
|
|
342
|
+
// Asked after create on macOS only when the link flag was omitted.
|
|
348
343
|
} finally {
|
|
349
344
|
rl.close();
|
|
350
345
|
}
|
|
@@ -389,7 +384,7 @@ export async function resolveNewOptions(nameArg, options = {}, deps = {}) {
|
|
|
389
384
|
if (install === undefined) install = false;
|
|
390
385
|
if (php === undefined) php = false;
|
|
391
386
|
if (phpExamples === undefined) phpExamples = false;
|
|
392
|
-
if (linkAtEnd
|
|
387
|
+
if (linkAtEnd == null && !interactive) linkAtEnd = false;
|
|
393
388
|
|
|
394
389
|
if (lang !== 'ts' && lang !== 'js') {
|
|
395
390
|
return { ok: false, error: 'Language must be ts or js.' };
|
|
@@ -397,11 +392,12 @@ export async function resolveNewOptions(nameArg, options = {}, deps = {}) {
|
|
|
397
392
|
if (styles !== 'scss' && styles !== 'css') {
|
|
398
393
|
return { ok: false, error: 'Styles must be scss or css.' };
|
|
399
394
|
}
|
|
400
|
-
if (phpExamples
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
395
|
+
if (phpExamples) {
|
|
396
|
+
log(
|
|
397
|
+
chalk.yellow(
|
|
398
|
+
'--php-examples is deprecated. Sample actions (ping, contact) are included with --php under api/actions/. This flag no longer copies examples/php/.'
|
|
399
|
+
)
|
|
400
|
+
);
|
|
405
401
|
}
|
|
406
402
|
|
|
407
403
|
const remoteCheck = validateGitRemote(remote);
|
|
@@ -564,7 +560,7 @@ async function maybeDoctorPreflight(deps = {}) {
|
|
|
564
560
|
}
|
|
565
561
|
|
|
566
562
|
/**
|
|
567
|
-
* Optionally link the new project (macOS only;
|
|
563
|
+
* Optionally link the new project (macOS only; --link, or ask when unset).
|
|
568
564
|
*
|
|
569
565
|
* @param {object} config
|
|
570
566
|
* @param {string} targetDir
|
|
@@ -580,9 +576,9 @@ async function maybeLinkProject(config, targetDir, deps = {}) {
|
|
|
580
576
|
return;
|
|
581
577
|
}
|
|
582
578
|
|
|
583
|
-
let shouldLink = config.linkAtEnd
|
|
579
|
+
let shouldLink = config.linkAtEnd;
|
|
584
580
|
const isTty = deps.isTTY != null ? Boolean(deps.isTTY) : Boolean(input.isTTY);
|
|
585
|
-
if (
|
|
581
|
+
if (shouldLink == null && isTty && deps.yes !== true) {
|
|
586
582
|
const rl =
|
|
587
583
|
deps.createReadline?.() ||
|
|
588
584
|
readline.createInterface({ input, output });
|
|
@@ -752,6 +748,7 @@ export async function createNew(nameArg, options = {}, deps = {}) {
|
|
|
752
748
|
if (config.install) log(' (npm install)');
|
|
753
749
|
if (config.linkAtEnd) log(' (stagepass link)');
|
|
754
750
|
if (config.productionSkipped) log(` (${PRODUCTION_HINT})`);
|
|
751
|
+
await reportPhpChoice(config, deps, log);
|
|
755
752
|
return 0;
|
|
756
753
|
}
|
|
757
754
|
|
|
@@ -845,6 +842,7 @@ export async function createNew(nameArg, options = {}, deps = {}) {
|
|
|
845
842
|
}
|
|
846
843
|
log(chalk.dim(`Declared modules (stagepass.json): ${formatModules(config.siteModules)}`));
|
|
847
844
|
log(chalk.dim(`PHP: ${config.php ? 'on' : 'off'}`));
|
|
845
|
+
await reportPhpChoice(config, deps, log);
|
|
848
846
|
|
|
849
847
|
const snippets = buildWebflowSnippets({
|
|
850
848
|
version: config.loaderVersion,
|
|
@@ -863,5 +861,30 @@ export async function createNew(nameArg, options = {}, deps = {}) {
|
|
|
863
861
|
return 0;
|
|
864
862
|
}
|
|
865
863
|
|
|
864
|
+
/**
|
|
865
|
+
* Origins hint plus a non-fatal PHP 8.2 / php-fpm check. The project is kept either way.
|
|
866
|
+
* @param {{ php?: boolean, name: string }} config
|
|
867
|
+
* @param {object} deps
|
|
868
|
+
* @param {(msg?: string) => void} log
|
|
869
|
+
*/
|
|
870
|
+
async function reportPhpChoice(config, deps, log) {
|
|
871
|
+
if (config.php !== true) return;
|
|
872
|
+
log(chalk.dim(phpOriginsHint(config.name)));
|
|
873
|
+
try {
|
|
874
|
+
const runtime = await checkPhpRuntime({
|
|
875
|
+
exec: deps.exec,
|
|
876
|
+
platform: deps.platform,
|
|
877
|
+
pathExists: deps.pathExists,
|
|
878
|
+
resolveCommand: deps.resolveCommand,
|
|
879
|
+
brewPrefix: deps.brewPrefix,
|
|
880
|
+
});
|
|
881
|
+
if (!runtime.ok) {
|
|
882
|
+
log(chalk.yellow(phpProjectWarning(runtime, `${config.name}.sp`)));
|
|
883
|
+
}
|
|
884
|
+
} catch {
|
|
885
|
+
log(chalk.yellow('PHP could not be checked. The project was still created.'));
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
|
|
866
889
|
/** Commander-facing alias */
|
|
867
890
|
export const newProject = createNew;
|
package/src/commands/npm-run.js
CHANGED
|
@@ -3,6 +3,8 @@ import path from 'path';
|
|
|
3
3
|
import chalk from 'chalk';
|
|
4
4
|
import { defaultSpawn } from '../lib/spawn.js';
|
|
5
5
|
import { ensureStagepassReady } from '../lib/ensure-running.js';
|
|
6
|
+
import { warnPhpProject } from '../lib/php-runtime.js';
|
|
7
|
+
import { ensurePhpFpm } from '../lib/php-fpm.js';
|
|
6
8
|
import { start as defaultStart } from './start.js';
|
|
7
9
|
|
|
8
10
|
/**
|
|
@@ -75,6 +77,18 @@ export async function runNpmScript(scriptName, options = {}, deps = {}) {
|
|
|
75
77
|
* @returns {Promise<number>}
|
|
76
78
|
*/
|
|
77
79
|
export async function watch(options = {}, deps = {}) {
|
|
80
|
+
const cwd = deps.cwd || process.cwd();
|
|
81
|
+
await warnPhpProject(cwd, {
|
|
82
|
+
fs: deps.fs,
|
|
83
|
+
exec: deps.exec,
|
|
84
|
+
platform: deps.platform,
|
|
85
|
+
pathExists: deps.pathExists,
|
|
86
|
+
resolveCommand: deps.resolveCommand,
|
|
87
|
+
brewPrefix: deps.brewPrefix,
|
|
88
|
+
domain: deps.domain,
|
|
89
|
+
warn: (m) => (deps.log || console.log)(chalk.yellow(m)),
|
|
90
|
+
ensurePhpFpm: deps.ensurePhpFpm || ensurePhpFpm,
|
|
91
|
+
});
|
|
78
92
|
await (deps.ensureStagepassReady || ensureStagepassReady)(options, {
|
|
79
93
|
...deps,
|
|
80
94
|
start: deps.start || defaultStart,
|
package/src/commands/reload.js
CHANGED
|
@@ -29,7 +29,11 @@ export async function reload(options = {}) {
|
|
|
29
29
|
|
|
30
30
|
try {
|
|
31
31
|
spinner.stop();
|
|
32
|
-
await ensureCaddyfileMigrated({
|
|
32
|
+
await ensureCaddyfileMigrated({
|
|
33
|
+
caddyfilePath: caddyFilePath,
|
|
34
|
+
projectsPath,
|
|
35
|
+
exec: (file, args, opts) => execa(file, args, opts),
|
|
36
|
+
});
|
|
33
37
|
await warnIfAllowAllOriginsActive({ caddyfilePath: caddyFilePath });
|
|
34
38
|
spinner.start('Reloading Caddy...');
|
|
35
39
|
|
package/src/commands/start.js
CHANGED
|
@@ -350,7 +350,7 @@ export async function start(options = {}) {
|
|
|
350
350
|
// 3. Migrate legacy Caddyfile blocks before boot; drop dead live-reload ports
|
|
351
351
|
await fs.ensureDir(caddyDir);
|
|
352
352
|
if (await fs.pathExists(caddyFile)) {
|
|
353
|
-
await ensureCaddyfileMigrated({ caddyfilePath: caddyFile, projectsPath });
|
|
353
|
+
await ensureCaddyfileMigrated({ caddyfilePath: caddyFile, projectsPath, exec });
|
|
354
354
|
const stale = await clearStaleDevPorts(projectsPath);
|
|
355
355
|
for (const domain of stale) {
|
|
356
356
|
const project = await getProject(domain, projectsPath);
|
package/src/commands/upgrade.js
CHANGED
|
@@ -26,6 +26,10 @@ import {
|
|
|
26
26
|
readStagepassJson,
|
|
27
27
|
resolveUpgradeModules,
|
|
28
28
|
} from '../lib/project-sync.js';
|
|
29
|
+
import {
|
|
30
|
+
defaultBuildScriptTemplatePath,
|
|
31
|
+
planBuildScriptUpgrade,
|
|
32
|
+
} from '../lib/build-script-upgrade.js';
|
|
29
33
|
|
|
30
34
|
const STAGEPASS_SCOPE = '@stagepass/';
|
|
31
35
|
|
|
@@ -166,7 +170,8 @@ export function applyStagepassVersions(pkg, target) {
|
|
|
166
170
|
/**
|
|
167
171
|
* Upgrade @stagepass/* deps in the current project's package.json and sync
|
|
168
172
|
* the declared modules into stagepass.json, AGENTS.md, the Cursor rule and
|
|
169
|
-
* tsconfig/jsconfig types.
|
|
173
|
+
* tsconfig/jsconfig types. Replaces scripts/build.mjs when it is still an
|
|
174
|
+
* unmodified scaffold from an earlier CLI.
|
|
170
175
|
*
|
|
171
176
|
* @param {object} [options]
|
|
172
177
|
* @param {boolean} [options.dryRun]
|
|
@@ -270,6 +275,22 @@ export async function upgrade(options = {}, deps = {}) {
|
|
|
270
275
|
if (!rl) rl = deps.createReadline?.() || readline.createInterface({ input, output });
|
|
271
276
|
return rl;
|
|
272
277
|
};
|
|
278
|
+
const closeRl = () => {
|
|
279
|
+
if (!rl) return;
|
|
280
|
+
rl.close();
|
|
281
|
+
rl = null;
|
|
282
|
+
};
|
|
283
|
+
const ask = async (question, def) => {
|
|
284
|
+
const answer = await getRl().question(`${question} (${def}): `);
|
|
285
|
+
const trimmed = String(answer || '').trim();
|
|
286
|
+
return trimmed === '' ? def : trimmed;
|
|
287
|
+
};
|
|
288
|
+
const confirmFn = async (question, defYes) => {
|
|
289
|
+
const answer = await getRl().question(`${question} (${defYes ? 'Y/n' : 'y/N'}): `);
|
|
290
|
+
const t = String(answer || '').trim().toLowerCase();
|
|
291
|
+
if (t === '') return defYes;
|
|
292
|
+
return ['y', 'yes'].includes(t);
|
|
293
|
+
};
|
|
273
294
|
let resolved;
|
|
274
295
|
try {
|
|
275
296
|
resolved = await resolveUpgradeModules(
|
|
@@ -279,21 +300,12 @@ export async function upgrade(options = {}, deps = {}) {
|
|
|
279
300
|
loadProjects: deps.loadProjects,
|
|
280
301
|
interactive,
|
|
281
302
|
log,
|
|
282
|
-
ask
|
|
283
|
-
|
|
284
|
-
const trimmed = String(answer || '').trim();
|
|
285
|
-
return trimmed === '' ? def : trimmed;
|
|
286
|
-
},
|
|
287
|
-
confirm: async (question, defYes) => {
|
|
288
|
-
const answer = await getRl().question(`${question} (${defYes ? 'Y/n' : 'y/N'}): `);
|
|
289
|
-
const t = String(answer || '').trim().toLowerCase();
|
|
290
|
-
if (t === '') return defYes;
|
|
291
|
-
return ['y', 'yes'].includes(t);
|
|
292
|
-
},
|
|
303
|
+
ask,
|
|
304
|
+
confirm: confirmFn,
|
|
293
305
|
}
|
|
294
306
|
);
|
|
295
307
|
} finally {
|
|
296
|
-
|
|
308
|
+
closeRl();
|
|
297
309
|
}
|
|
298
310
|
if (!resolved.ok) {
|
|
299
311
|
log(chalk.red(resolved.error));
|
|
@@ -311,25 +323,7 @@ export async function upgrade(options = {}, deps = {}) {
|
|
|
311
323
|
fse
|
|
312
324
|
);
|
|
313
325
|
|
|
314
|
-
|
|
315
|
-
if (plan.writes.length === 0) {
|
|
316
|
-
log(' Everything is up to date.');
|
|
317
|
-
}
|
|
318
|
-
for (const w of plan.writes) {
|
|
319
|
-
log(` ${w.file}: ${w.action}`);
|
|
320
|
-
}
|
|
321
|
-
for (const note of plan.notes) {
|
|
322
|
-
log(chalk.yellow(` note: ${note}`));
|
|
323
|
-
}
|
|
324
|
-
if (perModuleTypes === false && resolved.modules.length > 0 && !resolved.modules.includes('all')) {
|
|
325
|
-
log(
|
|
326
|
-
chalk.yellow(
|
|
327
|
-
' note: the published @stagepass/modules has no per-module types yet (needs 2.2.0); types use "@stagepass/modules". Run `stagepass upgrade` again once it is published.'
|
|
328
|
-
)
|
|
329
|
-
);
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
// Snippet: --version pin of loader on 2.x wins; resolve before writing so a failure changes nothing.
|
|
326
|
+
// Refuse an unpublished --version before asking about scripts/build.mjs or writing.
|
|
333
327
|
let loaderPub = '@stagepass/loader' in published ? published['@stagepass/loader'] : undefined;
|
|
334
328
|
const getLoaderPub = async () => {
|
|
335
329
|
if (loaderPub !== undefined) return loaderPub;
|
|
@@ -351,6 +345,64 @@ export async function upgrade(options = {}, deps = {}) {
|
|
|
351
345
|
if (t.resolved && satisfiesSimple(t.resolved, PACKAGES_MAJOR_RANGE)) snippetVersion = t.resolved;
|
|
352
346
|
}
|
|
353
347
|
|
|
348
|
+
/** @type {{ action: string, from?: string, content?: string, note?: string }} */
|
|
349
|
+
let buildUpgrade = { action: 'skipped' };
|
|
350
|
+
try {
|
|
351
|
+
let currentBuild;
|
|
352
|
+
try {
|
|
353
|
+
currentBuild = await fse.readFile(defaultBuildScriptTemplatePath(), 'utf8');
|
|
354
|
+
} catch (error) {
|
|
355
|
+
buildUpgrade = {
|
|
356
|
+
action: 'unreadable',
|
|
357
|
+
note: `Could not read the scaffold build script (${error instanceof Error ? error.message : String(error)}). The project script was left unchanged.`,
|
|
358
|
+
};
|
|
359
|
+
currentBuild = null;
|
|
360
|
+
}
|
|
361
|
+
if (currentBuild != null) {
|
|
362
|
+
buildUpgrade = await planBuildScriptUpgrade({
|
|
363
|
+
cwd,
|
|
364
|
+
currentSource: currentBuild,
|
|
365
|
+
interactive,
|
|
366
|
+
confirm: confirmFn,
|
|
367
|
+
fse,
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
if (buildUpgrade.action === 'update' && buildUpgrade.content) {
|
|
371
|
+
plan.writes.push({
|
|
372
|
+
file: 'scripts/build.mjs',
|
|
373
|
+
content: buildUpgrade.content,
|
|
374
|
+
action: `replace unmodified scaffold (${buildUpgrade.from})`,
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
} finally {
|
|
378
|
+
closeRl();
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
log(chalk.bold(`\nProject files for modules: ${resolved.modules.length ? resolved.modules.join(', ') : 'none'}`));
|
|
382
|
+
if (plan.writes.length === 0) {
|
|
383
|
+
log(' Everything is up to date.');
|
|
384
|
+
}
|
|
385
|
+
for (const w of plan.writes) {
|
|
386
|
+
log(` ${w.file}: ${w.action}`);
|
|
387
|
+
}
|
|
388
|
+
for (const note of plan.notes) {
|
|
389
|
+
log(chalk.yellow(` note: ${note}`));
|
|
390
|
+
}
|
|
391
|
+
if (buildUpgrade.action === 'custom') {
|
|
392
|
+
log(chalk.yellow(buildUpgrade.note));
|
|
393
|
+
} else if (buildUpgrade.action !== 'update' && buildUpgrade.note) {
|
|
394
|
+
const warn = buildUpgrade.action === 'declined' || buildUpgrade.action === 'symlink' || buildUpgrade.action === 'unreadable';
|
|
395
|
+
const line = ` ${buildUpgrade.note}`;
|
|
396
|
+
log(warn ? chalk.yellow(line) : line);
|
|
397
|
+
}
|
|
398
|
+
if (perModuleTypes === false && resolved.modules.length > 0 && !resolved.modules.includes('all')) {
|
|
399
|
+
log(
|
|
400
|
+
chalk.yellow(
|
|
401
|
+
' note: the published @stagepass/modules has no per-module types yet (needs 2.2.0); types use "@stagepass/modules". Run `stagepass upgrade` again once it is published.'
|
|
402
|
+
)
|
|
403
|
+
);
|
|
404
|
+
}
|
|
405
|
+
|
|
354
406
|
if (options.dryRun) {
|
|
355
407
|
log(chalk.dim('\nDry run: no files were modified.'));
|
|
356
408
|
} else {
|