Skip to content

Commit

Permalink
Merge pull request redwoodjs#315 from olance/patch-1
Browse files Browse the repository at this point in the history
Allow creating app in existing empty dir
  • Loading branch information
peterp authored Mar 24, 2020
2 parents 4ecebda + f8992d8 commit 192f9df
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ if (!targetDir) {
}

const newAppDir = path.resolve(process.cwd(), targetDir)
const appDirExists = fs.existsSync(newAppDir)

if (appDirExists && fs.readdirSync(newAppDir).length > 0) {
console.error(`'${newAppDir}' already exists and is not empty.`)
process.exit(1)
}

const createProjectTasks = ({ newAppDir }) => {
const tmpDownloadPath = tmp.tmpNameSync({
Expand All @@ -66,11 +72,8 @@ const createProjectTasks = ({ newAppDir }) => {

return [
{
title: `Creating directory '${newAppDir}'`,
title: `${appDirExists ? 'Using' : 'Creating'} directory '${newAppDir}'`,
task: () => {
if (fs.existsSync(newAppDir)) {
throw new Error(`'${newAppDir}' already exists.`)
}
fs.mkdirSync(newAppDir, { recursive: true })
},
},
Expand Down Expand Up @@ -159,7 +162,7 @@ new Listr(
.then(() => {
// TODO: show helpful out for next steps.
console.log()
console.log(`Thanks for trying out Redwood! We've created '${newAppDir}'`)
console.log(`Thanks for trying out Redwood! We've created your app in '${newAppDir}'`)
console.log()
console.log(
'Inside that directory you can run `yarn rw dev` to start the development server.'
Expand Down

0 comments on commit 192f9df

Please sign in to comment.