diff --git a/generators/app/index.js b/generators/app/index.js index 6e1fbd36..516a8ca0 100644 --- a/generators/app/index.js +++ b/generators/app/index.js @@ -167,6 +167,21 @@ class AppGenerator extends Generator [ { type: 'input' + , name: 'iKnowWhatImDoing' + , message: chalk.redBright( + chalk.inverse( ' Whoa there!! It would appear that your target directory is not empty! ' ) + + ' Type "YES" if you would like to proceed anyway.' + ) + , default: '' + , validate: ( iKnowWhatImDoing ) => + { + if ( 'YES' === iKnowWhatImDoing ) { return true; } + this.env.error( 'Bailing out' ); + } + , when: !( this._isRootSafe() ) + } + , { + type: 'input' , name: 'packageName' , message: ( 'What is the name of this ' diff --git a/lib/generator.js b/lib/generator.js index acfd4b2a..508d3d93 100644 --- a/lib/generator.js +++ b/lib/generator.js @@ -41,7 +41,6 @@ module.exports = * @param {Array} prompts An array of prompt definitions as would be passed to `this.prompt()`. * * @return {Array} The prompts for which no valid value has been supplied through a command line option. - * */ _promptsPruneByOptions: function ( prompts ) @@ -188,5 +187,27 @@ module.exports = } ); } + + , + /** + * Test whether the destination root is safely empty for generating an app in. + * + * @method _isRootSafe + * + * @return {Boolean Whether the destination root is safely empty for generating an app in. + */ + + _isRootSafe: function () + { + var root = this.destinationRoot() + , entries = fsCore.readdirSync( root ) + , safe = + [ + '.git' + ] + ; + + return 0 === _.difference( entries, safe ).length; + } } ;