@stagepass/cli 2.3.0 → 2.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/README.md +35 -24
  2. package/package.json +1 -1
  3. package/src/cli.js +48 -5
  4. package/src/commands/daemon.js +18 -2
  5. package/src/commands/dev.js +14 -0
  6. package/src/commands/link.js +11 -1
  7. package/src/commands/new.js +39 -16
  8. package/src/commands/npm-run.js +14 -0
  9. package/src/commands/reload.js +5 -1
  10. package/src/commands/start.js +1 -1
  11. package/src/commands/upgrade.js +84 -32
  12. package/src/lib/autostart.js +66 -8
  13. package/src/lib/build-script-upgrade.js +244 -0
  14. package/src/lib/caddy-version.js +31 -0
  15. package/src/lib/caddyfile.js +76 -36
  16. package/src/lib/doctor-site.js +15 -10
  17. package/src/lib/doctor.js +131 -30
  18. package/src/lib/migrate.js +29 -2
  19. package/src/lib/package-versions.js +1 -1
  20. package/src/lib/paths.js +5 -0
  21. package/src/lib/php-runtime.js +249 -0
  22. package/src/lib/scaffold.js +22 -16
  23. package/templates/project/README.md.tmpl +8 -6
  24. package/templates/project/api/README.md.tmpl +172 -5
  25. package/templates/project/api/action.php +100 -0
  26. package/templates/project/api/actions/boom.php +21 -0
  27. package/templates/project/api/actions/contact.php +46 -0
  28. package/templates/project/api/actions/ping.php +23 -0
  29. package/templates/project/api/actions.php +59 -0
  30. package/templates/project/api/env.example +25 -0
  31. package/templates/project/api/lib/bootstrap.php +44 -0
  32. package/templates/project/api/lib/config.php +180 -0
  33. package/templates/project/api/lib/request.php +94 -0
  34. package/templates/project/api/lib/response.php +97 -0
  35. package/templates/project/api/lib/security.php +114 -0
  36. package/templates/project/api/lib/validate.php +69 -0
  37. package/templates/project/gitignore +4 -0
  38. package/templates/project/php-private/config.php +24 -0
  39. package/templates/project/scripts/build.mjs +114 -8
  40. package/templates/project/examples/php/README.md.tmpl +0 -18
  41. package/templates/project/examples/php/form.php +0 -105
  42. package/templates/project/examples/php/proxy.php +0 -171
@@ -3,8 +3,11 @@ import { escapeCaddyQuotedString, validateRoot } from './paths.js';
3
3
  import { buildOriginAllowlistRegex, validateOriginList } from './origins.js';
4
4
  import { isValidDevPort, normalizeDevPort } from './dev-port.js';
5
5
 
6
- /** Marker written inside every Stagepass-managed site block. */
7
- export const BLOCK_VERSION = 'v2';
6
+ /**
7
+ * Marker written inside every Stagepass-managed site block.
8
+ * v3: success responses set one ACAO (deferred replace) so PHP CORS is not duplicated.
9
+ */
10
+ export const BLOCK_VERSION = 'v3';
8
11
 
9
12
  /**
10
13
  * Sensitive path / extension blocking (always on).
@@ -98,16 +101,7 @@ export function renderSiteBlock(domain, root, options = {}) {
98
101
  lines.push(' php_fastcgi 127.0.0.1:9000');
99
102
  }
100
103
  lines.push(' file_server');
101
-
102
- if (allowAllOrigins) {
103
- lines.push(' header Access-Control-Allow-Origin *');
104
- } else {
105
- lines.push(
106
- ' header @cors_origin Access-Control-Allow-Origin "{http.request.header.Origin}"',
107
- ' header @cors_origin Vary Origin'
108
- );
109
- }
110
-
104
+ lines.push(...deferredSuccessCorsLines(allowAllOrigins));
111
105
  lines.push(' }', '}', `# END: ${domain}`);
112
106
 
113
107
  return lines.join('\n');
@@ -140,16 +134,33 @@ function liveReloadHandleLines(port, allowAllOrigins) {
140
134
  ' flush_interval -1',
141
135
  ' }',
142
136
  ];
137
+ lines.push(...deferredSuccessCorsLines(allowAllOrigins));
138
+ lines.push(' }');
139
+ return lines;
140
+ }
141
+
142
+ /**
143
+ * One ACAO on HTTP 2xx, applied when the response is written.
144
+ * `>` replaces an upstream value (PHP) instead of adding a second one.
145
+ * Non-2xx responses are left alone so a PHP 403 does not gain ACAO.
146
+ * @param {boolean} allowAllOrigins
147
+ */
148
+ function deferredSuccessCorsLines(allowAllOrigins) {
143
149
  if (allowAllOrigins) {
144
- lines.push(' header Access-Control-Allow-Origin *');
145
- } else {
146
- lines.push(
147
- ' header @cors_origin Access-Control-Allow-Origin "{http.request.header.Origin}"',
148
- ' header @cors_origin Vary Origin'
149
- );
150
+ return [
151
+ ' header {',
152
+ ' >Access-Control-Allow-Origin *',
153
+ ' match status 2xx',
154
+ ' }',
155
+ ];
150
156
  }
151
- lines.push(' }', '');
152
- return lines;
157
+ return [
158
+ ' header @cors_origin {',
159
+ ' >Access-Control-Allow-Origin "{http.request.header.Origin}"',
160
+ ' >Vary Origin',
161
+ ' match status 2xx',
162
+ ' }',
163
+ ];
153
164
  }
154
165
 
155
166
  function allowAllCorsLines() {
@@ -190,6 +201,15 @@ function allowlistCorsLines(origins) {
190
201
  ];
191
202
  }
192
203
 
204
+ /**
205
+ * @param {string} blockText
206
+ * @returns {string|null} `v2`, `v3`, … or null when the block has no marker
207
+ */
208
+ function blockMarkerVersion(blockText) {
209
+ const m = blockText.match(/# stagepass-block:\s*(v\d+)/);
210
+ return m ? m[1] : null;
211
+ }
212
+
193
213
  /**
194
214
  * Parse Stagepass START/END blocks from a Caddyfile.
195
215
  * @param {string} content
@@ -302,9 +322,10 @@ export function removeBlock(content, domain) {
302
322
  }
303
323
 
304
324
  /**
305
- * Migrate legacy (pre-v2) Stagepass blocks to the current renderer.
325
+ * Rewrite blocks that are not the current marker.
306
326
  *
307
- * Legacy blocks get allowAllOrigins=true so existing Webflow embedding keeps working.
327
+ * No marker (pre-v2): allowAllOrigins=true so existing Webflow embedding keeps working.
328
+ * An older marker (v2): same options comment, current header rules.
308
329
  *
309
330
  * @param {string} content
310
331
  * @param {object} [opts]
@@ -313,24 +334,34 @@ export function removeBlock(content, domain) {
313
334
  export function migrateLegacyContent(content, opts = {}) {
314
335
  const warn = opts.warn || (() => {});
315
336
  const blocks = parseBlocks(content);
316
- const legacy = blocks.filter((b) => b.isLegacy);
317
-
318
- if (legacy.length === 0) {
319
- return { content, changed: false, migrated: [], skipped: [], warnings: [] };
337
+ const pending = blocks.filter((b) => blockMarkerVersion(b.full) !== BLOCK_VERSION);
338
+
339
+ if (pending.length === 0) {
340
+ return {
341
+ content,
342
+ changed: false,
343
+ migrated: [],
344
+ upgraded: [],
345
+ skipped: [],
346
+ warnings: [],
347
+ };
320
348
  }
321
349
 
322
350
  let next = content;
323
351
  const migrated = [];
352
+ const upgraded = [];
324
353
  const skipped = [];
325
354
  const warnings = [];
326
355
 
327
- const ordered = [...legacy].sort((a, b) => b.index - a.index);
356
+ const ordered = [...pending].sort((a, b) => b.index - a.index);
328
357
 
329
358
  for (const block of ordered) {
359
+ const legacy = blockMarkerVersion(block.full) == null;
360
+ const kind = legacy ? 'legacy block' : 'block';
330
361
  if (!block.root) {
331
362
  const reason = 'could not parse root path';
332
363
  skipped.push({ domain: block.domain, reason });
333
- const msg = `Left legacy block ${block.domain} unchanged (${reason}).`;
364
+ const msg = `Left ${kind} ${block.domain} unchanged (${reason}).`;
334
365
  warnings.push(msg);
335
366
  warn(msg);
336
367
  continue;
@@ -340,7 +371,7 @@ export function migrateLegacyContent(content, opts = {}) {
340
371
  if (!rootCheck.ok) {
341
372
  const reason = rootCheck.error;
342
373
  skipped.push({ domain: block.domain, reason });
343
- const msg = `Left legacy block ${block.domain} unchanged (${reason}).`;
374
+ const msg = `Left ${kind} ${block.domain} unchanged (${reason}).`;
344
375
  warnings.push(msg);
345
376
  warn(msg);
346
377
  continue;
@@ -348,14 +379,20 @@ export function migrateLegacyContent(content, opts = {}) {
348
379
 
349
380
  let newBlock;
350
381
  try {
351
- newBlock = renderSiteBlock(block.domain, rootCheck.path, {
352
- allowAllOrigins: true,
353
- origins: [],
354
- });
382
+ // Legacy (no marker) keeps allow-all. A versioned block keeps its options comment.
383
+ const renderOptions = legacy
384
+ ? { allowAllOrigins: true, origins: [] }
385
+ : {
386
+ allowAllOrigins: block.options.allowAllOrigins === true,
387
+ origins: block.options.origins || [],
388
+ php: block.options.php,
389
+ devPort: block.options.devPort,
390
+ };
391
+ newBlock = renderSiteBlock(block.domain, rootCheck.path, renderOptions);
355
392
  } catch (e) {
356
393
  const reason = e.message || String(e);
357
394
  skipped.push({ domain: block.domain, reason });
358
- const msg = `Left legacy block ${block.domain} unchanged (${reason}).`;
395
+ const msg = `Left ${kind} ${block.domain} unchanged (${reason}).`;
359
396
  warnings.push(msg);
360
397
  warn(msg);
361
398
  continue;
@@ -365,7 +402,9 @@ export function migrateLegacyContent(content, opts = {}) {
365
402
  next.slice(0, block.index) +
366
403
  newBlock.trim() +
367
404
  next.slice(block.index + block.length);
368
- migrated.push({ domain: block.domain, root: rootCheck.path });
405
+ const item = { domain: block.domain, root: rootCheck.path };
406
+ if (legacy) migrated.push(item);
407
+ else upgraded.push(item);
369
408
  }
370
409
 
371
410
  next = next.replace(/\n{3,}/g, '\n\n');
@@ -377,8 +416,9 @@ export function migrateLegacyContent(content, opts = {}) {
377
416
 
378
417
  return {
379
418
  content: next,
380
- changed: migrated.length > 0,
419
+ changed: migrated.length + upgraded.length > 0,
381
420
  migrated,
421
+ upgraded,
382
422
  skipped,
383
423
  warnings,
384
424
  };
@@ -16,6 +16,7 @@ import {
16
16
  resolveProjectOrigin,
17
17
  } from './project-sync.js';
18
18
  import { resolveCommand } from './exec.js';
19
+ import { checkPhpRuntime } from './php-runtime.js';
19
20
 
20
21
  /**
21
22
  * @param {object} [opts]
@@ -57,29 +58,33 @@ export async function runProjectSiteChecks(opts = {}) {
57
58
  message: 'PHP is off for this project (no php_fastcgi on link)',
58
59
  });
59
60
  } else if (php === true) {
60
- const resolve = opts.resolveCommand || resolveCommand;
61
- const phpPath = await resolve('php', opts.exec);
62
- const apiDir = path.join(cwd, 'api');
63
- const apiOk = await fs.pathExists(apiDir);
64
- if (!phpPath) {
61
+ const runtime = await checkPhpRuntime({
62
+ exec: opts.exec,
63
+ resolveCommand: opts.resolveCommand || resolveCommand,
64
+ pathExists: opts.pathExists,
65
+ platform: opts.platform,
66
+ brewPrefix: opts.brewPrefix,
67
+ });
68
+ const apiOk = await fs.pathExists(path.join(cwd, 'api'));
69
+ if (!runtime.ok) {
65
70
  checks.push({
66
71
  id: 'project.php',
67
- status: 'fail',
68
- message: 'Project enables PHP but php was not found on PATH',
69
- detail: 'Install PHP (stagepass setup) or set "php": false in stagepass.json',
72
+ status: runtime.status,
73
+ message: `Project enables PHP but ${runtime.message}`,
74
+ detail: runtime.detail || 'Install PHP (stagepass setup) or set "php": false in stagepass.json',
70
75
  });
71
76
  } else if (!apiOk) {
72
77
  checks.push({
73
78
  id: 'project.php',
74
79
  status: 'warn',
75
- message: `PHP enabled (php=${phpPath}) but api/ folder is missing`,
80
+ message: `PHP ${runtime.version.label} is installed but api/ is missing`,
76
81
  detail: 'Create api/ for handlers served via php_fastcgi',
77
82
  });
78
83
  } else {
79
84
  checks.push({
80
85
  id: 'project.php',
81
86
  status: 'ok',
82
- message: `PHP enabled for this project (php=${phpPath}, api/ present)`,
87
+ message: `PHP ${runtime.version.label} enabled for this project (php=${runtime.phpPath}, api/ present)`,
83
88
  });
84
89
  }
85
90
  }
package/src/lib/doctor.js CHANGED
@@ -1,16 +1,22 @@
1
1
  import fs from 'fs-extra';
2
+ import { createRequire } from 'node:module';
2
3
  import { runProjectSiteChecks } from './doctor-site.js';
3
4
  import path from 'node:path';
4
5
  import { defaultExec, resolveCommand } from './exec.js';
6
+ import { CADDY_UPGRADE_HINT, readCaddyVersion } from './caddy-version.js';
7
+ import { checkPhpRuntime } from './php-runtime.js';
5
8
  import {
6
9
  getCaddyfilePath,
7
10
  getProjectsPath,
8
11
  getCaddyRootCaPath,
12
+ getDaemonStatePath,
9
13
  } from './paths.js';
10
14
  import { parseBlocks } from './caddyfile.js';
11
15
  import { loadProjects } from './projects.js';
12
16
  import { runCertsCheck } from './certs.js';
13
- import { getAutostartStatus } from './autostart.js';
17
+ import { getAutostartStatus, isVersionedCellarNodeBin } from './autostart.js';
18
+ import { isPidAlive } from './dev-port.js';
19
+ import { isMacOS } from './platform.js';
14
20
  import {
15
21
  CHROME_LNA_HINT,
16
22
  findUnpinnedCdnSnippets,
@@ -18,6 +24,9 @@ import {
18
24
  scanProjectUnpinnedCdn,
19
25
  } from './cdn-snippets.js';
20
26
 
27
+ const CLI_VERSION = createRequire(import.meta.url)('../../package.json').version;
28
+ const AUTOSTART_ON = 'stagepass autostart on';
29
+
21
30
  /**
22
31
  * @typedef {'ok'|'warn'|'fail'|'info'} CheckStatus
23
32
  * @typedef {{ id: string, status: CheckStatus, message: string, detail?: string }} DoctorCheck
@@ -34,6 +43,50 @@ function check(id, status, message, detail) {
34
43
  return detail ? { id, status, message, detail } : { id, status, message };
35
44
  }
36
45
 
46
+ /** @param {unknown} value */
47
+ function safeVersion(value) {
48
+ return typeof value === 'string' && /^[0-9A-Za-z.+-]{1,32}$/.test(value) ? value : '';
49
+ }
50
+
51
+ /** @param {string} value */
52
+ function unescapeXml(value) {
53
+ return String(value)
54
+ .replace(/&lt;/g, '<')
55
+ .replace(/&gt;/g, '>')
56
+ .replace(/&quot;/g, '"')
57
+ .replace(/&apos;/g, "'")
58
+ .replace(/&amp;/g, '&');
59
+ }
60
+
61
+ /** @param {string} xml @returns {string[]} */
62
+ function plistProgramArguments(xml) {
63
+ const block = /<key>ProgramArguments<\/key>\s*<array>([\s\S]*?)<\/array>/.exec(
64
+ String(xml || '')
65
+ );
66
+ if (!block) return [];
67
+ const args = [];
68
+ const re = /<string>([^<]*)<\/string>/g;
69
+ let m;
70
+ while ((m = re.exec(block[1]))) args.push(unescapeXml(m[1]));
71
+ return args;
72
+ }
73
+
74
+ /**
75
+ * Version recorded by the running daemon, or null when the pid is dead / unreadable.
76
+ * @param {(p: string, enc?: string) => Promise<string>} readFile
77
+ * @param {string} statePath
78
+ */
79
+ async function readRunningDaemonVersion(readFile, statePath) {
80
+ try {
81
+ const data = JSON.parse(String(await readFile(statePath, 'utf8')));
82
+ const version = safeVersion(data && data.version);
83
+ if (!version || !isPidAlive(data.pid)) return null;
84
+ return version;
85
+ } catch {
86
+ return null;
87
+ }
88
+ }
89
+
37
90
  /**
38
91
  * Parse `lsof -nP -iTCP:443 -sTCP:LISTEN` output.
39
92
  * @param {string} stdout
@@ -151,41 +204,36 @@ export async function runDoctor(opts = {}) {
151
204
  }
152
205
  }
153
206
 
154
- // Caddy
207
+ // Caddy (v3 site blocks need 2.9+; unknown version keeps the previous ok check)
155
208
  const caddyPath = await resolveCommand('caddy', exec);
156
209
  if (!caddyPath) {
157
210
  checks.push(check('caddy', 'fail', 'Caddy not found on PATH'));
158
211
  } else {
159
- checks.push(check('caddy', 'ok', `Caddy found (${caddyPath})`));
212
+ const rel = await readCaddyVersion(exec);
213
+ if (rel.known && !rel.ok) {
214
+ checks.push(
215
+ check(
216
+ 'caddy',
217
+ 'warn',
218
+ `Caddy ${rel.version} is older than 2.9 (v3 site block needs 2.9 or newer)`,
219
+ CADDY_UPGRADE_HINT
220
+ )
221
+ );
222
+ } else if (rel.known) {
223
+ checks.push(check('caddy', 'ok', `Caddy ${rel.version} found (${caddyPath})`));
224
+ } else {
225
+ checks.push(check('caddy', 'ok', `Caddy found (${caddyPath})`));
226
+ }
160
227
  }
161
228
 
162
- // PHP / php-fpm
163
- const phpPath = await resolveCommand('php', exec);
164
- let phpFpmPath = await resolveCommand('php-fpm', exec);
165
- if (!phpFpmPath && brewPrefix) {
166
- const candidate = path.join(brewPrefix, 'sbin', 'php-fpm');
167
- if (await pathExists(candidate)) phpFpmPath = candidate;
168
- }
169
- if (!phpPath && !phpFpmPath) {
170
- checks.push(check('php', 'fail', 'PHP / php-fpm not found'));
171
- } else if (!phpFpmPath) {
172
- checks.push(
173
- check(
174
- 'php',
175
- 'warn',
176
- `PHP found (${phpPath}) but php-fpm binary not found`,
177
- 'Stagepass Caddy blocks use php_fastcgi 127.0.0.1:9000'
178
- )
179
- );
180
- } else {
181
- checks.push(
182
- check(
183
- 'php',
184
- 'ok',
185
- `PHP/php-fpm found (${phpFpmPath}${phpPath ? `; php=${phpPath}` : ''})`
186
- )
187
- );
188
- }
229
+ // PHP / php-fpm (version >= 8.2, php-fpm or php-cgi)
230
+ const phpRuntime = await checkPhpRuntime({
231
+ exec,
232
+ pathExists,
233
+ brewPrefix,
234
+ platform: opts.platform,
235
+ });
236
+ checks.push(check('php', phpRuntime.status, phpRuntime.message, phpRuntime.detail || undefined));
189
237
 
190
238
  // dnsmasq
191
239
  let dnsmasqPath = await resolveCommand('dnsmasq', exec);
@@ -462,6 +510,55 @@ export async function runDoctor(opts = {}) {
462
510
  );
463
511
  }
464
512
 
513
+ // #74: plist paths and the running daemon version (macOS, plist on disk).
514
+ if (isMacOS(opts.platform) && autostart.plistExists) {
515
+ let args = [];
516
+ try {
517
+ args = plistProgramArguments(await readFile(autostart.plistPath, 'utf8'));
518
+ } catch {
519
+ args = [];
520
+ }
521
+ const nodeArg = args[0] || '';
522
+ const cliArg = args[1] || '';
523
+ const nodeOk = nodeArg.length > 0 && (await pathExists(nodeArg));
524
+ const cliOk = cliArg.length > 0 && (await pathExists(cliArg));
525
+ if (!nodeOk || !cliOk) {
526
+ const which = [!nodeOk ? 'node' : '', !cliOk ? 'CLI' : ''].filter(Boolean).join(' and ');
527
+ checks.push(check('autostart.paths', 'fail', `LaunchAgent ${which} path is missing`, AUTOSTART_ON));
528
+ } else {
529
+ checks.push(check('autostart.paths', 'ok', 'LaunchAgent node and CLI paths exist'));
530
+ }
531
+ if (isVersionedCellarNodeBin(nodeArg)) {
532
+ checks.push(
533
+ check(
534
+ 'autostart.node',
535
+ 'warn',
536
+ 'LaunchAgent node path is a versioned Homebrew Cellar path',
537
+ AUTOSTART_ON
538
+ )
539
+ );
540
+ } else if (nodeOk) {
541
+ checks.push(check('autostart.node', 'ok', 'LaunchAgent node path is not a versioned Cellar path'));
542
+ }
543
+ const running = await readRunningDaemonVersion(
544
+ readFile,
545
+ opts.daemonStatePath || getDaemonStatePath()
546
+ );
547
+ const cliVersion = safeVersion(opts.cliVersion || CLI_VERSION);
548
+ if (running && cliVersion && running !== cliVersion) {
549
+ checks.push(
550
+ check(
551
+ 'autostart.version',
552
+ 'warn',
553
+ `Daemon version ${running} differs from CLI ${cliVersion}`,
554
+ AUTOSTART_ON
555
+ )
556
+ );
557
+ } else if (running && cliVersion && running === cliVersion) {
558
+ checks.push(check('autostart.version', 'ok', `Daemon version matches CLI ${cliVersion}`));
559
+ }
560
+ }
561
+
465
562
  // CDN snippets: canonical docs + current project snippet files (read-only)
466
563
  const snippets = opts.cdnSnippets || RECOMMENDED_CDN_SNIPPETS;
467
564
  const unpinned = findUnpinnedCdnSnippets(snippets);
@@ -537,6 +634,10 @@ export async function runDoctor(opts = {}) {
537
634
  skipSite: opts.skipSite === true,
538
635
  detectSite: opts.detectSite,
539
636
  loadProjects: opts.loadProjects,
637
+ exec,
638
+ pathExists,
639
+ platform: opts.platform,
640
+ brewPrefix,
540
641
  });
541
642
  for (const c of projectChecks) checks.push(check(c.id, c.status, c.message, c.detail));
542
643
  } catch (error) {
@@ -2,10 +2,12 @@ import fs from 'fs-extra';
2
2
  import path from 'path';
3
3
  import chalk from 'chalk';
4
4
  import {
5
+ BLOCK_VERSION,
5
6
  formatBackupStamp,
6
7
  migrateLegacyContent,
7
8
  parseBlocks,
8
9
  } from './caddyfile.js';
10
+ import { CADDY_UPGRADE_HINT, readCaddyVersion } from './caddy-version.js';
9
11
  import { ensureMigratedProject } from './projects.js';
10
12
  import { getCaddyfilePath, getProjectsPath } from './paths.js';
11
13
 
@@ -17,6 +19,8 @@ import { getCaddyfilePath, getProjectsPath } from './paths.js';
17
19
  * @param {string} [options.caddyfilePath]
18
20
  * @param {string} [options.projectsPath]
19
21
  * @param {boolean} [options.silent]
22
+ * @param {import('./exec.js').ExecFn} [options.exec]
23
+ * @param {Awaited<ReturnType<typeof readCaddyVersion>>} [options.caddy]
20
24
  * @returns {Promise<{ changed: boolean, migrated: Array, skipped: Array, backupPath: string|null }>}
21
25
  */
22
26
  export async function ensureCaddyfileMigrated(options = {}) {
@@ -25,10 +29,24 @@ export async function ensureCaddyfileMigrated(options = {}) {
25
29
  const silent = options.silent === true;
26
30
 
27
31
  if (!(await fs.pathExists(caddyfilePath))) {
28
- return { changed: false, migrated: [], skipped: [], backupPath: null };
32
+ return { changed: false, migrated: [], upgraded: [], skipped: [], backupPath: null };
29
33
  }
30
34
 
31
35
  const original = await fs.readFile(caddyfilePath, 'utf-8');
36
+ const caddy = options.caddy || (await readCaddyVersion(options.exec));
37
+ const current = new RegExp(`# stagepass-block:\\s*${BLOCK_VERSION}\\b`);
38
+ const stale = parseBlocks(original).some((block) => !current.test(block.full));
39
+ if (caddy.known && !caddy.ok && stale) {
40
+ if (!silent) {
41
+ console.log(
42
+ chalk.yellow(
43
+ ` Caddy ${caddy.version} is older than 2.9, so existing site blocks were left unchanged. ${CADDY_UPGRADE_HINT}`
44
+ )
45
+ );
46
+ }
47
+ return { changed: false, migrated: [], upgraded: [], skipped: [], backupPath: null };
48
+ }
49
+
32
50
  const result = migrateLegacyContent(original, {
33
51
  warn: silent
34
52
  ? () => {}
@@ -39,6 +57,7 @@ export async function ensureCaddyfileMigrated(options = {}) {
39
57
  return {
40
58
  changed: false,
41
59
  migrated: [],
60
+ upgraded: [],
42
61
  skipped: result.skipped,
43
62
  backupPath: null,
44
63
  };
@@ -52,7 +71,7 @@ export async function ensureCaddyfileMigrated(options = {}) {
52
71
  await ensureMigratedProject(item.domain, item.root, projectsPath);
53
72
  }
54
73
 
55
- if (!silent) {
74
+ if (!silent && result.migrated.length > 0) {
56
75
  console.log(
57
76
  chalk.yellow(
58
77
  ` Migrated ${result.migrated.length} legacy Caddy block(s). Backup: ${path.basename(backupPath)}`
@@ -67,10 +86,18 @@ export async function ensureCaddyfileMigrated(options = {}) {
67
86
  )
68
87
  );
69
88
  }
89
+ if (!silent && result.upgraded.length > 0) {
90
+ console.log(
91
+ chalk.dim(
92
+ ` Updated ${result.upgraded.length} Caddy block(s) to stagepass-block ${BLOCK_VERSION}.`
93
+ )
94
+ );
95
+ }
70
96
 
71
97
  return {
72
98
  changed: true,
73
99
  migrated: result.migrated,
100
+ upgraded: result.upgraded,
74
101
  skipped: result.skipped,
75
102
  backupPath,
76
103
  };
@@ -5,5 +5,5 @@
5
5
  * Sourced from packages/loader and packages/modules package.json at generate time.
6
6
  * The published CLI ships this snapshot; it cannot read the monorepo at runtime.
7
7
  */
8
- export const LOADER_VERSION = "2.4.0";
8
+ export const LOADER_VERSION = "2.5.0";
9
9
  export const MODULES_VERSION = "2.2.2";
package/src/lib/paths.js CHANGED
@@ -31,6 +31,11 @@ export function getDaemonStderrLogPath() {
31
31
  return path.join(getLogsDir(), 'daemon.stderr.log');
32
32
  }
33
33
 
34
+ /** Version and pid of the running `stagepass daemon` (~/.stagepass/daemon.json). */
35
+ export function getDaemonStatePath() {
36
+ return path.join(getStagepassDir(), 'daemon.json');
37
+ }
38
+
34
39
  /** LaunchAgent label (owned GitHub-io reverse DNS; not a third-party domain). */
35
40
  export const LAUNCH_AGENT_LABEL = 'io.github.arobertherz.stagepass';
36
41