@snap/valdi 1.0.6 → 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 (161) hide show
  1. package/README.md +22 -10
  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/{.metadata/.cursorrules.template → bundled-skills/skills/valdi-overview/skill.md} +23 -13
  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 +3 -9
  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 +1 -1
  53. package/dist/index.js +5 -0
  54. package/dist/setup/versions.js +1 -1
  55. package/dist/utils/skillsAdapters.js +140 -0
  56. package/dist/utils/skillsRegistry.js +40 -0
  57. package/package.json +6 -1
  58. package/.bazelignore +0 -2
  59. package/.bootstrap/apps/cli_application/AGENTS.md.template +0 -291
  60. package/.bootstrap/apps/cli_application/BUILD.bazel.template +0 -7
  61. package/.bootstrap/apps/cli_application/modules/{{MODULE_NAME}}/BUILD.bazel.template +0 -11
  62. package/.bootstrap/apps/cli_application/modules/{{MODULE_NAME}}/src/index.ts +0 -1
  63. package/.bootstrap/apps/ui_application/.eslint.rc +0 -27
  64. package/.bootstrap/apps/ui_application/AGENTS.md.template +0 -278
  65. package/.bootstrap/apps/ui_application/BUILD.bazel.template +0 -19
  66. package/.bootstrap/apps/ui_application/modules/{{MODULE_NAME}}/BUILD.bazel.template +0 -21
  67. package/.bootstrap/apps/ui_application/modules/{{MODULE_NAME}}/res/valdi@3x.png +0 -0
  68. package/.bootstrap/apps/ui_application/modules/{{MODULE_NAME}}/src/App.tsx +0 -133
  69. package/.bootstrap/apps/ui_application/package.json +0 -24
  70. package/.bootstrap/modules/cpp_bridge_module/BUILD.bazel.template +0 -21
  71. package/.bootstrap/modules/cpp_bridge_module/cpp/CalculatorModuleFactory.cpp.template +0 -28
  72. package/.bootstrap/modules/cpp_bridge_module/src/Calculator.d.ts +0 -4
  73. package/.bootstrap/modules/ios_android_bridge_module/BUILD.bazel.template +0 -39
  74. package/.bootstrap/modules/ios_android_bridge_module/android/CalculatorModuleFactory.kt.template +0 -18
  75. package/.bootstrap/modules/ios_android_bridge_module/ios/SCCCalculatorModuleFactory.m.template +0 -31
  76. package/.bootstrap/modules/ios_android_bridge_module/src/Calculator.d.ts +0 -4
  77. package/.bootstrap/modules/ios_android_view_module/BUILD.bazel.template +0 -41
  78. package/.bootstrap/modules/ios_android_view_module/android/CircleView.kt.template +0 -42
  79. package/.bootstrap/modules/ios_android_view_module/android/CircleViewAttributesBinder.kt.template +0 -60
  80. package/.bootstrap/modules/ios_android_view_module/ios/SCCCircleView.h +0 -6
  81. package/.bootstrap/modules/ios_android_view_module/ios/SCCCircleView.m +0 -82
  82. package/.bootstrap/modules/ios_android_view_module/src/Circle.tsx.template +0 -15
  83. package/.bootstrap/modules/ui_component/BUILD.bazel.template +0 -34
  84. package/.bootstrap/modules/ui_component/src/NewModuleComponent.tsx +0 -45
  85. package/.config/copyconfig.json +0 -10
  86. package/.editorconfig +0 -21
  87. package/.eslintignore +0 -1
  88. package/.eslintrc.js +0 -72
  89. package/.github/README.md +0 -164
  90. package/.metadata/.bazelrc.template +0 -91
  91. package/.metadata/.bazelversion.template +0 -1
  92. package/.metadata/.editorconfig.template +0 -37
  93. package/.metadata/.eslintrc.js.template +0 -27
  94. package/.metadata/.gitignore.template +0 -4
  95. package/.metadata/.prettierrc.json.template +0 -7
  96. package/.metadata/.watchmanconfig.template +0 -8
  97. package/.metadata/README.md.template +0 -31
  98. package/.metadata/WORKSPACE.template +0 -57
  99. package/.metadata/config.yaml.template +0 -1
  100. package/.metadata/package.json.template +0 -23
  101. package/.prettierignore +0 -2
  102. package/.prettierrc.json +0 -7
  103. package/LINUX_COMPATIBILITY.md +0 -248
  104. package/prettier.config.js +0 -4
  105. package/scripts/sync-agents-md.sh +0 -44
  106. package/scripts/update-agents-templates.ts +0 -170
  107. package/spec/support/jasmine.json +0 -6
  108. package/src/commands/bootstrap.ts +0 -409
  109. package/src/commands/build.ts +0 -89
  110. package/src/commands/devSetup.ts +0 -17
  111. package/src/commands/doctor.ts +0 -1832
  112. package/src/commands/export.ts +0 -131
  113. package/src/commands/hotreload.ts +0 -108
  114. package/src/commands/install.ts +0 -93
  115. package/src/commands/lint.ts +0 -15
  116. package/src/commands/lint_commands/lintCheck.ts +0 -53
  117. package/src/commands/lint_commands/lintFormat.ts +0 -49
  118. package/src/commands/log.ts +0 -108
  119. package/src/commands/newModule.ts +0 -286
  120. package/src/commands/package.ts +0 -102
  121. package/src/commands/projectsync.ts +0 -488
  122. package/src/commands/test.ts +0 -68
  123. package/src/core/constants.ts +0 -97
  124. package/src/core/errors.ts +0 -10
  125. package/src/index.ts +0 -22
  126. package/src/setup/DevSetupHelper.ts +0 -290
  127. package/src/setup/linuxSetup.ts +0 -261
  128. package/src/setup/macOSSetup.ts +0 -156
  129. package/src/setup/setupEntryPoint.ts +0 -64
  130. package/src/setup/versions.ts +0 -8
  131. package/src/utils/ArgumentsResolver.ts +0 -23
  132. package/src/utils/BazelClient.ts +0 -285
  133. package/src/utils/Digraph.ts +0 -81
  134. package/src/utils/LoadingIndicator.ts +0 -43
  135. package/src/utils/applicationUtils.ts +0 -276
  136. package/src/utils/buildInfo.ts +0 -99
  137. package/src/utils/byString.ts +0 -3
  138. package/src/utils/cliUtils.ts +0 -112
  139. package/src/utils/copyBootstrapFiles.ts +0 -30
  140. package/src/utils/deviceUtils.ts +0 -76
  141. package/src/utils/errorUtils.ts +0 -63
  142. package/src/utils/fileUtils.ts +0 -257
  143. package/src/utils/githubUtils.ts +0 -102
  144. package/src/utils/jsonUtils.ts +0 -30
  145. package/src/utils/lintUtils.ts +0 -190
  146. package/src/utils/linuxDistro.spec.ts +0 -219
  147. package/src/utils/linuxDistro.ts +0 -326
  148. package/src/utils/logUtils.ts +0 -9
  149. package/src/utils/pathUtils.ts +0 -12
  150. package/src/utils/stringUtils.spec.ts +0 -95
  151. package/src/utils/stringUtils.ts +0 -103
  152. package/src/utils/tempDir.ts +0 -24
  153. package/src/utils/zipUtils.ts +0 -14
  154. package/test/ValdiSmokeTest.ts +0 -279
  155. package/test/helpers/AsyncHelpers.ts +0 -113
  156. package/test/helpers/CommandHelpers.ts +0 -37
  157. package/test/helpers/ProjectHelpers.ts +0 -153
  158. package/test/helpers/StreamHelpers.ts +0 -37
  159. package/test/helpers/TypeScriptClient.ts +0 -217
  160. package/tsconfig.dist.json +0 -8
  161. package/tsconfig.json +0 -42
@@ -1,290 +0,0 @@
1
- import fs from 'fs';
2
- import path from 'path';
3
- import { ANSI_COLORS } from '../core/constants';
4
- import { LoadingIndicator } from '../utils/LoadingIndicator';
5
- import { spawnCliCommand } from '../utils/cliUtils';
6
- import { wrapInColor } from '../utils/logUtils';
7
- import { withTempDir } from '../utils/tempDir';
8
- import { decompressTo } from '../utils/zipUtils';
9
- import { ANDROID_BUILD_TOOLS_VERSION, ANDROID_NDK_VERSION, ANDROID_PLATFORM_VERSION } from './versions';
10
-
11
- export const HOME_DIR = process.env['HOME'] ?? '';
12
-
13
- // Platform-specific Android SDK locations matching documentation
14
- function getAndroidHomeDir(): string {
15
- const platform = process.platform;
16
- if (platform === 'darwin') {
17
- return path.join(HOME_DIR, 'Library', 'Android', 'sdk');
18
- } else {
19
- // Linux and others
20
- return path.join(HOME_DIR, 'Android', 'Sdk');
21
- }
22
- }
23
-
24
- const ANDROID_HOME_TARGET_DIR = getAndroidHomeDir();
25
-
26
- export interface EnvVariable {
27
- name: string;
28
- value: string;
29
- }
30
-
31
- export class DevSetupHelper {
32
- async download(url: string): Promise<ArrayBuffer> {
33
- return new LoadingIndicator(async () => {
34
- const response = await fetch(url);
35
-
36
- return response.arrayBuffer();
37
- })
38
- .setText(`${wrapInColor('Downloading', ANSI_COLORS.YELLOW_COLOR)} ${url}...`)
39
- .show();
40
- }
41
-
42
- async downloadToPath(url: string, dest: string): Promise<void> {
43
- const body = await this.download(url);
44
-
45
- const dir = path.dirname(dest);
46
- if (!fs.existsSync(dir)) {
47
- fs.mkdirSync(dir, { recursive: true });
48
- }
49
-
50
- await fs.promises.writeFile(dest, new Uint8Array(body));
51
- }
52
-
53
- async runShell(
54
- guide: string,
55
- commands: string[],
56
- additionalEnvVariables: { [key: string]: string } = {},
57
- ): Promise<string> {
58
- let command = '';
59
- for (const key in additionalEnvVariables) {
60
- command += `export ${key}="${additionalEnvVariables[key] as string}"\n`;
61
- }
62
- command += commands.join(' && ');
63
- console.log(`${wrapInColor(guide, ANSI_COLORS.YELLOW_COLOR)}...`);
64
- for (const command of commands) {
65
- console.log(`- ${command}`);
66
- }
67
-
68
- const result = await spawnCliCommand(command, undefined, 'inherit', false, true);
69
- return result.stdout;
70
- }
71
-
72
- async writeEnvVariablesToRcFile(envVariables: readonly EnvVariable[]): Promise<void> {
73
- const expectedEnvVariable = envVariables.map(e => `export ${e.name}=${e.value}`);
74
- const rcFile = this.getRcFile();
75
- if (!rcFile) {
76
- console.log();
77
- console.log(
78
- `${wrapInColor(`Unrecognized shell ${process.env['SHELL'] ?? ''}. Please add the following env variables to your shell configuration file manually:`, ANSI_COLORS.RED_COLOR)}`,
79
- );
80
- for (const l of expectedEnvVariable) {
81
- console.log(l);
82
- }
83
- console.log();
84
- return;
85
- }
86
-
87
- return new LoadingIndicator(async () => {
88
- let originalRcLines: readonly string[] = [];
89
- let rcLines: string[] = [];
90
- if (fs.existsSync(rcFile)) {
91
- const fileBody = await fs.promises.readFile(rcFile, 'utf8');
92
- originalRcLines = fileBody.split('\n');
93
- rcLines = [...originalRcLines];
94
- }
95
-
96
- const valdiConfHeader = `# Valdi configuration end`;
97
- let insertionIndex = rcLines.indexOf(valdiConfHeader);
98
-
99
- if (insertionIndex < 0) {
100
- rcLines.push(`# Valdi configuration begin`, valdiConfHeader);
101
- insertionIndex = rcLines.length - 1;
102
- }
103
-
104
- for (const envVariable of expectedEnvVariable) {
105
- if (!rcLines.includes(envVariable)) {
106
- rcLines.splice(insertionIndex++, 0, envVariable);
107
- }
108
- }
109
-
110
- if (rcLines.length !== originalRcLines.length) {
111
- const content = rcLines.join('\n');
112
- await fs.promises.writeFile(rcFile, content, 'utf8');
113
- }
114
- })
115
- .setText(
116
- wrapInColor(
117
- `Updating ${rcFile} to include ${envVariables.map(e => e.name).join(', ')}...`,
118
- ANSI_COLORS.YELLOW_COLOR,
119
- ),
120
- )
121
- .show();
122
- }
123
-
124
- onComplete(): void {
125
- let suffix = '';
126
- const rcFile = this.getRcFile();
127
-
128
- if (rcFile) {
129
- suffix += ` Please run ${wrapInColor(`source ${rcFile}`, ANSI_COLORS.YELLOW_COLOR)} or restart your terminal.`;
130
- }
131
- console.log(`${wrapInColor('Dev setup completed!', ANSI_COLORS.GREEN_COLOR)}.${suffix}`);
132
- console.log();
133
- console.log(wrapInColor('📝 Next steps:', ANSI_COLORS.BLUE_COLOR));
134
- console.log(' 1. Restart your terminal or source your shell configuration');
135
- console.log(' 2. Install VSCode/Cursor extensions for the best development experience:');
136
- console.log(` ${wrapInColor('https://github.com/Snapchat/Valdi/blob/main/docs/INSTALL.md#vscodecursor-setup-optional-but-recommended', ANSI_COLORS.BLUE_COLOR)}`);
137
- console.log(' 3. Run `valdi doctor` to verify your setup');
138
- console.log(' 4. Create your first project with `valdi bootstrap`');
139
- }
140
-
141
- async setupGitLfs(): Promise<void> {
142
- await this.runShell('Initializing git-lfs', ['git lfs install']);
143
- }
144
-
145
- async setupShellAutoComplete(): Promise<void> {
146
- const rcFile = this.getRcFile();
147
- if (!rcFile) {
148
- console.log(
149
- wrapInColor(
150
- 'Could not determine shell configuration file, skipping autocomplete setup...',
151
- ANSI_COLORS.YELLOW_COLOR,
152
- ),
153
- );
154
- return;
155
- }
156
-
157
- const shell = process.env['SHELL'] ?? '';
158
- let autoCompleteLines: string[] = [];
159
-
160
- if (shell.endsWith('/zsh')) {
161
- autoCompleteLines = ['autoload -U compinit && compinit', 'autoload -U bashcompinit && bashcompinit'];
162
- } else if (shell.endsWith('/bash')) {
163
- // Bash completion is typically handled by bash-completion package
164
- // We'll check if it's already enabled
165
- autoCompleteLines = ['# Bash completion is enabled'];
166
- }
167
-
168
- if (autoCompleteLines.length === 0 || autoCompleteLines[0] === '# Bash completion is enabled') {
169
- // For bash, we don't need to add anything as it's usually auto-loaded
170
- if (shell.endsWith('/bash')) {
171
- console.log(wrapInColor('Shell autocomplete setup complete (bash)', ANSI_COLORS.GREEN_COLOR));
172
- }
173
- return;
174
- }
175
-
176
- return new LoadingIndicator(async () => {
177
- let originalRcLines: readonly string[] = [];
178
- let rcLines: string[] = [];
179
- if (fs.existsSync(rcFile)) {
180
- const fileBody = await fs.promises.readFile(rcFile, 'utf8');
181
- originalRcLines = fileBody.split('\n');
182
- rcLines = [...originalRcLines];
183
- }
184
-
185
- // Check if autocomplete is already configured
186
- let needsUpdate = false;
187
- for (const line of autoCompleteLines) {
188
- if (!rcLines.includes(line)) {
189
- needsUpdate = true;
190
- break;
191
- }
192
- }
193
-
194
- if (needsUpdate) {
195
- // Find the Valdi configuration section or add to the top
196
- const valdiConfBegin = rcLines.indexOf('# Valdi configuration begin');
197
- const insertIndex = valdiConfBegin >= 0 ? valdiConfBegin : 0;
198
-
199
- // Insert autocomplete lines at the beginning (before Valdi config or at top)
200
- for (let i = autoCompleteLines.length - 1; i >= 0; i--) {
201
- const line = autoCompleteLines[i];
202
- if (line && !rcLines.includes(line)) {
203
- rcLines.splice(insertIndex, 0, line);
204
- }
205
- }
206
-
207
- const content = rcLines.join('\n');
208
- await fs.promises.writeFile(rcFile, content, 'utf8');
209
- }
210
- })
211
- .setText(wrapInColor('Setting up shell autocomplete...', ANSI_COLORS.YELLOW_COLOR))
212
- .show();
213
- }
214
-
215
- async setupAndroidSDK(commandLineToolsURL: string, javaHomeOverride?: string | undefined): Promise<void> {
216
- console.log(wrapInColor('Setting up Android SDK...', ANSI_COLORS.YELLOW_COLOR));
217
- if (!process.env['ANDROID_HOME']) {
218
- await withTempDir(async tempDir => {
219
- const filename = path.join(tempDir, path.basename(commandLineToolsURL));
220
- await this.downloadToPath(commandLineToolsURL, filename);
221
- const targetDir = path.join(ANDROID_HOME_TARGET_DIR, 'cmdline-tools');
222
- await decompressTo(filename, targetDir);
223
-
224
- const target = path.join(targetDir, 'latest');
225
- if (fs.existsSync(target)) {
226
- await fs.promises.rm(target, { recursive: true, force: true });
227
- }
228
- fs.renameSync(path.join(targetDir, 'cmdline-tools'), target);
229
- });
230
- process.env['ANDROID_HOME'] = ANDROID_HOME_TARGET_DIR;
231
-
232
- // Set ANDROID_HOME with platform-specific path
233
- const androidHomeValue = process.platform === 'darwin'
234
- ? '"$HOME/Library/Android/sdk"'
235
- : '"$HOME/Android/Sdk"';
236
- await this.writeEnvVariablesToRcFile([{ name: 'ANDROID_HOME', value: androidHomeValue }]);
237
- }
238
-
239
- const androidHome = process.env['ANDROID_HOME'] ?? '';
240
- const sdkManagerBin = path.join(androidHome, 'cmdline-tools/latest/bin/sdkmanager');
241
-
242
- const sdkManagerEnvVariables: { [key: string]: string } = {};
243
- if (javaHomeOverride) {
244
- sdkManagerEnvVariables['JAVA_HOME'] = javaHomeOverride;
245
- }
246
-
247
- await this.runShell(
248
- 'Installing Android platform',
249
- [`${sdkManagerBin} --install 'platforms;${ANDROID_PLATFORM_VERSION}'`],
250
- sdkManagerEnvVariables,
251
- );
252
- await this.runShell(
253
- 'Installing Android NDK',
254
- [`${sdkManagerBin} --install 'ndk;${ANDROID_NDK_VERSION}'`],
255
- sdkManagerEnvVariables,
256
- );
257
- await this.runShell(
258
- 'Installing Android build-tools',
259
- [`${sdkManagerBin} --install 'build-tools;${ANDROID_BUILD_TOOLS_VERSION}'`],
260
- sdkManagerEnvVariables,
261
- );
262
-
263
- const ndkBundle = path.join(androidHome, 'ndk-bundle');
264
- if (!fs.existsSync(ndkBundle)) {
265
- fs.symlinkSync(`ndk/${ANDROID_NDK_VERSION}`, ndkBundle);
266
- }
267
-
268
- // Set up Android environment variables including platform-tools in PATH
269
- await this.writeEnvVariablesToRcFile([
270
- { name: 'ANDROID_NDK_HOME', value: `"$ANDROID_HOME/ndk-bundle"` },
271
- { name: 'PATH', value: `"$ANDROID_HOME/platform-tools:$PATH"` },
272
- ]);
273
- }
274
-
275
- private getRcFile(): string | undefined {
276
- const homeDir = process.env['HOME'] ?? '';
277
- const shell = process.env['SHELL'] ?? '';
278
- if (shell.endsWith('/zsh')) {
279
- return path.join(homeDir, '.zshrc');
280
- } else if (shell.endsWith('/bash')) {
281
- return path.join(homeDir, '.bashrc');
282
- } else if (shell.endsWith('/ksh')) {
283
- return path.join(homeDir, '.kshrc');
284
- } else if (shell.endsWith('/tcsh')) {
285
- return path.join(homeDir, '.tcshrc');
286
- } else {
287
- return undefined;
288
- }
289
- }
290
- }
@@ -1,261 +0,0 @@
1
- import { execSync } from 'child_process';
2
- import fs from 'fs';
3
- import os from 'os';
4
- import path from 'path';
5
- import { ANSI_COLORS } from '../core/constants';
6
- import { checkCommandExists } from '../utils/cliUtils';
7
- import {
8
- LinuxDistroType,
9
- buildInstallCommand,
10
- detectLinuxDistro,
11
- getCommonPackageMappings,
12
- getGitLfsRepoSetupCommand,
13
- getPackageName,
14
- needsGitLfsRepoSetup,
15
- } from '../utils/linuxDistro';
16
- import { wrapInColor } from '../utils/logUtils';
17
- import { DevSetupHelper, HOME_DIR } from './DevSetupHelper';
18
- import { ANDROID_LINUX_COMMANDLINE_TOOLS } from './versions';
19
-
20
- const BAZELISK_URL = 'https://github.com/bazelbuild/bazelisk/releases/download/v1.26.0/bazelisk-linux-amd64';
21
-
22
- /**
23
- * Maps Node.js architecture names to Debian package architecture names.
24
- * @returns Debian package architecture string (e.g., 'amd64', 'arm64', 'armhf')
25
- */
26
- function getDebianArchitecture(): string {
27
- const nodeArch = os.arch();
28
-
29
- // Map Node.js arch names to Debian package arch names
30
- switch (nodeArch) {
31
- case 'x64': {
32
- return 'amd64';
33
- }
34
- case 'arm64': {
35
- return 'arm64';
36
- }
37
- case 'arm': {
38
- return 'armhf';
39
- }
40
- case 'ia32': {
41
- return 'i386';
42
- }
43
- default: {
44
- // Fallback to amd64 for unknown architectures
45
- console.log(
46
- wrapInColor(
47
- `Warning: Unknown architecture '${nodeArch}', defaulting to amd64`,
48
- ANSI_COLORS.YELLOW_COLOR,
49
- ),
50
- );
51
- return 'amd64';
52
- }
53
- }
54
- }
55
-
56
- export async function linuxSetup(): Promise<void> {
57
- const devSetup = new DevSetupHelper();
58
-
59
- // Detect Linux distribution
60
- const distro = detectLinuxDistro();
61
- console.log(
62
- wrapInColor(
63
- `Detected distribution: ${distro.name} (${distro.packageManager.name})`,
64
- ANSI_COLORS.BLUE_COLOR,
65
- ),
66
- );
67
-
68
- if (distro.type === LinuxDistroType.UNKNOWN) {
69
- console.log();
70
- console.log(wrapInColor('Unable to detect Linux distribution.', ANSI_COLORS.YELLOW_COLOR));
71
- console.log(
72
- wrapInColor(
73
- 'Please manually install the following dependencies and re-run this command:',
74
- ANSI_COLORS.YELLOW_COLOR,
75
- ),
76
- );
77
- console.log(' - git');
78
- console.log(' - git-lfs');
79
- console.log(' - npm (Node.js)');
80
- console.log(' - openjdk-17-jdk (or equivalent Java 17 JDK)');
81
- console.log(' - watchman');
82
- console.log(' - adb (Android Debug Bridge)');
83
- console.log(' - fontconfig development libraries');
84
- console.log(' - zlib development libraries');
85
- console.log();
86
- console.log(
87
- wrapInColor(
88
- 'For manual installation instructions, see: https://github.com/Snapchat/Valdi/blob/main/docs/INSTALL.md',
89
- ANSI_COLORS.BLUE_COLOR,
90
- ),
91
- );
92
- throw new Error('Unable to proceed with automatic setup on unknown Linux distribution');
93
- }
94
-
95
- const packageMappings = getCommonPackageMappings();
96
-
97
- // Setup git-lfs repository if needed (only for Debian/Ubuntu and RHEL-based)
98
- const repoSetupCommand = getGitLfsRepoSetupCommand(distro);
99
- if (repoSetupCommand && needsGitLfsRepoSetup(distro)) {
100
- try {
101
- await devSetup.runShell('Setting up git-lfs repository', [repoSetupCommand]);
102
- } catch {
103
- console.log(
104
- wrapInColor(
105
- `Warning: git-lfs repository setup failed. Will try to install git-lfs from standard repositories.`,
106
- ANSI_COLORS.YELLOW_COLOR,
107
- ),
108
- );
109
- }
110
- }
111
-
112
- // Build list of packages to install
113
- const packagesToInstall: string[] = [];
114
-
115
- // Always needed packages
116
- if (!checkCommandExists('npm')) {
117
- packagesToInstall.push(getPackageName(packageMappings['npm']!, distro));
118
- }
119
- if (!checkCommandExists('java')) {
120
- packagesToInstall.push(getPackageName(packageMappings['openjdk-17']!, distro));
121
- }
122
- if (!checkCommandExists('git-lfs')) {
123
- packagesToInstall.push(getPackageName(packageMappings['git-lfs']!, distro));
124
- }
125
- if (!checkCommandExists('watchman')) {
126
- packagesToInstall.push(getPackageName(packageMappings['watchman']!, distro));
127
- }
128
- if (!checkCommandExists('adb')) {
129
- packagesToInstall.push(getPackageName(packageMappings['adb']!, distro));
130
- }
131
-
132
- // Development libraries
133
- packagesToInstall.push(
134
- getPackageName(packageMappings['fontconfig']!, distro),
135
- getPackageName(packageMappings['zlib']!, distro),
136
- );
137
-
138
- // Install all packages
139
- if (packagesToInstall.length > 0) {
140
- const installCommand = buildInstallCommand(packagesToInstall, distro);
141
-
142
- try {
143
- await devSetup.runShell(`Installing dependencies via ${distro.packageManager.name}`, [installCommand]);
144
- } catch {
145
- console.log();
146
- console.log(wrapInColor('Some packages failed to install.', ANSI_COLORS.YELLOW_COLOR));
147
- console.log(wrapInColor('Common issues:', ANSI_COLORS.YELLOW_COLOR));
148
-
149
- if (distro.type === LinuxDistroType.REDHAT) {
150
- console.log(' - watchman may require EPEL repository on RHEL-based systems');
151
- console.log(' Run: sudo dnf install epel-release (or sudo yum install epel-release)');
152
- } else if (distro.type === LinuxDistroType.ARCH) {
153
- console.log(' - Some packages may be in the AUR');
154
- console.log(' Consider using an AUR helper like yay or paru');
155
- }
156
-
157
- console.log();
158
- console.log(wrapInColor('Continuing with setup...', ANSI_COLORS.YELLOW_COLOR));
159
- }
160
- } else {
161
- console.log(wrapInColor('All required packages are already installed.', ANSI_COLORS.GREEN_COLOR));
162
- }
163
-
164
- await devSetup.setupGitLfs();
165
-
166
- await devSetup.setupShellAutoComplete();
167
-
168
- // Install libtinfo5 for Debian-based systems (needed for some Android tools)
169
- if (distro.type === LinuxDistroType.DEBIAN) {
170
- const libtinfoInstalled = checkCommandExists('dpkg') &&
171
- (() => {
172
- try {
173
- execSync('dpkg -l libtinfo5', { stdio: 'ignore' });
174
- return true;
175
- } catch {
176
- return false;
177
- }
178
- })();
179
-
180
- if (!libtinfoInstalled) {
181
- try {
182
- const arch = getDebianArchitecture();
183
- const version = '6.3-2ubuntu0.1';
184
- const packageName = `libtinfo5_${version}_${arch}.deb`;
185
- const packageUrl = `https://security.ubuntu.com/ubuntu/pool/universe/n/ncurses/${packageName}`;
186
- const tempPath = path.join(HOME_DIR, `.valdi/tmp/${packageName}`);
187
-
188
- // Ensure temp directory exists
189
- const tempDir = path.dirname(tempPath);
190
- if (!fs.existsSync(tempDir)) {
191
- fs.mkdirSync(tempDir, { recursive: true });
192
- }
193
-
194
- console.log(
195
- wrapInColor(
196
- `Downloading libtinfo5 for ${arch} architecture...`,
197
- ANSI_COLORS.BLUE_COLOR,
198
- ),
199
- );
200
-
201
- // Download using DevSetupHelper (more robust than wget)
202
- await devSetup.downloadToPath(packageUrl, tempPath);
203
-
204
- // Install the package
205
- await devSetup.runShell('Installing libtinfo5 (required for Android tools)', [
206
- `sudo apt install -y ${tempPath}`,
207
- ]);
208
-
209
- // Clean up
210
- fs.unlinkSync(tempPath);
211
- } catch (error) {
212
- console.log(
213
- wrapInColor(
214
- 'Warning: libtinfo5 installation failed. Some Android command-line tools may not work.',
215
- ANSI_COLORS.YELLOW_COLOR,
216
- ),
217
- );
218
- console.log(
219
- wrapInColor(
220
- `Details: ${error instanceof Error ? error.message : 'Unknown error'}`,
221
- ANSI_COLORS.YELLOW_COLOR,
222
- ),
223
- );
224
- console.log(wrapInColor('You may need to install it manually if you encounter issues.', ANSI_COLORS.YELLOW_COLOR));
225
- }
226
- }
227
- } else if (distro.type === LinuxDistroType.REDHAT) {
228
- // For RHEL-based systems, try to install ncurses-compat-libs if available
229
- try {
230
- await devSetup.runShell('Installing ncurses compatibility libraries (for Android tools)', [
231
- buildInstallCommand(['ncurses-compat-libs'], distro),
232
- ]);
233
- } catch {
234
- console.log(
235
- wrapInColor(
236
- 'Warning: ncurses-compat-libs installation failed. Some Android command-line tools may not work.',
237
- ANSI_COLORS.YELLOW_COLOR,
238
- ),
239
- );
240
- }
241
- }
242
-
243
- const bazeliskPathSuffix = '.valdi/bin/bazelisk';
244
- const bazeliskTargetPath = path.join(HOME_DIR, bazeliskPathSuffix);
245
-
246
- if (fs.existsSync(bazeliskTargetPath)) {
247
- console.log(wrapInColor('Bazelisk already installed.', ANSI_COLORS.GREEN_COLOR));
248
- } else {
249
- await devSetup.downloadToPath(BAZELISK_URL, bazeliskTargetPath);
250
-
251
- // Add executable permission to the downloaded binary
252
- const stats = fs.statSync(bazeliskTargetPath);
253
- fs.chmodSync(bazeliskTargetPath, stats.mode | 0o111);
254
- }
255
-
256
- await devSetup.writeEnvVariablesToRcFile([{ name: 'PATH', value: `"$HOME/.valdi/bin:$PATH"` }]);
257
-
258
- await devSetup.setupAndroidSDK(ANDROID_LINUX_COMMANDLINE_TOOLS);
259
-
260
- devSetup.onComplete();
261
- }