@stagepass/cli 2.0.0 → 2.1.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 +54 -7
- package/TESTING-macos.md +58 -0
- package/bin/index.js +2 -2
- package/package.json +3 -1
- package/src/cli.js +197 -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 +56 -0
- package/src/commands/new.js +368 -0
- package/src/commands/npm-run.js +84 -0
- package/src/commands/stop.js +15 -0
- package/src/commands/upgrade.js +198 -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.js +503 -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-name.js +47 -0
- package/src/lib/remote-url.js +63 -0
- package/src/lib/scaffold.js +186 -0
- package/src/lib/snippets.js +83 -0
- package/src/lib/spawn.js +30 -0
- package/templates/project/AGENTS.md.tmpl +37 -0
- package/templates/project/README.md.tmpl +44 -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,54 @@ 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). Never uses sudo. `--json` available. 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/*` in the current `package.json` and 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` (default: yes). |
|
|
88
|
+
| `--git` / `--no-git` | `git init` (default: yes). |
|
|
89
|
+
| `--remote <url>` | Set `origin` after git init (rejects URLs with embedded credentials). |
|
|
90
|
+
| `--install` / `--no-install` | Run `npm install` (default: no). |
|
|
91
|
+
| `-y, --yes` | Non-interactive; use defaults for omitted flags. |
|
|
92
|
+
| `--dry-run` | Print the file plan without writing. |
|
|
93
|
+
|
|
94
|
+
The name must be DNS-safe (lowercase `a-z`, `0-9`, hyphens; 1 to 63 chars; no leading/trailing hyphen). Existing files are never overwritten. Generated projects include `scripts/build.mjs` (content-hashed `dist/` + `manifest.json`), Webflow head/footer snippets (jsDelivr `@2` with `loader/dist/loader.min.js` and optional `modules/dist/{inject,cookies}.min.js`; also document `all` / `maintenance`), and an `AGENTS.md` with safe development rules.
|
|
95
|
+
|
|
96
|
+
### `upgrade` options
|
|
97
|
+
|
|
98
|
+
| Option | Behaviour |
|
|
99
|
+
| :--- | :--- |
|
|
100
|
+
| `--version <x>` | Target version (default: this CLI version from its `package.json`). Dist-tags such as `latest` resolve via `npm view`. (Implemented as `--target` internally so it does not collide with `stagepass --version`.) |
|
|
101
|
+
| `--dry-run` | Show changes without writing `package.json`. |
|
|
55
102
|
|
|
56
|
-
|
|
103
|
+
Only `package.json` is modified. `npm install` is printed, not run. Snippets use the major pin `@2` plus an optional exact pin note.
|
|
57
104
|
|
|
58
105
|
### Domain argument (`link` / `unlink`)
|
|
59
106
|
|
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.1.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,131 @@ 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
|
+
.action(async (options) => {
|
|
201
|
+
const code = await doctor(options);
|
|
202
|
+
process.exitCode = code;
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
const certsCmd = program
|
|
206
|
+
.command('certs')
|
|
207
|
+
.description('Certificate helpers for the Caddy local CA');
|
|
208
|
+
|
|
209
|
+
certsCmd
|
|
210
|
+
.command('check')
|
|
211
|
+
.description('Check Caddy local CA validity, trust, and optional TLS handshakes (read-only)')
|
|
212
|
+
.option('-v, --verbose', 'Show detailed output')
|
|
213
|
+
.option('--json', 'Machine-readable JSON output')
|
|
214
|
+
.option('--skip-handshake', 'Skip per-domain TLS handshake checks')
|
|
215
|
+
.action(async (options) => {
|
|
216
|
+
const code = await certsCheck(options);
|
|
217
|
+
process.exitCode = code;
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
certsCmd
|
|
221
|
+
.command('trust')
|
|
222
|
+
.description('Trust the Caddy local root CA via `caddy trust` (confirmation required)')
|
|
223
|
+
.option('-y, --yes', 'Skip interactive confirmation')
|
|
224
|
+
.option('-v, --verbose', 'Show detailed output')
|
|
225
|
+
.action(async (options) => {
|
|
226
|
+
const code = await certsTrust(options);
|
|
227
|
+
process.exitCode = code;
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
program
|
|
231
|
+
.command('autostart')
|
|
232
|
+
.description('Manage login LaunchAgent for Stagepass (macOS)')
|
|
233
|
+
.argument('<action>', 'on | off | status')
|
|
234
|
+
.option('-v, --verbose', 'Show detailed output')
|
|
235
|
+
.option('--json', 'JSON output for status')
|
|
236
|
+
.action(async (action, options) => {
|
|
237
|
+
const normalized = String(action || '').toLowerCase();
|
|
238
|
+
if (!['on', 'off', 'status'].includes(normalized)) {
|
|
239
|
+
console.error(chalk.red('Usage: stagepass autostart on|off|status'));
|
|
240
|
+
process.exitCode = 1;
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
const code = await autostart(normalized, options);
|
|
244
|
+
process.exitCode = code;
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
program
|
|
248
|
+
.command('daemon')
|
|
249
|
+
.description('Foreground daemon for LaunchAgent (non-interactive; never uses sudo)')
|
|
250
|
+
.action(async () => {
|
|
251
|
+
const code = await daemon();
|
|
252
|
+
process.exitCode = code;
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
// --- Package 3: project scaffold / npm wrappers / upgrade ---
|
|
256
|
+
// Keep this block self-contained for easy merges with other cli.js changes.
|
|
257
|
+
program
|
|
258
|
+
.command('upgrade')
|
|
259
|
+
.description(
|
|
260
|
+
'Bump @stagepass/* in the current package.json and print Webflow snippets'
|
|
261
|
+
)
|
|
262
|
+
.option('--dry-run', 'Show changes without writing package.json')
|
|
263
|
+
.option(
|
|
264
|
+
'--target <version>',
|
|
265
|
+
'Target version (default: this CLI version; dist-tags use npm view)'
|
|
266
|
+
)
|
|
267
|
+
// Public docs use `--version`; rewriteArgvForUpgrade maps it to `--target`
|
|
268
|
+
// so it does not collide with the root `stagepass --version` handler.
|
|
269
|
+
.option('-v, --verbose', 'Show detailed output')
|
|
270
|
+
.action(async (options) => {
|
|
271
|
+
const code = await upgrade({
|
|
272
|
+
...options,
|
|
273
|
+
version: options.target,
|
|
274
|
+
});
|
|
275
|
+
process.exitCode = code;
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
program
|
|
279
|
+
.command('watch')
|
|
280
|
+
.description('Run `npm run watch` in the current project')
|
|
281
|
+
.option('-v, --verbose', 'Show the underlying npm command')
|
|
282
|
+
.action(async (options) => {
|
|
283
|
+
const code = await watch(options);
|
|
284
|
+
process.exitCode = code;
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
program
|
|
288
|
+
.command('build')
|
|
289
|
+
.description('Run `npm run build` in the current project')
|
|
290
|
+
.option('-v, --verbose', 'Show the underlying npm command')
|
|
291
|
+
.action(async (options) => {
|
|
292
|
+
const code = await build(options);
|
|
293
|
+
process.exitCode = code;
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
program
|
|
297
|
+
.command('new')
|
|
298
|
+
.description('Scaffold a new Stagepass Webflow project')
|
|
299
|
+
.argument('[name]', 'DNS-safe project name')
|
|
300
|
+
.option('--dir <dir>', 'Target directory (default: ./<name>)')
|
|
301
|
+
.option('--author <author>', 'Author for package.json (default: git user.name)')
|
|
302
|
+
.option('--lang <lang>', 'ts or js (default: ts)')
|
|
303
|
+
.option('--styles <styles>', 'scss or css (default: scss)')
|
|
304
|
+
.option('--modules', 'Include @stagepass/modules')
|
|
305
|
+
.option('--no-modules', 'Skip @stagepass/modules')
|
|
306
|
+
.option('--git', 'Initialize a git repository')
|
|
307
|
+
.option('--no-git', 'Do not initialize git')
|
|
308
|
+
.option('--remote <url>', 'Git remote URL (requires git)')
|
|
309
|
+
.option('--install', 'Run npm install after scaffolding')
|
|
310
|
+
.option('--no-install', 'Do not run npm install (default)')
|
|
311
|
+
.option('-y, --yes', 'Non-interactive; accept defaults for omitted flags')
|
|
312
|
+
.option('--dry-run', 'Print the file plan without writing')
|
|
313
|
+
.option('-v, --verbose', 'Show detailed output')
|
|
314
|
+
.action(async (name, options) => {
|
|
315
|
+
const code = await createNew(name, options);
|
|
316
|
+
process.exitCode = code;
|
|
317
|
+
});
|
|
318
|
+
|
|
122
319
|
return program;
|
|
123
320
|
}
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import inquirer from 'inquirer';
|
|
3
|
+
import { defaultExec } from '../lib/exec.js';
|
|
4
|
+
import { loadProjects } from '../lib/projects.js';
|
|
5
|
+
import { getProjectsPath } from '../lib/paths.js';
|
|
6
|
+
import { runCertsCheck, assertNoDestructiveCertOps } from '../lib/certs.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Read-only certificate report.
|
|
10
|
+
* @param {object} [options]
|
|
11
|
+
* @param {boolean} [options.json]
|
|
12
|
+
* @param {boolean} [options.verbose]
|
|
13
|
+
* @param {boolean} [options.skipHandshake]
|
|
14
|
+
* @returns {Promise<number>}
|
|
15
|
+
*/
|
|
16
|
+
export async function certsCheck(options = {}) {
|
|
17
|
+
assertNoDestructiveCertOps();
|
|
18
|
+
|
|
19
|
+
const projectsPath = getProjectsPath();
|
|
20
|
+
const doc = await loadProjects(projectsPath);
|
|
21
|
+
const domains = Object.keys(doc.projects || {});
|
|
22
|
+
|
|
23
|
+
const report = await runCertsCheck({
|
|
24
|
+
domains: options.skipHandshake ? [] : domains,
|
|
25
|
+
skipHandshake: options.skipHandshake === true,
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
let exitCode = 0;
|
|
29
|
+
if (report.root.status === 'fail') exitCode = 1;
|
|
30
|
+
if (report.trust && !report.trust.trusted) exitCode = 1;
|
|
31
|
+
for (const hs of report.handshakes || []) {
|
|
32
|
+
if (hs.status === 'fail') exitCode = 1;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (options.json) {
|
|
36
|
+
console.log(
|
|
37
|
+
JSON.stringify(
|
|
38
|
+
{
|
|
39
|
+
ok: exitCode === 0,
|
|
40
|
+
root: {
|
|
41
|
+
status: report.root.status,
|
|
42
|
+
path: report.root.path,
|
|
43
|
+
reason: report.root.reason,
|
|
44
|
+
fingerprint256: report.root.fingerprint256,
|
|
45
|
+
daysRemaining: report.root.validity?.daysRemaining ?? null,
|
|
46
|
+
},
|
|
47
|
+
trust: {
|
|
48
|
+
trusted: Boolean(report.trust?.trusted),
|
|
49
|
+
error: report.trust?.error || null,
|
|
50
|
+
orphans: report.orphans || [],
|
|
51
|
+
},
|
|
52
|
+
secondaryRoots: report.secondaryRoots || [],
|
|
53
|
+
handshakes: report.handshakes || [],
|
|
54
|
+
},
|
|
55
|
+
null,
|
|
56
|
+
2
|
|
57
|
+
)
|
|
58
|
+
);
|
|
59
|
+
return exitCode;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
console.log(chalk.bold('\nStagepass certs check\n'));
|
|
63
|
+
|
|
64
|
+
const rootTag =
|
|
65
|
+
report.root.status === 'ok'
|
|
66
|
+
? chalk.green('ok')
|
|
67
|
+
: report.root.status === 'warn'
|
|
68
|
+
? chalk.yellow('warn')
|
|
69
|
+
: chalk.red('fail');
|
|
70
|
+
console.log(`[${rootTag}] Root CA: ${report.root.reason}`);
|
|
71
|
+
console.log(chalk.dim(` ${report.root.path}`));
|
|
72
|
+
if (report.root.fingerprint256) {
|
|
73
|
+
console.log(chalk.dim(` SHA-256 ${report.root.fingerprint256}`));
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (report.trust?.trusted) {
|
|
77
|
+
console.log(`[${chalk.green('ok')}] System keychain trusts this root`);
|
|
78
|
+
} else {
|
|
79
|
+
console.log(
|
|
80
|
+
`[${chalk.red('fail')}] System keychain does not trust this root`
|
|
81
|
+
);
|
|
82
|
+
if (report.trust?.error) {
|
|
83
|
+
console.log(chalk.dim(` ${report.trust.error}`));
|
|
84
|
+
}
|
|
85
|
+
console.log(chalk.dim(' Fix: stagepass certs trust'));
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (report.orphans?.length) {
|
|
89
|
+
console.log(
|
|
90
|
+
`[${chalk.yellow('warn')}] Orphaned Caddy roots in keychain (report only; never deleted):`
|
|
91
|
+
);
|
|
92
|
+
for (const orphan of report.orphans) {
|
|
93
|
+
console.log(
|
|
94
|
+
chalk.dim(
|
|
95
|
+
` SHA-1 ${orphan.sha1 || 'unknown'} SHA-256 ${orphan.sha256}`
|
|
96
|
+
)
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
} else {
|
|
100
|
+
console.log(`[${chalk.green('ok')}] No orphaned Caddy roots reported`);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
for (const secondary of report.secondaryRoots || []) {
|
|
104
|
+
console.log(`[${chalk.yellow('warn')}] ${secondary.note}`);
|
|
105
|
+
console.log(chalk.dim(` ${secondary.path}`));
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if ((report.handshakes || []).length === 0) {
|
|
109
|
+
console.log(chalk.dim('TLS handshake: skipped (no linked domains or --skip-handshake)'));
|
|
110
|
+
} else {
|
|
111
|
+
for (const hs of report.handshakes) {
|
|
112
|
+
const tag =
|
|
113
|
+
hs.status === 'ok'
|
|
114
|
+
? chalk.green('ok')
|
|
115
|
+
: hs.status === 'warn'
|
|
116
|
+
? chalk.yellow('warn')
|
|
117
|
+
: chalk.red('fail');
|
|
118
|
+
console.log(`[${tag}] TLS ${hs.servername}: ${hs.reason}`);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
console.log(chalk.bold(`\nExit ${exitCode}`));
|
|
123
|
+
return exitCode;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Run `caddy trust` after explicit confirmation (or --yes).
|
|
128
|
+
* @param {object} [options]
|
|
129
|
+
* @param {boolean} [options.yes]
|
|
130
|
+
* @param {boolean} [options.verbose]
|
|
131
|
+
* @param {import('../lib/exec.js').ExecFn} [options.exec]
|
|
132
|
+
* @param {(q: object[]) => Promise<object>} [options.prompt]
|
|
133
|
+
* @returns {Promise<number>}
|
|
134
|
+
*/
|
|
135
|
+
export async function certsTrust(options = {}) {
|
|
136
|
+
assertNoDestructiveCertOps();
|
|
137
|
+
const exec = options.exec || defaultExec;
|
|
138
|
+
const prompt = options.prompt || ((questions) => inquirer.prompt(questions));
|
|
139
|
+
|
|
140
|
+
let confirmed = options.yes === true;
|
|
141
|
+
if (!confirmed) {
|
|
142
|
+
const canPrompt = typeof options.prompt === 'function' || process.stdin.isTTY;
|
|
143
|
+
if (!canPrompt) {
|
|
144
|
+
console.log(
|
|
145
|
+
chalk.red(
|
|
146
|
+
'certs trust requires interactive confirmation or --yes (refusing non-TTY without --yes).'
|
|
147
|
+
)
|
|
148
|
+
);
|
|
149
|
+
return 1;
|
|
150
|
+
}
|
|
151
|
+
const answers = await prompt([
|
|
152
|
+
{
|
|
153
|
+
type: 'confirm',
|
|
154
|
+
name: 'ok',
|
|
155
|
+
message:
|
|
156
|
+
'Install/trust the Caddy local root CA in the System keychain via `caddy trust`?',
|
|
157
|
+
default: false,
|
|
158
|
+
},
|
|
159
|
+
]);
|
|
160
|
+
confirmed = answers.ok === true;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
if (!confirmed) {
|
|
164
|
+
console.log(chalk.dim('Cancelled.'));
|
|
165
|
+
return 1;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
try {
|
|
169
|
+
// caddy trust may prompt for an admin password; always inherit stdio.
|
|
170
|
+
await exec('caddy', ['trust'], { stdio: 'inherit' });
|
|
171
|
+
console.log(chalk.green('caddy trust completed.'));
|
|
172
|
+
console.log(
|
|
173
|
+
chalk.dim(
|
|
174
|
+
'Re-check with: stagepass certs check (restart browsers if needed)'
|
|
175
|
+
)
|
|
176
|
+
);
|
|
177
|
+
return 0;
|
|
178
|
+
} catch (error) {
|
|
179
|
+
console.log(chalk.red('caddy trust failed.'));
|
|
180
|
+
console.log(
|
|
181
|
+
chalk.dim(error instanceof Error ? error.message : String(error))
|
|
182
|
+
);
|
|
183
|
+
return 1;
|
|
184
|
+
}
|
|
185
|
+
}
|