@snap/valdi 1.0.1 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.bootstrap/modules/cpp_bridge_module/BUILD.bazel.template +3 -3
- package/.bootstrap/modules/cpp_bridge_module/cpp/CalculatorModuleFactory.cpp.template +18 -19
- package/.bootstrap/modules/cpp_bridge_module/src/Calculator.d.ts +3 -0
- package/.github/README.md +164 -0
- package/.metadata/.cursorrules.template +60 -0
- package/.metadata/.editorconfig.template +37 -0
- package/{.bootstrap/apps/ui_application → .metadata}/AGENTS.md.template +84 -4
- package/LINUX_COMPATIBILITY.md +248 -0
- package/README.md +110 -23
- package/dist/commands/bootstrap.js +80 -19
- package/dist/commands/doctor.js +361 -54
- package/dist/commands/newModule.js +15 -12
- package/dist/core/constants.js +3 -0
- package/dist/index.js +5 -0
- package/dist/setup/DevSetupHelper.js +81 -6
- package/dist/setup/linuxSetup.js +149 -11
- package/dist/setup/macOSSetup.js +96 -8
- package/dist/utils/githubUtils.js +74 -2
- package/dist/utils/linuxDistro.js +255 -0
- package/dist/utils/linuxDistro.spec.js +170 -0
- package/dist/utils/stringUtils.js +60 -0
- package/dist/utils/stringUtils.spec.js +63 -0
- package/package.json +11 -3
- package/scripts/sync-agents-md.sh +44 -0
- package/scripts/update-agents-templates.ts +170 -0
- package/src/commands/bootstrap.ts +118 -25
- package/src/commands/doctor.ts +469 -59
- package/src/commands/newModule.ts +18 -19
- package/src/core/constants.ts +3 -0
- package/src/index.ts +5 -0
- package/src/setup/DevSetupHelper.ts +108 -6
- package/src/setup/linuxSetup.ts +235 -12
- package/src/setup/macOSSetup.ts +122 -8
- package/src/utils/githubUtils.ts +98 -2
- package/src/utils/linuxDistro.spec.ts +219 -0
- package/src/utils/linuxDistro.ts +326 -0
- package/src/utils/stringUtils.spec.ts +77 -1
- package/src/utils/stringUtils.ts +88 -0
- package/test/ValdiSmokeTest.ts +5 -4
- package/test/helpers/TypeScriptClient.ts +2 -2
- package/.bootstrap/apps/cli_application/AGENTS.md.template +0 -215
|
@@ -13,7 +13,7 @@ import { makeCommandHandler } from '../utils/errorUtils';
|
|
|
13
13
|
import type { Replacements } from '../utils/fileUtils';
|
|
14
14
|
import { fileExists } from '../utils/fileUtils';
|
|
15
15
|
import { wrapInColor } from '../utils/logUtils';
|
|
16
|
-
import { toPascalCase, toSnakeCase } from '../utils/stringUtils';
|
|
16
|
+
import { toPascalCase, toSnakeCase, sanitizeProjectName, validateProjectName } from '../utils/stringUtils';
|
|
17
17
|
|
|
18
18
|
const referenceString = `
|
|
19
19
|
******************************************
|
|
@@ -164,25 +164,15 @@ async function getModuleName(argv: ArgumentsResolver<CommandParameters>): Promis
|
|
|
164
164
|
name: 'moduleName',
|
|
165
165
|
message: 'Please provide a name for this module:',
|
|
166
166
|
validate: (input: string) => {
|
|
167
|
-
const
|
|
168
|
-
if (
|
|
169
|
-
|
|
167
|
+
const validationError = validateProjectName(input);
|
|
168
|
+
if (validationError) {
|
|
169
|
+
return validationError;
|
|
170
170
|
}
|
|
171
171
|
|
|
172
|
-
|
|
173
|
-
const
|
|
174
|
-
const isSnakeCase = snakeCaseName === input;
|
|
175
|
-
if (!isSnakeCase) {
|
|
176
|
-
throw new CliError(
|
|
177
|
-
`Valid names may contain only A-Z, a-z, 0-9, '-', '_', '.', and must start with a letter (ie: '${snakeCaseName}').`,
|
|
178
|
-
);
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
const destPath = path.join(process.cwd(), input);
|
|
172
|
+
const sanitized = sanitizeProjectName(input);
|
|
173
|
+
const destPath = path.join(process.cwd(), sanitized);
|
|
182
174
|
if (fileExists(destPath)) {
|
|
183
|
-
|
|
184
|
-
`Path ${destPath} already exists. Choose a different name or delete the folder and try again.`,
|
|
185
|
-
);
|
|
175
|
+
return `Path ${destPath} already exists. Choose a different name or delete the folder and try again.`;
|
|
186
176
|
}
|
|
187
177
|
|
|
188
178
|
return true;
|
|
@@ -192,7 +182,7 @@ async function getModuleName(argv: ArgumentsResolver<CommandParameters>): Promis
|
|
|
192
182
|
{},
|
|
193
183
|
);
|
|
194
184
|
|
|
195
|
-
return result.moduleName ?? '';
|
|
185
|
+
return sanitizeProjectName(result.moduleName ?? '');
|
|
196
186
|
});
|
|
197
187
|
}
|
|
198
188
|
|
|
@@ -229,7 +219,16 @@ async function valdiNewModule(argv: ArgumentsResolver<CommandParameters>) {
|
|
|
229
219
|
const checks: Checks = skipChecks ? {} : await promptChecks();
|
|
230
220
|
const valdiModulePath = checks.valdiModulePath ?? path.join(await getBazelWorkspaceRoot(), 'modules');
|
|
231
221
|
|
|
232
|
-
|
|
222
|
+
let moduleName = await getModuleName(argv);
|
|
223
|
+
|
|
224
|
+
// Validate module name if provided via command line argument
|
|
225
|
+
if (argv.getArgument('moduleName')) {
|
|
226
|
+
const validationError = validateProjectName(moduleName);
|
|
227
|
+
if (validationError) {
|
|
228
|
+
throw new CliError(validationError);
|
|
229
|
+
}
|
|
230
|
+
moduleName = sanitizeProjectName(moduleName);
|
|
231
|
+
}
|
|
233
232
|
|
|
234
233
|
const destPath = path.join(valdiModulePath, moduleName);
|
|
235
234
|
const didConfirm = skipChecks || (await finalConfirmation(destPath, argv));
|
package/src/core/constants.ts
CHANGED
|
@@ -41,6 +41,9 @@ export enum TEMPLATE_BASE_PATHS {
|
|
|
41
41
|
README = 'README.md.template',
|
|
42
42
|
WATCHMAN_CONFIG = '.watchmanconfig.template',
|
|
43
43
|
GIT_IGNORE = '.gitignore.template',
|
|
44
|
+
EDITOR_CONFIG = '.editorconfig.template',
|
|
45
|
+
CURSOR_RULES = '.cursorrules.template',
|
|
46
|
+
AGENTS = 'AGENTS.md.template',
|
|
44
47
|
}
|
|
45
48
|
|
|
46
49
|
export const VALID_PLATFORMS: string[] = [PLATFORM.ANDROID, PLATFORM.IOS, PLATFORM.MACOS, PLATFORM.CLI];
|
package/src/index.ts
CHANGED
|
@@ -13,6 +13,11 @@ function main() {
|
|
|
13
13
|
.demandCommand(1, 'Need at least one command to execute')
|
|
14
14
|
.recommendCommands()
|
|
15
15
|
.strict()
|
|
16
|
+
.option('debug', {
|
|
17
|
+
describe: 'Run with debug logging',
|
|
18
|
+
type: 'boolean',
|
|
19
|
+
default: false,
|
|
20
|
+
})
|
|
16
21
|
.version('version', 'Show version number', version)
|
|
17
22
|
.scriptName('valdi')
|
|
18
23
|
.wrap(yargs.terminalWidth())
|
|
@@ -9,8 +9,19 @@ import { decompressTo } from '../utils/zipUtils';
|
|
|
9
9
|
import { ANDROID_BUILD_TOOLS_VERSION, ANDROID_NDK_VERSION, ANDROID_PLATFORM_VERSION } from './versions';
|
|
10
10
|
|
|
11
11
|
export const HOME_DIR = process.env['HOME'] ?? '';
|
|
12
|
-
|
|
13
|
-
|
|
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();
|
|
14
25
|
|
|
15
26
|
export interface EnvVariable {
|
|
16
27
|
name: string;
|
|
@@ -118,6 +129,87 @@ export class DevSetupHelper {
|
|
|
118
129
|
suffix += ` Please run ${wrapInColor(`source ${rcFile}`, ANSI_COLORS.YELLOW_COLOR)} or restart your terminal.`;
|
|
119
130
|
}
|
|
120
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();
|
|
121
213
|
}
|
|
122
214
|
|
|
123
215
|
async setupAndroidSDK(commandLineToolsURL: string, javaHomeOverride?: string | undefined): Promise<void> {
|
|
@@ -126,7 +218,7 @@ export class DevSetupHelper {
|
|
|
126
218
|
await withTempDir(async tempDir => {
|
|
127
219
|
const filename = path.join(tempDir, path.basename(commandLineToolsURL));
|
|
128
220
|
await this.downloadToPath(commandLineToolsURL, filename);
|
|
129
|
-
const targetDir = path.join(
|
|
221
|
+
const targetDir = path.join(ANDROID_HOME_TARGET_DIR, 'cmdline-tools');
|
|
130
222
|
await decompressTo(filename, targetDir);
|
|
131
223
|
|
|
132
224
|
const target = path.join(targetDir, 'latest');
|
|
@@ -135,8 +227,13 @@ export class DevSetupHelper {
|
|
|
135
227
|
}
|
|
136
228
|
fs.renameSync(path.join(targetDir, 'cmdline-tools'), target);
|
|
137
229
|
});
|
|
138
|
-
process.env['ANDROID_HOME'] =
|
|
139
|
-
|
|
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 }]);
|
|
140
237
|
}
|
|
141
238
|
|
|
142
239
|
const androidHome = process.env['ANDROID_HOME'] ?? '';
|
|
@@ -167,7 +264,12 @@ export class DevSetupHelper {
|
|
|
167
264
|
if (!fs.existsSync(ndkBundle)) {
|
|
168
265
|
fs.symlinkSync(`ndk/${ANDROID_NDK_VERSION}`, ndkBundle);
|
|
169
266
|
}
|
|
170
|
-
|
|
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
|
+
]);
|
|
171
273
|
}
|
|
172
274
|
|
|
173
275
|
private getRcFile(): string | undefined {
|
package/src/setup/linuxSetup.ts
CHANGED
|
@@ -1,34 +1,257 @@
|
|
|
1
|
+
import { execSync } from 'child_process';
|
|
1
2
|
import fs from 'fs';
|
|
3
|
+
import os from 'os';
|
|
2
4
|
import path from 'path';
|
|
5
|
+
import { ANSI_COLORS } from '../core/constants';
|
|
3
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';
|
|
4
17
|
import { DevSetupHelper, HOME_DIR } from './DevSetupHelper';
|
|
5
18
|
import { ANDROID_LINUX_COMMANDLINE_TOOLS } from './versions';
|
|
6
19
|
|
|
7
20
|
const BAZELISK_URL = 'https://github.com/bazelbuild/bazelisk/releases/download/v1.26.0/bazelisk-linux-amd64';
|
|
8
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
|
+
|
|
9
56
|
export async function linuxSetup(): Promise<void> {
|
|
10
57
|
const devSetup = new DevSetupHelper();
|
|
11
58
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
+
);
|
|
15
67
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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();
|
|
20
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
|
+
}
|
|
21
119
|
if (!checkCommandExists('java')) {
|
|
22
|
-
|
|
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
|
+
}
|
|
23
241
|
}
|
|
24
242
|
|
|
25
243
|
const bazeliskPathSuffix = '.valdi/bin/bazelisk';
|
|
26
244
|
const bazeliskTargetPath = path.join(HOME_DIR, bazeliskPathSuffix);
|
|
27
|
-
|
|
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);
|
|
28
250
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
251
|
+
// Add executable permission to the downloaded binary
|
|
252
|
+
const stats = fs.statSync(bazeliskTargetPath);
|
|
253
|
+
fs.chmodSync(bazeliskTargetPath, stats.mode | 0o111);
|
|
254
|
+
}
|
|
32
255
|
|
|
33
256
|
await devSetup.writeEnvVariablesToRcFile([{ name: 'PATH', value: `"$HOME/.valdi/bin:$PATH"` }]);
|
|
34
257
|
|
package/src/setup/macOSSetup.ts
CHANGED
|
@@ -7,9 +7,57 @@ import { ANDROID_MACOS_COMMANDLINE_TOOLS } from './versions';
|
|
|
7
7
|
export async function macOSSetup(): Promise<void> {
|
|
8
8
|
const devSetup = new DevSetupHelper();
|
|
9
9
|
|
|
10
|
+
// Check if xcode-select command exists
|
|
10
11
|
if (!checkCommandExists('xcode-select')) {
|
|
11
12
|
throw new CliError(
|
|
12
|
-
'Xcode
|
|
13
|
+
'Xcode command line tools are not installed.\n\n' +
|
|
14
|
+
'Please install Xcode from the App Store, then run:\n' +
|
|
15
|
+
' sudo xcode-select -s /Applications/Xcode.app\n\n' +
|
|
16
|
+
'After installation, run valdi dev_setup again.',
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// Verify Xcode is properly configured
|
|
21
|
+
try {
|
|
22
|
+
const xcodePathResult = await runCliCommand('xcode-select -p');
|
|
23
|
+
const xcodePath = xcodePathResult.stdout.trim();
|
|
24
|
+
|
|
25
|
+
if (!xcodePath || !fs.existsSync(xcodePath)) {
|
|
26
|
+
throw new CliError(
|
|
27
|
+
'Xcode command line tools path is not configured correctly.\n\n' +
|
|
28
|
+
'Please run:\n' +
|
|
29
|
+
' sudo xcode-select -s /Applications/Xcode.app\n\n' +
|
|
30
|
+
'Or if you have Xcode with a different name (e.g., beta versions):\n' +
|
|
31
|
+
' sudo xcode-select -s /Applications/YourXcode.app\n\n' +
|
|
32
|
+
'After configuration, run valdi dev_setup again.',
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Extract Xcode.app path from the Developer path
|
|
37
|
+
const xcodeAppPath = xcodePath.replace(/\/Contents\/Developer\/?$/, '');
|
|
38
|
+
|
|
39
|
+
// Verify the Xcode app exists
|
|
40
|
+
if (!fs.existsSync(xcodeAppPath) || !xcodeAppPath.includes('Xcode')) {
|
|
41
|
+
throw new CliError(
|
|
42
|
+
'Xcode installation not found.\n\n' +
|
|
43
|
+
`xcode-select points to ${xcodePath}\n` +
|
|
44
|
+
`but Xcode app not found at ${xcodeAppPath}\n\n` +
|
|
45
|
+
'Please install Xcode from the App Store:\n' +
|
|
46
|
+
' https://apps.apple.com/us/app/xcode/id497799835\n\n' +
|
|
47
|
+
'Then configure it with:\n' +
|
|
48
|
+
' sudo xcode-select -s /Applications/Xcode.app\n\n' +
|
|
49
|
+
'After installation, run valdi dev_setup again.',
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
} catch (error) {
|
|
53
|
+
if (error instanceof CliError) {
|
|
54
|
+
throw error;
|
|
55
|
+
}
|
|
56
|
+
throw new CliError(
|
|
57
|
+
'Failed to verify Xcode installation.\n\n' +
|
|
58
|
+
'Please ensure Xcode is installed from the App Store and properly configured:\n' +
|
|
59
|
+
' sudo xcode-select -s /Applications/Xcode.app\n\n' +
|
|
60
|
+
'After setup, run valdi dev_setup again.',
|
|
13
61
|
);
|
|
14
62
|
}
|
|
15
63
|
|
|
@@ -17,21 +65,87 @@ export async function macOSSetup(): Promise<void> {
|
|
|
17
65
|
await devSetup.runShell('Homebrew not found. Installing', [
|
|
18
66
|
'/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"',
|
|
19
67
|
]);
|
|
68
|
+
|
|
69
|
+
// Configure Homebrew PATH in .zprofile
|
|
70
|
+
const homeDir = process.env['HOME'] ?? '';
|
|
71
|
+
const zprofilePath = `${homeDir}/.zprofile`;
|
|
72
|
+
const brewShellenvLine = 'eval "$(/opt/homebrew/bin/brew shellenv)"';
|
|
73
|
+
|
|
74
|
+
try {
|
|
75
|
+
let zprofileContent = '';
|
|
76
|
+
if (fs.existsSync(zprofilePath)) {
|
|
77
|
+
zprofileContent = fs.readFileSync(zprofilePath, 'utf8');
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (!zprofileContent.includes(brewShellenvLine)) {
|
|
81
|
+
const newContent = zprofileContent + '\n' + brewShellenvLine + '\n';
|
|
82
|
+
fs.writeFileSync(zprofilePath, newContent, 'utf8');
|
|
83
|
+
console.log('Added Homebrew to PATH in .zprofile');
|
|
84
|
+
}
|
|
85
|
+
} catch {
|
|
86
|
+
console.log('Note: Could not automatically configure Homebrew PATH in .zprofile');
|
|
87
|
+
}
|
|
20
88
|
}
|
|
21
89
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
]
|
|
90
|
+
// Install dependencies, skipping already installed ones
|
|
91
|
+
const packages = ['npm', 'bazelisk', 'openjdk@17', 'temurin', 'git-lfs', 'watchman', 'ios-webkit-debug-proxy'];
|
|
92
|
+
const packagesToInstall: string[] = [];
|
|
93
|
+
|
|
94
|
+
for (const pkg of packages) {
|
|
95
|
+
try {
|
|
96
|
+
// Check if package is already installed (from any tap)
|
|
97
|
+
const result = await runCliCommand(`brew list ${pkg}`);
|
|
98
|
+
if (result.returnCode !== 0) {
|
|
99
|
+
packagesToInstall.push(pkg);
|
|
100
|
+
}
|
|
101
|
+
} catch {
|
|
102
|
+
// Package not installed, add to list
|
|
103
|
+
packagesToInstall.push(pkg);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (packagesToInstall.length > 0) {
|
|
108
|
+
await devSetup.runShell(
|
|
109
|
+
`Installing dependencies from Homebrew (${packagesToInstall.length}/${packages.length})`,
|
|
110
|
+
[`brew install ${packagesToInstall.join(' ')}`]
|
|
111
|
+
);
|
|
112
|
+
} else {
|
|
113
|
+
console.log('All Homebrew dependencies are already installed');
|
|
114
|
+
}
|
|
25
115
|
|
|
26
|
-
|
|
116
|
+
await devSetup.setupGitLfs();
|
|
117
|
+
|
|
118
|
+
await devSetup.setupShellAutoComplete();
|
|
119
|
+
|
|
120
|
+
// Check if JDK symlink exists and points to the correct location
|
|
121
|
+
const jdkSymlinkPath = '/Library/Java/JavaVirtualMachines/openjdk-17.jdk';
|
|
122
|
+
const jdkSourcePath = '/opt/homebrew/opt/openjdk@17/libexec/openjdk.jdk';
|
|
123
|
+
|
|
124
|
+
let needsJdkSymlink = false;
|
|
125
|
+
if (fs.existsSync(jdkSymlinkPath)) {
|
|
126
|
+
try {
|
|
127
|
+
const linkTarget = fs.readlinkSync(jdkSymlinkPath);
|
|
128
|
+
if (linkTarget !== jdkSourcePath) {
|
|
129
|
+
needsJdkSymlink = true;
|
|
130
|
+
}
|
|
131
|
+
} catch {
|
|
132
|
+
// Not a symlink or can't read it, needs to be set up
|
|
133
|
+
needsJdkSymlink = true;
|
|
134
|
+
}
|
|
135
|
+
} else {
|
|
136
|
+
needsJdkSymlink = true;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (needsJdkSymlink) {
|
|
140
|
+
console.log('\nSetting up JDK symlink (requires admin password)...');
|
|
27
141
|
await devSetup.runShell('Setting up JDK', [
|
|
28
|
-
'sudo ln -sfn /opt/homebrew/opt/openjdk@
|
|
142
|
+
'sudo ln -sfn /opt/homebrew/opt/openjdk@17/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-17.jdk',
|
|
29
143
|
]);
|
|
30
144
|
}
|
|
31
145
|
|
|
32
146
|
await devSetup.writeEnvVariablesToRcFile([
|
|
33
|
-
{ name: 'PATH', value: '"/opt/homebrew/opt/openjdk@
|
|
34
|
-
{ name: 'JAVA_HOME', value: '`/usr/libexec/java_home -v
|
|
147
|
+
{ name: 'PATH', value: '"/opt/homebrew/opt/openjdk@17/bin:$PATH"' },
|
|
148
|
+
{ name: 'JAVA_HOME', value: '`/usr/libexec/java_home -v 17`' },
|
|
35
149
|
]);
|
|
36
150
|
|
|
37
151
|
const javaHome = await runCliCommand('/usr/libexec/java_home');
|