Skip to content

Commit

Permalink
fix(commands): do not ask to remove existing directory when non-inter…
Browse files Browse the repository at this point in the history
…active
  • Loading branch information
sammoore authored and danstepanov committed Dec 20, 2023
1 parent 88fd2be commit 0728ea9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/silver-ears-lie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'create-expo-stack': patch
---

fix: do not ask to remove existing directory when non-interactive
9 changes: 7 additions & 2 deletions cli/src/commands/create-expo-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,13 @@ const command: GluegunCommand = {
cliResults.projectName = first;
}

// Validate the project name
await validateProjectName(exists, removeAsync, prompt, cliResults.projectName);
// Validate the project name; we may or may not be interactive, so conditionally pass in prompt
await validateProjectName(
exists,
removeAsync,
!(useDefault || optionsPassedIn || skipCLI || useBlankTypescript) ? prompt : null,
cliResults.projectName
);

// By this point, all cliResults should be set
info('');
Expand Down
16 changes: 10 additions & 6 deletions cli/src/utilities/validateProjectName.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
import { ExistsResult } from 'fs-jetpack/types';
import { GluegunPrompt } from 'gluegun';

export async function validateProjectName(exists: (path: string) => ExistsResult, removeAsync: (path?: string) => Promise<void>, prompt: GluegunPrompt, projectName: string): Promise<void> {
if (exists(projectName)) {
export async function validateProjectName(exists: (path: string) => ExistsResult, removeAsync: (path?: string) => Promise<void>, prompt: GluegunPrompt | null, projectName: string): Promise<void> {
if (!exists(projectName)) {
return;
}

if (prompt != null) {
const confirmDelete = await prompt.ask([
{
type: 'confirm',
name: 'delete',
message: `A folder with the name '${projectName}' already exists. Do you want to delete it?`
},
]);

if (confirmDelete.delete) {
await removeAsync(projectName);
console.log(`Deleted existing directory: ${projectName}`);
} else {
throw new Error(`Exiting, a project with the name '${projectName}' already exists.`);
return void console.log(`Deleted existing directory: ${projectName}`);
}
}

throw new Error(`A project with the name '${projectName}' already exists.`);
}

1 comment on commit 0728ea9

@vercel
Copy link

@vercel vercel bot commented on 0728ea9 Dec 20, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.