@stagepass/cli 2.4.0 → 2.5.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 +63 -19
- package/package.json +1 -1
- package/src/cli.js +4 -2
- package/src/commands/dev.js +11 -2
- package/src/commands/new.js +10 -3
- package/src/commands/start.js +23 -1
- package/src/commands/upgrade.js +165 -43
- package/src/lib/ai-guide.js +497 -20
- package/src/lib/build-script-upgrade.js +30 -11
- package/src/lib/cdn-base.js +20 -0
- package/src/lib/cdn-snippets.js +7 -5
- package/src/lib/doctor-site.js +17 -0
- package/src/lib/htaccess-upgrade.js +79 -0
- package/src/lib/live-server.js +141 -34
- package/src/lib/project-sync.js +527 -32
- package/src/lib/registry.js +8 -6
- package/src/lib/scaffold.js +40 -5
- package/src/lib/snippets.js +235 -29
- package/src/lib/versions.js +9 -8
- package/templates/project/AGENTS.md.tmpl +2 -35
- package/templates/project/README.md.tmpl +4 -2
- package/templates/project/api/README.md.tmpl +16 -161
- package/templates/project/api/action.php +14 -2
- package/templates/project/api/env.example +11 -1
- package/templates/project/api/lib/config.php +8 -5
- package/templates/project/api/lib/request.php +366 -3
- package/templates/project/api/lib/security.php +116 -34
- package/templates/project/htaccess +7 -0
- package/templates/project/php-private/config.php +5 -3
- package/templates/project/scripts/build.mjs +15 -1
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.
|
|
9
|
+
Published CLI 2.4.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.
|
|
24
|
+
- Published CLI 2.4.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).
|
|
@@ -56,7 +56,7 @@ Linked: https://my-project.sp -> /absolute/path/to/project
|
|
|
56
56
|
| `stagepass unlink [domain]` | Remove the site block and `projects.json` entry, reload Caddy. |
|
|
57
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. 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. |
|
|
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 and later 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. |
|
|
@@ -65,8 +65,8 @@ Linked: https://my-project.sp -> /absolute/path/to/project
|
|
|
65
65
|
| `stagepass new [name]` | Scaffold a lean Webflow project (TypeScript + SCSS by default). |
|
|
66
66
|
| `stagepass build` | Run `npm run build` in the current project (forwards exit code). |
|
|
67
67
|
| `stagepass watch` | Run `npm run watch` in the current project (forwards exit code). If Stagepass is not running, asks to start it (TTY) or prints a `stagepass start` hint (non-TTY / CI); warns with `stagepass link` when the cwd is not linked. |
|
|
68
|
-
| `stagepass dev` | Like `stagepass watch`, plus live reload on the linked `.sp` domain (CSS can swap without a full reload). Same running check as watch; requires `stagepass link` (hard error if unlinked). |
|
|
69
|
-
| `stagepass upgrade` | Bump `@stagepass/*`, sync declared modules, `AGENTS.md`, the Cursor rule and `types
|
|
68
|
+
| `stagepass dev` | Like `stagepass watch`, plus live reload on the linked `.sp` domain (CSS can swap without a full reload). Same running check as watch; requires `stagepass link` (hard error if unlinked). When `stagepass.json` has `"php": true`, also watches `api/` and `.php/` (same SSE stream and debounce; ignores `.env`, `.php/.env`, `.php/rate-limit/`, logs, pid files, key and certificate files, and editor temp files). A missing folder does not stop the command. |
|
|
69
|
+
| `stagepass upgrade` | Bump `@stagepass/*`, sync declared modules, `AGENTS.stagepass.md`, the short pointer in `AGENTS.md`, the Cursor rule and editor types (`types` or `stagepass.d.ts`), print Webflow snippets. Since 2.4.1, writes a missing PHP `.htaccess` when `"php": true`. |
|
|
70
70
|
|
|
71
71
|
All commands support `-v, --verbose` where applicable.
|
|
72
72
|
|
|
@@ -77,8 +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. 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`.
|
|
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 and later uses the Homebrew `bin/node` shim when the running node is a versioned Cellar path.
|
|
81
|
+
- Published CLI 2.3.1 and later `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`.
|
|
82
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.
|
|
83
83
|
- Manual macOS checklist: [`TESTING-macos.md`](./TESTING-macos.md).
|
|
84
84
|
|
|
@@ -95,7 +95,7 @@ These are different prompts. Grant only the narrow dialog macOS shows. Stagepass
|
|
|
95
95
|
#### Install location and LaunchAgent paths
|
|
96
96
|
|
|
97
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.
|
|
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
|
+
- `autostart on` records **absolute** Node and CLI paths plus the validated Homebrew `PATH`. Published CLI 2.3.1 and later 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.
|
|
99
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.
|
|
100
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.
|
|
101
101
|
- Development checkouts (`packages/cli`, Desktop test packs) and the published global install are different binaries; compare behaviour with one style at a time.
|
|
@@ -120,17 +120,46 @@ Scaffold a project with flags for every choice (interactive prompts only on a TT
|
|
|
120
120
|
| `--link` / `--no-link` | After scaffolding, run `stagepass link` (macOS only). Default: off; interactive macOS may offer it. |
|
|
121
121
|
| `--git` / `--no-git` | `git init` (default: yes). |
|
|
122
122
|
| `--remote <url>` | Set `origin` after git init (rejects URLs with embedded credentials). |
|
|
123
|
+
| `--cursor-rule` | Write `.cursor/rules/stagepass.mdc` even when the target has no `.cursor/` directory. Without this flag the rule is written only if `.cursor/` already exists. |
|
|
123
124
|
| `--install` / `--no-install` | Run `npm install` (default: no). |
|
|
124
125
|
| `-y, --yes` | Non-interactive; use defaults for omitted flags. |
|
|
125
126
|
| `--dry-run` | Print the file plan without writing. |
|
|
126
127
|
|
|
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`,
|
|
128
|
+
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`, `AGENTS.stagepass.md` (the CLI-owned guide), a short pointer in `AGENTS.md`, and a `.gitignore`. `.cursor/rules/stagepass.mdc` (`alwaysApply: true`, pointer to `@AGENTS.stagepass.md`) is written only when the target already has a `.cursor/` directory or you pass `--cursor-rule`. `@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`.
|
|
128
129
|
|
|
129
130
|
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
|
|
|
131
132
|
### PHP
|
|
132
133
|
|
|
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`
|
|
134
|
+
`--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` sits in the same folder as `api/`. That folder is the document root (the project root locally, `dist/` after `stagepass build`). Copy `api/.env.example` to `.env` in the project root (or use `.php/.env`) and set `ALLOWED_ORIGINS` (include `https://<name>.sp`). There is no mail. `load_config()` reads that project-root `.env` and `.php/.env`. It never reads `api/.env`.
|
|
135
|
+
|
|
136
|
+
Caddy already returns 404 for any path segment that starts with `.` (`/.env`, `/api/.env`, `/.php/`). Since 2.4.1, `stagepass new --php` ships a web-root `.htaccess` with the Apache rule below, and `stagepass build` copies it into `dist/` when the project has one. CLI 2.4.0 and older do not ship that file. `stagepass new` refuses to overwrite an existing `.htaccess`. nginx does not read `.htaccess`; add the snippet below in the server block before `location ~ \.php$`. Prefer real environment variables so a `.env` file is not required in the web root.
|
|
137
|
+
|
|
138
|
+
`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/` to `dist/api/`, `.php/config.php` to `dist/.php/config.php`, and a project-root `.htaccess` to `dist/.htaccess` when `"php": true` and the file exists. It does not copy `.env`, `.php/.env`, or `.php/rate-limit/`. The copy also skips logs, pid files, and key, certificate, or database files (`.pem`, `.key`, `.p12`, `.pfx`, `.crt`, `.cer`, `.sqlite`, `.db`). It keeps `.htaccess` and `.env.example`. A `dist/.htaccess` already on disk stays when the project has none. Upload `dist/` (the folder that contains `api/`). That folder is the web root, so `.php/` is public on Apache and nginx unless hidden paths are denied. The public URL stays `/api/action.php`.
|
|
139
|
+
|
|
140
|
+
Apache, in the web root `.htaccess`. `AllowOverride All` and `mod_rewrite` are required. The rule follows HTML5 Boilerplate [`file_access.conf`](https://github.com/h5bp/server-configs-apache/blob/main/h5bp/security/file_access.conf), wrapped in `IfModule`:
|
|
141
|
+
|
|
142
|
+
```apache
|
|
143
|
+
<IfModule mod_rewrite.c>
|
|
144
|
+
RewriteEngine On
|
|
145
|
+
RewriteCond %{REQUEST_URI} "!(^|/)\.well-known/([^./]+./?)+$" [NC]
|
|
146
|
+
RewriteCond %{SCRIPT_FILENAME} -d [OR]
|
|
147
|
+
RewriteCond %{SCRIPT_FILENAME} -f
|
|
148
|
+
RewriteRule "(^|/)\." - [F]
|
|
149
|
+
</IfModule>
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
nginx, inside the server block, before the PHP `location ~ \.php$` block. If this location comes later, `/.php/config.php` can be passed to php-fpm. The rule follows HTML5 Boilerplate [`security_file_access.conf`](https://github.com/h5bp/server-configs-nginx/blob/main/h5bp/location/security_file_access.conf):
|
|
153
|
+
|
|
154
|
+
```nginx
|
|
155
|
+
location ~* /\.(?!well-known\/) {
|
|
156
|
+
deny all;
|
|
157
|
+
}
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
Both rules were tested on 12 November 2026 on php:8.2-apache (`AllowOverride All`, `a2enmod rewrite`) and on nginx 1.27 with php:8.2-fpm. `/.env`, `/.php/config.php`, `/api/.env.example`, and `/.git/HEAD` returned HTTP 403, with no secret or config leak. `/api/action.php?action=ping` returned HTTP 200, `{"status":"success","data":{"pong":true},"message":null}`. `/.well-known/test.txt` returned HTTP 200, body `well-known-ok`. `/.well-known/` as a directory with no index file returned HTTP 403 on both servers (no DirectoryIndex). Visible files under `/.well-known/` stay reachable. CLI 2.4.0 and older still need these rules added by hand. Since 2.4.1 the Apache rule ships in the PHP scaffold, and `stagepass upgrade` writes a missing project `.htaccess` when `"php": true` ([quYArF43](https://trello.com/c/quYArF43)). nginx still needs the snippet on the host.
|
|
161
|
+
|
|
162
|
+
`stagepass dev` / `watch` serve PHP from the project root, so edits show up on the next request. When `"php": true`, `stagepass dev` also watches `api/` and `.php/` and reloads the browser on that same live-reload stream and debounce as `dist/`. It ignores `.env`, `.php/.env`, `.php/rate-limit/`, logs, pid files, key, certificate, and database files (`.pem`, `.key`, `.p12`, `.pfx`, `.crt`, `.cer`, `.sqlite`, `.db`), and editor temp files (`~`, `.swp`, `.DS_Store`). A missing `api/` or `.php/` does not stop the command. The start log names those directories. Without `"php": true` live reload stays on the output directory. From the folder that contains `api/`, `php -S 127.0.0.1:8080 -t .` matches `/api/action.php`. `php -S` does not apply Caddy's hidden-path 404. Do not point it at a folder that already contains a real `.env`. Prefer `stagepass dev` or the linked `.sp` domain. `sp.resolveLocalUrl` returns a URL only during an active `.sp` session. On Webflow, `window.location.origin` is the Webflow host, which does not run PHP. Fetch the absolute PHP host, for example `https://php.example.com/api/action.php`. `rate_limit_allows()` logs storage faults (directory, file, `flock`, or a thrown error). The response is HTTP 503, JSend `error`, `Retry-After: 60`, and no internals, unless `APP_ENV` is `local`, `development`, or `dev` (trimmed, any case). Empty, unset, and every other value stay closed. A limit hit stays HTTP 429. `client_ip()` uses `REMOTE_ADDR` unless that peer is in `TRUSTED_PROXIES`, then reads `TRUSTED_PROXY_HEADER` (`x-forwarded-for` or RFC 7239 `forwarded`) from right to left. This applies to projects created with CLI 2.5.0. CLI 2.4.1 and older stay fail-open and use only `REMOTE_ADDR`. `stagepass upgrade` does not change `api/`. Copy `api/lib/security.php`, `api/lib/request.php`, `api/lib/config.php`, `.php/config.php`, and `api/action.php` from a new scaffold, or re-scaffold. [sgt7wKlT](https://trello.com/c/sgt7wKlT). `stagepass upgrade` does not add the `api/` or `.php/` boilerplate. When `"php": true` and the project root has no `.htaccess`, it writes the shipped template (same bytes as `stagepass new --php`). An existing `.htaccess` is left unchanged. If that file has no `RewriteRule "(^|/)\." - [F]` line, upgrade prints a hint and still exits 0. CLI 2.4.0 and older do not write that file. The website guide is live at [https://stagepass.one/docs/php/](https://stagepass.one/docs/php/) (source outline: [docs/php.md](https://github.com/arobertherz/stagepass/blob/master/docs/php.md)).
|
|
134
163
|
|
|
135
164
|
### Declared modules (`stagepass.json`)
|
|
136
165
|
|
|
@@ -140,9 +169,10 @@ Interactively (macOS), `new` runs a read-only `doctor` preflight and can offer `
|
|
|
140
169
|
|
|
141
170
|
`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:
|
|
142
171
|
|
|
143
|
-
-
|
|
144
|
-
-
|
|
145
|
-
-
|
|
172
|
+
- `AGENTS.stagepass.md` (CLI-owned): feature set, safe rules, local workflow, editor types, the loader API, full sections for declared modules, a "not available; enable by …" line for the others, and the rule never to use undeclared `sp.<module>`. When `stagepass.json` has `"php": true` and `api/lib/` is present, it also documents the PHP helpers. The first line is `<!-- stagepass:managed cli=<version> sha256=<body> -->`. Do not edit it by hand. `stagepass upgrade` rewrites it. Your notes belong in `AGENTS.md`.
|
|
173
|
+
- a short pointer in `AGENTS.md` (between `<!-- stagepass:begin -->` and `<!-- stagepass:end -->`) that tells agents to read `AGENTS.stagepass.md`;
|
|
174
|
+
- `.cursor/rules/stagepass.mdc` with `alwaysApply: true` and a pointer to `@AGENTS.stagepass.md`, only when `.cursor/` already exists or `--cursor-rule` is set (`AGENTS.md` stays the tool-neutral guide);
|
|
175
|
+
- `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. Published `@stagepass/loader` 2.5.0 `global.d.ts` augments `Window` with `sp` and `stagepass` (both `StagepassAPI`) and declares global `var sp` / `var stagepass`. The scaffold `src/main.ts` still narrows `sp` to `log` for the ready line. The official types are wider.
|
|
146
176
|
|
|
147
177
|
The legacy boolean `"modules": true|false` is still read; `upgrade` replaces it with a list (`true` becomes `["all"]` without a TTY).
|
|
148
178
|
|
|
@@ -163,16 +193,30 @@ Still not recognised: tags without `src`, `data-src` only, other hosts without a
|
|
|
163
193
|
| `--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. |
|
|
164
194
|
| `--site-modules <list>` | Set the modules list directly (`none`, `all`, or a comma list). |
|
|
165
195
|
| `--skip-site` | Do not fetch the live site. |
|
|
166
|
-
| `-y, --yes` | Accept the detected or existing list without asking.
|
|
196
|
+
| `-y, --yes` | Accept the detected or existing list without asking. Also replaces an unmodified `scripts/build.mjs`, and a hand-edited `AGENTS.stagepass.md`. Required for those replacements when there is no TTY. |
|
|
167
197
|
| `--dry-run` | Print every planned change; write no file. |
|
|
198
|
+
| `--cursor-rule` | Write `.cursor/rules/stagepass.mdc` even when the project has no `.cursor/` directory. |
|
|
168
199
|
|
|
169
200
|
`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:
|
|
170
201
|
|
|
171
202
|
- `stagepass.json`: writes the `modules` list.
|
|
172
|
-
- `AGENTS.md`: created
|
|
173
|
-
-
|
|
174
|
-
-
|
|
175
|
-
- `
|
|
203
|
+
- `AGENTS.stagepass.md`: created when missing. Rewritten when the managed hash still matches and the generated text changed. A hand edit (hash mismatch, or no `stagepass:managed` header) is replaced only with `--yes` or a TTY confirmation (default yes). Without a TTY and without `--yes`, the file stays and the CLI prints a hint that names `--yes`. A second run writes nothing when the file is already current. A symlink is left unchanged.
|
|
204
|
+
- `AGENTS.md`: created if missing (title plus the short pointer). Otherwise only the pointer between the markers is replaced, or appended when there are none. Text outside the markers stays byte for byte, including older generated sections. Upgrade prints a hint when those older sections are still outside the markers. Broken markers are left alone with a hint.
|
|
205
|
+
- `.cursor/rules/stagepass.mdc`: not created unless `.cursor/` already exists or `--cursor-rule` is set. An existing rule is never deleted. With stagepass markers, only the managed block is refreshed (`alwaysApply: true`, pointer to `@AGENTS.stagepass.md`). The previous generated frontmatter (`globs: src/**`, `alwaysApply: false`) is updated when it is still unchanged. A rule without markers is left alone. `stagepass doctor` does not warn about a missing rule when `.cursor/` is absent. When `.cursor/` exists, a missing or stale rule is a warning.
|
|
206
|
+
- `CLAUDE.md`: when the file already exists, the same short pointer is inserted or refreshed. The file is not created.
|
|
207
|
+
- `tsconfig.json` / `jsconfig.json`: a plain JSON file that already has `compilerOptions.types` is updated in place. The rest of the JSON is preserved. Comments, invalid JSON, and a missing `types` array are not edited. See [Types in existing projects](#types-in-existing-projects).
|
|
208
|
+
- `scripts/build.mjs`: replaced 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 TTY prompt defaults to yes. `--yes` replaces it without asking, including when there is no TTY. Without a TTY and without `--yes`, the file stays and the CLI prints a hint that names `--yes`. `--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. CLI 2.4.1 and older replace it even without a TTY and without `--yes`.
|
|
209
|
+
|
|
210
|
+
Those two replacements (`scripts/build.mjs` when it is still a known scaffold, and `AGENTS.stagepass.md` when it was edited by hand or has no managed header) are the upgrade writes that wait for a TTY answer or `--yes`. A managed `AGENTS.stagepass.md` whose hash still matches is refreshed without asking. The others stay non-interactive, with or without a TTY: `package.json` range updates, missing `@stagepass/loader` and `@stagepass/modules` devDependencies (an existing spec is not removed), `stagepass.d.ts` when the file is missing or already has the `// @stagepass-types` marker, and a missing `.htaccess` when `"php": true`. Those do not replace a hand-edited source file. A custom `scripts/build.mjs`, a `stagepass.d.ts` without the marker, and an existing `.htaccess` stay as they are. `upgrade --json` matches CLI 2.4.0 and later: the flag is unknown, stdout is empty, and nothing is written. There is no JSON object on that command.
|
|
211
|
+
- `.htaccess`: since 2.4.1, when `stagepass.json` has `"php": true` and the project root has no `.htaccess`, upgrade writes the shipped template (same bytes as `stagepass new --php`). An existing file is not modified. If it has no `RewriteRule "(^|/)\." - [F]` line, a hint points at https://stagepass.one/docs/php/ and `api/README.md` and the command still exits 0. A symlink or directory at that name is left in place. Projects without `"php": true` are unchanged. `--dry-run` writes nothing. CLI 2.4.0 and older do not write this file.
|
|
212
|
+
|
|
213
|
+
### Types in existing projects
|
|
214
|
+
|
|
215
|
+
Since 2.5.0, when the editor reports `Cannot find name 'sp'` and the page still runs, run `stagepass upgrade`. CLI 2.4.1 and older only update a plain `compilerOptions.types` array. Upgrade writes `package.json` only. It does not run `npm install`.
|
|
216
|
+
|
|
217
|
+
1. `stagepass upgrade` (`--dry-run` prints the plan and writes nothing). `@stagepass/loader` is added to `devDependencies` when it is missing. `@stagepass/modules` is added only when the declared module list is not empty. A plain `tsconfig.json` or `jsconfig.json` that already has a `types` array is updated. Otherwise upgrade writes `stagepass.d.ts` (first line `// @stagepass-types`) with `/// <reference types="..." />` lines, at the project root when that path is included, or under a directory `include` already covers. A config with comments or invalid JSON is not edited. If `include` or `files` would not cover the reference file, upgrade reports that and leaves the config unchanged. A `stagepass.d.ts` without the marker is left unchanged. With no `tsconfig.json` or `jsconfig.json`, the reference file is still written at the project root. Upgrade does not create a config. Editors load `stagepass.d.ts` only as part of a project, so the command prints a note (also on `--dry-run`): add a `jsconfig.json` or `tsconfig.json` that includes your sources, for example `{"include": ["src", "stagepass.d.ts"]}`, then run `stagepass upgrade` again. A missing `stagepass.json` does not skip this step.
|
|
218
|
+
2. `npm install`
|
|
219
|
+
3. In the editor command palette: `TypeScript: Restart TS Server`.
|
|
176
220
|
|
|
177
221
|
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.
|
|
178
222
|
|
|
@@ -293,7 +337,7 @@ The v3 block needs Caddy 2.9 or newer (`brew upgrade caddy`). Homebrew does not
|
|
|
293
337
|
| 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). |
|
|
294
338
|
| 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. |
|
|
295
339
|
| 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`. |
|
|
340
|
+
| Login autostart points at a deleted Homebrew Node, or `doctor` warns that the daemon version differs from the CLI | Published CLI 2.3.1 and later. 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`. |
|
|
297
341
|
| `stagepass start` spinner floods the terminal (weird ANSI) | Upgrade to a build with the spinner geometry guard. Rare with TTY width `0`. |
|
|
298
342
|
| `start` asks for a password at every boot | There is no unconditional `sudo -v`. Only confirmed conflict resolution may use `sudo kill` / `apachectl`. |
|
|
299
343
|
| 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
|
@@ -323,13 +323,14 @@ export function createProgram(deps = {}) {
|
|
|
323
323
|
program
|
|
324
324
|
.command('upgrade')
|
|
325
325
|
.description(
|
|
326
|
-
'Bump @stagepass/*, sync project files, replace an unmodified scripts/build.mjs, print Webflow snippets'
|
|
326
|
+
'Bump @stagepass/*, sync project files, replace an unmodified scripts/build.mjs, add a missing PHP .htaccess, print Webflow snippets'
|
|
327
327
|
)
|
|
328
328
|
.option('--dry-run', 'Show changes without writing any file')
|
|
329
|
+
.option('--cursor-rule', 'Write .cursor/rules/stagepass.mdc even when .cursor/ is absent')
|
|
329
330
|
.option('--site <host>', 'Live Webflow site to detect loaded modules from (https)')
|
|
330
331
|
.option('--site-modules <list>', 'Modules the site loads: none, all, or inject,cookies,maintenance')
|
|
331
332
|
.option('--skip-site', 'Do not fetch the live site')
|
|
332
|
-
.option('-y, --yes', 'Non-interactive; accept detected or existing modules and an unmodified scripts/build.mjs')
|
|
333
|
+
.option('-y, --yes', 'Non-interactive; accept detected or existing modules and replace an unmodified scripts/build.mjs')
|
|
333
334
|
.option(
|
|
334
335
|
'--target <version>',
|
|
335
336
|
'Target version, range or dist-tag; must be published on npm (default: ^<latest published 2.x>, ^2 offline)'
|
|
@@ -397,6 +398,7 @@ export function createProgram(deps = {}) {
|
|
|
397
398
|
.option('--git', 'Initialize a git repository')
|
|
398
399
|
.option('--no-git', 'Do not initialize git')
|
|
399
400
|
.option('--remote <url>', 'Git remote URL (requires git)')
|
|
401
|
+
.option('--cursor-rule', 'Write .cursor/rules/stagepass.mdc even when .cursor/ is absent')
|
|
400
402
|
.option('--install', 'Run npm install after scaffolding')
|
|
401
403
|
.option('--no-install', 'Do not run npm install (default)')
|
|
402
404
|
.option('-y, --yes', 'Non-interactive; accept defaults for omitted flags')
|
package/src/commands/dev.js
CHANGED
|
@@ -15,8 +15,8 @@ import {
|
|
|
15
15
|
clearStaleDevPorts,
|
|
16
16
|
} from '../lib/projects.js';
|
|
17
17
|
import { applySiteBlock } from '../lib/apply-site-block.js';
|
|
18
|
-
import { createLiveServer, resolveOutputDir } from '../lib/live-server.js';
|
|
19
|
-
import { readStagepassJson } from '../lib/project-sync.js';
|
|
18
|
+
import { createLiveServer, resolveOutputDir, PHP_WATCH_DIRS } from '../lib/live-server.js';
|
|
19
|
+
import { phpFromStagepassConfig, 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';
|
|
@@ -159,6 +159,7 @@ export async function dev(options = {}, deps = {}) {
|
|
|
159
159
|
/** @type {NodeJS.Signals | null} */
|
|
160
160
|
let stopSignal = null;
|
|
161
161
|
let setupDone = false;
|
|
162
|
+
let phpLive = false;
|
|
162
163
|
|
|
163
164
|
try {
|
|
164
165
|
let project = await getProject(domain, projectsPath);
|
|
@@ -205,6 +206,9 @@ export async function dev(options = {}, deps = {}) {
|
|
|
205
206
|
return 1;
|
|
206
207
|
}
|
|
207
208
|
|
|
209
|
+
const stagepass = await readStagepassJson(cwd, fse);
|
|
210
|
+
phpLive = phpFromStagepassConfig(stagepass.data) === true;
|
|
211
|
+
|
|
208
212
|
if (options.verbose) {
|
|
209
213
|
log(chalk.dim(`Live reload watching ${outDir.rel}/ → https://${domain}/__stagepass/live`));
|
|
210
214
|
}
|
|
@@ -213,6 +217,7 @@ export async function dev(options = {}, deps = {}) {
|
|
|
213
217
|
const server = createServer({
|
|
214
218
|
projectRoot: rootCheck.path,
|
|
215
219
|
outDir: outDir.rel,
|
|
220
|
+
php: phpLive,
|
|
216
221
|
log: options.verbose ? (m) => log(chalk.dim(m)) : () => {},
|
|
217
222
|
});
|
|
218
223
|
live = await server.listen(0);
|
|
@@ -343,6 +348,10 @@ export async function dev(options = {}, deps = {}) {
|
|
|
343
348
|
});
|
|
344
349
|
|
|
345
350
|
log(chalk.green(`Live reload on https://${domain}/__stagepass/live (127.0.0.1:${live.port})`));
|
|
351
|
+
if (phpLive) {
|
|
352
|
+
const names = PHP_WATCH_DIRS.map((dir) => `${dir}/`).join(' and ');
|
|
353
|
+
log(chalk.dim(`Live reload also watching ${names}`));
|
|
354
|
+
}
|
|
346
355
|
if (options.verbose) {
|
|
347
356
|
log(chalk.dim('Running: npm run watch'));
|
|
348
357
|
}
|
package/src/commands/new.js
CHANGED
|
@@ -20,8 +20,9 @@ import {
|
|
|
20
20
|
printWebflowSnippets,
|
|
21
21
|
} from '../lib/snippets.js';
|
|
22
22
|
|
|
23
|
-
import {
|
|
23
|
+
import { SNIPPET_LOADER_VERSION } from '../lib/cdn-base.js';
|
|
24
24
|
import { formatModules, normalizeModulesList } from '../lib/project-modules.js';
|
|
25
|
+
import { cursorDirPresent } from '../lib/project-sync.js';
|
|
25
26
|
import { describeDetection, detectSite, normalizeSiteUrl } from '../lib/site-detect.js';
|
|
26
27
|
import {
|
|
27
28
|
PACKAGES_MAJOR_RANGE,
|
|
@@ -438,8 +439,8 @@ export async function resolveNewOptions(nameArg, options = {}, deps = {}) {
|
|
|
438
439
|
remote: remoteCheck.remote,
|
|
439
440
|
install,
|
|
440
441
|
dryRun: options.dryRun === true,
|
|
441
|
-
|
|
442
|
-
|
|
442
|
+
cursorRule: options.cursorRule === true,
|
|
443
|
+
loaderVersion: deps.packagesVersion || SNIPPET_LOADER_VERSION,
|
|
443
444
|
},
|
|
444
445
|
};
|
|
445
446
|
}
|
|
@@ -653,6 +654,9 @@ export async function createNew(nameArg, options = {}, deps = {}) {
|
|
|
653
654
|
const targetDir = path.isAbsolute(config.dir)
|
|
654
655
|
? config.dir
|
|
655
656
|
: path.resolve(cwd, config.dir);
|
|
657
|
+
if (config.cursorRule !== true) {
|
|
658
|
+
config.cursorRule = await cursorDirPresent(targetDir, fse);
|
|
659
|
+
}
|
|
656
660
|
|
|
657
661
|
const templatesRootResolved = path.resolve(templatesRoot);
|
|
658
662
|
const readTemplate = async (rel) => {
|
|
@@ -847,6 +851,9 @@ export async function createNew(nameArg, options = {}, deps = {}) {
|
|
|
847
851
|
const snippets = buildWebflowSnippets({
|
|
848
852
|
version: config.loaderVersion,
|
|
849
853
|
moduleList: config.siteModules,
|
|
854
|
+
gitRemote: config.git ? config.remote || '' : '',
|
|
855
|
+
gitBranch: config.git ? 'main' : '',
|
|
856
|
+
projectName: config.name,
|
|
850
857
|
});
|
|
851
858
|
printWebflowSnippets(snippets, log);
|
|
852
859
|
|
package/src/commands/start.js
CHANGED
|
@@ -26,8 +26,24 @@ import {
|
|
|
26
26
|
LAUNCH_AGENT_LABEL,
|
|
27
27
|
} from '../lib/autostart.js';
|
|
28
28
|
import { ensurePhpFpm } from '../lib/php-fpm.js';
|
|
29
|
+
import { buildOfficialHeadSnippets, printWebflowHeadSnippets } from '../lib/snippets.js';
|
|
30
|
+
import { declaredModules, readStagepassJson } from '../lib/project-sync.js';
|
|
29
31
|
import { certsTrust, certsRenew } from './certs.js';
|
|
30
32
|
|
|
33
|
+
/**
|
|
34
|
+
* Loader plus the modules declared in this project's stagepass.json.
|
|
35
|
+
* @param {string} cwd
|
|
36
|
+
*/
|
|
37
|
+
async function printStartHeadSnippets(cwd) {
|
|
38
|
+
const sp = await readStagepassJson(cwd);
|
|
39
|
+
const declared = declaredModules(sp.data);
|
|
40
|
+
const moduleList = Array.isArray(declared) ? declared : [];
|
|
41
|
+
printWebflowHeadSnippets(buildOfficialHeadSnippets({ moduleList }));
|
|
42
|
+
if (moduleList.length === 0) {
|
|
43
|
+
console.log('No modules are declared in stagepass.json.');
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
31
47
|
const PORT_IGNORE = ['Google Chrome', 'Chrome Helper', 'OneDrive', 'Music', 'Safari', 'caddy'];
|
|
32
48
|
|
|
33
49
|
/**
|
|
@@ -412,6 +428,7 @@ export async function start(options = {}) {
|
|
|
412
428
|
return 1;
|
|
413
429
|
}
|
|
414
430
|
}
|
|
431
|
+
let kickstarted = false;
|
|
415
432
|
try {
|
|
416
433
|
await exec('launchctl', buildLaunchctlKickstartArgs(uid));
|
|
417
434
|
if (!options.verbose) {
|
|
@@ -426,7 +443,7 @@ export async function start(options = {}) {
|
|
|
426
443
|
chalk.green(`✔ kickstart gui/${uid}/${LAUNCH_AGENT_LABEL}`)
|
|
427
444
|
);
|
|
428
445
|
}
|
|
429
|
-
|
|
446
|
+
kickstarted = true;
|
|
430
447
|
} catch (error) {
|
|
431
448
|
if (!options.verbose) spinner.fail('launchctl kickstart failed.');
|
|
432
449
|
console.log(
|
|
@@ -435,6 +452,10 @@ export async function start(options = {}) {
|
|
|
435
452
|
console.log(chalk.dim('Falling back to direct caddy start...'));
|
|
436
453
|
if (!options.verbose) spinner.start('Booting background services...');
|
|
437
454
|
}
|
|
455
|
+
if (kickstarted) {
|
|
456
|
+
await printStartHeadSnippets(options.cwd || process.cwd());
|
|
457
|
+
return 0;
|
|
458
|
+
}
|
|
438
459
|
}
|
|
439
460
|
|
|
440
461
|
// Direct caddy start (no LaunchAgent)
|
|
@@ -454,6 +475,7 @@ export async function start(options = {}) {
|
|
|
454
475
|
} else {
|
|
455
476
|
console.log(chalk.green('✔ Stagepass is active.'));
|
|
456
477
|
}
|
|
478
|
+
await printStartHeadSnippets(options.cwd || process.cwd());
|
|
457
479
|
return 0;
|
|
458
480
|
} catch (error) {
|
|
459
481
|
if (!options.verbose) spinner.fail('Failed to start.');
|