fix(init): Don't overwrite existing files when initializing a new project (#556)
Co-authored-by: Aaron <aaronklinker1@gmail.com>
This commit is contained in:
@@ -59,6 +59,16 @@ export async function initialize(options: {
|
||||
input.template ??= defaultTemplate;
|
||||
input.packageManager ??= options.packageManager;
|
||||
|
||||
const isExists = await fs.pathExists(input.directory);
|
||||
if (isExists) {
|
||||
const isEmpty = (await fs.readdir(input.directory)).length === 0;
|
||||
if (!isEmpty) {
|
||||
consola.error(
|
||||
`The directory ${path.resolve(input.directory)} is not empty. Aborted.`,
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
await cloneProject(input);
|
||||
|
||||
const cdPath = path.relative(process.cwd(), path.resolve(input.directory));
|
||||
@@ -145,6 +155,9 @@ async function cloneProject({
|
||||
.move(
|
||||
path.join(directory, '_gitignore'),
|
||||
path.join(directory, '.gitignore'),
|
||||
{
|
||||
overwrite: true,
|
||||
},
|
||||
)
|
||||
.catch((err) =>
|
||||
consola.warn('Failed to move _gitignore to .gitignore:', err),
|
||||
|
||||
Reference in New Issue
Block a user