MCPcopy Create free account
hub / github.com/Snapchat/Valdi / valdiBootstrap

Function valdiBootstrap

npm_modules/cli/src/commands/bootstrap.ts:270–359  ·  view source on GitHub ↗
(argv: ArgumentsResolver<CommandParameters>)

Source from the content-addressed store, hash-verified

268}
269
270async function valdiBootstrap(argv: ArgumentsResolver<CommandParameters>) {
271 // Set up a Valdi project in the current directory. Will go through a flow to ask some questions to the user like the name of the application. This will create the following files:
272 // user_config.yaml: User configuration file
273 // application_names.bzl: Bazel macro file with application names
274 const curDir = process.cwd();
275
276 console.log(`\nCurrent directory: ${wrapInColor(curDir, ANSI_COLORS.GREEN_COLOR)}`);
277
278 if (isAlreadyInitialized()) {
279 // Check for existing project files
280 // If the directory already contains a project, prompt the user to re-run command with explicit --with-cleanup flag
281 if (argv.getArgument('withCleanup')) {
282 console.log(wrapInColor('Deleting all files in current directory...', ANSI_COLORS.YELLOW_COLOR));
283 deleteAll(curDir);
284 } else {
285 throw new CliError(
286 `Detected existing project files. Please remove them before re-running 'valdi bootstrap'.\nYou can run '${wrapInColor('valdi bootstrap --with-cleanup', ANSI_COLORS.YELLOW_COLOR, ANSI_COLORS.RED_COLOR)}' to remove ALL FILES in the current directory.`,
287 );
288 }
289 } else if (!isDirectoryEmpty(curDir)) {
290 // Folder contains non project files
291 // Prompt for manual clean up to prevent accidental deletion of important files
292 throw new CliError(
293 "Current directory is not empty. Please run 'valdi bootstrap' in an empty directory or manually clean up existing files.",
294 );
295 }
296
297 if (!(await getShouldBootstrap(argv))) {
298 throw new CliError('Bootstrap process aborted.');
299 }
300
301 const applicationType = await getApplicationType(argv);
302
303 // Prompt user for input
304 // - Application Name
305 let projectName = await getProjectName(argv);
306
307 // Validate project name if provided via command line argument
308 if (argv.getArgument('projectName')) {
309 const validationError = validateProjectName(projectName);
310 if (validationError) {
311 throw new CliError(validationError);
312 }
313 projectName = sanitizeProjectName(projectName);
314 }
315
316 if (!projectName) {
317 throw new CliError('Project name cannot be empty.');
318 }
319
320 const valdiReleaseTag = await resolveValdiReleaseTag(argv, VALDI_GIT_URL, DEFAULT_VALDI_RELEASE_TAG);
321 const valdiWidgetsReleaseTag = await resolveValdiReleaseTag(
322 argv,
323 VALDI_WIDGETS_GIT_URL,
324 DEFAULT_VALDI_WIDGETS_RELEASE_TAG,
325 'valdiWidgetsVersion',
326 );
327

Callers

nothing calls this directly

Calls 15

getVersionMethod · 0.95
wrapInColorFunction · 0.90
deleteAllFunction · 0.90
isDirectoryEmptyFunction · 0.90
validateProjectNameFunction · 0.90
sanitizeProjectNameFunction · 0.90
runProjectSyncFunction · 0.90
getAllProjectSyncTargetsFunction · 0.90
isAlreadyInitializedFunction · 0.85
getShouldBootstrapFunction · 0.85
getApplicationTypeFunction · 0.85
getProjectNameFunction · 0.85

Tested by

no test coverage detected