@@ -3,6 +3,8 @@ import fs from 'fs.promised';
33import copy from 'recursive-copy' ;
44import mkdirp from 'mkdirp' ;
55import ora from 'ora' ;
6+ import chalk from 'chalk' ;
7+ import inquirer from 'inquirer' ;
68import promisify from 'es6-promisify' ;
79import spawn from 'cross-spawn-promise' ;
810import path from 'path' ;
@@ -28,6 +30,10 @@ export default asyncCommand({
2830 description : 'Directory to create the app within' ,
2931 defaultDescription : '<name>'
3032 } ,
33+ force : {
34+ description : 'Force option to create the directory for the new app' ,
35+ default : false
36+ } ,
3137 type : {
3238 description : 'A project template to start from' ,
3339 choices : [
@@ -80,16 +86,37 @@ export default asyncCommand({
8086 }
8187 catch ( err ) { }
8288
83- if ( exists ) {
84- throw Error ( 'Directory already exists.' ) ;
89+ if ( exists && argv . force ) {
90+ const question = {
91+ type : 'confirm' ,
92+ name : 'enableForce' ,
93+ message : `You are using '--force'. Do you wish to continue?` ,
94+ default : false ,
95+ } ;
96+
97+ let { enableForce } = await inquirer . prompt ( question ) ;
98+
99+ if ( enableForce ) {
100+ process . stdout . write ( 'Initializing project in the current directory...\n' ) ;
101+ } else {
102+ process . stderr . write ( chalk . red ( 'Error: Cannot initialize in the current directory\n' ) ) ;
103+ process . exit ( 1 ) ;
104+ }
105+ }
106+
107+ if ( exists && ! argv . force ) {
108+ process . stderr . write ( chalk . red ( 'Error: Cannot initialize in the current directory, please specify a different destination\n' ) ) ;
109+ process . exit ( 1 ) ;
85110 }
86111
87112 let spinner = ora ( {
88113 text : 'Creating project' ,
89114 color : 'magenta'
90115 } ) . start ( ) ;
91116
92- await promisify ( mkdirp ) ( target ) ;
117+ if ( ! exists ) {
118+ await promisify ( mkdirp ) ( target ) ;
119+ }
93120
94121 await copy (
95122 path . resolve ( __dirname , '../..' , template ) ,
0 commit comments