Skip to content

Commit

Permalink
feat: add continue and overwrite option on existing dir (#375)
Browse files Browse the repository at this point in the history
* feat: add abort/clear/overwrite options on existing dir

* chore: add changeset

* feat: add 'recommended' to 'Abort installation'

* feat: add confirmation before overwriting existing dir
  • Loading branch information
c-ehrlich committed Aug 30, 2022
1 parent 9fd0b53 commit 296c79b
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 12 deletions.
7 changes: 7 additions & 0 deletions .changeset/seven-pillows-exercise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"create-t3-app": minor
---

feat: add option to continue and overwrite on existing directory

for reference see: https://github.com/t3-oss/create-t3-app/issues/230
62 changes: 50 additions & 12 deletions cli/src/helpers/scaffoldProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,58 @@ export const scaffoldProject = async ({
);
} else {
spinner.stopAndPersist();
const { overwriteDir } = await inquirer.prompt<{ overwriteDir: boolean }>(
{
name: "overwriteDir",
type: "confirm",
message: `${chalk.redBright.bold("Warning:")} ${chalk.cyan.bold(
projectName,
)} already exists and isn't empty. Do you want to overwrite it?`,
default: false,
},
);
if (!overwriteDir) {
const { overwriteDir } = await inquirer.prompt<{
overwriteDir: "abort" | "clear" | "overwrite";
}>({
name: "overwriteDir",
type: "list",
message: `${chalk.redBright.bold("Warning:")} ${chalk.cyan.bold(
projectName,
)} already exists and isn't empty. How would you like to proceed?`,
choices: [
{
name: "Abort installation (recommended)",
value: "abort",
short: "Abort",
},
{
name: "Clear the directory and continue installation",
value: "clear",
short: "Clear",
},
{
name: "Continue installation and overwrite conflicting files",
value: "overwrite",
short: "Overwrite",
},
],
default: "abort",
});
if (overwriteDir === "abort") {
spinner.fail("Aborting installation...");
process.exit(0);
} else {
}

const overwriteAction =
overwriteDir === "clear"
? "clear the directory"
: "overwrite conflicting files";

const { confirmOverwriteDir } = await inquirer.prompt<{
confirmOverwriteDir: boolean;
}>({
name: "confirmOverwriteDir",
type: "confirm",
message: `Are you sure you want to ${overwriteAction}?`,
default: false,
});

if (!confirmOverwriteDir) {
spinner.fail("Aborting installation...");
process.exit(0);
}

if (overwriteDir === "clear") {
spinner.info(
`Emptying ${chalk.cyan.bold(projectName)} and creating t3 app..\n`,
);
Expand Down

1 comment on commit 296c79b

@vercel
Copy link

@vercel vercel bot commented on 296c79b Aug 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

create-t3-app – ./

create-t3-app-nu.vercel.app
create-t3-app-git-main-t3-oss.vercel.app
create-t3-app-t3-oss.vercel.app

Please sign in to comment.