@stagepass/cli 2.0.0 → 2.2.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 +87 -7
- package/TESTING-macos.md +58 -0
- package/bin/index.js +2 -2
- package/package.json +3 -1
- package/src/cli.js +204 -0
- package/src/commands/autostart.js +85 -0
- package/src/commands/certs.js +185 -0
- package/src/commands/daemon.js +126 -0
- package/src/commands/doctor.js +57 -0
- package/src/commands/new.js +455 -0
- package/src/commands/npm-run.js +84 -0
- package/src/commands/stop.js +15 -0
- package/src/commands/upgrade.js +276 -0
- package/src/lib/ai-guide.js +161 -0
- package/src/lib/autostart.js +360 -0
- package/src/lib/cdn-snippets.js +27 -0
- package/src/lib/certs.js +476 -0
- package/src/lib/doctor-site.js +89 -0
- package/src/lib/doctor.js +521 -0
- package/src/lib/exec.js +71 -0
- package/src/lib/paths.js +58 -0
- package/src/lib/platform.js +47 -0
- package/src/lib/project-modules.js +98 -0
- package/src/lib/project-name.js +47 -0
- package/src/lib/project-sync.js +394 -0
- package/src/lib/remote-url.js +63 -0
- package/src/lib/scaffold.js +212 -0
- package/src/lib/site-detect.js +242 -0
- package/src/lib/snippets.js +94 -0
- package/src/lib/spawn.js +30 -0
- package/src/lib/versions.js +27 -0
- package/templates/project/AGENTS.md.tmpl +39 -0
- package/templates/project/README.md.tmpl +44 -0
- package/templates/project/gitignore +7 -0
- package/templates/project/jsconfig.json.tmpl +14 -0
- package/templates/project/scripts/build.mjs +110 -0
- package/templates/project/src/main.js.tmpl +29 -0
- package/templates/project/src/main.ts.tmpl +29 -0
- package/templates/project/src/styles.css.tmpl +8 -0
- package/templates/project/src/styles.scss.tmpl +8 -0
- package/templates/project/stagepass.json.tmpl +8 -0
- package/templates/project/tsconfig.json.tmpl +13 -0
package/README.md
CHANGED
|
@@ -6,24 +6,26 @@ The CLI sets up and manages the local Stagepass infrastructure (`.sp` domains, C
|
|
|
6
6
|
|
|
7
7
|
## Install
|
|
8
8
|
|
|
9
|
-
Requires Node.js **18+** (`engines.node`: `>=18.0.0`) on **macOS** with Homebrew.
|
|
9
|
+
Requires Node.js **18+** (`engines.node`: `>=18.0.0`) on **macOS** with Homebrew. Development and CI use Node 22 or 24; the published package keeps `engines.node` at `>=18.0.0` so existing consumers are not broken by an engines bump.
|
|
10
10
|
|
|
11
11
|
```bash
|
|
12
|
-
npm install -g @stagepass/cli@2
|
|
12
|
+
npm install -g @stagepass/cli@2
|
|
13
13
|
```
|
|
14
14
|
|
|
15
15
|
Or without a global install:
|
|
16
16
|
|
|
17
17
|
```bash
|
|
18
|
-
npx @stagepass/cli@2
|
|
18
|
+
npx @stagepass/cli@2 setup
|
|
19
19
|
```
|
|
20
20
|
|
|
21
21
|
## Requirements
|
|
22
22
|
|
|
23
|
-
- macOS
|
|
24
|
-
- Node.js 18+
|
|
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
|
+
- Node.js 18+ at runtime (`engines.node`); use Node 22 or 24 for local development and CI
|
|
25
25
|
- Homebrew
|
|
26
26
|
|
|
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).
|
|
28
|
+
|
|
27
29
|
## Quick Start
|
|
28
30
|
|
|
29
31
|
Recommended order:
|
|
@@ -51,9 +53,87 @@ Linked: https://my-project.sp -> /absolute/path/to/project
|
|
|
51
53
|
| `stagepass link [domain]` | Link the current directory to a `.sp` domain, write/update the Caddyfile + `~/.stagepass/projects.json`, reload Caddy. |
|
|
52
54
|
| `stagepass unlink [domain]` | Remove the site block and `projects.json` entry, reload Caddy. |
|
|
53
55
|
| `stagepass reload` | Reload Caddy configuration. Migrates legacy Caddyfile blocks if needed. |
|
|
54
|
-
| `stagepass stop` | Stop background services. |
|
|
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, plus the current project's declared modules vs. its live site). Never uses sudo. `--json`, `--skip-site`. Exit `1` if any fail. |
|
|
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
|
+
| `stagepass certs trust` | Run `caddy trust` after interactive confirmation (or `--yes`). |
|
|
60
|
+
| `stagepass autostart on\|off\|status` | Manage a user LaunchAgent (`io.github.arobertherz.stagepass`) that runs `stagepass daemon` at login. |
|
|
61
|
+
| `stagepass daemon` | Non-interactive foreground helper for the LaunchAgent (certs check log-only, then `caddy run`). Never uses sudo. |
|
|
62
|
+
| `stagepass new [name]` | Scaffold a lean Webflow project (TypeScript + SCSS by default). |
|
|
63
|
+
| `stagepass build` | Run `npm run build` in the current project (forwards exit code). |
|
|
64
|
+
| `stagepass watch` | Run `npm run watch` in the current project (forwards exit code). |
|
|
65
|
+
| `stagepass upgrade` | Bump `@stagepass/*`, sync declared modules, `AGENTS.md`, the Cursor rule and `types`, print Webflow snippets. |
|
|
66
|
+
|
|
67
|
+
All commands support `-v, --verbose` where applicable.
|
|
68
|
+
|
|
69
|
+
### Doctor / certificates / autostart
|
|
70
|
+
|
|
71
|
+
- `doctor` and `certs check` are read-only. They never delete keychain items or certificate files.
|
|
72
|
+
- Prefer CDN major pin `@2` in Webflow custom code (doctor warns if recommended snippets would use `@latest`).
|
|
73
|
+
- Chrome may require Local Network Access permission for public HTTPS pages that load `https://*.sp` assets.
|
|
74
|
+
- Autostart runs as your user (same privilege model as `caddy start` inside `stagepass start`). If port 443 cannot be bound, `daemon` logs a clear error and exits `0` so launchd KeepAlive does not restart-loop. Use interactive `stagepass start` to resolve conflicts.
|
|
75
|
+
- Manual macOS checklist: [`TESTING-macos.md`](./TESTING-macos.md).
|
|
76
|
+
|
|
77
|
+
### `new` options
|
|
78
|
+
|
|
79
|
+
Scaffold a project with flags for every choice (interactive prompts only on a TTY without `--yes`):
|
|
80
|
+
|
|
81
|
+
| Option | Behaviour |
|
|
82
|
+
| :--- | :--- |
|
|
83
|
+
| `--dir <dir>` | Target directory (default: `./<name>`). |
|
|
84
|
+
| `--author <name>` | `package.json` author (default: `git config user.name`). |
|
|
85
|
+
| `--lang ts\|js` | Language (default: `ts`). |
|
|
86
|
+
| `--styles scss\|css` | Styles (default: `scss`). |
|
|
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`. |
|
|
90
|
+
| `--git` / `--no-git` | `git init` (default: yes). |
|
|
91
|
+
| `--remote <url>` | Set `origin` after git init (rejects URLs with embedded credentials). |
|
|
92
|
+
| `--install` / `--no-install` | Run `npm install` (default: no). |
|
|
93
|
+
| `-y, --yes` | Non-interactive; use defaults for omitted flags. |
|
|
94
|
+
| `--dry-run` | Print the file plan without writing. |
|
|
95
|
+
|
|
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.2.0` (same major as the CDN pin `@2`, minor that ships the per-module types).
|
|
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.
|
|
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.
|
|
117
|
+
|
|
118
|
+
### `upgrade` options
|
|
119
|
+
|
|
120
|
+
| Option | Behaviour |
|
|
121
|
+
| :--- | :--- |
|
|
122
|
+
| `--version <x>` | Target loader/modules version (default: the version this CLI targets, currently `2.2.0`). Dist-tags such as `latest` resolve via `npm view`. (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.
|
|
55
135
|
|
|
56
|
-
|
|
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.
|
|
57
137
|
|
|
58
138
|
### Domain argument (`link` / `unlink`)
|
|
59
139
|
|
package/TESTING-macos.md
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# macOS manual checklist (CLI operations)
|
|
2
|
+
|
|
3
|
+
Use this after installing a local build of `@stagepass/cli` on macOS with Homebrew.
|
|
4
|
+
|
|
5
|
+
## Prerequisites
|
|
6
|
+
|
|
7
|
+
- Node 18+ on PATH
|
|
8
|
+
- Homebrew installed
|
|
9
|
+
- A throwaway project folder (example: `~/Sites/my-project`)
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install -g . # from repo packages/cli, or use npx against the workspace build
|
|
13
|
+
stagepass setup
|
|
14
|
+
stagepass link my-project --origin my-project.webflow.io
|
|
15
|
+
stagepass start
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## doctor
|
|
19
|
+
|
|
20
|
+
- [ ] `stagepass doctor` prints ok/warn/fail lines and a summary
|
|
21
|
+
- [ ] Exit code is `0` when there are no fails; `1` when any fail
|
|
22
|
+
- [ ] `stagepass doctor --json` prints valid JSON with `checks` and `summary`
|
|
23
|
+
- [ ] Missing Homebrew / Caddy / PHP / dnsmasq surfaces as fail (temporarily rename binaries to verify)
|
|
24
|
+
- [ ] Missing `/etc/resolver/sp` surfaces as fail
|
|
25
|
+
- [ ] Port 443 section reports the listener (or warns if empty / permission denied). Doctor must never ask for sudo
|
|
26
|
+
- [ ] Linked project whose folder was deleted surfaces as fail
|
|
27
|
+
- [ ] Chrome Local Network Access hint is printed
|
|
28
|
+
- [ ] CDN check reports recommended snippets use `@2` (not `@latest`)
|
|
29
|
+
|
|
30
|
+
## certs
|
|
31
|
+
|
|
32
|
+
- [ ] `stagepass certs check` reports root path under `~/Library/Application Support/Caddy/pki/authorities/local/root.crt`
|
|
33
|
+
- [ ] Warns when root expires in under 90 days (use a lab machine or mock if needed)
|
|
34
|
+
- [ ] Reports System keychain trust status for "Caddy Local Authority"
|
|
35
|
+
- [ ] Orphaned old Caddy roots are listed with SHA-1 and SHA-256 (never deleted by the CLI)
|
|
36
|
+
- [ ] Optional TLS handshake lines appear for each linked `.sp` domain while Caddy is running
|
|
37
|
+
- [ ] `stagepass certs check --json` works
|
|
38
|
+
- [ ] `stagepass certs trust` asks for confirmation; declining does nothing
|
|
39
|
+
- [ ] `stagepass certs trust --yes` runs `caddy trust`
|
|
40
|
+
- [ ] After trust, Safari / Chrome / Firefox show a valid certificate for `https://my-project.sp`
|
|
41
|
+
- [ ] There is **no** `certs renew` command in 2.1.0
|
|
42
|
+
|
|
43
|
+
## autostart / daemon
|
|
44
|
+
|
|
45
|
+
- [ ] `stagepass autostart status` shows label `io.github.arobertherz.stagepass`
|
|
46
|
+
- [ ] `stagepass autostart on` writes `~/Library/LaunchAgents/io.github.arobertherz.stagepass.plist` with absolute node + CLI paths
|
|
47
|
+
- [ ] Plist has `RunAtLoad` and `KeepAlive` / `SuccessfulExit` false
|
|
48
|
+
- [ ] Logs appear under `~/.stagepass/logs/`
|
|
49
|
+
- [ ] After logout/login (or `launchctl bootstrap`), daemon starts Caddy via `caddy run`
|
|
50
|
+
- [ ] `stagepass stop` still stops services; when autostart is on it prints a hint that login may restart Caddy
|
|
51
|
+
- [ ] `stagepass autostart off` boots out the agent and removes the plist
|
|
52
|
+
- [ ] If port 443 cannot be bound, daemon logs a clear message and exits `0` (no KeepAlive restart-loop; not a silent success)
|
|
53
|
+
- [ ] Cold-start daemon logs cert root/trust only (no TLS handshake attempts before `caddy run`)
|
|
54
|
+
|
|
55
|
+
## Regression (must stay unchanged)
|
|
56
|
+
|
|
57
|
+
- [ ] `stagepass start` / `stop` / `link` / `unlink` / `reload` / `setup` behave as in 2.0.0
|
|
58
|
+
- [ ] No dependency major upgrades required for these commands
|
package/bin/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stagepass/cli",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "Local Development Orchestrator for Webflow",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "bin/index.js",
|
|
@@ -12,7 +12,9 @@
|
|
|
12
12
|
"src/cli.js",
|
|
13
13
|
"src/commands/*.js",
|
|
14
14
|
"src/lib/*.js",
|
|
15
|
+
"templates",
|
|
15
16
|
"README.md",
|
|
17
|
+
"TESTING-macos.md",
|
|
16
18
|
"LICENSE"
|
|
17
19
|
],
|
|
18
20
|
"scripts": {
|
package/src/cli.js
CHANGED
|
@@ -7,6 +7,20 @@ import { unlink as defaultUnlink } from './commands/unlink.js';
|
|
|
7
7
|
import { start as defaultStart } from './commands/start.js';
|
|
8
8
|
import { stop as defaultStop } from './commands/stop.js';
|
|
9
9
|
import { reload as defaultReload } from './commands/reload.js';
|
|
10
|
+
import { doctor as defaultDoctor } from './commands/doctor.js';
|
|
11
|
+
import {
|
|
12
|
+
certsCheck as defaultCertsCheck,
|
|
13
|
+
certsTrust as defaultCertsTrust,
|
|
14
|
+
} from './commands/certs.js';
|
|
15
|
+
import { autostart as defaultAutostart } from './commands/autostart.js';
|
|
16
|
+
import { daemon as defaultDaemon } from './commands/daemon.js';
|
|
17
|
+
import { upgrade as defaultUpgrade } from './commands/upgrade.js';
|
|
18
|
+
import {
|
|
19
|
+
watch as defaultWatch,
|
|
20
|
+
build as defaultBuild,
|
|
21
|
+
} from './commands/npm-run.js';
|
|
22
|
+
import { createNew as defaultCreateNew } from './commands/new.js';
|
|
23
|
+
import { assertSupportedPlatform } from './lib/platform.js';
|
|
10
24
|
|
|
11
25
|
const require = createRequire(import.meta.url);
|
|
12
26
|
const { version: packageVersion } = require('../package.json');
|
|
@@ -15,6 +29,37 @@ function collectRepeatable(value, previous) {
|
|
|
15
29
|
return previous.concat([value]);
|
|
16
30
|
}
|
|
17
31
|
|
|
32
|
+
/**
|
|
33
|
+
* Commander reserves root `--version` for the CLI version. Rewrite
|
|
34
|
+
* `stagepass upgrade --version <x>` to `--target` so the subcommand receives it.
|
|
35
|
+
* `stagepass --version` is unchanged.
|
|
36
|
+
*
|
|
37
|
+
* @param {string[]} argv
|
|
38
|
+
* @returns {string[]}
|
|
39
|
+
*/
|
|
40
|
+
export function rewriteArgvForUpgrade(argv) {
|
|
41
|
+
const out = [...argv];
|
|
42
|
+
// Prefer the first bare `upgrade` token after node/script.
|
|
43
|
+
let idx = -1;
|
|
44
|
+
for (let i = 2; i < out.length; i++) {
|
|
45
|
+
if (out[i] === 'upgrade') {
|
|
46
|
+
idx = i;
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
if (!String(out[i]).startsWith('-')) break;
|
|
50
|
+
}
|
|
51
|
+
if (idx === -1) return out;
|
|
52
|
+
|
|
53
|
+
for (let i = idx + 1; i < out.length; i++) {
|
|
54
|
+
if (out[i] === '--version' && out[i + 1] && !String(out[i + 1]).startsWith('-')) {
|
|
55
|
+
out[i] = '--target';
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
if (out[i] === '--') break;
|
|
59
|
+
}
|
|
60
|
+
return out;
|
|
61
|
+
}
|
|
62
|
+
|
|
18
63
|
/**
|
|
19
64
|
* Build the Commander program (no parse). Injectable handlers for unit tests.
|
|
20
65
|
*
|
|
@@ -25,7 +70,17 @@ function collectRepeatable(value, previous) {
|
|
|
25
70
|
* @param {typeof defaultStart} [deps.start]
|
|
26
71
|
* @param {typeof defaultStop} [deps.stop]
|
|
27
72
|
* @param {typeof defaultReload} [deps.reload]
|
|
73
|
+
* @param {typeof defaultDoctor} [deps.doctor]
|
|
74
|
+
* @param {typeof defaultCertsCheck} [deps.certsCheck]
|
|
75
|
+
* @param {typeof defaultCertsTrust} [deps.certsTrust]
|
|
76
|
+
* @param {typeof defaultAutostart} [deps.autostart]
|
|
77
|
+
* @param {typeof defaultDaemon} [deps.daemon]
|
|
78
|
+
* @param {typeof defaultUpgrade} [deps.upgrade]
|
|
79
|
+
* @param {typeof defaultWatch} [deps.watch]
|
|
80
|
+
* @param {typeof defaultBuild} [deps.build]
|
|
81
|
+
* @param {typeof defaultCreateNew} [deps.createNew]
|
|
28
82
|
* @param {string} [deps.version]
|
|
83
|
+
* @param {() => void} [deps.assertPlatform]
|
|
29
84
|
*/
|
|
30
85
|
export function createProgram(deps = {}) {
|
|
31
86
|
const setup = deps.setup || defaultSetup;
|
|
@@ -34,7 +89,18 @@ export function createProgram(deps = {}) {
|
|
|
34
89
|
const start = deps.start || defaultStart;
|
|
35
90
|
const stop = deps.stop || defaultStop;
|
|
36
91
|
const reload = deps.reload || defaultReload;
|
|
92
|
+
const doctor = deps.doctor || defaultDoctor;
|
|
93
|
+
const certsCheck = deps.certsCheck || defaultCertsCheck;
|
|
94
|
+
const certsTrust = deps.certsTrust || defaultCertsTrust;
|
|
95
|
+
const autostart = deps.autostart || defaultAutostart;
|
|
96
|
+
const daemon = deps.daemon || defaultDaemon;
|
|
97
|
+
const upgrade = deps.upgrade || defaultUpgrade;
|
|
98
|
+
const watch = deps.watch || defaultWatch;
|
|
99
|
+
const build = deps.build || defaultBuild;
|
|
100
|
+
const createNew = deps.createNew || defaultCreateNew;
|
|
37
101
|
const version = deps.version || packageVersion;
|
|
102
|
+
const assertPlatform =
|
|
103
|
+
deps.assertPlatform || (() => assertSupportedPlatform());
|
|
38
104
|
|
|
39
105
|
const program = new Command();
|
|
40
106
|
|
|
@@ -43,6 +109,11 @@ export function createProgram(deps = {}) {
|
|
|
43
109
|
.description('The missing link between Webflow and local dev.')
|
|
44
110
|
.version(version);
|
|
45
111
|
|
|
112
|
+
// Runs before every system command action. --help / --version never hit this.
|
|
113
|
+
program.hook('preAction', () => {
|
|
114
|
+
assertPlatform();
|
|
115
|
+
});
|
|
116
|
+
|
|
46
117
|
program
|
|
47
118
|
.command('setup')
|
|
48
119
|
.description('Install dependencies (Caddy, PHP, Dnsmasq) and configure .sp domain')
|
|
@@ -119,5 +190,138 @@ export function createProgram(deps = {}) {
|
|
|
119
190
|
await stop(options);
|
|
120
191
|
});
|
|
121
192
|
|
|
193
|
+
// --- Package 2: CLI operations (doctor, certs, autostart, daemon) ---
|
|
194
|
+
// Keep this block self-contained for easy merges with other cli.js changes.
|
|
195
|
+
program
|
|
196
|
+
.command('doctor')
|
|
197
|
+
.description('Diagnose the local Stagepass stack (read-only; never uses sudo)')
|
|
198
|
+
.option('-v, --verbose', 'Show extra detail for ok checks')
|
|
199
|
+
.option('--json', 'Machine-readable JSON output')
|
|
200
|
+
.option('--skip-site', 'Do not fetch the live site of the current project')
|
|
201
|
+
.action(async (options) => {
|
|
202
|
+
const code = await doctor(options);
|
|
203
|
+
process.exitCode = code;
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
const certsCmd = program
|
|
207
|
+
.command('certs')
|
|
208
|
+
.description('Certificate helpers for the Caddy local CA');
|
|
209
|
+
|
|
210
|
+
certsCmd
|
|
211
|
+
.command('check')
|
|
212
|
+
.description('Check Caddy local CA validity, trust, and optional TLS handshakes (read-only)')
|
|
213
|
+
.option('-v, --verbose', 'Show detailed output')
|
|
214
|
+
.option('--json', 'Machine-readable JSON output')
|
|
215
|
+
.option('--skip-handshake', 'Skip per-domain TLS handshake checks')
|
|
216
|
+
.action(async (options) => {
|
|
217
|
+
const code = await certsCheck(options);
|
|
218
|
+
process.exitCode = code;
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
certsCmd
|
|
222
|
+
.command('trust')
|
|
223
|
+
.description('Trust the Caddy local root CA via `caddy trust` (confirmation required)')
|
|
224
|
+
.option('-y, --yes', 'Skip interactive confirmation')
|
|
225
|
+
.option('-v, --verbose', 'Show detailed output')
|
|
226
|
+
.action(async (options) => {
|
|
227
|
+
const code = await certsTrust(options);
|
|
228
|
+
process.exitCode = code;
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
program
|
|
232
|
+
.command('autostart')
|
|
233
|
+
.description('Manage login LaunchAgent for Stagepass (macOS)')
|
|
234
|
+
.argument('<action>', 'on | off | status')
|
|
235
|
+
.option('-v, --verbose', 'Show detailed output')
|
|
236
|
+
.option('--json', 'JSON output for status')
|
|
237
|
+
.action(async (action, options) => {
|
|
238
|
+
const normalized = String(action || '').toLowerCase();
|
|
239
|
+
if (!['on', 'off', 'status'].includes(normalized)) {
|
|
240
|
+
console.error(chalk.red('Usage: stagepass autostart on|off|status'));
|
|
241
|
+
process.exitCode = 1;
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
const code = await autostart(normalized, options);
|
|
245
|
+
process.exitCode = code;
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
program
|
|
249
|
+
.command('daemon')
|
|
250
|
+
.description('Foreground daemon for LaunchAgent (non-interactive; never uses sudo)')
|
|
251
|
+
.action(async () => {
|
|
252
|
+
const code = await daemon();
|
|
253
|
+
process.exitCode = code;
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
// --- Package 3: project scaffold / npm wrappers / upgrade ---
|
|
257
|
+
// Keep this block self-contained for easy merges with other cli.js changes.
|
|
258
|
+
program
|
|
259
|
+
.command('upgrade')
|
|
260
|
+
.description(
|
|
261
|
+
'Bump @stagepass/*, sync modules, AGENTS.md, Cursor rule and types, print Webflow snippets'
|
|
262
|
+
)
|
|
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')
|
|
268
|
+
.option(
|
|
269
|
+
'--target <version>',
|
|
270
|
+
'Target loader/modules version (default: the version this CLI targets; dist-tags use npm view)'
|
|
271
|
+
)
|
|
272
|
+
// Public docs use `--version`; rewriteArgvForUpgrade maps it to `--target`
|
|
273
|
+
// so it does not collide with the root `stagepass --version` handler.
|
|
274
|
+
.option('-v, --verbose', 'Show detailed output')
|
|
275
|
+
.action(async (options) => {
|
|
276
|
+
const code = await upgrade({
|
|
277
|
+
...options,
|
|
278
|
+
version: options.target,
|
|
279
|
+
});
|
|
280
|
+
process.exitCode = code;
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
program
|
|
284
|
+
.command('watch')
|
|
285
|
+
.description('Run `npm run watch` in the current project')
|
|
286
|
+
.option('-v, --verbose', 'Show the underlying npm command')
|
|
287
|
+
.action(async (options) => {
|
|
288
|
+
const code = await watch(options);
|
|
289
|
+
process.exitCode = code;
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
program
|
|
293
|
+
.command('build')
|
|
294
|
+
.description('Run `npm run build` in the current project')
|
|
295
|
+
.option('-v, --verbose', 'Show the underlying npm command')
|
|
296
|
+
.action(async (options) => {
|
|
297
|
+
const code = await build(options);
|
|
298
|
+
process.exitCode = code;
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
program
|
|
302
|
+
.command('new')
|
|
303
|
+
.description('Scaffold a new Stagepass Webflow project')
|
|
304
|
+
.argument('[name]', 'DNS-safe project name')
|
|
305
|
+
.option('--dir <dir>', 'Target directory (default: ./<name>)')
|
|
306
|
+
.option('--author <author>', 'Author for package.json (default: git user.name)')
|
|
307
|
+
.option('--lang <lang>', 'ts or js (default: ts)')
|
|
308
|
+
.option('--styles <styles>', 'scss or css (default: scss)')
|
|
309
|
+
.option('--modules', 'Include @stagepass/modules (npm, types)')
|
|
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')
|
|
313
|
+
.option('--git', 'Initialize a git repository')
|
|
314
|
+
.option('--no-git', 'Do not initialize git')
|
|
315
|
+
.option('--remote <url>', 'Git remote URL (requires git)')
|
|
316
|
+
.option('--install', 'Run npm install after scaffolding')
|
|
317
|
+
.option('--no-install', 'Do not run npm install (default)')
|
|
318
|
+
.option('-y, --yes', 'Non-interactive; accept defaults for omitted flags')
|
|
319
|
+
.option('--dry-run', 'Print the file plan without writing')
|
|
320
|
+
.option('-v, --verbose', 'Show detailed output')
|
|
321
|
+
.action(async (name, options) => {
|
|
322
|
+
const code = await createNew(name, options);
|
|
323
|
+
process.exitCode = code;
|
|
324
|
+
});
|
|
325
|
+
|
|
122
326
|
return program;
|
|
123
327
|
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import {
|
|
3
|
+
enableAutostart,
|
|
4
|
+
disableAutostart,
|
|
5
|
+
getAutostartStatus,
|
|
6
|
+
LAUNCH_AGENT_LABEL,
|
|
7
|
+
} from '../lib/autostart.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @param {'on'|'off'|'status'} action
|
|
11
|
+
* @param {object} [options]
|
|
12
|
+
* @param {boolean} [options.verbose]
|
|
13
|
+
* @param {boolean} [options.json]
|
|
14
|
+
* @returns {Promise<number>}
|
|
15
|
+
*/
|
|
16
|
+
export async function autostart(action, options = {}) {
|
|
17
|
+
if (action === 'status') {
|
|
18
|
+
const status = await getAutostartStatus();
|
|
19
|
+
if (options.json) {
|
|
20
|
+
console.log(
|
|
21
|
+
JSON.stringify(
|
|
22
|
+
{
|
|
23
|
+
label: status.label,
|
|
24
|
+
plistPath: status.plistPath,
|
|
25
|
+
plistExists: status.plistExists,
|
|
26
|
+
loaded: status.loaded,
|
|
27
|
+
logsDir: status.logsDir,
|
|
28
|
+
},
|
|
29
|
+
null,
|
|
30
|
+
2
|
|
31
|
+
)
|
|
32
|
+
);
|
|
33
|
+
} else {
|
|
34
|
+
console.log(chalk.bold('\nStagepass autostart status\n'));
|
|
35
|
+
console.log(`Label: ${status.label}`);
|
|
36
|
+
console.log(`Plist: ${status.plistPath}`);
|
|
37
|
+
console.log(`Exists: ${status.plistExists ? 'yes' : 'no'}`);
|
|
38
|
+
console.log(`Loaded: ${status.loaded ? 'yes' : 'no'}`);
|
|
39
|
+
console.log(`Logs: ${status.logsDir}`);
|
|
40
|
+
if (!status.loaded && status.printError && options.verbose) {
|
|
41
|
+
console.log(chalk.dim(`launchctl: ${status.printError}`));
|
|
42
|
+
}
|
|
43
|
+
console.log(
|
|
44
|
+
chalk.dim(
|
|
45
|
+
'\nNote: the LaunchAgent runs as your user (same as `caddy start` in stagepass start).'
|
|
46
|
+
)
|
|
47
|
+
);
|
|
48
|
+
console.log(
|
|
49
|
+
chalk.dim(
|
|
50
|
+
'If port 443 bind fails, daemon logs the error and exits 0 so launchd KeepAlive does not restart-loop. Use stagepass start for interactive recovery.'
|
|
51
|
+
)
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
return 0;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (action === 'on') {
|
|
58
|
+
console.log(chalk.bold('\nEnabling Stagepass autostart...'));
|
|
59
|
+
const result = await enableAutostart();
|
|
60
|
+
if (!result.ok) {
|
|
61
|
+
console.log(chalk.red(`Failed: ${result.error}`));
|
|
62
|
+
return 1;
|
|
63
|
+
}
|
|
64
|
+
console.log(chalk.green(`LaunchAgent installed: ${result.plistPath}`));
|
|
65
|
+
console.log(chalk.dim(`Label: ${LAUNCH_AGENT_LABEL}`));
|
|
66
|
+
console.log(chalk.dim(`Node: ${result.paths.nodePath}`));
|
|
67
|
+
console.log(chalk.dim(`CLI: ${result.paths.cliPath}`));
|
|
68
|
+
console.log(
|
|
69
|
+
chalk.dim(
|
|
70
|
+
'Runs `stagepass daemon` at login (caddy run in the foreground). Never uses sudo.'
|
|
71
|
+
)
|
|
72
|
+
);
|
|
73
|
+
return 0;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (action === 'off') {
|
|
77
|
+
console.log(chalk.bold('\nDisabling Stagepass autostart...'));
|
|
78
|
+
const result = await disableAutostart();
|
|
79
|
+
console.log(chalk.green(`LaunchAgent removed: ${result.plistPath}`));
|
|
80
|
+
return 0;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
console.log(chalk.red(`Unknown autostart action: ${action}`));
|
|
84
|
+
return 1;
|
|
85
|
+
}
|