@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.
@@ -0,0 +1,126 @@
1
+ import fs from 'fs-extra';
2
+ import chalk from 'chalk';
3
+ import { defaultExec } from '../lib/exec.js';
4
+ import { getCaddyfilePath, getLogsDir } from '../lib/paths.js';
5
+ import { runCertsCheck } from '../lib/certs.js';
6
+ import { loadProjects } from '../lib/projects.js';
7
+ import { getProjectsPath } from '../lib/paths.js';
8
+
9
+ /**
10
+ * Detect bind / permission failures that will not self-heal on immediate restart.
11
+ * LaunchAgent KeepAlive (SuccessfulExit=false) must not restart-loop on these.
12
+ * @param {string} detail
13
+ * @returns {boolean}
14
+ */
15
+ export function isPermanentDaemonFailure(detail) {
16
+ return /permission denied|bind|address already in use|EADDRINUSE|EACCES/i.test(
17
+ String(detail || '')
18
+ );
19
+ }
20
+
21
+ /**
22
+ * Non-interactive foreground daemon for LaunchAgent use.
23
+ * Never uses sudo. Runs certs check (log only, no TLS handshake), then `caddy run`.
24
+ *
25
+ * Existing `stagepass start` also launches Caddy as the user (sudo is only for
26
+ * port conflict helpers). Binding TCP 443 as a user LaunchAgent is therefore
27
+ * expected to work on macOS the same way. Permanent startup failures (missing
28
+ * Caddyfile, port 443 bind) exit 0 after logging so launchd KeepAlive does not
29
+ * restart-loop; unexpected mid-run failures exit 1 so KeepAlive can retry.
30
+ *
31
+ * @param {object} [options]
32
+ * @param {import('../lib/exec.js').ExecFn} [options.exec]
33
+ * @param {(file: string, args: string[], opts?: object) => Promise<unknown>} [options.runForeground]
34
+ * @param {(msg: string) => void} [options.log]
35
+ * @returns {Promise<number>}
36
+ */
37
+ export async function daemon(options = {}) {
38
+ const log =
39
+ options.log ||
40
+ ((msg) => {
41
+ const line = `[stagepass daemon] ${msg}`;
42
+ console.error(line);
43
+ });
44
+
45
+ const exec = options.exec || defaultExec;
46
+ const caddyfilePath = options.caddyfilePath || getCaddyfilePath();
47
+ const pathExists = options.pathExists || ((p) => fs.pathExists(p));
48
+
49
+ await fs.ensureDir(options.logsDir || getLogsDir());
50
+
51
+ if (!(await pathExists(caddyfilePath))) {
52
+ log(`Caddyfile missing: ${caddyfilePath}`);
53
+ log('Refusing to start. Run: stagepass setup && stagepass link');
54
+ // Exit 0: permanent until the user fixes config; avoid KeepAlive restart loop.
55
+ return 0;
56
+ }
57
+
58
+ // Non-interactive cert check (log only; never prompts; never repairs).
59
+ // Skip TLS handshakes: Caddy is not running yet during cold start.
60
+ try {
61
+ const projectsPath = options.projectsPath || getProjectsPath();
62
+ const doc = await loadProjects(projectsPath);
63
+ const domains = Object.keys(doc.projects || {});
64
+ const report = await runCertsCheck({
65
+ exec,
66
+ domains,
67
+ skipHandshake: true,
68
+ handshakeTimeoutMs: 2000,
69
+ });
70
+ log(`certs root: ${report.root.status} ${report.root.reason}`);
71
+ log(
72
+ `certs trust: ${report.trust?.trusted ? 'trusted' : 'NOT trusted'}${
73
+ report.trust?.error ? ` (${report.trust.error})` : ''
74
+ }`
75
+ );
76
+ if (report.orphans?.length) {
77
+ log(
78
+ `certs orphans: ${report.orphans.length} (report only; SHA-1 ${report.orphans
79
+ .map((o) => o.sha1 || '?')
80
+ .join(', ')})`
81
+ );
82
+ }
83
+ } catch (error) {
84
+ log(
85
+ `certs check failed (continuing): ${
86
+ error instanceof Error ? error.message : String(error)
87
+ }`
88
+ );
89
+ }
90
+
91
+ const args = ['run', '--config', caddyfilePath, '--adapter', 'caddyfile'];
92
+ log(`starting: caddy ${args.join(' ')}`);
93
+
94
+ const runForeground =
95
+ options.runForeground ||
96
+ (async (file, fileArgs) => {
97
+ // Inherit stdio so LaunchAgent log redirects capture Caddy output.
98
+ return exec(file, fileArgs, { stdio: 'inherit' });
99
+ });
100
+
101
+ try {
102
+ await runForeground('caddy', args);
103
+ log('caddy exited cleanly');
104
+ return 0;
105
+ } catch (error) {
106
+ const err = /** @type {{ message?: string, stderr?: string, code?: string|number }} */ (
107
+ error
108
+ );
109
+ const detail = [err.message, err.stderr].filter(Boolean).join(' | ');
110
+ log(`caddy failed: ${detail}`);
111
+ if (isPermanentDaemonFailure(detail)) {
112
+ log(
113
+ 'Port 443 bind/listen failed for the user LaunchAgent. Exiting without KeepAlive retry. Use interactive `stagepass start` (which can resolve conflicts with confirmation), or free port 443, then retry.'
114
+ );
115
+ if (process.stderr.isTTY) {
116
+ console.error(chalk.red(detail));
117
+ }
118
+ // Exit 0 so SuccessfulExit=false KeepAlive does not restart-loop.
119
+ return 0;
120
+ }
121
+ if (process.stderr.isTTY) {
122
+ console.error(chalk.red(detail));
123
+ }
124
+ return 1;
125
+ }
126
+ }
@@ -0,0 +1,56 @@
1
+ import chalk from 'chalk';
2
+ import { runDoctor } from '../lib/doctor.js';
3
+
4
+ /**
5
+ * @param {object} [options]
6
+ * @param {boolean} [options.json]
7
+ * @param {boolean} [options.verbose]
8
+ * @returns {Promise<number>} exit code
9
+ */
10
+ export async function doctor(options = {}) {
11
+ const result = await runDoctor({
12
+ skipHandshake: options.skipHandshake === true,
13
+ });
14
+
15
+ if (options.json) {
16
+ const payload = {
17
+ ok: result.exitCode === 0,
18
+ summary: result.summary,
19
+ checks: result.checks,
20
+ hints: result.hints,
21
+ };
22
+ console.log(JSON.stringify(payload, null, 2));
23
+ return result.exitCode;
24
+ }
25
+
26
+ console.log(chalk.bold('\nStagepass doctor\n'));
27
+
28
+ for (const item of result.checks) {
29
+ const tag =
30
+ item.status === 'ok'
31
+ ? chalk.green('ok')
32
+ : item.status === 'warn'
33
+ ? chalk.yellow('warn')
34
+ : item.status === 'fail'
35
+ ? chalk.red('fail')
36
+ : chalk.cyan(item.status);
37
+ console.log(`[${tag}] ${item.message}`);
38
+ if (item.detail && (options.verbose || item.status !== 'ok')) {
39
+ console.log(chalk.dim(` ${item.detail}`));
40
+ }
41
+ }
42
+
43
+ console.log('');
44
+ for (const hint of result.hints) {
45
+ console.log(chalk.cyan(`hint: ${hint}`));
46
+ }
47
+
48
+ const { ok, warn, fail } = result.summary;
49
+ console.log(
50
+ chalk.bold(
51
+ `\nSummary: ${ok} ok, ${warn} warn, ${fail} fail (exit ${result.exitCode})`
52
+ )
53
+ );
54
+
55
+ return result.exitCode;
56
+ }
@@ -0,0 +1,368 @@
1
+ import fs from 'fs-extra';
2
+ import path from 'node:path';
3
+ import readline from 'node:readline/promises';
4
+ import { stdin as input, stdout as output } from 'node:process';
5
+ import chalk from 'chalk';
6
+ import { createRequire } from 'module';
7
+ import { defaultExec } from '../lib/exec.js';
8
+ import { defaultSpawn } from '../lib/spawn.js';
9
+ import { validateProjectName } from '../lib/project-name.js';
10
+ import { validateGitRemote } from '../lib/remote-url.js';
11
+ import {
12
+ defaultTemplatesRoot,
13
+ planScaffoldFiles,
14
+ findConflicts,
15
+ } from '../lib/scaffold.js';
16
+ import {
17
+ buildWebflowSnippets,
18
+ printWebflowSnippets,
19
+ } from '../lib/snippets.js';
20
+
21
+ const require = createRequire(import.meta.url);
22
+ const { version: cliVersion } = require('../../package.json');
23
+
24
+ /**
25
+ * Resolve a boolean flag that may appear as --foo / --no-foo.
26
+ * Only argv is trusted: Commander defaults negated pairs to true, which would
27
+ * break defaults like --install (off unless passed).
28
+ *
29
+ * @param {object} _options
30
+ * @param {string} key
31
+ * @param {string[]} argv
32
+ * @param {boolean|undefined} defaultValue undefined = still unset
33
+ */
34
+ export function resolveBoolFlag(_options, key, argv, defaultValue) {
35
+ const pos = `--${key}`;
36
+ const neg = `--no-${key}`;
37
+ if (argv.includes(neg)) return false;
38
+ if (argv.includes(pos)) return true;
39
+ return defaultValue;
40
+ }
41
+
42
+ /**
43
+ * @param {object} options Commander options
44
+ * @param {object} [deps]
45
+ */
46
+ async function resolveAuthor(options, deps) {
47
+ if (options.author != null && String(options.author).trim() !== '') {
48
+ return String(options.author).trim();
49
+ }
50
+ const exec = deps.exec || defaultExec;
51
+ try {
52
+ const { stdout } = await exec('git', ['config', 'user.name']);
53
+ return String(stdout || '').trim();
54
+ } catch {
55
+ return '';
56
+ }
57
+ }
58
+
59
+ /**
60
+ * @param {import('node:readline/promises').Interface} rl
61
+ * @param {string} question
62
+ * @param {string} [defaultValue]
63
+ */
64
+ async function ask(rl, question, defaultValue = '') {
65
+ const suffix = defaultValue ? ` (${defaultValue})` : '';
66
+ const answer = await rl.question(`${question}${suffix}: `);
67
+ const trimmed = String(answer || '').trim();
68
+ return trimmed === '' ? defaultValue : trimmed;
69
+ }
70
+
71
+ /**
72
+ * @param {import('node:readline/promises').Interface} rl
73
+ * @param {string} question
74
+ * @param {boolean} defaultYes
75
+ */
76
+ async function askYesNo(rl, question, defaultYes) {
77
+ const hint = defaultYes ? 'Y/n' : 'y/N';
78
+ const answer = await rl.question(`${question} (${hint}): `);
79
+ const trimmed = String(answer || '').trim().toLowerCase();
80
+ if (trimmed === '') return defaultYes;
81
+ if (['y', 'yes'].includes(trimmed)) return true;
82
+ if (['n', 'no'].includes(trimmed)) return false;
83
+ return defaultYes;
84
+ }
85
+
86
+ /**
87
+ * Merge flags + optional interactive prompts into a resolved config.
88
+ * @param {string|undefined} nameArg
89
+ * @param {object} options
90
+ * @param {object} deps
91
+ */
92
+ export async function resolveNewOptions(nameArg, options = {}, deps = {}) {
93
+ const isTty =
94
+ deps.isTTY != null ? Boolean(deps.isTTY) : Boolean(input.isTTY);
95
+ const interactive = isTty && options.yes !== true;
96
+ const authorDefault = await resolveAuthor(options, deps);
97
+ const argv = Array.isArray(deps.argv) ? deps.argv : process.argv;
98
+
99
+ /** @type {string} */
100
+ let name = nameArg ? String(nameArg).trim() : '';
101
+ /** @type {string} */
102
+ let dir = options.dir != null ? String(options.dir) : '';
103
+ let lang = options.lang === 'js' || options.lang === 'ts' ? options.lang : '';
104
+ let styles =
105
+ options.styles === 'css' || options.styles === 'scss' ? options.styles : '';
106
+
107
+ // Prefer argv for --foo / --no-foo so Commander default quirks do not flip defaults.
108
+ let modules = resolveBoolFlag(options, 'modules', argv, undefined);
109
+ let git = resolveBoolFlag(options, 'git', argv, undefined);
110
+ let install = resolveBoolFlag(options, 'install', argv, undefined);
111
+ let remote = options.remote != null ? String(options.remote).trim() : '';
112
+
113
+ if (interactive) {
114
+ const rl =
115
+ deps.createReadline?.() ||
116
+ readline.createInterface({ input, output });
117
+ try {
118
+ if (!name) {
119
+ name = await ask(rl, 'Project name (DNS-safe)');
120
+ }
121
+ if (!dir) {
122
+ dir = await ask(rl, 'Directory', name || '.');
123
+ }
124
+ if (!options.author) {
125
+ const nextAuthor = await ask(rl, 'Author', authorDefault);
126
+ options = { ...options, author: nextAuthor };
127
+ }
128
+ if (!lang) {
129
+ const raw = await ask(rl, 'Language (ts|js)', 'ts');
130
+ lang = raw === 'js' ? 'js' : 'ts';
131
+ }
132
+ if (!styles) {
133
+ const raw = await ask(rl, 'Styles (scss|css)', 'scss');
134
+ styles = raw === 'css' ? 'css' : 'scss';
135
+ }
136
+ if (modules === undefined) {
137
+ modules = await askYesNo(rl, 'Include @stagepass/modules?', true);
138
+ }
139
+ if (git === undefined) {
140
+ git = await askYesNo(rl, 'Initialize git repository?', true);
141
+ }
142
+ if (git && !remote) {
143
+ remote = await ask(rl, 'Git remote URL (optional)', '');
144
+ }
145
+ if (install === undefined) {
146
+ install = await askYesNo(rl, 'Run npm install now?', false);
147
+ }
148
+ } finally {
149
+ rl.close();
150
+ }
151
+ }
152
+
153
+ // Non-interactive / --yes defaults
154
+ if (!name) {
155
+ return { ok: false, error: 'Project name is required (pass [name] or use a TTY).' };
156
+ }
157
+ const nameCheck = validateProjectName(name);
158
+ if (!nameCheck.ok) {
159
+ return { ok: false, error: nameCheck.error };
160
+ }
161
+ name = nameCheck.name;
162
+
163
+ if (!dir) dir = name;
164
+ if (!lang) lang = 'ts';
165
+ if (!styles) styles = 'scss';
166
+ if (modules === undefined) modules = true;
167
+ if (git === undefined) git = true;
168
+ if (install === undefined) install = false;
169
+
170
+ if (lang !== 'ts' && lang !== 'js') {
171
+ return { ok: false, error: 'Language must be ts or js.' };
172
+ }
173
+ if (styles !== 'scss' && styles !== 'css') {
174
+ return { ok: false, error: 'Styles must be scss or css.' };
175
+ }
176
+
177
+ const remoteCheck = validateGitRemote(remote);
178
+ if (!remoteCheck.ok) {
179
+ return { ok: false, error: remoteCheck.error };
180
+ }
181
+ if (remoteCheck.remote && !git) {
182
+ return {
183
+ ok: false,
184
+ error: 'A git remote requires git init. Pass --git or omit --no-git.',
185
+ };
186
+ }
187
+
188
+ const author =
189
+ options.author != null && String(options.author).trim() !== ''
190
+ ? String(options.author).trim()
191
+ : authorDefault;
192
+
193
+ return {
194
+ ok: true,
195
+ config: {
196
+ name,
197
+ dir,
198
+ author,
199
+ lang,
200
+ styles,
201
+ modules,
202
+ git,
203
+ remote: remoteCheck.remote,
204
+ install,
205
+ dryRun: options.dryRun === true,
206
+ loaderVersion: deps.cliVersion || cliVersion,
207
+ },
208
+ };
209
+ }
210
+
211
+ /**
212
+ * Scaffold a new Stagepass project.
213
+ *
214
+ * @param {string|undefined} nameArg
215
+ * @param {object} [options]
216
+ * @param {object} [deps]
217
+ * @returns {Promise<number>} exit code
218
+ */
219
+ export async function createNew(nameArg, options = {}, deps = {}) {
220
+ const fse = deps.fs || fs;
221
+ const exec = deps.exec || defaultExec;
222
+ const spawn = deps.spawn || defaultSpawn;
223
+ const log = deps.log || console.log;
224
+ const error = deps.error || console.error;
225
+ const cwd = deps.cwd || process.cwd();
226
+ const templatesRoot = deps.templatesRoot || defaultTemplatesRoot();
227
+
228
+ const resolved = await resolveNewOptions(nameArg, options, deps);
229
+ if (!resolved.ok) {
230
+ error(chalk.red(resolved.error));
231
+ return 1;
232
+ }
233
+
234
+ const config = resolved.config;
235
+ const targetDir = path.isAbsolute(config.dir)
236
+ ? config.dir
237
+ : path.resolve(cwd, config.dir);
238
+
239
+ const templatesRootResolved = path.resolve(templatesRoot);
240
+ const readTemplate = async (rel) => {
241
+ const abs = path.resolve(templatesRootResolved, rel);
242
+ const relToRoot = path.relative(templatesRootResolved, abs);
243
+ if (
244
+ relToRoot.startsWith('..') ||
245
+ path.isAbsolute(relToRoot) ||
246
+ relToRoot.split(path.sep).includes('..')
247
+ ) {
248
+ throw new Error(`Template path escapes templates root: ${rel}`);
249
+ }
250
+ return fse.readFile(abs, 'utf8');
251
+ };
252
+
253
+ let files;
254
+ try {
255
+ files = await planScaffoldFiles(config, { readTemplate });
256
+ } catch (err) {
257
+ error(chalk.red(err instanceof Error ? err.message : String(err)));
258
+ return 1;
259
+ }
260
+
261
+ for (const file of files) {
262
+ const rel = String(file.relativePath || '');
263
+ if (
264
+ !rel ||
265
+ path.isAbsolute(rel) ||
266
+ rel.split(/[\\/]/).includes('..')
267
+ ) {
268
+ error(chalk.red(`Refusing unsafe output path: ${rel || '(empty)'}`));
269
+ return 1;
270
+ }
271
+ }
272
+
273
+ const conflicts = await findConflicts(targetDir, files, fse);
274
+ if (conflicts.length > 0) {
275
+ error(chalk.red('Refusing to overwrite existing files:'));
276
+ for (const rel of conflicts) {
277
+ error(` ${rel}`);
278
+ }
279
+ return 1;
280
+ }
281
+
282
+ if (config.dryRun) {
283
+ log(chalk.bold(`Dry run: would create project in ${targetDir}`));
284
+ for (const file of files) {
285
+ log(` ${file.relativePath}`);
286
+ }
287
+ if (config.git) log(' (git init)');
288
+ if (config.remote) log(` (git remote add origin ${config.remote})`);
289
+ if (config.install) log(' (npm install)');
290
+ return 0;
291
+ }
292
+
293
+ await fse.ensureDir(targetDir);
294
+
295
+ for (const file of files) {
296
+ const abs = path.resolve(targetDir, file.relativePath);
297
+ const relToTarget = path.relative(targetDir, abs);
298
+ if (
299
+ relToTarget.startsWith('..') ||
300
+ path.isAbsolute(relToTarget) ||
301
+ relToTarget.split(path.sep).includes('..')
302
+ ) {
303
+ error(chalk.red(`Refusing to write outside project directory: ${file.relativePath}`));
304
+ return 1;
305
+ }
306
+ await fse.ensureDir(path.dirname(abs));
307
+ await fse.writeFile(abs, file.contents, 'utf8');
308
+ }
309
+
310
+ if (config.git) {
311
+ try {
312
+ await exec('git', ['init'], { cwd: targetDir });
313
+ if (config.remote) {
314
+ await exec('git', ['remote', 'add', 'origin', config.remote], {
315
+ cwd: targetDir,
316
+ });
317
+ }
318
+ } catch (err) {
319
+ error(
320
+ chalk.red(
321
+ `Git setup failed: ${err instanceof Error ? err.message : String(err)}`
322
+ )
323
+ );
324
+ return 1;
325
+ }
326
+ }
327
+
328
+ if (config.install) {
329
+ try {
330
+ const result = await spawn('npm', ['install'], {
331
+ cwd: targetDir,
332
+ stdio: 'inherit',
333
+ shell: false,
334
+ env: process.env,
335
+ });
336
+ if (result.code !== 0) {
337
+ error(chalk.red(`npm install exited with code ${result.code}`));
338
+ return typeof result.code === 'number' ? result.code : 1;
339
+ }
340
+ } catch (err) {
341
+ error(
342
+ chalk.red(
343
+ `npm install failed: ${err instanceof Error ? err.message : String(err)}`
344
+ )
345
+ );
346
+ return 1;
347
+ }
348
+ }
349
+
350
+ log(chalk.green(`Created Stagepass project at ${targetDir}`));
351
+ log(chalk.dim('Next:'));
352
+ if (!config.install) {
353
+ log(` cd ${path.relative(cwd, targetDir) || '.'} && npm install`);
354
+ }
355
+ log(' npm run build');
356
+ log(` stagepass link ${config.name} --origin my-project.webflow.io`);
357
+
358
+ const snippets = buildWebflowSnippets({
359
+ version: config.loaderVersion,
360
+ modules: config.modules,
361
+ });
362
+ printWebflowSnippets(snippets, log);
363
+
364
+ return 0;
365
+ }
366
+
367
+ /** Commander-facing alias */
368
+ export const newProject = createNew;
@@ -0,0 +1,84 @@
1
+ import fs from 'fs-extra';
2
+ import path from 'path';
3
+ import chalk from 'chalk';
4
+ import { defaultSpawn } from '../lib/spawn.js';
5
+
6
+ /**
7
+ * Run an npm lifecycle script in cwd via spawn (no shell).
8
+ *
9
+ * @param {string} scriptName
10
+ * @param {object} [options]
11
+ * @param {boolean} [options.verbose]
12
+ * @param {object} [deps]
13
+ * @param {typeof fs} [deps.fs]
14
+ * @param {string} [deps.cwd]
15
+ * @param {import('../lib/spawn.js').SpawnFn} [deps.spawn]
16
+ * @param {(msg?: string) => void} [deps.log]
17
+ * @param {(msg?: string) => void} [deps.error]
18
+ * @returns {Promise<number>} exit code
19
+ */
20
+ export async function runNpmScript(scriptName, options = {}, deps = {}) {
21
+ const fse = deps.fs || fs;
22
+ const cwd = deps.cwd || process.cwd();
23
+ const spawn = deps.spawn || defaultSpawn;
24
+ const log = deps.log || console.log;
25
+ const error = deps.error || console.error;
26
+ const pkgPath = path.join(cwd, 'package.json');
27
+
28
+ if (!(await fse.pathExists(pkgPath))) {
29
+ error(chalk.red('No package.json found in the current directory.'));
30
+ return 1;
31
+ }
32
+
33
+ let pkg;
34
+ try {
35
+ pkg = JSON.parse(await fse.readFile(pkgPath, 'utf8'));
36
+ } catch {
37
+ error(chalk.red('package.json is not valid JSON.'));
38
+ return 1;
39
+ }
40
+
41
+ if (!pkg.scripts || typeof pkg.scripts[scriptName] !== 'string') {
42
+ error(
43
+ chalk.red(
44
+ `No "${scriptName}" script in package.json. Add one, or run this command inside a Stagepass project created with \`stagepass new\`.`
45
+ )
46
+ );
47
+ return 1;
48
+ }
49
+
50
+ if (options.verbose) {
51
+ log(chalk.dim(`Running: npm run ${scriptName}`));
52
+ }
53
+
54
+ try {
55
+ const result = await spawn('npm', ['run', scriptName], {
56
+ cwd,
57
+ stdio: 'inherit',
58
+ shell: false,
59
+ env: process.env,
60
+ });
61
+ return typeof result.code === 'number' ? result.code : 1;
62
+ } catch (err) {
63
+ error(chalk.red(err instanceof Error ? err.message : String(err)));
64
+ return 1;
65
+ }
66
+ }
67
+
68
+ /**
69
+ * @param {object} [options]
70
+ * @param {object} [deps]
71
+ * @returns {Promise<number>}
72
+ */
73
+ export async function watch(options = {}, deps = {}) {
74
+ return runNpmScript('watch', options, deps);
75
+ }
76
+
77
+ /**
78
+ * @param {object} [options]
79
+ * @param {object} [deps]
80
+ * @returns {Promise<number>}
81
+ */
82
+ export async function build(options = {}, deps = {}) {
83
+ return runNpmScript('build', options, deps);
84
+ }
@@ -1,6 +1,7 @@
1
1
  import { execa } from 'execa';
2
2
  import chalk from 'chalk';
3
3
  import ora from 'ora';
4
+ import { getAutostartStatus } from '../lib/autostart.js';
4
5
 
5
6
  export async function stop(options = {}) {
6
7
  console.log(chalk.bold('\nšŸ›‘ Stopping Stagepass...'));
@@ -34,6 +35,20 @@ export async function stop(options = {}) {
34
35
  console.log(chalk.green('āœ” Services stopped.'));
35
36
  }
36
37
 
38
+ // Non-breaking hint only: existing stop semantics stay unchanged.
39
+ try {
40
+ const status = await getAutostartStatus();
41
+ if (status.loaded || status.plistExists) {
42
+ console.log(
43
+ chalk.dim(
44
+ 'Autostart is enabled; Caddy may start again at next login. Use `stagepass autostart off` to disable permanently.'
45
+ )
46
+ );
47
+ }
48
+ } catch {
49
+ // ignore status failures
50
+ }
51
+
37
52
  } catch (error) {
38
53
  if (!options.verbose) spinner.fail('Error stopping services.');
39
54
  console.error(chalk.red(error.message));