MCPcopy Index your code
hub / github.com/remix-run/react-router / copyTempDirToAppDirStep

Function copyTempDirToAppDirStep

packages/create-react-router/index.ts:362–441  ·  view source on GitHub ↗
(ctx: Context)

Source from the content-addressed store, hash-verified

360}
361
362async function copyTempDirToAppDirStep(ctx: Context) {
363 await ensureDirectory(ctx.cwd);
364
365 let files1 = await getDirectoryFilesRecursive(ctx.tempDir);
366 let files2 = await getDirectoryFilesRecursive(ctx.cwd);
367 let collisions = files1
368 .filter((f) => files2.includes(f))
369 .sort((a, b) => a.localeCompare(b));
370
371 if (collisions.length > 0) {
372 let getFileList = (prefix: string) => {
373 let moreFiles = collisions.length - 5;
374 let lines = ["", ...collisions.slice(0, 5)];
375 if (moreFiles > 0) {
376 lines.push(`and ${moreFiles} more...`);
377 }
378 return lines.join(`\n${prefix}`);
379 };
380
381 if (ctx.overwrite) {
382 info(
383 "Overwrite:",
384 `overwriting files due to \`--overwrite\`:${getFileList(" ")}`,
385 );
386 } else if (!ctx.interactive) {
387 error(
388 "Oh no!",
389 `Destination directory contains files that would be overwritten\n` +
390 ` and no \`--overwrite\` flag was included in a non-interactive\n` +
391 ` environment. The following files would be overwritten:` +
392 getFileList(" "),
393 );
394 throw new Error(
395 "File collisions detected in a non-interactive environment",
396 );
397 } else {
398 if (ctx.debug) {
399 debug(`Colliding files:${getFileList(" ")}`);
400 }
401
402 let { overwrite } = await ctx.prompt({
403 name: "overwrite",
404 type: "confirm",
405 label: title("overwrite"),
406 message:
407 `Your project directory contains files that will be overwritten by\n` +
408 ` this template (you can force with \`--overwrite\`)\n\n` +
409 ` Files that would be overwritten:` +
410 `${getFileList(" ")}\n\n` +
411 ` Do you wish to continue?\n` +
412 ` `,
413 initial: false,
414 });
415 if (!overwrite) {
416 throw new Error("Exiting to avoid overwriting files");
417 }
418 }
419 }

Callers

nothing calls this directly

Calls 8

ensureDirectoryFunction · 0.90
infoFunction · 0.90
errorFunction · 0.90
debugFunction · 0.90
getFileListFunction · 0.85
titleFunction · 0.85
updatePackageJSONFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…