forced degit template extraction in case of non empty installation directory (#937)
* revert recursive file removal routine * forced degit overwrite without previous file removal * add changeset
This commit is contained in:
parent
001594faa0
commit
cf4c97cf54
2 changed files with 7 additions and 23 deletions
5
.changeset/friendly-hotels-explode.md
Normal file
5
.changeset/friendly-hotels-explode.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'create-astro': minor
|
||||||
|
---
|
||||||
|
|
||||||
|
forced degit template extraction in case of non empty installation directory
|
|
@ -20,26 +20,6 @@ export function mkdirp(dir: string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Delete all files, subdirectories, and symlinks in a given
|
|
||||||
* directory.
|
|
||||||
*
|
|
||||||
* @param dir the directory to empty
|
|
||||||
* @returns a promise for emptying a given directory
|
|
||||||
*/
|
|
||||||
export async function emptyDir(dir: string) {
|
|
||||||
const items = await fs.promises.readdir(dir);
|
|
||||||
return Promise.all(
|
|
||||||
items.map(async (item) => {
|
|
||||||
const itemPath = path.join(dir, item);
|
|
||||||
const stat = await fs.promises.stat(itemPath);
|
|
||||||
return stat.isDirectory()
|
|
||||||
? fs.promises.rm(itemPath, { recursive: true, force: true }) // To remove directories
|
|
||||||
: fs.promises.unlink(itemPath); // Remove files and symlinks
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const { version } = JSON.parse(fs.readFileSync(new URL('../package.json', import.meta.url), 'utf-8'));
|
const { version } = JSON.parse(fs.readFileSync(new URL('../package.json', import.meta.url), 'utf-8'));
|
||||||
|
|
||||||
const POSTPROCESS_FILES = ['package.json', 'astro.config.mjs', 'CHANGELOG.md']; // some files need processing after copying.
|
const POSTPROCESS_FILES = ['package.json', 'astro.config.mjs', 'CHANGELOG.md']; // some files need processing after copying.
|
||||||
|
@ -57,14 +37,13 @@ export async function main() {
|
||||||
const response = await prompts({
|
const response = await prompts({
|
||||||
type: 'confirm',
|
type: 'confirm',
|
||||||
name: 'forceOverwrite',
|
name: 'forceOverwrite',
|
||||||
message: `Directory not empty. Delete ${cwd} to continue?`,
|
message: 'Directory not empty. Continue [force overwrite]?',
|
||||||
initial: false,
|
initial: false,
|
||||||
});
|
});
|
||||||
if (!response.forceOverwrite) {
|
if (!response.forceOverwrite) {
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
mkdirp(cwd);
|
||||||
await emptyDir(cwd);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
mkdirp(cwd);
|
mkdirp(cwd);
|
||||||
|
|
Loading…
Reference in a new issue