From 40cdf466a9ecad58ff5c856c7e408ad75fdcb5f4 Mon Sep 17 00:00:00 2001 From: Jakub Bogucki <610941+jakub300@users.noreply.github.com> Date: Mon, 11 Jun 2018 11:12:28 +0200 Subject: [PATCH] Prevent running on existing project and force running page sub generator on existing project (#379) * Fix check of existing project when using page subgenerator * When creating new project check if project exists in current directory * Update error text --- generators/app/index.js | 16 ++++++++++++++++ generators/page/index.js | 7 +++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/generators/app/index.js b/generators/app/index.js index 326886c3..bb59b4b5 100644 --- a/generators/app/index.js +++ b/generators/app/index.js @@ -11,6 +11,22 @@ module.exports = class extends Generator { super(args, opts); } + initializing() { + if (this.config.existed) { + this.log('A Chisel project already exists in this folder.'); + this.log( + 'If you are trying to setup an existing project, check out the' + + ' documentation at https://www.getchisel.co/docs/setup/' + ); + this.log( + 'If the process of generating project was interrupted and you would' + + ' like to continue, we recommend cleaning up the directory and' + + ' starting again.' + ); + process.exit(1); + } + } + prompting() { const done = this.async(); diff --git a/generators/page/index.js b/generators/page/index.js index 5ff324a7..008a262a 100644 --- a/generators/page/index.js +++ b/generators/page/index.js @@ -37,12 +37,11 @@ module.exports = class extends Generator { * @public */ initializing() { - try { - this.configuration = this.config.get('config'); - } catch (ex) { + if(!this.config.existed) { this.log('You need to run this generator in a project directory.'); - process.exit(); + process.exit(1); } + this.configuration = this.config.get('config'); this.pages = this.config.get('pages'); }