Skip to content

Commit

Permalink
fix: does the target path exist without judgment
Browse files Browse the repository at this point in the history
  • Loading branch information
hacxy committed Dec 16, 2024
1 parent 7969633 commit e04121b
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cpSync, renameSync, rmSync } from 'node:fs';
import { cpSync, existsSync, renameSync, rmSync } from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { confirm, input } from '@inquirer/prompts';
Expand Down Expand Up @@ -31,17 +31,19 @@ export async function bootstrap() {
const targetPath = path.resolve(process.cwd(), projectName);

// check dir is empty
const isRemove = await confirm({
message: `Target directory ${targetPath} is not empty. Remove existing files and continue?`,
default: true
}).catch(() => {
errorLog('Cancelled!');
});

if (isRemove) {
rmSync(targetPath, { force: true, recursive: true });
}
if (existsSync(targetPath)) {
const isRemove = await confirm({
message: `Target directory ${targetPath} is not empty. Remove existing files and continue?`,
default: true
}).catch(() => {
errorLog('Cancelled!');
process.exit(0);
});

if (isRemove) {
rmSync(targetPath, { force: true, recursive: true });
}
}
cpSync(finalTempPath, targetPath, { recursive: true });
renameSync(path.resolve(targetPath, '_gitignore'), path.resolve(targetPath, '.gitignore'));
renamePackageName(projectName, targetPath);
Expand Down

0 comments on commit e04121b

Please sign in to comment.