Skip to content

Commit

Permalink
feat(create-nuxt-app): add --overwrite-dir flag (#799)
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesgeorge007 authored Jun 14, 2021
1 parent b5b716c commit e45bdbb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
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

0 comments on commit e45bdbb

Please # to comment.