Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

Commit e45bdbb

Browse files
feat(create-nuxt-app): add --overwrite-dir flag (#799)
1 parent b5b716c commit e45bdbb

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ Show debug logs
123123

124124
Alias: `-v`. Show version number and exit.
125125

126+
### `--overwrite-dir`
127+
128+
Overwrite the target directory.
129+
126130
## Credits
127131

128132
- [egoist](https://github.com/egoist)

packages/create-nuxt-app/lib/cli.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,23 @@ cli
3030
.option('-i, --info', 'Print out debugging information relating to the local environment')
3131
.option('--answers <json>', 'Skip all the prompts and use the provided answers')
3232
.option('--verbose', 'Show debug logs')
33+
.option('--overwrite-dir', 'Overwrite the target directory')
3334
.action((outDir = '.', cliOptions) => {
3435
if (cliOptions.info) {
3536
return showEnvInfo()
3637
}
3738
console.log()
3839
console.log(chalk`{cyan create-nuxt-app v${version}}`)
3940

40-
if (fs.existsSync(outDir) && fs.readdirSync(outDir).length) {
41+
const { answers, overwriteDir, verbose } = cliOptions
42+
if (fs.existsSync(outDir) && fs.readdirSync(outDir).length && !overwriteDir) {
4143
const baseDir = outDir === '.' ? path.basename(process.cwd()) : outDir
4244
return console.error(chalk.red(
4345
`Could not create project in ${chalk.bold(baseDir)} because the directory is not empty.`))
4446
}
4547

4648
console.log(chalk`✨ Generating Nuxt.js project in {cyan ${outDir}}`)
4749

48-
const { verbose, answers } = cliOptions
4950
const logLevel = verbose ? 4 : 2
5051
// See https://sao.vercel.app/api.html#standalone-cli
5152
sao({ generator, outDir, logLevel, answers, cliOptions })

0 commit comments

Comments
 (0)