(ctx: Context)
| 360 | } |
| 361 | |
| 362 | async 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 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…