@vizzly-testing/cli 0.25.0 → 0.26.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/dist/cli.js +14 -3
- package/dist/commands/finalize.js +42 -2
- package/dist/commands/preview.js +56 -7
- package/dist/commands/tdd-daemon.js +195 -22
- package/dist/reporter/reporter-bundle.iife.js +2 -2
- package/dist/tdd/server-registry.js +245 -0
- package/dist/utils/ci-env.js +1 -1
- package/dist/utils/global-config.js +26 -0
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -11,7 +11,7 @@ import { projectListCommand, projectRemoveCommand, projectSelectCommand, project
|
|
|
11
11
|
import { runCommand, validateRunOptions } from './commands/run.js';
|
|
12
12
|
import { statusCommand, validateStatusOptions } from './commands/status.js';
|
|
13
13
|
import { tddCommand, validateTddOptions } from './commands/tdd.js';
|
|
14
|
-
import { runDaemonChild, tddStartCommand, tddStatusCommand, tddStopCommand } from './commands/tdd-daemon.js';
|
|
14
|
+
import { runDaemonChild, tddListCommand, tddStartCommand, tddStatusCommand, tddStopCommand } from './commands/tdd-daemon.js';
|
|
15
15
|
import { uploadCommand, validateUploadOptions } from './commands/upload.js';
|
|
16
16
|
import { validateWhoamiOptions, whoamiCommand } from './commands/whoami.js';
|
|
17
17
|
import { createPluginServices } from './plugin-api.js';
|
|
@@ -22,6 +22,7 @@ import { openBrowser } from './utils/browser.js';
|
|
|
22
22
|
import { colors } from './utils/colors.js';
|
|
23
23
|
import { loadConfig } from './utils/config-loader.js';
|
|
24
24
|
import { getContext } from './utils/context.js';
|
|
25
|
+
import { saveUserPath } from './utils/global-config.js';
|
|
25
26
|
import * as output from './utils/output.js';
|
|
26
27
|
import { getPackageVersion } from './utils/package-info.js';
|
|
27
28
|
|
|
@@ -188,7 +189,7 @@ const formatHelp = (cmd, helper) => {
|
|
|
188
189
|
lines.push('');
|
|
189
190
|
return lines.join('\n');
|
|
190
191
|
};
|
|
191
|
-
program.name('vizzly').description('Vizzly CLI for visual regression testing').version(getPackageVersion()).option('-c, --config <path>', 'Config file path').option('--token <token>', 'Vizzly API token').option('-v, --verbose', 'Verbose output (shorthand for --log-level debug)').option('--log-level <level>', 'Log level: debug, info, warn, error (default: info, or VIZZLY_LOG_LEVEL env var)').option('--json', 'Machine-readable output').option('--color', 'Force colored output (even in non-TTY)').option('--no-color', 'Disable colored output').configureHelp({
|
|
192
|
+
program.name('vizzly').description('Vizzly CLI for visual regression testing').version(getPackageVersion()).option('-c, --config <path>', 'Config file path').option('--token <token>', 'Vizzly API token').option('-v, --verbose', 'Verbose output (shorthand for --log-level debug)').option('--log-level <level>', 'Log level: debug, info, warn, error (default: info, or VIZZLY_LOG_LEVEL env var)').option('--json', 'Machine-readable output').option('--color', 'Force colored output (even in non-TTY)').option('--no-color', 'Disable colored output').option('--strict', 'Fail on any error (default: be resilient, warn on non-critical issues)').configureHelp({
|
|
192
193
|
formatHelp
|
|
193
194
|
});
|
|
194
195
|
|
|
@@ -300,6 +301,12 @@ tddCmd.command('status').description('Check TDD server status').action(async opt
|
|
|
300
301
|
await tddStatusCommand(options, globalOptions);
|
|
301
302
|
});
|
|
302
303
|
|
|
304
|
+
// TDD List - List all running servers (for menubar app integration)
|
|
305
|
+
tddCmd.command('list').description('List all running TDD servers').action(async options => {
|
|
306
|
+
const globalOptions = program.opts();
|
|
307
|
+
await tddListCommand(options, globalOptions);
|
|
308
|
+
});
|
|
309
|
+
|
|
303
310
|
// TDD Run - One-off test run with ephemeral server (generates static report)
|
|
304
311
|
tddCmd.command('run <command>').description('Run tests once in TDD mode with local visual comparisons').option('--port <port>', 'Port for TDD server', '47392').option('--branch <branch>', 'Git branch override').option('--environment <env>', 'Environment name', 'test').option('--threshold <number>', 'Comparison threshold', parseFloat).option('--token <token>', 'API token override').option('--timeout <ms>', 'Server timeout in milliseconds', '30000').option('--baseline-build <id>', 'Use specific build as baseline').option('--baseline-comparison <id>', 'Use specific comparison as baseline').option('--set-baseline', 'Accept current screenshots as new baseline (overwrites existing)').option('--fail-on-diff', 'Fail tests when visual differences are detected').option('--no-open', 'Skip opening report in browser').action(async (command, options) => {
|
|
305
312
|
const globalOptions = program.opts();
|
|
@@ -412,7 +419,7 @@ program.command('finalize').description('Finalize a parallel build after all sha
|
|
|
412
419
|
}
|
|
413
420
|
await finalizeCommand(parallelId, options, globalOptions);
|
|
414
421
|
});
|
|
415
|
-
program.command('preview').description('Upload static files as a preview for a build').argument('[path]', 'Path to static files (dist/, build/, out/)').option('-b, --build <id>', 'Build ID to attach preview to').option('-p, --parallel-id <id>', 'Look up build by parallel ID').option('--base <path>', 'Override auto-detected base path').option('--open', 'Open preview URL in browser after upload').option('--dry-run', 'Show what would be uploaded without uploading').option('-x, --exclude <pattern>', 'Exclude files/dirs (repeatable, e.g. -x "*.log" -x "temp/")', (val, prev) => prev ? [...prev, val] : [val]).option('-i, --include <pattern>', 'Override default exclusions (repeatable, e.g. -i package.json -i tests/)', (val, prev) => prev ? [...prev, val] : [val]).action(async (path, options) => {
|
|
422
|
+
program.command('preview').description('Upload static files as a preview for a build').argument('[path]', 'Path to static files (dist/, build/, out/)').option('-b, --build <id>', 'Build ID to attach preview to').option('-p, --parallel-id <id>', 'Look up build by parallel ID').option('--base <path>', 'Override auto-detected base path').option('--open', 'Open preview URL in browser after upload').option('--dry-run', 'Show what would be uploaded without uploading').option('--public-link', 'Acknowledge that preview URL grants access to anyone with the link (required for private projects)').option('-x, --exclude <pattern>', 'Exclude files/dirs (repeatable, e.g. -x "*.log" -x "temp/")', (val, prev) => prev ? [...prev, val] : [val]).option('-i, --include <pattern>', 'Override default exclusions (repeatable, e.g. -i package.json -i tests/)', (val, prev) => prev ? [...prev, val] : [val]).action(async (path, options) => {
|
|
416
423
|
const globalOptions = program.opts();
|
|
417
424
|
|
|
418
425
|
// Show helpful error if path is missing
|
|
@@ -521,4 +528,8 @@ program.command('project:remove').description('Remove project configuration for
|
|
|
521
528
|
const globalOptions = program.opts();
|
|
522
529
|
await projectRemoveCommand(options, globalOptions);
|
|
523
530
|
});
|
|
531
|
+
|
|
532
|
+
// Save user's PATH for menubar app (non-blocking, runs in background)
|
|
533
|
+
// This auto-configures the menubar app so it can find npx/node
|
|
534
|
+
saveUserPath().catch(() => {});
|
|
524
535
|
program.parse();
|
|
@@ -7,6 +7,7 @@ import { createApiClient as defaultCreateApiClient, finalizeParallelBuild as def
|
|
|
7
7
|
import { loadConfig as defaultLoadConfig } from '../utils/config-loader.js';
|
|
8
8
|
import * as defaultOutput from '../utils/output.js';
|
|
9
9
|
import { writeSession as defaultWriteSession } from '../utils/session.js';
|
|
10
|
+
let MISSING_BUILD_HINTS = [' • No screenshots were uploaded with this parallel-id', ' • Tests were skipped or failed before capturing screenshots', ' • The parallel-id does not match what was used during test runs'];
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
13
|
* Finalize command implementation
|
|
@@ -89,15 +90,54 @@ export async function finalizeCommand(parallelId, options = {}, globalOptions =
|
|
|
89
90
|
};
|
|
90
91
|
} catch (error) {
|
|
91
92
|
output.stopSpinner();
|
|
93
|
+
let status = error.context?.status;
|
|
92
94
|
|
|
93
95
|
// Don't fail CI for Vizzly infrastructure issues (5xx errors)
|
|
94
|
-
|
|
96
|
+
// Note: --strict does NOT affect 5xx handling - infrastructure issues are out of user's control
|
|
95
97
|
if (status >= 500) {
|
|
96
98
|
output.warn('Vizzly API unavailable - finalize skipped.');
|
|
97
99
|
return {
|
|
98
100
|
success: true,
|
|
99
101
|
result: {
|
|
100
|
-
skipped: true
|
|
102
|
+
skipped: true,
|
|
103
|
+
reason: 'api-unavailable'
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Handle missing builds gracefully (404 errors)
|
|
109
|
+
// This happens when: no screenshots were uploaded, tests were skipped, or parallel-id doesn't exist
|
|
110
|
+
if (status === 404) {
|
|
111
|
+
let isStrict = globalOptions.strict;
|
|
112
|
+
if (isStrict) {
|
|
113
|
+
output.error(`No build found for parallel ID: ${parallelId}`);
|
|
114
|
+
output.blank();
|
|
115
|
+
output.info('This can happen when:');
|
|
116
|
+
for (let hint of MISSING_BUILD_HINTS) {
|
|
117
|
+
output.info(hint);
|
|
118
|
+
}
|
|
119
|
+
exit(1);
|
|
120
|
+
return {
|
|
121
|
+
success: false,
|
|
122
|
+
reason: 'no-build-found',
|
|
123
|
+
error
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// Non-strict mode: warn but don't fail CI
|
|
128
|
+
output.warn(`No build found for parallel ID: ${parallelId} - finalize skipped.`);
|
|
129
|
+
if (globalOptions.verbose) {
|
|
130
|
+
output.info('Possible reasons:');
|
|
131
|
+
for (let hint of MISSING_BUILD_HINTS) {
|
|
132
|
+
output.info(hint);
|
|
133
|
+
}
|
|
134
|
+
output.info('Use --strict flag to fail CI when no build is found.');
|
|
135
|
+
}
|
|
136
|
+
return {
|
|
137
|
+
success: true,
|
|
138
|
+
result: {
|
|
139
|
+
skipped: true,
|
|
140
|
+
reason: 'no-build-found'
|
|
101
141
|
}
|
|
102
142
|
};
|
|
103
143
|
}
|
package/dist/commands/preview.js
CHANGED
|
@@ -12,7 +12,7 @@ import { readFile, realpath, stat, unlink } from 'node:fs/promises';
|
|
|
12
12
|
import { tmpdir } from 'node:os';
|
|
13
13
|
import { join, resolve } from 'node:path';
|
|
14
14
|
import { promisify } from 'node:util';
|
|
15
|
-
import { createApiClient as defaultCreateApiClient, uploadPreviewZip as defaultUploadPreviewZip } from '../api/index.js';
|
|
15
|
+
import { createApiClient as defaultCreateApiClient, getBuild as defaultGetBuild, uploadPreviewZip as defaultUploadPreviewZip } from '../api/index.js';
|
|
16
16
|
import { openBrowser as defaultOpenBrowser } from '../utils/browser.js';
|
|
17
17
|
import { loadConfig as defaultLoadConfig } from '../utils/config-loader.js';
|
|
18
18
|
import { detectBranch as defaultDetectBranch } from '../utils/git.js';
|
|
@@ -273,6 +273,7 @@ export async function previewCommand(path, options = {}, globalOptions = {}, dep
|
|
|
273
273
|
let {
|
|
274
274
|
loadConfig = defaultLoadConfig,
|
|
275
275
|
createApiClient = defaultCreateApiClient,
|
|
276
|
+
getBuild = defaultGetBuild,
|
|
276
277
|
uploadPreviewZip = defaultUploadPreviewZip,
|
|
277
278
|
readSession = defaultReadSession,
|
|
278
279
|
formatSessionAge = defaultFormatSessionAge,
|
|
@@ -377,6 +378,59 @@ export async function previewCommand(path, options = {}, globalOptions = {}, dep
|
|
|
377
378
|
};
|
|
378
379
|
}
|
|
379
380
|
|
|
381
|
+
// Create API client for non-dry-run operations (reused for visibility check and upload)
|
|
382
|
+
let client;
|
|
383
|
+
if (!options.dryRun) {
|
|
384
|
+
client = createApiClient({
|
|
385
|
+
baseUrl: config.apiUrl,
|
|
386
|
+
token: config.apiKey,
|
|
387
|
+
command: 'preview'
|
|
388
|
+
});
|
|
389
|
+
|
|
390
|
+
// Check project visibility for private projects
|
|
391
|
+
let buildResponse;
|
|
392
|
+
try {
|
|
393
|
+
buildResponse = await getBuild(client, buildId);
|
|
394
|
+
} catch (error) {
|
|
395
|
+
if (error.status === 404) {
|
|
396
|
+
output.error(`Build not found: ${buildId}`);
|
|
397
|
+
} else {
|
|
398
|
+
output.error('Failed to verify project visibility', error);
|
|
399
|
+
}
|
|
400
|
+
exit(1);
|
|
401
|
+
// Return is for testing (exit is mocked in tests)
|
|
402
|
+
return {
|
|
403
|
+
success: false,
|
|
404
|
+
reason: 'build-fetch-failed',
|
|
405
|
+
error
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
// Check if project is private and user hasn't acknowledged public link access
|
|
410
|
+
// Note: API returns { build, project } at top level, not nested
|
|
411
|
+
// Use === false to handle undefined/missing isPublic defensively
|
|
412
|
+
let project = buildResponse.project;
|
|
413
|
+
let isPrivate = project && project.isPublic === false;
|
|
414
|
+
if (isPrivate && !options.publicLink) {
|
|
415
|
+
output.error('This project is private.');
|
|
416
|
+
output.blank();
|
|
417
|
+
output.print(' Preview URLs grant access to anyone with the link (until expiration).');
|
|
418
|
+
output.blank();
|
|
419
|
+
output.print(' To proceed, acknowledge this by using:');
|
|
420
|
+
output.blank();
|
|
421
|
+
output.print(' vizzly preview ./dist --public-link');
|
|
422
|
+
output.blank();
|
|
423
|
+
output.print(' Or set your project to public in Vizzly settings.');
|
|
424
|
+
output.blank();
|
|
425
|
+
exit(1);
|
|
426
|
+
// Return is for testing (exit is mocked in tests)
|
|
427
|
+
return {
|
|
428
|
+
success: false,
|
|
429
|
+
reason: 'private-project-no-flag'
|
|
430
|
+
};
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
|
|
380
434
|
// Check for zip command availability (skip for dry-run)
|
|
381
435
|
if (!options.dryRun) {
|
|
382
436
|
let zipInfo = getZipCommand();
|
|
@@ -532,13 +586,8 @@ export async function previewCommand(path, options = {}, globalOptions = {}, dep
|
|
|
532
586
|
let compressionRatio = ((1 - zipBuffer.length / totalSize) * 100).toFixed(0);
|
|
533
587
|
output.updateSpinner(`Compressed to ${formatBytes(zipBuffer.length)} (${compressionRatio}% smaller)`);
|
|
534
588
|
|
|
535
|
-
// Upload
|
|
589
|
+
// Upload (reuse client created earlier)
|
|
536
590
|
output.updateSpinner('Uploading preview...');
|
|
537
|
-
let client = createApiClient({
|
|
538
|
-
baseUrl: config.apiUrl,
|
|
539
|
-
token: config.apiKey,
|
|
540
|
-
command: 'preview'
|
|
541
|
-
});
|
|
542
591
|
let result = await uploadPreviewZip(client, buildId, zipBuffer);
|
|
543
592
|
output.stopSpinner();
|
|
544
593
|
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { spawn } from 'node:child_process';
|
|
2
2
|
import { existsSync, mkdirSync, readFileSync, unlinkSync, writeFileSync } from 'node:fs';
|
|
3
3
|
import { homedir } from 'node:os';
|
|
4
|
-
import { join } from 'node:path';
|
|
4
|
+
import { basename, join } from 'node:path';
|
|
5
|
+
import { getServerRegistry } from '../tdd/server-registry.js';
|
|
5
6
|
import * as output from '../utils/output.js';
|
|
6
7
|
import { tddCommand } from './tdd.js';
|
|
7
8
|
|
|
@@ -16,32 +17,72 @@ export async function tddStartCommand(options = {}, globalOptions = {}) {
|
|
|
16
17
|
verbose: globalOptions.verbose,
|
|
17
18
|
color: !globalOptions.noColor
|
|
18
19
|
});
|
|
20
|
+
let registry = getServerRegistry();
|
|
21
|
+
let colors = output.getColors();
|
|
19
22
|
|
|
20
|
-
// Check if
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
23
|
+
// Check if THIS directory already has a server running
|
|
24
|
+
let existingServer = registry.find({
|
|
25
|
+
directory: process.cwd()
|
|
26
|
+
});
|
|
27
|
+
if (existingServer) {
|
|
28
|
+
// Verify it's actually running
|
|
29
|
+
if (await isServerRunning(existingServer.port)) {
|
|
30
|
+
output.header('tdd', 'local');
|
|
31
|
+
output.print(` ${output.statusDot('success')} Already running`);
|
|
32
|
+
output.blank();
|
|
33
|
+
output.printBox(colors.brand.info(colors.underline(`http://localhost:${existingServer.port}`)), {
|
|
34
|
+
title: 'Dashboard',
|
|
35
|
+
style: 'branded'
|
|
36
|
+
});
|
|
37
|
+
if (options.open) {
|
|
38
|
+
openDashboard(existingServer.port);
|
|
39
|
+
}
|
|
40
|
+
return;
|
|
41
|
+
} else {
|
|
42
|
+
// Stale entry - clean it up (registry and local files)
|
|
43
|
+
registry.unregister({
|
|
44
|
+
directory: process.cwd()
|
|
45
|
+
});
|
|
46
|
+
let vizzlyDir = join(process.cwd(), '.vizzly');
|
|
47
|
+
let pidFile = join(vizzlyDir, 'server.pid');
|
|
48
|
+
let serverFile = join(vizzlyDir, 'server.json');
|
|
49
|
+
if (existsSync(pidFile)) unlinkSync(pidFile);
|
|
50
|
+
if (existsSync(serverFile)) unlinkSync(serverFile);
|
|
33
51
|
}
|
|
34
|
-
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Determine port: user-specified or auto-allocate
|
|
55
|
+
let port;
|
|
56
|
+
let autoAllocated = false;
|
|
57
|
+
if (options.port) {
|
|
58
|
+
// User specified a port - use it (will fail if busy)
|
|
59
|
+
port = options.port;
|
|
60
|
+
|
|
61
|
+
// Check if user-specified port is in use
|
|
62
|
+
if (await isServerRunning(port)) {
|
|
63
|
+
output.header('tdd', 'local');
|
|
64
|
+
output.print(` ${output.statusDot('error')} Port ${port} is already in use`);
|
|
65
|
+
output.blank();
|
|
66
|
+
output.hint('Try a different port: vizzly tdd start --port 47393');
|
|
67
|
+
output.hint('Or let Vizzly auto-allocate: vizzly tdd start');
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
} else {
|
|
71
|
+
// Auto-allocate an available port
|
|
72
|
+
// Note: There's a small race window between finding a port and binding.
|
|
73
|
+
// The registry acts as a soft reservation, and findAvailablePort does
|
|
74
|
+
// an actual TCP bind test to minimize this window.
|
|
75
|
+
port = await registry.findAvailablePort();
|
|
76
|
+
autoAllocated = port !== 47392;
|
|
35
77
|
}
|
|
36
78
|
try {
|
|
37
79
|
// Ensure .vizzly directory exists
|
|
38
|
-
|
|
80
|
+
let vizzlyDir = join(process.cwd(), '.vizzly');
|
|
39
81
|
if (!existsSync(vizzlyDir)) {
|
|
40
82
|
mkdirSync(vizzlyDir, {
|
|
41
83
|
recursive: true
|
|
42
84
|
});
|
|
43
85
|
}
|
|
44
|
-
const port = options.port || 47392;
|
|
45
86
|
|
|
46
87
|
// Show header first so debug messages appear below it
|
|
47
88
|
output.header('tdd', 'local');
|
|
@@ -119,7 +160,28 @@ export async function tddStartCommand(options = {}, globalOptions = {}) {
|
|
|
119
160
|
process.exit(1);
|
|
120
161
|
}
|
|
121
162
|
|
|
122
|
-
//
|
|
163
|
+
// Register server in global registry (for menubar app)
|
|
164
|
+
try {
|
|
165
|
+
let registry = getServerRegistry();
|
|
166
|
+
|
|
167
|
+
// Clean up any stale servers first
|
|
168
|
+
registry.cleanupStale();
|
|
169
|
+
|
|
170
|
+
// Register this server with log file path for menubar to read
|
|
171
|
+
let serverLogFile = join(process.cwd(), '.vizzly', 'server.log');
|
|
172
|
+
registry.register({
|
|
173
|
+
pid: child.pid,
|
|
174
|
+
port: port,
|
|
175
|
+
directory: process.cwd(),
|
|
176
|
+
name: basename(process.cwd()),
|
|
177
|
+
startedAt: new Date().toISOString(),
|
|
178
|
+
logFile: serverLogFile
|
|
179
|
+
});
|
|
180
|
+
} catch {
|
|
181
|
+
// Non-fatal
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// Also write legacy server.json for SDK discovery (backwards compatibility)
|
|
123
185
|
try {
|
|
124
186
|
const globalVizzlyDir = join(homedir(), '.vizzly');
|
|
125
187
|
if (!existsSync(globalVizzlyDir)) {
|
|
@@ -138,8 +200,11 @@ export async function tddStartCommand(options = {}, globalOptions = {}) {
|
|
|
138
200
|
// Non-fatal, SDK can still use health check
|
|
139
201
|
}
|
|
140
202
|
|
|
141
|
-
//
|
|
142
|
-
|
|
203
|
+
// Show auto-allocated port message if applicable
|
|
204
|
+
if (autoAllocated) {
|
|
205
|
+
output.print(` ${output.statusDot('info')} Auto-assigned port ${colors.brand.textTertiary(`:${port}`)}`);
|
|
206
|
+
output.blank();
|
|
207
|
+
}
|
|
143
208
|
|
|
144
209
|
// Show dashboard URL in a branded box
|
|
145
210
|
let dashboardUrl = `http://localhost:${port}`;
|
|
@@ -177,6 +242,17 @@ export async function tddStartCommand(options = {}, globalOptions = {}) {
|
|
|
177
242
|
export async function runDaemonChild(options = {}, globalOptions = {}) {
|
|
178
243
|
const vizzlyDir = join(process.cwd(), '.vizzly');
|
|
179
244
|
const port = options.port || 47392;
|
|
245
|
+
|
|
246
|
+
// Set up log file for menubar app to read
|
|
247
|
+
const logFile = join(vizzlyDir, 'server.log');
|
|
248
|
+
|
|
249
|
+
// Configure output to write JSON logs to file (before tddCommand configures it)
|
|
250
|
+
output.configure({
|
|
251
|
+
logFile,
|
|
252
|
+
json: globalOptions.json,
|
|
253
|
+
verbose: globalOptions.verbose,
|
|
254
|
+
color: !globalOptions.noColor
|
|
255
|
+
});
|
|
180
256
|
try {
|
|
181
257
|
// Use existing tddCommand but with daemon mode
|
|
182
258
|
const {
|
|
@@ -200,7 +276,8 @@ export async function runDaemonChild(options = {}, globalOptions = {}) {
|
|
|
200
276
|
pid: process.pid,
|
|
201
277
|
port: port,
|
|
202
278
|
startTime: Date.now(),
|
|
203
|
-
failOnDiff: options.failOnDiff || false
|
|
279
|
+
failOnDiff: options.failOnDiff || false,
|
|
280
|
+
logFile: logFile
|
|
204
281
|
};
|
|
205
282
|
writeFileSync(join(vizzlyDir, 'server.json'), JSON.stringify(serverInfo, null, 2));
|
|
206
283
|
|
|
@@ -212,7 +289,18 @@ export async function runDaemonChild(options = {}, globalOptions = {}) {
|
|
|
212
289
|
const serverFile = join(vizzlyDir, 'server.json');
|
|
213
290
|
if (existsSync(serverFile)) unlinkSync(serverFile);
|
|
214
291
|
|
|
215
|
-
//
|
|
292
|
+
// Unregister from global registry (for menubar app)
|
|
293
|
+
try {
|
|
294
|
+
let registry = getServerRegistry();
|
|
295
|
+
registry.unregister({
|
|
296
|
+
port: port,
|
|
297
|
+
directory: process.cwd()
|
|
298
|
+
});
|
|
299
|
+
} catch {
|
|
300
|
+
// Non-fatal
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
// Clean up legacy global server file
|
|
216
304
|
try {
|
|
217
305
|
const globalServerFile = join(homedir(), '.vizzly', 'server.json');
|
|
218
306
|
if (existsSync(globalServerFile)) unlinkSync(globalServerFile);
|
|
@@ -329,12 +417,35 @@ export async function tddStopCommand(options = {}, globalOptions = {}) {
|
|
|
329
417
|
// Clean up files
|
|
330
418
|
if (existsSync(pidFile)) unlinkSync(pidFile);
|
|
331
419
|
if (existsSync(serverFile)) unlinkSync(serverFile);
|
|
420
|
+
|
|
421
|
+
// Unregister from global registry (for menubar app)
|
|
422
|
+
try {
|
|
423
|
+
let registry = getServerRegistry();
|
|
424
|
+
registry.unregister({
|
|
425
|
+
port: port,
|
|
426
|
+
directory: process.cwd()
|
|
427
|
+
});
|
|
428
|
+
} catch {
|
|
429
|
+
// Non-fatal
|
|
430
|
+
}
|
|
431
|
+
output.print(` ${output.statusDot('success')} Server stopped`);
|
|
332
432
|
} catch (error) {
|
|
333
433
|
if (error.code === 'ESRCH') {
|
|
334
434
|
// Process not found - clean up stale files
|
|
335
435
|
output.warn('TDD server was not running (cleaning up stale files)');
|
|
336
436
|
if (existsSync(pidFile)) unlinkSync(pidFile);
|
|
337
437
|
if (existsSync(serverFile)) unlinkSync(serverFile);
|
|
438
|
+
|
|
439
|
+
// Still unregister from registry
|
|
440
|
+
try {
|
|
441
|
+
let registry = getServerRegistry();
|
|
442
|
+
registry.unregister({
|
|
443
|
+
port: port,
|
|
444
|
+
directory: process.cwd()
|
|
445
|
+
});
|
|
446
|
+
} catch {
|
|
447
|
+
// Non-fatal
|
|
448
|
+
}
|
|
338
449
|
} else {
|
|
339
450
|
output.error('Error stopping TDD server', error);
|
|
340
451
|
}
|
|
@@ -475,4 +586,66 @@ function openDashboard(port = 47392) {
|
|
|
475
586
|
detached: true,
|
|
476
587
|
stdio: 'ignore'
|
|
477
588
|
}).unref();
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
/**
|
|
592
|
+
* List all running TDD servers from the global registry
|
|
593
|
+
* @param {Object} options - Command options
|
|
594
|
+
* @param {Object} globalOptions - Global CLI options
|
|
595
|
+
*/
|
|
596
|
+
export async function tddListCommand(_options, globalOptions = {}) {
|
|
597
|
+
output.configure({
|
|
598
|
+
json: globalOptions.json,
|
|
599
|
+
verbose: globalOptions.verbose,
|
|
600
|
+
color: !globalOptions.noColor
|
|
601
|
+
});
|
|
602
|
+
let registry = getServerRegistry();
|
|
603
|
+
|
|
604
|
+
// Clean up stale servers first
|
|
605
|
+
let cleaned = registry.cleanupStale();
|
|
606
|
+
if (cleaned > 0 && globalOptions.verbose) {
|
|
607
|
+
output.debug('tdd', `Cleaned up ${cleaned} stale server(s)`);
|
|
608
|
+
}
|
|
609
|
+
let servers = registry.list();
|
|
610
|
+
|
|
611
|
+
// JSON output
|
|
612
|
+
if (globalOptions.json) {
|
|
613
|
+
console.log(JSON.stringify({
|
|
614
|
+
servers
|
|
615
|
+
}, null, 2));
|
|
616
|
+
return;
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
// No servers
|
|
620
|
+
if (servers.length === 0) {
|
|
621
|
+
output.info('No TDD servers running');
|
|
622
|
+
output.hint('Start one with: vizzly tdd start');
|
|
623
|
+
return;
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
// Table output
|
|
627
|
+
let colors = output.getColors();
|
|
628
|
+
output.header('tdd', 'servers');
|
|
629
|
+
output.blank();
|
|
630
|
+
for (let server of servers) {
|
|
631
|
+
let uptimeStr = '';
|
|
632
|
+
if (server.startedAt) {
|
|
633
|
+
let startTime = new Date(server.startedAt).getTime();
|
|
634
|
+
let uptime = Math.floor((Date.now() - startTime) / 1000);
|
|
635
|
+
let hours = Math.floor(uptime / 3600);
|
|
636
|
+
let minutes = Math.floor(uptime % 3600 / 60);
|
|
637
|
+
if (hours > 0) uptimeStr += `${hours}h `;
|
|
638
|
+
if (minutes > 0 || hours > 0) uptimeStr += `${minutes}m`;else uptimeStr = '<1m';
|
|
639
|
+
}
|
|
640
|
+
let name = server.name || basename(server.directory);
|
|
641
|
+
let portStr = colors.brand.textTertiary(`:${server.port}`);
|
|
642
|
+
let uptimeLabel = uptimeStr ? colors.brand.textMuted(` · ${uptimeStr}`) : '';
|
|
643
|
+
output.print(` ${output.statusDot('success')} ${name}${portStr}${uptimeLabel}`);
|
|
644
|
+
output.print(` ${colors.brand.textMuted(server.directory)}`);
|
|
645
|
+
if (globalOptions.verbose) {
|
|
646
|
+
output.print(` ${colors.brand.textMuted(`PID: ${server.pid}`)}`);
|
|
647
|
+
}
|
|
648
|
+
output.blank();
|
|
649
|
+
}
|
|
650
|
+
output.print(` ${colors.brand.textTertiary(`${servers.length} server(s) running`)}`);
|
|
478
651
|
}
|