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

feat(create-nuxt-app): add --overwrite-dir flag #799

Merged
merged 2 commits into from
Jun 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ Show debug logs

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

### `--overwrite-dir`

Overwrite the target directory.

## Credits

- [egoist](https://github.com/egoist)
Expand Down
5 changes: 3 additions & 2 deletions packages/create-nuxt-app/lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,23 @@ cli
.option('-i, --info', 'Print out debugging information relating to the local environment')
.option('--answers <json>', 'Skip all the prompts and use the provided answers')
.option('--verbose', 'Show debug logs')
.option('--overwrite-dir', 'Overwrite the target directory')
.action((outDir = '.', cliOptions) => {
if (cliOptions.info) {
return showEnvInfo()
}
console.log()
console.log(chalk`{cyan create-nuxt-app v${version}}`)

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

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

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