@snap/valdi 1.0.7 → 1.0.8

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 (160) hide show
  1. package/README.md +12 -3
  2. package/bundled-skills/CONTRIBUTING_SKILLS.md +74 -0
  3. package/bundled-skills/registry.json +20 -0
  4. package/bundled-skills/skills/valdi-android/skill.md +89 -0
  5. package/bundled-skills/skills/valdi-async/skill.md +246 -0
  6. package/bundled-skills/skills/valdi-async/tests/BUILD.bazel +19 -0
  7. package/bundled-skills/skills/valdi-async/tests/README.md +25 -0
  8. package/bundled-skills/skills/valdi-async/tests/src/reference.tsx +210 -0
  9. package/bundled-skills/skills/valdi-async/tests/tsconfig.json +1 -0
  10. package/bundled-skills/skills/valdi-bazel/skill.md +122 -0
  11. package/bundled-skills/skills/valdi-compiler/skill.md +108 -0
  12. package/bundled-skills/skills/valdi-component-tests/skill.md +430 -0
  13. package/bundled-skills/skills/valdi-component-tests/tests/BUILD.bazel +24 -0
  14. package/bundled-skills/skills/valdi-component-tests/tests/README.md +35 -0
  15. package/bundled-skills/skills/valdi-component-tests/tests/src/ProfileCard.tsx +38 -0
  16. package/bundled-skills/skills/valdi-component-tests/tests/test/ProfileCardTest.spec.tsx +107 -0
  17. package/bundled-skills/skills/valdi-component-tests/tests/tsconfig.json +1 -0
  18. package/bundled-skills/skills/valdi-cpp-runtime/skill.md +103 -0
  19. package/bundled-skills/skills/valdi-custom-view/skill.md +62 -0
  20. package/bundled-skills/skills/valdi-ios/skill.md +93 -0
  21. package/bundled-skills/skills/valdi-migrate/skill.md +175 -0
  22. package/bundled-skills/skills/valdi-migrate/tests/BUILD.bazel +23 -0
  23. package/bundled-skills/skills/valdi-migrate/tests/README.md +70 -0
  24. package/bundled-skills/skills/valdi-migrate/tests/check_antipatterns.py +89 -0
  25. package/bundled-skills/skills/valdi-migrate/tests/compose_example.kt +94 -0
  26. package/bundled-skills/skills/valdi-migrate/tests/flutter_example.dart +129 -0
  27. package/bundled-skills/skills/valdi-migrate/tests/react_example.tsx +98 -0
  28. package/bundled-skills/skills/valdi-migrate/tests/src/expected_valdi.tsx +267 -0
  29. package/bundled-skills/skills/valdi-migrate/tests/tsconfig.json +3 -0
  30. package/bundled-skills/skills/valdi-overview/skill.md +63 -0
  31. package/bundled-skills/skills/valdi-perf/skill.md +197 -0
  32. package/bundled-skills/skills/valdi-perf/tests/BUILD.bazel +19 -0
  33. package/bundled-skills/skills/valdi-perf/tests/README.md +26 -0
  34. package/bundled-skills/skills/valdi-perf/tests/src/reference.tsx +202 -0
  35. package/bundled-skills/skills/valdi-perf/tests/tsconfig.json +1 -0
  36. package/bundled-skills/skills/valdi-polyglot-module/skill.md +85 -0
  37. package/bundled-skills/skills/valdi-setup/skill.md +129 -0
  38. package/bundled-skills/skills/valdi-testing/skill.md +65 -0
  39. package/bundled-skills/skills/valdi-tsx/skill.md +385 -0
  40. package/bundled-skills/skills/valdi-tsx/tests/BUILD.bazel +19 -0
  41. package/bundled-skills/skills/valdi-tsx/tests/README.md +29 -0
  42. package/bundled-skills/skills/valdi-tsx/tests/src/reference.tsx +173 -0
  43. package/bundled-skills/skills/valdi-tsx/tests/tsconfig.json +1 -0
  44. package/dist/commands/bootstrap.js +0 -7
  45. package/dist/commands/newModule.js +10 -14
  46. package/dist/commands/skills.js +16 -0
  47. package/dist/commands/skills_commands/create.js +125 -0
  48. package/dist/commands/skills_commands/install.js +96 -0
  49. package/dist/commands/skills_commands/list.js +83 -0
  50. package/dist/commands/skills_commands/remove.js +41 -0
  51. package/dist/commands/skills_commands/update.js +59 -0
  52. package/dist/core/constants.js +0 -1
  53. package/dist/setup/versions.js +1 -1
  54. package/dist/utils/skillsAdapters.js +140 -0
  55. package/dist/utils/skillsRegistry.js +40 -0
  56. package/package.json +6 -1
  57. package/.bazelignore +0 -2
  58. package/.bootstrap/apps/cli_application/BUILD.bazel.template +0 -7
  59. package/.bootstrap/apps/cli_application/modules/{{MODULE_NAME}}/BUILD.bazel.template +0 -11
  60. package/.bootstrap/apps/cli_application/modules/{{MODULE_NAME}}/src/index.ts +0 -1
  61. package/.bootstrap/apps/ui_application/.eslint.rc +0 -27
  62. package/.bootstrap/apps/ui_application/BUILD.bazel.template +0 -19
  63. package/.bootstrap/apps/ui_application/modules/{{MODULE_NAME}}/BUILD.bazel.template +0 -21
  64. package/.bootstrap/apps/ui_application/modules/{{MODULE_NAME}}/res/valdi@3x.png +0 -0
  65. package/.bootstrap/apps/ui_application/modules/{{MODULE_NAME}}/src/App.tsx +0 -133
  66. package/.bootstrap/apps/ui_application/package.json +0 -24
  67. package/.bootstrap/modules/cpp_bridge_module/BUILD.bazel.template +0 -21
  68. package/.bootstrap/modules/cpp_bridge_module/cpp/CalculatorModuleFactory.cpp.template +0 -28
  69. package/.bootstrap/modules/cpp_bridge_module/src/Calculator.d.ts +0 -4
  70. package/.bootstrap/modules/ios_android_bridge_module/BUILD.bazel.template +0 -39
  71. package/.bootstrap/modules/ios_android_bridge_module/android/CalculatorModuleFactory.kt.template +0 -18
  72. package/.bootstrap/modules/ios_android_bridge_module/ios/SCCCalculatorModuleFactory.m.template +0 -31
  73. package/.bootstrap/modules/ios_android_bridge_module/src/Calculator.d.ts +0 -4
  74. package/.bootstrap/modules/ios_android_view_module/BUILD.bazel.template +0 -41
  75. package/.bootstrap/modules/ios_android_view_module/android/CircleView.kt.template +0 -42
  76. package/.bootstrap/modules/ios_android_view_module/android/CircleViewAttributesBinder.kt.template +0 -60
  77. package/.bootstrap/modules/ios_android_view_module/ios/SCCCircleView.h +0 -6
  78. package/.bootstrap/modules/ios_android_view_module/ios/SCCCircleView.m +0 -82
  79. package/.bootstrap/modules/ios_android_view_module/src/Circle.tsx.template +0 -15
  80. package/.bootstrap/modules/ui_component/BUILD.bazel.template +0 -34
  81. package/.bootstrap/modules/ui_component/src/NewModuleComponent.tsx +0 -45
  82. package/.config/copyconfig.json +0 -10
  83. package/.editorconfig +0 -21
  84. package/.eslintignore +0 -1
  85. package/.eslintrc.js +0 -72
  86. package/.github/README.md +0 -164
  87. package/.metadata/.bazelrc.template +0 -91
  88. package/.metadata/.bazelversion.template +0 -1
  89. package/.metadata/.cursorrules.template +0 -60
  90. package/.metadata/.editorconfig.template +0 -37
  91. package/.metadata/.eslintrc.js.template +0 -27
  92. package/.metadata/.gitignore.template +0 -4
  93. package/.metadata/.prettierrc.json.template +0 -7
  94. package/.metadata/.watchmanconfig.template +0 -8
  95. package/.metadata/AGENTS.md.template +0 -282
  96. package/.metadata/README.md.template +0 -31
  97. package/.metadata/WORKSPACE.template +0 -57
  98. package/.metadata/config.yaml.template +0 -1
  99. package/.metadata/package.json.template +0 -23
  100. package/.prettierignore +0 -2
  101. package/.prettierrc.json +0 -7
  102. package/LINUX_COMPATIBILITY.md +0 -248
  103. package/prettier.config.js +0 -4
  104. package/scripts/sync-agents-md.sh +0 -44
  105. package/scripts/update-agents-templates.ts +0 -170
  106. package/spec/support/jasmine.json +0 -6
  107. package/src/commands/bootstrap.ts +0 -410
  108. package/src/commands/build.ts +0 -89
  109. package/src/commands/devSetup.ts +0 -17
  110. package/src/commands/doctor.ts +0 -1832
  111. package/src/commands/export.ts +0 -131
  112. package/src/commands/hotreload.ts +0 -108
  113. package/src/commands/install.ts +0 -93
  114. package/src/commands/lint.ts +0 -15
  115. package/src/commands/lint_commands/lintCheck.ts +0 -53
  116. package/src/commands/lint_commands/lintFormat.ts +0 -49
  117. package/src/commands/log.ts +0 -108
  118. package/src/commands/newModule.ts +0 -286
  119. package/src/commands/package.ts +0 -102
  120. package/src/commands/projectsync.ts +0 -488
  121. package/src/commands/test.ts +0 -68
  122. package/src/core/constants.ts +0 -98
  123. package/src/core/errors.ts +0 -10
  124. package/src/index.ts +0 -27
  125. package/src/setup/DevSetupHelper.ts +0 -290
  126. package/src/setup/linuxSetup.ts +0 -261
  127. package/src/setup/macOSSetup.ts +0 -156
  128. package/src/setup/setupEntryPoint.ts +0 -64
  129. package/src/setup/versions.ts +0 -8
  130. package/src/utils/ArgumentsResolver.ts +0 -23
  131. package/src/utils/BazelClient.ts +0 -285
  132. package/src/utils/Digraph.ts +0 -81
  133. package/src/utils/LoadingIndicator.ts +0 -43
  134. package/src/utils/applicationUtils.ts +0 -276
  135. package/src/utils/buildInfo.ts +0 -99
  136. package/src/utils/byString.ts +0 -3
  137. package/src/utils/cliUtils.ts +0 -112
  138. package/src/utils/copyBootstrapFiles.ts +0 -30
  139. package/src/utils/deviceUtils.ts +0 -76
  140. package/src/utils/errorUtils.ts +0 -63
  141. package/src/utils/fileUtils.ts +0 -257
  142. package/src/utils/githubUtils.ts +0 -102
  143. package/src/utils/jsonUtils.ts +0 -30
  144. package/src/utils/lintUtils.ts +0 -190
  145. package/src/utils/linuxDistro.spec.ts +0 -219
  146. package/src/utils/linuxDistro.ts +0 -326
  147. package/src/utils/logUtils.ts +0 -9
  148. package/src/utils/pathUtils.ts +0 -12
  149. package/src/utils/stringUtils.spec.ts +0 -95
  150. package/src/utils/stringUtils.ts +0 -103
  151. package/src/utils/tempDir.ts +0 -24
  152. package/src/utils/zipUtils.ts +0 -14
  153. package/test/ValdiSmokeTest.ts +0 -279
  154. package/test/helpers/AsyncHelpers.ts +0 -113
  155. package/test/helpers/CommandHelpers.ts +0 -37
  156. package/test/helpers/ProjectHelpers.ts +0 -153
  157. package/test/helpers/StreamHelpers.ts +0 -37
  158. package/test/helpers/TypeScriptClient.ts +0 -217
  159. package/tsconfig.dist.json +0 -8
  160. package/tsconfig.json +0 -42
@@ -1,1832 +0,0 @@
1
- /**
2
- * @fileoverview Valdi CLI Doctor Command - Environment Health Diagnostics
3
- *
4
- * This module implements the `valdi doctor` command, which performs comprehensive
5
- * health checks on the Valdi development environment. It validates system requirements,
6
- * tool installations, workspace configuration, and provides actionable feedback
7
- * for resolving issues.
8
- *
9
- * @author rohanjsh
10
- *
11
- * @example
12
- * ```bash
13
- * # Basic health check (dev environment only)
14
- * valdi doctor
15
- *
16
- * # Include project-specific checks
17
- * valdi doctor --project
18
- *
19
- * # Include framework development checks
20
- * valdi doctor --framework
21
- *
22
- * # Detailed diagnostics with verbose output
23
- * valdi doctor --verbose
24
- *
25
- * # Machine-readable JSON output for CI/CD
26
- * valdi doctor --json
27
- *
28
- * # Attempt automatic fixes where possible
29
- * valdi doctor --fix
30
- * ```
31
-
32
- * @see {@link https://bazel.build/install} Bazel Installation Guide
33
- * @see {@link https://nodejs.org} Node.js Installation
34
- */
35
-
36
- import * as fs from 'fs';
37
- import * as os from 'os';
38
- import path from 'path';
39
- import type { Argv } from 'yargs';
40
- import { ANSI_COLORS } from '../core/constants';
41
-
42
- import { ANDROID_NDK_VERSION, ANDROID_PLATFORM_VERSION } from '../setup/versions';
43
- import type { ArgumentsResolver } from '../utils/ArgumentsResolver';
44
- import { BazelClient } from '../utils/BazelClient';
45
- import { checkCommandExists, runCliCommand } from '../utils/cliUtils';
46
- import { makeCommandHandler } from '../utils/errorUtils';
47
- import {
48
- type LinuxDistroInfo,
49
- buildInstallCommand,
50
- detectLinuxDistro,
51
- getCommonPackageMappings,
52
- getPackageName,
53
- } from '../utils/linuxDistro';
54
- import { wrapInColor } from '../utils/logUtils';
55
-
56
- /** Discord support link for troubleshooting */
57
- const DISCORD_SUPPORT_URL = 'https://discord.gg/uJyNEeYX2U';
58
-
59
- /**
60
- * Command line parameters for the doctor command.
61
- *
62
- * @interface CommandParameters
63
- */
64
- interface CommandParameters {
65
- /** Enable detailed diagnostic information output */
66
- verbose: boolean;
67
- /** Attempt to automatically fix issues where possible */
68
- fix: boolean;
69
- /** Output results in JSON format for machine processing */
70
- json: boolean;
71
- /** Include framework development checks (git-lfs, temurin, etc.) */
72
- framework: boolean;
73
- /** Include project-specific checks (workspace structure, etc.) */
74
- project: boolean;
75
- }
76
-
77
- /**
78
- * Represents the result of a single diagnostic check.
79
- *
80
- * @interface DiagnosticResult
81
- */
82
- interface DiagnosticResult {
83
- /** Human-readable name of the diagnostic check */
84
- name: string;
85
- /** Status of the check: pass (✓), warn (⚠), or fail (✗) */
86
- status: 'pass' | 'warn' | 'fail';
87
- /** Primary message describing the check result */
88
- message: string;
89
- /** Optional detailed information about the check */
90
- details?: string;
91
- /** Whether this issue can potentially be auto-fixed */
92
- fixable?: boolean;
93
- /** Command or instruction to fix the issue */
94
- fixCommand?: string;
95
- /** Category for grouping related checks */
96
- category?: string;
97
- }
98
-
99
- /**
100
- * Represents a group of related diagnostic checks with their overall status.
101
- *
102
- * @interface GroupedDiagnosticResult
103
- */
104
- interface GroupedDiagnosticResult {
105
- /** Category name for the group */
106
- category: string;
107
- /** Overall status of the group (worst status among all checks) */
108
- status: 'pass' | 'warn' | 'fail';
109
- /** Summary message for the group */
110
- message: string;
111
- /** Individual check results within this group */
112
- checks: DiagnosticResult[];
113
- /** Issues found in this group (only checks with warn/fail status) */
114
- issues: DiagnosticResult[];
115
- }
116
-
117
- /**
118
- * Main class responsible for performing Valdi environment health diagnostics.
119
- *
120
- * This class orchestrates various system checks to ensure the development environment
121
- * is properly configured for Valdi development. It validates:
122
- * - Node.js version compatibility (≥18.0.0)
123
- * - Bazel build system installation and functionality (with version validation)
124
- * - Java JDK installation (Java 17+ required)
125
- * - Platform-specific development tools (Android SDK, Xcode)
126
- * - Required development dependencies (git, npm, watchman, ios-webkit-debug-proxy)
127
- * - Optional project-specific checks (workspace structure)
128
- * - Optional framework development tools (git-lfs, temurin)
129
- *
130
- * @class ValdiDoctor
131
- */
132
- class ValdiDoctor {
133
- /** Collection of diagnostic check results */
134
- private readonly results: DiagnosticResult[] = [];
135
-
136
- /** Whether to show detailed diagnostic information */
137
- private readonly verbose: boolean;
138
-
139
- /** Whether to attempt automatic fixes for detected issues */
140
- private readonly autoFix: boolean;
141
-
142
- /** Whether to output results in JSON format */
143
- private readonly jsonOutput: boolean;
144
-
145
- /** Whether to include framework development checks */
146
- private readonly frameworkMode: boolean;
147
-
148
- /** Whether to include project-specific checks */
149
- private readonly projectMode: boolean;
150
-
151
- /** Cached Linux distribution info (only on Linux) */
152
- private readonly linuxDistro?: LinuxDistroInfo;
153
-
154
- /**
155
- * Creates a new ValdiDoctor instance.
156
- *
157
- * @param verbose - Enable detailed diagnostic output
158
- * @param autoFix - Attempt to automatically fix issues where possible
159
- * @param jsonOutput - Output results in JSON format for machine processing
160
- * @param frameworkMode - Include framework development checks
161
- * @param projectMode - Include project-specific checks
162
- */
163
- constructor(verbose: boolean, autoFix: boolean, jsonOutput: boolean, frameworkMode: boolean, projectMode: boolean) {
164
- this.verbose = verbose;
165
- this.autoFix = autoFix;
166
- this.jsonOutput = jsonOutput;
167
- this.frameworkMode = frameworkMode;
168
- this.projectMode = projectMode;
169
-
170
- // Detect Linux distribution if on Linux
171
- if (os.platform() === 'linux') {
172
- this.linuxDistro = detectLinuxDistro();
173
- }
174
- }
175
-
176
- /**
177
- * Executes diagnostic checks based on the target audience.
178
- *
179
- * **App Development Mode (default):**
180
- * - Essential tools for building Valdi applications
181
- * - Node.js, Bazel (with version validation)
182
- * - Basic Android SDK and Java setup (Java 17+ required)
183
- * - Core development tools (git, npm, watchman, ios-webkit-debug-proxy)
184
- *
185
- * **Project Mode (--project flag):**
186
- * - All app development checks plus
187
- * - Workspace structure validation (WORKSPACE file, .bazelrc)
188
- *
189
- * **Framework Development Mode (--framework flag):**
190
- * - All app development checks plus
191
- * - Advanced development tools (git-lfs, temurin)
192
- * - Detailed environment variable validation
193
- * - Platform-specific development packages
194
- *
195
- * @returns Promise that resolves when all diagnostics are complete
196
- *
197
- * @example
198
- * ```typescript
199
- * // App development checks only
200
- * await doctor.runDiagnostics();
201
- *
202
- * // App development + project checks
203
- * await doctor.runDiagnostics(); // with projectMode = true
204
- *
205
- * // App development + framework checks
206
- * await doctor.runDiagnostics(); // with frameworkMode = true
207
- * ```
208
- */
209
- async runDiagnostics(): Promise<DiagnosticResult['status']> {
210
- if (!this.jsonOutput) {
211
- let mode = 'app development';
212
- if (this.frameworkMode) mode = 'framework development';
213
- if (this.projectMode) mode += ' + project';
214
- console.log(wrapInColor(`Running Valdi environment diagnostics (${mode} mode)...`, ANSI_COLORS.BLUE_COLOR));
215
- console.log();
216
- }
217
-
218
- // Core checks for all users
219
- await this.checkNodeVersion();
220
- await this.checkBazelInstallation();
221
-
222
- // Project-specific checks (only if requested)
223
- if (this.projectMode) {
224
- this.checkWorkspaceStructure();
225
- }
226
-
227
- // Essential platform tools
228
- await this.checkEssentialPlatformTools();
229
-
230
- // Java for Android development
231
- await this.checkJavaInstallation();
232
-
233
- // Android SDK basics
234
- this.checkAndroidSDKBasics();
235
-
236
- // Core development dependencies
237
- await this.checkCoreDependencies();
238
-
239
- // Git LFS initialization check
240
- await this.checkGitLfsInitialization();
241
-
242
- // Shell autocomplete configuration
243
- this.checkShellAutoComplete();
244
-
245
- // VSCode/Cursor extensions check
246
- await this.checkEditorExtensions();
247
-
248
- // Framework-specific checks (only if requested)
249
- if (this.frameworkMode) {
250
- this.checkFrameworkDependencies();
251
- this.checkAdvancedAndroidSDK();
252
- this.checkEnvironmentVariables();
253
- }
254
-
255
- return this.results.some(r => r.status === 'fail') ? 'fail' : 'pass';
256
- }
257
-
258
- /**
259
- * Outputs the diagnostic results in the appropriate format.
260
- *
261
- * Depending on the configuration, this method will either:
262
- * - Output structured JSON for machine processing (--json flag)
263
- * - Display formatted, colored output for human consumption
264
- *
265
-
266
- *
267
- * @example
268
- * ```typescript
269
- * doctor.printResults(); // Human-readable output
270
- * ```
271
- */
272
- printResults(): void {
273
- if (this.jsonOutput) {
274
- this.printJsonResults();
275
- } else {
276
- this.printFormattedResults();
277
- }
278
- }
279
-
280
- /**
281
- * Adds a diagnostic result to the internal collection.
282
- *
283
- * @param result - The diagnostic result to add
284
- * @private
285
-
286
- */
287
- private addResult(result: DiagnosticResult): void {
288
- this.results.push(result);
289
- }
290
-
291
- /**
292
- * Groups diagnostic results by category for more concise output.
293
- *
294
- * @returns Array of grouped diagnostic results
295
- * @private
296
- */
297
- private groupResultsByCategory(): GroupedDiagnosticResult[] {
298
- const groups = new Map<string, DiagnosticResult[]>();
299
-
300
- // Group results by category, with fallback for uncategorized results
301
- for (const result of this.results) {
302
- const category = result.category || result.name;
303
- if (!groups.has(category)) {
304
- groups.set(category, []);
305
- }
306
- const categoryGroup = groups.get(category);
307
- if (categoryGroup) {
308
- categoryGroup.push(result);
309
- }
310
- }
311
-
312
- // Convert to grouped results with overall status
313
- const groupedResults: GroupedDiagnosticResult[] = [];
314
- for (const [category, checks] of groups.entries()) {
315
- // Determine overall status (worst status wins)
316
- let overallStatus: 'pass' | 'warn' | 'fail' = 'pass';
317
- for (const check of checks) {
318
- if (check.status === 'fail') {
319
- overallStatus = 'fail';
320
- break;
321
- } else if (check.status === 'warn' && overallStatus === 'pass') {
322
- overallStatus = 'warn';
323
- }
324
- }
325
-
326
- // Create summary message
327
- const warnCount = checks.filter(c => c.status === 'warn').length;
328
- const failCount = checks.filter(c => c.status === 'fail').length;
329
-
330
- let message: string;
331
- if (overallStatus === 'pass') {
332
- const firstCheck = checks[0];
333
- message = checks.length === 1 && firstCheck ? firstCheck.message : `All ${checks.length} checks passed`;
334
- } else {
335
- const issues = failCount + warnCount;
336
- message = `${issues} issue${issues > 1 ? 's' : ''} found`;
337
- }
338
-
339
- groupedResults.push({
340
- category,
341
- status: overallStatus,
342
- message,
343
- checks,
344
- issues: checks.filter(c => c.status !== 'pass'),
345
- });
346
- }
347
-
348
- return groupedResults;
349
- }
350
-
351
- /**
352
- * Attempts to automatically fix a detected issue.
353
- *
354
- * This method executes the provided fix command and reports the outcome.
355
- * It only runs when auto-fix mode is enabled and provides user feedback
356
- * about the success or failure of the fix attempt.
357
- *
358
- * @param tool - Name of the tool being fixed (for user feedback)
359
- * @param command - Shell command to execute for the fix
360
- * @returns Promise that resolves when the fix attempt is complete
361
- */
362
- private async attemptAutoFix(tool: string, command: string): Promise<void> {
363
- if (!this.autoFix) {
364
- return;
365
- }
366
-
367
- try {
368
- console.log(wrapInColor(`Attempting to fix ${tool}...`, ANSI_COLORS.YELLOW_COLOR));
369
- const { returnCode } = await runCliCommand(command);
370
-
371
- if (returnCode === 0) {
372
- console.log(wrapInColor(`✓ Successfully fixed ${tool}`, ANSI_COLORS.GREEN_COLOR));
373
- } else {
374
- console.log(wrapInColor(`✗ Failed to fix ${tool}`, ANSI_COLORS.RED_COLOR));
375
- }
376
- } catch (error) {
377
- console.log(wrapInColor(`✗ Failed to fix ${tool}: ${error instanceof Error ? error.message : 'Unknown error'}`, ANSI_COLORS.RED_COLOR));
378
- }
379
- }
380
-
381
- /**
382
- * Validates Node.js installation and version compatibility.
383
- *
384
- * Valdi requires Node.js version 18.0.0 or higher for optimal compatibility.
385
- * This method:
386
- * 1. Checks if Node.js is installed and accessible via PATH
387
- * 2. Validates the version meets minimum requirements (≥18.0.0)
388
- * 3. Optionally attempts to upgrade to Node.js 20 if auto-fix is enabled
389
- * 4. Provides specific installation/upgrade instructions
390
- *
391
- * @returns Promise that resolves when the check is complete
392
- */
393
- private async checkNodeVersion(): Promise<void> {
394
- try {
395
- const { stdout } = await runCliCommand('node --version');
396
- const version = stdout.trim();
397
- const versionParts = version.replace('v', '').split('.');
398
- const majorVersionStr = versionParts[0];
399
-
400
- if (!majorVersionStr) {
401
- throw new Error('Invalid version format');
402
- }
403
-
404
- const majorVersion = Number.parseInt(majorVersionStr, 10);
405
-
406
- if (majorVersion >= 18) {
407
- this.addResult({
408
- name: 'Node.js version',
409
- status: 'pass',
410
- message: `Node.js ${version} is installed`,
411
- category: 'Node.js installation',
412
- });
413
-
414
- // Suggest upgrading to Node.js 20 for better performance
415
- if (this.autoFix && majorVersion < 20) {
416
- await this.attemptAutoFix('node', 'nvm install 20 && nvm use 20');
417
- }
418
- } else {
419
- this.addResult({
420
- name: 'Node.js version',
421
- status: 'fail',
422
- message: `Node.js ${version} is outdated. Valdi requires Node.js 18 or higher`,
423
- fixable: true,
424
- fixCommand: 'nvm install 18 && nvm use 18',
425
- category: 'Node.js installation',
426
- });
427
-
428
- if (this.autoFix) {
429
- await this.attemptAutoFix('node', 'nvm install 18 && nvm use 18');
430
- }
431
- }
432
- } catch {
433
- this.addResult({
434
- name: 'Node.js version',
435
- status: 'fail',
436
- message: 'Node.js is not installed or not in PATH',
437
- fixable: true,
438
- fixCommand: 'Install Node.js from https://nodejs.org or use nvm',
439
- category: 'Node.js installation',
440
- });
441
- }
442
- }
443
-
444
- /**
445
- * Validates Bazel build system installation and functionality.
446
- *
447
- * Bazel is the core build system for Valdi projects. This method:
448
- * 1. Attempts to create a BazelClient instance
449
- * 2. Executes `bazel version` to verify installation and functionality
450
- * 3. Validates version against .bazelversion file if available
451
- * 4. Provides installation guidance if Bazel is missing or broken
452
- *
453
- * @returns Promise that resolves when the check is complete
454
- * @see {@link https://bazel.build/install} Bazel Installation Guide
455
- */
456
- private async checkBazelInstallation(): Promise<void> {
457
- try {
458
- const bazel = new BazelClient();
459
- const [returnCode, versionInfo, errorInfo] = await bazel.getVersion();
460
-
461
- if (returnCode === 0 && versionInfo) {
462
- const versionLine = versionInfo.split('\n')[0] || 'Unknown version';
463
-
464
- // Extract version number for comparison
465
- const versionMatch = versionLine.match(/(\d+\.\d+\.\d+)/);
466
- const installedVersion = versionMatch?.[1];
467
-
468
- // Check against .bazelversion file
469
- const bazelVersionFile = path.join(process.cwd(), '.bazelversion');
470
- let expectedVersion: string | undefined;
471
-
472
- try {
473
- if (fs.existsSync(bazelVersionFile)) {
474
- expectedVersion = fs.readFileSync(bazelVersionFile, 'utf8').trim();
475
- }
476
- } catch {
477
- // Ignore file read errors
478
- }
479
-
480
- if (expectedVersion && installedVersion && installedVersion !== expectedVersion) {
481
- this.addResult({
482
- name: 'Bazel version',
483
- status: 'warn',
484
- message: `Bazel version mismatch: installed ${installedVersion}, expected ${expectedVersion}`,
485
- details: 'Version mismatch may cause build issues. Consider updating Bazel.',
486
- fixable: true,
487
- fixCommand: `Install Bazel ${expectedVersion} or run a trial bazel command to verify compatibility`,
488
- category: 'Bazel installation',
489
- });
490
- } else {
491
- this.addResult({
492
- name: 'Bazel installation',
493
- status: 'pass',
494
- message: `Bazel is installed: ${versionLine}${expectedVersion ? ` (matches expected ${expectedVersion})` : ''}`,
495
- category: 'Bazel installation',
496
- });
497
- }
498
- } else {
499
- this.addResult({
500
- name: 'Bazel installation',
501
- status: 'fail',
502
- message: 'Bazel is installed but not working correctly',
503
- details: errorInfo || versionInfo || 'Unknown error',
504
- category: 'Bazel installation',
505
- });
506
- }
507
- } catch {
508
- this.addResult({
509
- name: 'Bazel installation',
510
- status: 'fail',
511
- message: 'Bazel is not installed or not in PATH',
512
- fixable: true,
513
- fixCommand: 'Install Bazel from https://bazel.build/install',
514
- category: 'Bazel installation',
515
- });
516
- }
517
- }
518
-
519
- /**
520
- * Validates Valdi workspace structure and configuration files.
521
- *
522
- * **WORKSPACE File Requirement:**
523
- * Every Valdi application requires a WORKSPACE file at the project root. This file:
524
- * - Defines the Bazel workspace name
525
- * - Imports the Valdi framework as an external dependency
526
- * - Configures build rules and toolchains for Valdi development
527
- * - Is automatically created by `valdi bootstrap` when starting a new project
528
- *
529
- * **Configuration Files:**
530
- * - WORKSPACE file (required for all Valdi apps)
531
- * - .bazelrc file (recommended for build optimization and consistency)
532
- *
533
- * This method checks the current working directory for these essential files
534
- * and provides guidance if they're missing.
535
- *
536
- * @private
537
- *
538
- * @see {@link https://bazel.build/concepts/build-ref#workspace} Bazel Workspace Documentation
539
- *
540
- * @example
541
- * ```typescript
542
- * this.checkWorkspaceStructure();
543
- * // Results in diagnostic output like:
544
- * // ✓ Valid Valdi workspace detected
545
- * // ✗ Not in a Valdi workspace directory
546
- * ```
547
- */
548
- private checkWorkspaceStructure(): void {
549
- const workspaceFile = path.join(process.cwd(), 'WORKSPACE');
550
- const bazelrcFile = path.join(process.cwd(), '.bazelrc');
551
-
552
- if (fs.existsSync(workspaceFile)) {
553
- this.addResult({
554
- name: 'Valdi workspace',
555
- status: 'pass',
556
- message: 'Valid Valdi workspace detected',
557
- category: 'Workspace configuration',
558
- });
559
- } else {
560
- this.addResult({
561
- name: 'Valdi workspace',
562
- status: 'fail',
563
- message: 'Not in a Valdi workspace directory',
564
- details: 'WORKSPACE file is required for all Valdi applications. Run `valdi bootstrap` to create a new project or navigate to an existing Valdi project root.',
565
- fixable: true,
566
- fixCommand: 'valdi bootstrap',
567
- category: 'Workspace configuration',
568
- });
569
- }
570
-
571
- if (fs.existsSync(bazelrcFile)) {
572
- this.addResult({
573
- name: 'Bazel configuration',
574
- status: 'pass',
575
- message: '.bazelrc file found',
576
- category: 'Workspace configuration',
577
- });
578
- } else {
579
- this.addResult({
580
- name: 'Bazel configuration',
581
- status: 'warn',
582
- message: '.bazelrc file not found',
583
- details: 'A .bazelrc file provides build optimization and consistency. Consider creating one or use `valdi bootstrap` for new projects.',
584
- fixable: true,
585
- fixCommand: 'Create .bazelrc file with Valdi-specific build configurations',
586
- category: 'Workspace configuration',
587
- });
588
- }
589
- }
590
-
591
- /**
592
- * Validates essential platform tools needed for app development.
593
- *
594
- * Focuses on core tools that app developers need:
595
- * - Android SDK (basic check)
596
- * - Xcode (macOS only, for iOS apps)
597
- *
598
- * @returns Promise that resolves when essential platform checks are complete
599
- * @private
600
- */
601
- private async checkEssentialPlatformTools(): Promise<void> {
602
- // Check Android SDK (essential for mobile app development)
603
- const androidHome = process.env['ANDROID_HOME'] || process.env['ANDROID_SDK_ROOT'];
604
- if (androidHome && fs.existsSync(androidHome)) {
605
- this.addResult({
606
- name: 'Android SDK',
607
- status: 'pass',
608
- message: `Android SDK found at ${androidHome}`,
609
- category: 'Android installation',
610
- });
611
- } else {
612
- this.addResult({
613
- name: 'Android SDK',
614
- status: 'warn',
615
- message: 'Android SDK not found',
616
- details: 'Required for Android app development. Set ANDROID_HOME environment variable.',
617
- fixable: true,
618
- fixCommand: 'Install Android Studio and set ANDROID_HOME',
619
- category: 'Android installation',
620
- });
621
- }
622
-
623
- // Check Xcode (macOS only, essential for iOS app development)
624
- if (os.platform() === 'darwin') {
625
- await this.checkXcodeInstallation();
626
- }
627
- }
628
-
629
- /**
630
- * Validates comprehensive Xcode installation and configuration.
631
- *
632
- * Performs thorough checks matching dev_setup requirements:
633
- * - xcode-select command exists
634
- * - xcode-select path is configured and valid
635
- * - /Applications/Xcode.app exists
636
- *
637
- * @returns Promise that resolves when Xcode checks are complete
638
- * @private
639
- */
640
- private async checkXcodeInstallation(): Promise<void> {
641
- // Check if xcode-select command exists
642
- if (!checkCommandExists('xcode-select')) {
643
- this.addResult({
644
- name: 'Xcode',
645
- status: 'fail',
646
- message: 'Xcode command line tools not installed',
647
- details: 'Required for iOS app development',
648
- fixable: true,
649
- fixCommand: 'Install Xcode from App Store (https://apps.apple.com/us/app/xcode/id497799835)',
650
- category: 'iOS development',
651
- });
652
- return;
653
- }
654
-
655
- // Check if Xcode is properly configured
656
- try {
657
- const { stdout } = await runCliCommand('xcode-select -p');
658
- const xcodePath = stdout.trim();
659
-
660
- if (!xcodePath || !fs.existsSync(xcodePath)) {
661
- this.addResult({
662
- name: 'Xcode configuration',
663
- status: 'fail',
664
- message: 'Xcode command line tools path is not configured correctly',
665
- fixable: true,
666
- fixCommand: 'Run: sudo xcode-select -s /Applications/Xcode.app (or your Xcode path)',
667
- category: 'iOS development',
668
- });
669
- return;
670
- }
671
-
672
- // Extract Xcode.app path from the Developer path
673
- // xcode-select -p typically returns: /Applications/Xcode.app/Contents/Developer
674
- const xcodeAppPath = xcodePath.replace(/\/Contents\/Developer\/?$/, '');
675
-
676
- if (fs.existsSync(xcodeAppPath) && xcodeAppPath.includes('Xcode')) {
677
- // Xcode is installed and configured
678
- this.addResult({
679
- name: 'Xcode',
680
- status: 'pass',
681
- message: `Xcode found at ${xcodeAppPath}`,
682
- category: 'iOS development',
683
- });
684
- } else {
685
- // Path doesn't point to an Xcode installation
686
- this.addResult({
687
- name: 'Xcode',
688
- status: 'fail',
689
- message: 'Xcode installation not found',
690
- details: `xcode-select points to ${xcodePath}, but Xcode app not found at ${xcodeAppPath}`,
691
- fixable: true,
692
- fixCommand: 'Install Xcode from App Store (https://apps.apple.com/us/app/xcode/id497799835)',
693
- category: 'iOS development',
694
- });
695
- }
696
- } catch {
697
- this.addResult({
698
- name: 'Xcode',
699
- status: 'fail',
700
- message: 'Xcode not properly configured',
701
- fixable: true,
702
- fixCommand: 'Run: sudo xcode-select -s /Applications/Xcode.app (or your Xcode path)',
703
- category: 'iOS development',
704
- });
705
- }
706
- }
707
-
708
- /**
709
- * Validates Java JDK installation and configuration as set up by dev_setup.
710
- *
711
- * Checks for Java installation and configuration that dev_setup manages:
712
- * - Java JDK availability and version (Java 17+)
713
- * - JAVA_HOME environment variable
714
- * - Java symlink configuration (macOS)
715
- * - Java runtime availability (Linux)
716
- *
717
- * @returns Promise that resolves when Java checks are complete
718
- * @private
719
- */
720
- private async checkJavaInstallation(): Promise<void> {
721
- // Check if Java is available
722
- if (checkCommandExists('java')) {
723
- try {
724
- const { stdout, stderr } = await runCliCommand('java -version');
725
- // java -version typically outputs to stderr, but check both
726
- const versionInfo = stderr || stdout || '';
727
-
728
- // Try multiple version string formats:
729
- // 1. version "17.0.16" (older format)
730
- // 2. openjdk 17.0.16 (OpenJDK format)
731
- // 3. java version "17.0.16" (alternative format)
732
- let versionMatch = versionInfo.match(/version "([^"]+)"/);
733
- if (!versionMatch) {
734
- versionMatch = versionInfo.match(/openjdk\s+(\d+\.\d+\.\d+)/i);
735
- }
736
- if (!versionMatch) {
737
- versionMatch = versionInfo.match(/java\s+(\d+\.\d+\.\d+)/i);
738
- }
739
-
740
- const version = versionMatch?.[1] ?? 'Unknown version';
741
-
742
- // Check if Java version is 17 or higher
743
- const majorVersionMatch = version.match(/^(\d+)/);
744
- const majorVersion = majorVersionMatch?.[1] ? Number.parseInt(majorVersionMatch[1], 10) : 0;
745
-
746
- if (majorVersion >= 17) {
747
- this.addResult({
748
- name: 'Java Runtime',
749
- status: 'pass',
750
- message: `Java is installed: ${version}`,
751
- category: 'Java installation',
752
- });
753
- } else if (majorVersion > 0) {
754
- this.addResult({
755
- name: 'Java Runtime',
756
- status: 'fail',
757
- message: `Java ${version} is outdated. Java 17+ is required`,
758
- details: 'dev_setup installs Java 17 for Android development',
759
- fixable: true,
760
- fixCommand: this.getJavaInstallCommand(),
761
- category: 'Java installation',
762
- });
763
- } else {
764
- // Could detect java but not parse version
765
- this.addResult({
766
- name: 'Java Runtime',
767
- status: 'pass',
768
- message: 'Java is installed',
769
- details: `Version info: ${versionInfo.split('\n')[0] || 'Unable to parse version'}`,
770
- category: 'Java installation',
771
- });
772
- }
773
- } catch {
774
- this.addResult({
775
- name: 'Java Runtime',
776
- status: 'pass',
777
- message: 'Java is installed',
778
- category: 'Java installation',
779
- });
780
- }
781
- } else {
782
- this.addResult({
783
- name: 'Java Runtime',
784
- status: 'fail',
785
- message: 'Java not found in PATH',
786
- details: 'dev_setup installs Java JDK for Android development',
787
- fixable: true,
788
- fixCommand: this.getJavaInstallCommand(),
789
- category: 'Java installation',
790
- });
791
- }
792
-
793
- // Check JAVA_HOME environment variable
794
- const javaHome = process.env['JAVA_HOME'];
795
- if (javaHome && fs.existsSync(javaHome)) {
796
- this.addResult({
797
- name: 'JAVA_HOME',
798
- status: 'pass',
799
- message: `JAVA_HOME set to ${javaHome}`,
800
- category: 'Java installation',
801
- });
802
- } else {
803
- this.addResult({
804
- name: 'JAVA_HOME',
805
- status: 'warn',
806
- message: 'JAVA_HOME not set or invalid',
807
- details: 'dev_setup configures JAVA_HOME for Android development',
808
- fixable: true,
809
- fixCommand: os.platform() === 'darwin' ? 'export JAVA_HOME=`/usr/libexec/java_home -v 17`' : 'Set JAVA_HOME environment variable',
810
- category: 'Java installation',
811
- });
812
- }
813
-
814
- // Check Java tools in PATH
815
- const pathEnv = process.env['PATH'] || '';
816
- if (os.platform() === 'darwin') {
817
- if (pathEnv.includes('/opt/homebrew/opt/openjdk@17/bin')) {
818
- this.addResult({
819
- name: 'Java PATH',
820
- status: 'pass',
821
- message: 'Java tools in PATH',
822
- category: 'Java installation',
823
- });
824
- } else if (pathEnv.includes('/opt/homebrew/opt/openjdk@11/bin')) {
825
- this.addResult({
826
- name: 'Java PATH',
827
- status: 'fail',
828
- message: 'Java 11 in PATH, but Java 17 is required',
829
- details: 'dev_setup installs Java 17 for Android development',
830
- fixable: true,
831
- fixCommand: 'export PATH="/opt/homebrew/opt/openjdk@17/bin:$PATH"',
832
- category: 'Java installation',
833
- });
834
- } else {
835
- this.addResult({
836
- name: 'Java PATH',
837
- status: 'warn',
838
- message: 'Java tools not in PATH',
839
- details: 'dev_setup adds Java tools to PATH',
840
- fixable: true,
841
- fixCommand: 'export PATH="/opt/homebrew/opt/openjdk@17/bin:$PATH"',
842
- category: 'Java installation',
843
- });
844
- }
845
- }
846
-
847
- // macOS-specific Java JDK symlink check
848
- if (os.platform() === 'darwin') {
849
- const jdk17Symlink = '/Library/Java/JavaVirtualMachines/openjdk-17.jdk';
850
- const jdk11Symlink = '/Library/Java/JavaVirtualMachines/openjdk-11.jdk';
851
-
852
- if (fs.existsSync(jdk17Symlink)) {
853
- this.addResult({
854
- name: 'Java JDK symlink',
855
- status: 'pass',
856
- message: 'OpenJDK 17 symlink configured',
857
- category: 'Java installation',
858
- });
859
- } else if (fs.existsSync(jdk11Symlink)) {
860
- this.addResult({
861
- name: 'Java JDK symlink',
862
- status: 'warn',
863
- message: 'OpenJDK 11 symlink found, but Java 17 is required',
864
- details: 'dev_setup installs Java 17',
865
- fixable: true,
866
- fixCommand: 'sudo ln -sfn /opt/homebrew/opt/openjdk@17/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-17.jdk',
867
- category: 'Java installation',
868
- });
869
- } else {
870
- this.addResult({
871
- name: 'Java JDK symlink',
872
- status: 'warn',
873
- message: 'OpenJDK symlink not found',
874
- details: 'dev_setup creates symlink for system-wide Java access',
875
- fixable: true,
876
- fixCommand: 'sudo ln -sfn /opt/homebrew/opt/openjdk@17/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-17.jdk',
877
- category: 'Java installation',
878
- });
879
- }
880
- }
881
- }
882
-
883
-
884
-
885
- /**
886
- * Validates basic Android SDK components needed for app development.
887
- *
888
- * Checks essential Android SDK components without overwhelming users:
889
- * - Android Platform (latest)
890
- * - Build Tools (basic check)
891
- *
892
- * @private
893
- */
894
- private checkAndroidSDKBasics(): void {
895
- const androidHome = process.env['ANDROID_HOME'] || process.env['ANDROID_SDK_ROOT'];
896
-
897
- if (!androidHome || !fs.existsSync(androidHome)) {
898
- this.addResult({
899
- name: 'Android SDK Components',
900
- status: 'warn',
901
- message: 'Cannot check Android SDK components - ANDROID_HOME not set',
902
- details: 'Set ANDROID_HOME environment variable for Android development',
903
- fixable: true,
904
- fixCommand: 'Install Android Studio and set ANDROID_HOME',
905
- category: 'Android installation',
906
- });
907
- return;
908
- }
909
-
910
- // Check for any Android Platform (not specific version)
911
- const platformsDir = path.join(androidHome, 'platforms');
912
- if (fs.existsSync(platformsDir)) {
913
- const platforms = fs.readdirSync(platformsDir).filter(dir => dir.startsWith('android-'));
914
- if (platforms.length > 0) {
915
- this.addResult({
916
- name: 'Android Platform',
917
- status: 'pass',
918
- message: `Android Platform installed (${platforms.length} version${platforms.length > 1 ? 's' : ''})`,
919
- category: 'Android installation',
920
- });
921
- } else {
922
- this.addResult({
923
- name: 'Android Platform',
924
- status: 'warn',
925
- message: 'No Android Platform found',
926
- details: 'Install an Android Platform via Android Studio SDK Manager',
927
- fixable: true,
928
- fixCommand: 'Open Android Studio > SDK Manager > Install an Android Platform',
929
- category: 'Android installation',
930
- });
931
- }
932
- } else {
933
- this.addResult({
934
- name: 'Android Platform',
935
- status: 'warn',
936
- message: 'Android platforms directory not found',
937
- fixable: true,
938
- fixCommand: 'Install Android Studio and configure SDK',
939
- category: 'Android installation',
940
- });
941
- }
942
-
943
- // Check for any Build Tools (not specific version)
944
- const buildToolsDir = path.join(androidHome, 'build-tools');
945
- if (fs.existsSync(buildToolsDir)) {
946
- const buildTools = fs.readdirSync(buildToolsDir);
947
- if (buildTools.length > 0) {
948
- this.addResult({
949
- name: 'Android Build Tools',
950
- status: 'pass',
951
- message: `Android Build Tools installed (${buildTools.length} version${buildTools.length > 1 ? 's' : ''})`,
952
- category: 'Android installation',
953
- });
954
- } else {
955
- this.addResult({
956
- name: 'Android Build Tools',
957
- status: 'warn',
958
- message: 'No Android Build Tools found',
959
- fixable: true,
960
- fixCommand: 'Install Build Tools via Android Studio SDK Manager',
961
- category: 'Android installation',
962
- });
963
- }
964
- } else {
965
- this.addResult({
966
- name: 'Android Build Tools',
967
- status: 'warn',
968
- message: 'Build tools directory not found',
969
- fixable: true,
970
- fixCommand: 'Install Android Studio and configure SDK',
971
- category: 'Android installation',
972
- });
973
- }
974
- }
975
-
976
- /**
977
- * Validates core development dependencies needed for app development.
978
- *
979
- * Focuses on essential tools that app developers need:
980
- * - git: Version control (essential)
981
- * - npm: Package management (essential)
982
- * - watchman: File watching for hot reloader (essential)
983
- * - ios-webkit-debug-proxy: iOS debugging for hot reloader (macOS only, essential)
984
- *
985
- * @returns Promise that resolves when core dependency checks are complete
986
- * @private
987
- */
988
- private async checkCoreDependencies(): Promise<void> {
989
- const coreDeps = ['git', 'npm', 'watchman'];
990
-
991
- for (const dep of coreDeps) {
992
- await this.checkSingleDependency(dep, 'fail'); // Core deps are critical
993
- }
994
-
995
- // Platform-specific core dependencies
996
- if (os.platform() === 'darwin') {
997
- await this.checkSingleDependency('ios_webkit_debug_proxy', 'fail'); // Essential for hot reloader
998
- }
999
- }
1000
-
1001
- /**
1002
- * Validates Git LFS initialization status.
1003
- *
1004
- * Checks if git-lfs is installed and properly initialized.
1005
- * dev_setup runs `git lfs install` to configure Git LFS hooks.
1006
- *
1007
- * @returns Promise that resolves when Git LFS check is complete
1008
- * @private
1009
- */
1010
- private async checkGitLfsInitialization(): Promise<void> {
1011
- // First check if git-lfs command exists
1012
- if (!checkCommandExists('git-lfs')) {
1013
- const fixCommand = this.getFixCommandForDependency('git-lfs');
1014
- this.addResult({
1015
- name: 'Git LFS',
1016
- status: 'warn',
1017
- message: 'git-lfs not installed',
1018
- details: 'Required for working with large files in the repository',
1019
- fixable: true,
1020
- fixCommand,
1021
- category: 'Development tools',
1022
- });
1023
- return;
1024
- }
1025
-
1026
- // Check if git lfs is initialized by checking the config
1027
- try {
1028
- const { stdout, returnCode } = await runCliCommand('git config --global --get filter.lfs.process');
1029
-
1030
- if (returnCode === 0 && stdout.trim()) {
1031
- this.addResult({
1032
- name: 'Git LFS initialization',
1033
- status: 'pass',
1034
- message: 'git-lfs is initialized',
1035
- category: 'Development tools',
1036
- });
1037
- } else {
1038
- this.addResult({
1039
- name: 'Git LFS initialization',
1040
- status: 'warn',
1041
- message: 'git-lfs is installed but not initialized',
1042
- details: 'Run git lfs install to configure Git LFS hooks',
1043
- fixable: true,
1044
- fixCommand: 'git lfs install',
1045
- category: 'Development tools',
1046
- });
1047
-
1048
- if (this.autoFix) {
1049
- await this.attemptAutoFix('git-lfs', 'git lfs install');
1050
- }
1051
- }
1052
- } catch {
1053
- this.addResult({
1054
- name: 'Git LFS initialization',
1055
- status: 'warn',
1056
- message: 'git-lfs is installed but not initialized',
1057
- details: 'Run git lfs install to configure Git LFS hooks',
1058
- fixable: true,
1059
- fixCommand: 'git lfs install',
1060
- category: 'Development tools',
1061
- });
1062
-
1063
- if (this.autoFix) {
1064
- await this.attemptAutoFix('git-lfs', 'git lfs install');
1065
- }
1066
- }
1067
- }
1068
-
1069
- /**
1070
- * Validates shell autocomplete configuration.
1071
- *
1072
- * Checks if shell autocomplete (compinit/bashcompinit) is configured.
1073
- * dev_setup adds these to shell RC files for better CLI experience.
1074
- *
1075
- * @private
1076
- */
1077
- private checkShellAutoComplete(): void {
1078
- const homeDir = process.env['HOME'] ?? '';
1079
- const shell = process.env['SHELL'] ?? '';
1080
-
1081
- let rcFile: string | undefined;
1082
- let requiredLines: string[] = [];
1083
-
1084
- // Determine shell and required configuration
1085
- if (shell.endsWith('/zsh')) {
1086
- rcFile = path.join(homeDir, '.zshrc');
1087
- requiredLines = ['autoload -U compinit && compinit', 'autoload -U bashcompinit && bashcompinit'];
1088
- } else if (shell.endsWith('/bash')) {
1089
- rcFile = path.join(homeDir, '.bashrc');
1090
- // Bash typically auto-loads completion, so we're more lenient
1091
- requiredLines = [];
1092
- } else {
1093
- // Unknown shell, skip check
1094
- return;
1095
- }
1096
-
1097
- if (!rcFile || !fs.existsSync(rcFile)) {
1098
- this.addResult({
1099
- name: 'Shell autocomplete',
1100
- status: 'warn',
1101
- message: `Shell configuration file not found (${rcFile || 'unknown'})`,
1102
- details: 'Shell autocomplete improves CLI experience',
1103
- category: 'Development tools',
1104
- });
1105
- return;
1106
- }
1107
-
1108
- // For bash, we just report success since it typically handles completion automatically
1109
- if (requiredLines.length === 0) {
1110
- this.addResult({
1111
- name: 'Shell autocomplete',
1112
- status: 'pass',
1113
- message: 'Shell autocomplete configured (bash)',
1114
- category: 'Development tools',
1115
- });
1116
- return;
1117
- }
1118
-
1119
- // Read RC file and check for required lines
1120
- try {
1121
- const rcContent = fs.readFileSync(rcFile, 'utf8');
1122
- const rcLines = rcContent.split('\n');
1123
-
1124
- const missingLines: string[] = [];
1125
- for (const required of requiredLines) {
1126
- if (!rcLines.includes(required)) {
1127
- missingLines.push(required);
1128
- }
1129
- }
1130
-
1131
- if (missingLines.length === 0) {
1132
- this.addResult({
1133
- name: 'Shell autocomplete',
1134
- status: 'pass',
1135
- message: 'Shell autocomplete configured',
1136
- category: 'Development tools',
1137
- });
1138
- } else {
1139
- this.addResult({
1140
- name: 'Shell autocomplete',
1141
- status: 'warn',
1142
- message: 'Shell autocomplete not fully configured',
1143
- details: `Missing in ${rcFile}: ${missingLines.join(', ')}`,
1144
- fixable: true,
1145
- fixCommand: `Add to ${rcFile}: ${missingLines.join(' && ')}`,
1146
- category: 'Development tools',
1147
- });
1148
- }
1149
- } catch {
1150
- this.addResult({
1151
- name: 'Shell autocomplete',
1152
- status: 'warn',
1153
- message: 'Could not verify shell autocomplete configuration',
1154
- category: 'Development tools',
1155
- });
1156
- }
1157
- }
1158
-
1159
- /**
1160
- * Validates VSCode/Cursor extensions installation.
1161
- *
1162
- * Checks if Valdi extensions are installed in VSCode or Cursor:
1163
- * - valdi-vivaldi: Device logs and language support
1164
- * - valdi-debug: JavaScript debugger
1165
- *
1166
- * @returns Promise that resolves when extension checks are complete
1167
- * @private
1168
- */
1169
- private async checkEditorExtensions(): Promise<void> {
1170
- const hasCode = checkCommandExists('code');
1171
- const hasCursor = checkCommandExists('cursor');
1172
-
1173
- if (!hasCode && !hasCursor) {
1174
- // No editor installed, skip check
1175
- return;
1176
- }
1177
-
1178
- let extensionsInstalled = false;
1179
-
1180
- // Check VSCode extensions
1181
- if (hasCode) {
1182
- try {
1183
- const { stdout } = await runCliCommand('code --list-extensions');
1184
- const installedExtensions = stdout.toLowerCase();
1185
-
1186
- const hasVivaldi = installedExtensions.includes('valdi-vivaldi');
1187
- const hasDebug = installedExtensions.includes('valdi-debug');
1188
-
1189
- if (hasVivaldi && hasDebug) {
1190
- extensionsInstalled = true;
1191
- this.addResult({
1192
- name: 'VSCode Extensions',
1193
- status: 'pass',
1194
- message: 'Valdi extensions installed in VSCode',
1195
- category: 'Development tools',
1196
- });
1197
- }
1198
- } catch {
1199
- // Could not check VSCode extensions
1200
- }
1201
- }
1202
-
1203
- // Check Cursor extensions
1204
- if (hasCursor) {
1205
- try {
1206
- const { stdout } = await runCliCommand('cursor --list-extensions');
1207
- const installedExtensions = stdout.toLowerCase();
1208
-
1209
- const hasVivaldi = installedExtensions.includes('valdi-vivaldi');
1210
- const hasDebug = installedExtensions.includes('valdi-debug');
1211
-
1212
- if (hasVivaldi && hasDebug) {
1213
- extensionsInstalled = true;
1214
- this.addResult({
1215
- name: 'Cursor Extensions',
1216
- status: 'pass',
1217
- message: 'Valdi extensions installed in Cursor',
1218
- category: 'Development tools',
1219
- });
1220
- }
1221
- } catch {
1222
- // Could not check Cursor extensions
1223
- }
1224
- }
1225
-
1226
- // If neither editor has extensions, show info
1227
- if (!extensionsInstalled && (hasCode || hasCursor)) {
1228
- const editor = hasCode ? 'VSCode' : 'Cursor';
1229
- this.addResult({
1230
- name: `${editor} Extensions`,
1231
- status: 'warn',
1232
- message: 'Valdi editor extensions not installed',
1233
- details: 'Extensions provide syntax highlighting, debugging, and device logs',
1234
- fixable: true,
1235
- fixCommand: 'See installation instructions: https://github.com/Snapchat/Valdi/blob/main/docs/INSTALL.md#vscodecursor-setup-optional-but-recommended',
1236
- category: 'Development tools',
1237
- });
1238
- }
1239
- }
1240
-
1241
- /**
1242
- * Validates framework development dependencies.
1243
- *
1244
- * Additional tools needed for framework development:
1245
- * - temurin: Alternative JDK (macOS)
1246
- *
1247
- * Note: git-lfs is now checked in core dependencies with initialization verification
1248
- *
1249
- * @private
1250
- */
1251
- private checkFrameworkDependencies(): void {
1252
- // git-lfs is now checked in core with initialization verification
1253
-
1254
- // Platform-specific framework dependencies
1255
- if (os.platform() === 'darwin') {
1256
- // Check for temurin package
1257
- const temurinPath = '/opt/homebrew/opt/temurin';
1258
- if (fs.existsSync(temurinPath)) {
1259
- this.addResult({
1260
- name: 'temurin package',
1261
- status: 'pass',
1262
- message: 'temurin installed via Homebrew',
1263
- category: 'Framework tools',
1264
- });
1265
- } else {
1266
- this.addResult({
1267
- name: 'temurin package',
1268
- status: 'warn',
1269
- message: 'temurin not found',
1270
- details: 'Alternative JDK for framework development',
1271
- fixable: true,
1272
- fixCommand: 'brew install temurin',
1273
- category: 'Framework tools',
1274
- });
1275
- }
1276
- }
1277
- }
1278
-
1279
- /**
1280
- * Validates advanced Android SDK components for framework development.
1281
- *
1282
- * Detailed Android SDK validation including:
1283
- * - Specific platform versions
1284
- * - NDK installation
1285
- * - Command line tools
1286
- *
1287
- * @private
1288
- */
1289
- private checkAdvancedAndroidSDK(): void {
1290
- const androidHome = process.env['ANDROID_HOME'] || process.env['ANDROID_SDK_ROOT'];
1291
-
1292
- if (!androidHome || !fs.existsSync(androidHome)) {
1293
- return; // Already checked in basics
1294
- }
1295
-
1296
- // Check specific Android Platform version
1297
- const platformPath = path.join(androidHome, 'platforms', ANDROID_PLATFORM_VERSION);
1298
- if (fs.existsSync(platformPath)) {
1299
- this.addResult({
1300
- name: `Android Platform ${ANDROID_PLATFORM_VERSION}`,
1301
- status: 'pass',
1302
- message: `Android Platform ${ANDROID_PLATFORM_VERSION} installed`,
1303
- category: 'Android installation',
1304
- });
1305
- } else {
1306
- this.addResult({
1307
- name: `Android Platform ${ANDROID_PLATFORM_VERSION}`,
1308
- status: 'warn',
1309
- message: `Android Platform ${ANDROID_PLATFORM_VERSION} not found`,
1310
- details: 'Specific platform version for framework development',
1311
- fixable: true,
1312
- fixCommand: `sdkmanager --install 'platforms;${ANDROID_PLATFORM_VERSION}'`,
1313
- category: 'Android installation',
1314
- });
1315
- }
1316
-
1317
- // Check Android NDK
1318
- const ndkPath = path.join(androidHome, 'ndk', ANDROID_NDK_VERSION);
1319
- if (fs.existsSync(ndkPath)) {
1320
- this.addResult({
1321
- name: 'Android NDK',
1322
- status: 'pass',
1323
- message: `Android NDK ${ANDROID_NDK_VERSION} installed`,
1324
- category: 'Android installation',
1325
- });
1326
- } else {
1327
- this.addResult({
1328
- name: 'Android NDK',
1329
- status: 'warn',
1330
- message: `Android NDK ${ANDROID_NDK_VERSION} not found`,
1331
- details: 'Required for native development in framework',
1332
- fixable: true,
1333
- fixCommand: `sdkmanager --install 'ndk;${ANDROID_NDK_VERSION}'`,
1334
- category: 'Android installation',
1335
- });
1336
- }
1337
- }
1338
-
1339
-
1340
-
1341
-
1342
-
1343
- /**
1344
- * Checks a single dependency and reports its status.
1345
- * @private
1346
- */
1347
- private async checkSingleDependency(dep: string, failureLevel: 'warn' | 'fail'): Promise<void> {
1348
- // Determine category based on dependency type
1349
- let category: string;
1350
- if (['git', 'npm', 'watchman', 'ios_webkit_debug_proxy'].includes(dep)) {
1351
- category = 'Development tools';
1352
- } else if (['git-lfs', 'temurin'].includes(dep)) {
1353
- category = 'Framework tools';
1354
- } else {
1355
- category = 'Development tools';
1356
- }
1357
-
1358
- if (checkCommandExists(dep)) {
1359
- try {
1360
- const { stdout } = await runCliCommand(`${dep} --version`);
1361
- const versionLine = stdout.split('\n')[0] || 'Unknown version';
1362
- this.addResult({
1363
- name: `${dep} installation`,
1364
- status: 'pass',
1365
- message: `${dep} is installed: ${versionLine}`,
1366
- category,
1367
- });
1368
- } catch {
1369
- this.addResult({
1370
- name: `${dep} installation`,
1371
- status: 'pass',
1372
- message: `${dep} is installed`,
1373
- category,
1374
- });
1375
- }
1376
- } else {
1377
- const fixCommand = this.getFixCommandForDependency(dep);
1378
- this.addResult({
1379
- name: `${dep} installation`,
1380
- status: failureLevel,
1381
- message: `${dep} is not installed or not in PATH`,
1382
- fixable: true,
1383
- fixCommand,
1384
- category,
1385
- });
1386
-
1387
- if (this.autoFix && failureLevel === 'fail') {
1388
- await this.attemptAutoFix(dep, fixCommand);
1389
- }
1390
- }
1391
- }
1392
-
1393
- /**
1394
- * Validates environment variables as configured by dev_setup.
1395
- *
1396
- * Checks for essential environment variables that dev_setup configures:
1397
- * - ANDROID_HOME: Android SDK location
1398
- * - ANDROID_NDK_HOME: Android NDK location
1399
- * - JAVA_HOME: Java JDK location
1400
- * - PATH modifications: Java, Android tools, Bazelisk
1401
- *
1402
- * @private
1403
- */
1404
- private checkEnvironmentVariables(): void {
1405
- // Check ANDROID_HOME
1406
- const androidHome = process.env['ANDROID_HOME'];
1407
- if (androidHome && fs.existsSync(androidHome)) {
1408
- this.addResult({
1409
- name: 'ANDROID_HOME',
1410
- status: 'pass',
1411
- message: `ANDROID_HOME set to ${androidHome}`,
1412
- category: 'Android installation',
1413
- });
1414
- } else {
1415
- this.addResult({
1416
- name: 'ANDROID_HOME',
1417
- status: 'fail',
1418
- message: 'ANDROID_HOME not set or invalid',
1419
- details: 'dev_setup configures ANDROID_HOME for Android development',
1420
- fixable: true,
1421
- fixCommand: 'valdi dev_setup',
1422
- category: 'Android installation',
1423
- });
1424
- }
1425
-
1426
- // Check ANDROID_NDK_HOME
1427
- const androidNdkHome = process.env['ANDROID_NDK_HOME'];
1428
- if (androidNdkHome && fs.existsSync(androidNdkHome)) {
1429
- this.addResult({
1430
- name: 'ANDROID_NDK_HOME',
1431
- status: 'pass',
1432
- message: `ANDROID_NDK_HOME set to ${androidNdkHome}`,
1433
- category: 'Android installation',
1434
- });
1435
- } else {
1436
- this.addResult({
1437
- name: 'ANDROID_NDK_HOME',
1438
- status: 'warn',
1439
- message: 'ANDROID_NDK_HOME not set or invalid',
1440
- details: 'dev_setup configures ANDROID_NDK_HOME for native development',
1441
- fixable: true,
1442
- fixCommand: 'valdi dev_setup',
1443
- category: 'Android installation',
1444
- });
1445
- }
1446
-
1447
- // Check platform-tools in PATH
1448
- const pathEnvAndroid = process.env['PATH'] || '';
1449
- const androidHomeForPath = process.env['ANDROID_HOME'];
1450
- if (androidHomeForPath) {
1451
- const platformToolsInPath = pathEnvAndroid.includes(`${androidHomeForPath}/platform-tools`) ||
1452
- pathEnvAndroid.includes('platform-tools');
1453
- if (platformToolsInPath) {
1454
- this.addResult({
1455
- name: 'Android platform-tools PATH',
1456
- status: 'pass',
1457
- message: 'Android platform-tools in PATH',
1458
- category: 'Android installation',
1459
- });
1460
- } else {
1461
- this.addResult({
1462
- name: 'Android platform-tools PATH',
1463
- status: 'warn',
1464
- message: 'Android platform-tools not in PATH',
1465
- details: 'dev_setup adds platform-tools (containing adb) to PATH',
1466
- fixable: true,
1467
- fixCommand: 'export PATH="$ANDROID_HOME/platform-tools:$PATH"',
1468
- category: 'Android installation',
1469
- });
1470
- }
1471
- }
1472
-
1473
- // JAVA_HOME is checked in Java installation section to avoid duplication
1474
-
1475
- // Check PATH modifications
1476
- const pathEnv = process.env['PATH'] || '';
1477
-
1478
- // Check for Bazelisk in PATH (Linux only - Java PATH checked in Java section)
1479
- if (os.platform() === 'linux') {
1480
- if (pathEnv.includes('/.valdi/bin')) {
1481
- this.addResult({
1482
- name: 'Bazelisk PATH',
1483
- status: 'pass',
1484
- message: 'Bazelisk directory in PATH',
1485
- category: 'Bazel installation',
1486
- });
1487
- } else {
1488
- this.addResult({
1489
- name: 'Bazelisk PATH',
1490
- status: 'warn',
1491
- message: 'Bazelisk directory not in PATH',
1492
- details: 'dev_setup adds ~/.valdi/bin to PATH for Bazelisk',
1493
- fixable: true,
1494
- fixCommand: 'export PATH="$HOME/.valdi/bin:$PATH"',
1495
- category: 'Bazel installation',
1496
- });
1497
- }
1498
- }
1499
- }
1500
-
1501
- /**
1502
- * Gets the appropriate Java installation command for the current platform
1503
- * @private
1504
- */
1505
- private getJavaInstallCommand(): string {
1506
- if (os.platform() === 'darwin') {
1507
- return 'brew install openjdk@17';
1508
- } else if (os.platform() === 'linux' && this.linuxDistro) {
1509
- const packageMappings = getCommonPackageMappings();
1510
- const javaPackage = getPackageName(packageMappings['openjdk-17']!, this.linuxDistro);
1511
- return buildInstallCommand([javaPackage], this.linuxDistro);
1512
- } else {
1513
- return 'Install Java 17 JDK for your distribution';
1514
- }
1515
- }
1516
-
1517
- /**
1518
- * Generates platform-specific fix commands for missing dependencies.
1519
- *
1520
- * Provides appropriate installation commands based on the current platform
1521
- * and the specific dependency that's missing. Enhanced to support all
1522
- * dependencies that dev_setup installs.
1523
- *
1524
- * @param dep - The name of the missing dependency
1525
- * @returns Platform-appropriate installation command or instruction
1526
- * @private
1527
- */
1528
- private getFixCommandForDependency(dep: string): string {
1529
- // macOS-specific dependencies
1530
- if (os.platform() === 'darwin') {
1531
- switch (dep) {
1532
- case 'git': {
1533
- return 'brew install git';
1534
- }
1535
- case 'npm': {
1536
- return 'Install Node.js from https://nodejs.org (includes npm)';
1537
- }
1538
- case 'watchman': {
1539
- return 'brew install watchman';
1540
- }
1541
- case 'git-lfs': {
1542
- return 'brew install git-lfs';
1543
- }
1544
- case 'bazelisk': {
1545
- return 'brew install bazelisk';
1546
- }
1547
- case 'ios_webkit_debug_proxy': {
1548
- return 'brew install ios-webkit-debug-proxy';
1549
- }
1550
- default: {
1551
- return `brew install ${dep}`;
1552
- }
1553
- }
1554
- }
1555
-
1556
- // Linux dependencies with distribution detection
1557
- if (os.platform() === 'linux' && this.linuxDistro) {
1558
- const packageMappings = getCommonPackageMappings();
1559
-
1560
- switch (dep) {
1561
- case 'git': {
1562
- return buildInstallCommand(['git'], this.linuxDistro);
1563
- }
1564
- case 'npm': {
1565
- return buildInstallCommand([getPackageName(packageMappings['npm']!, this.linuxDistro)], this.linuxDistro);
1566
- }
1567
- case 'watchman': {
1568
- const watchmanPkg = getPackageName(packageMappings['watchman']!, this.linuxDistro);
1569
- const cmd = buildInstallCommand([watchmanPkg], this.linuxDistro);
1570
- // Add note for RHEL-based systems
1571
- if (this.linuxDistro.packageManager.name === 'yum' || this.linuxDistro.packageManager.name === 'dnf') {
1572
- return `${cmd} (may require EPEL repository)`;
1573
- }
1574
- return cmd;
1575
- }
1576
- case 'git-lfs': {
1577
- return buildInstallCommand([getPackageName(packageMappings['git-lfs']!, this.linuxDistro)], this.linuxDistro);
1578
- }
1579
- case 'bazelisk': {
1580
- return 'valdi dev_setup';
1581
- }
1582
- case 'adb': {
1583
- return buildInstallCommand([getPackageName(packageMappings['adb']!, this.linuxDistro)], this.linuxDistro);
1584
- }
1585
- default: {
1586
- return buildInstallCommand([dep], this.linuxDistro);
1587
- }
1588
- }
1589
- }
1590
-
1591
- // Fallback for unknown platforms or when distro detection fails
1592
- switch (dep) {
1593
- case 'npm': {
1594
- return 'Install Node.js from https://nodejs.org (includes npm)';
1595
- }
1596
- case 'bazelisk': {
1597
- return 'valdi dev_setup';
1598
- }
1599
- default: {
1600
- return `Install ${dep} using your system's package manager`;
1601
- }
1602
- }
1603
- }
1604
-
1605
- /**
1606
- * Outputs diagnostic results in JSON format for machine processing.
1607
- *
1608
- * Generates a structured JSON report containing:
1609
- * - ISO timestamp of the diagnostic run
1610
- * - Summary statistics (passed, warnings, failed, total)
1611
- * - Complete array of diagnostic results with all details
1612
- *
1613
- * This format is ideal for:
1614
- * - CI/CD pipeline integration
1615
- * - Automated monitoring and alerting
1616
- * - Programmatic analysis of environment health
1617
- * @example
1618
- * ```json
1619
- * {
1620
- * "timestamp": "2024-01-15T10:30:00.000Z",
1621
- * "summary": { "passed": 8, "warnings": 0, "failed": 1, "total": 9 },
1622
- * "results": [...]
1623
- * }
1624
- * ```
1625
- */
1626
- private printJsonResults(): void {
1627
- const passCount = this.results.filter(r => r.status === 'pass').length;
1628
- const warnCount = this.results.filter(r => r.status === 'warn').length;
1629
- const failCount = this.results.filter(r => r.status === 'fail').length;
1630
-
1631
- const output = {
1632
- timestamp: new Date().toISOString(),
1633
- summary: {
1634
- passed: passCount,
1635
- warnings: warnCount,
1636
- failed: failCount,
1637
- total: this.results.length,
1638
- },
1639
- results: this.results,
1640
- };
1641
-
1642
- console.log(JSON.stringify(output, null, 2));
1643
- }
1644
-
1645
- /**
1646
- * Outputs diagnostic results in human-readable format with colors and icons.
1647
- *
1648
- * Generates a formatted report with:
1649
- * - Grouped categories for better readability
1650
- * - Colored status icons (✓ ⚠ ✗) for visual clarity
1651
- * - Detailed issue information only when problems exist
1652
- * - Optional verbose details when requested
1653
- * - Actionable fix commands for failed checks
1654
- * - Summary statistics and overall health assessment
1655
- *
1656
- * The output uses ANSI color codes for enhanced readability:
1657
- * - Green (✓): Successful checks
1658
- * - Yellow (⚠): Warnings that don't block development
1659
- * - Red (✗): Critical failures requiring attention
1660
- * @example
1661
- * ```
1662
- * Valdi Doctor Report
1663
- * ==================================================
1664
- * ✓ Node.js installation
1665
- * ✗ Java installation
1666
- * • JAVA_HOME not set or invalid
1667
- * • Java tools not in PATH
1668
- * ==================================================
1669
- * Summary: 1 passed, 0 warnings, 1 failed
1670
- * ```
1671
- */
1672
- private printFormattedResults(): void {
1673
- console.log(wrapInColor('Valdi Doctor Report', ANSI_COLORS.BLUE_COLOR));
1674
- console.log('='.repeat(50));
1675
- console.log();
1676
-
1677
- const groupedResults = this.groupResultsByCategory();
1678
- let totalPassCount = 0;
1679
- let totalWarnCount = 0;
1680
- let totalFailCount = 0;
1681
-
1682
- for (const group of groupedResults) {
1683
- const statusIcon = group.status === 'pass' ? '✓' : group.status === 'warn' ? '⚠' : '✗';
1684
- const statusColor = group.status === 'pass' ? ANSI_COLORS.GREEN_COLOR :
1685
- group.status === 'warn' ? ANSI_COLORS.YELLOW_COLOR : ANSI_COLORS.RED_COLOR;
1686
-
1687
- console.log(`${wrapInColor(statusIcon, statusColor)} ${group.category}`);
1688
-
1689
- // Show issues when there are problems
1690
- if (group.issues.length > 0) {
1691
- for (const issue of group.issues) {
1692
- console.log(` • ${issue.message}`);
1693
-
1694
- if (this.verbose && issue.details) {
1695
- console.log(` ${wrapInColor('Details:', ANSI_COLORS.GRAY_COLOR)} ${issue.details}`);
1696
- }
1697
-
1698
- if (issue.fixable && issue.fixCommand) {
1699
- console.log(` ${wrapInColor('Fix:', ANSI_COLORS.BLUE_COLOR)} ${issue.fixCommand}`);
1700
- }
1701
- }
1702
- }
1703
-
1704
- console.log();
1705
-
1706
- // Count individual check results for summary
1707
- for (const check of group.checks) {
1708
- if (check.status === 'pass') totalPassCount++;
1709
- else if (check.status === 'warn') totalWarnCount++;
1710
- else totalFailCount++;
1711
- }
1712
- }
1713
-
1714
- console.log('='.repeat(50));
1715
- console.log(`${wrapInColor('Summary:', ANSI_COLORS.BLUE_COLOR)} ${totalPassCount} passed, ${totalWarnCount} warnings, ${totalFailCount} failed`);
1716
-
1717
- if (totalFailCount > 0) {
1718
- console.log();
1719
- console.log(wrapInColor('Some issues need to be resolved before Valdi can work properly.', ANSI_COLORS.RED_COLOR));
1720
- console.log();
1721
- console.log(wrapInColor('Still having trouble? Come get help on Discord:', ANSI_COLORS.BLUE_COLOR));
1722
- console.log(wrapInColor(DISCORD_SUPPORT_URL, ANSI_COLORS.BLUE_COLOR));
1723
- console.log(wrapInColor('Please paste the entire output of this command when asking for help.', ANSI_COLORS.YELLOW_COLOR));
1724
- } else if (totalWarnCount > 0) {
1725
- console.log();
1726
- console.log(wrapInColor('Your environment is mostly ready, but some optional tools are missing.', ANSI_COLORS.YELLOW_COLOR));
1727
- } else {
1728
- console.log();
1729
- console.log(wrapInColor('Your Valdi development environment is ready! 🎉', ANSI_COLORS.GREEN_COLOR));
1730
- }
1731
- }
1732
- }
1733
-
1734
- /**
1735
- * Main entry point for the Valdi doctor command.
1736
- *
1737
- * This function serves as the command handler that:
1738
- * 1. Extracts command line arguments (verbose, fix, json)
1739
- * 2. Creates a new ValdiDoctor instance with the specified configuration
1740
- * 3. Executes the complete diagnostic suite
1741
- * 4. Outputs results in the requested format
1742
- *
1743
- * @param argv - Resolved command line arguments
1744
- * @returns Promise that resolves when the doctor command completes
1745
- *
1746
- * @example
1747
- * ```bash
1748
- * valdi doctor --verbose --fix --json
1749
- * ```
1750
- */
1751
- async function valdiDoctor(argv: ArgumentsResolver<CommandParameters>): Promise<void> {
1752
- const verbose = argv.getArgument('verbose');
1753
- const autoFix = argv.getArgument('fix');
1754
- const jsonOutput = argv.getArgument('json');
1755
- const frameworkMode = argv.getArgument('framework');
1756
- const projectMode = argv.getArgument('project');
1757
-
1758
- const doctor = new ValdiDoctor(verbose, autoFix, jsonOutput, frameworkMode, projectMode);
1759
- const status = await doctor.runDiagnostics();
1760
- doctor.printResults();
1761
-
1762
- if (status === 'fail') {
1763
- throw new Error('valdi doctor failed');
1764
- }
1765
- }
1766
-
1767
- // ============================================================================
1768
- // YARGS COMMAND CONFIGURATION
1769
- // ============================================================================
1770
-
1771
- /**
1772
- * The command name as it appears in the CLI.
1773
-
1774
- */
1775
- export const command = 'doctor';
1776
-
1777
- /**
1778
- * Human-readable description of the command for help output.
1779
-
1780
- */
1781
- export const describe = 'Check your Valdi development environment for common issues';
1782
-
1783
- /**
1784
- * Configures command line options and their validation.
1785
- *
1786
- * Defines three main options:
1787
- * - `--verbose` (-v): Enable detailed diagnostic output
1788
- * - `--fix` (-f): Attempt automatic fixes where possible
1789
- * - `--json` (-j): Output results in JSON format for automation
1790
- *
1791
- * @param yargs - The yargs instance to configure
1792
-
1793
- */
1794
- export const builder = (yargs: Argv<CommandParameters>): void => {
1795
- yargs
1796
- .option('verbose', {
1797
- describe: 'Show detailed diagnostic information',
1798
- type: 'boolean',
1799
- default: false,
1800
- alias: 'v',
1801
- })
1802
- .option('fix', {
1803
- describe: 'Attempt to automatically fix issues where possible',
1804
- type: 'boolean',
1805
- default: false,
1806
- alias: 'f',
1807
- })
1808
- .option('json', {
1809
- describe: 'Output results in JSON format',
1810
- type: 'boolean',
1811
- default: false,
1812
- alias: 'j',
1813
- })
1814
- .option('framework', {
1815
- describe: 'Include framework development checks (git-lfs, temurin, etc.)',
1816
- type: 'boolean',
1817
- default: false,
1818
- alias: 'F',
1819
- })
1820
- .option('project', {
1821
- describe: 'Include project-specific checks (workspace structure, etc.)',
1822
- type: 'boolean',
1823
- default: false,
1824
- alias: 'p',
1825
- });
1826
- };
1827
-
1828
- /**
1829
- * The command handler wrapped with error handling and logging.
1830
-
1831
- */
1832
- export const handler = makeCommandHandler(valdiDoctor);