Skip to content

Commit

Permalink
Merge pull request #164 from PascalPrecht/fix/init-cmd
Browse files Browse the repository at this point in the history
fix(commands/init): throw meaningful error if project folder already exists
  • Loading branch information
izqui committed Aug 8, 2018
2 parents b31557d + 22b1763 commit e364646
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/commands/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,23 @@ exports.handler = function ({ reporter, name, template }) {

const basename = name.split('.')[0]
const tasks = new TaskList([
{
title: 'Checking project existence',
task: async (ctx, task) => {
const projectPath = path.resolve(process.cwd(), basename)
const exists = await fs.pathExists(projectPath)
if (exists) {
throw new Error(`Couldn't initialize project. Project with name ${basename} already exists in ${projectPath}. Use different <name> or rename existing project folder.`)
}
}
},
{
title: 'Clone template',
task: async (ctx, task) => {
task.output = `Cloning ${template} into ${basename}...`

const repo = await clone(template, basename, { shallow: true })
console.log(`Template cloned to ${basename}`)
// console.log(`Template cloned to ${basename}`)
}
},
{
Expand Down

0 comments on commit e364646

Please sign in to comment.