Skip to content

Commit

Permalink
Empty dir if it exists before processing generation.
Browse files Browse the repository at this point in the history
  • Loading branch information
saiat3 committed Aug 15, 2019
1 parent b189caa commit b6d40f6
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions src/Generator.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const fs = require('fs');
const path = require('path');
const pluralize = require('pluralize');
const Confirm = require('prompt-confirm');

const GeneralHelper = require('./helpers/general-helper');

Expand All @@ -17,21 +18,32 @@ class Generator {
}

init() {
this.checkDirValidity();
this.prepareVariables();

this.createMainComponent();
this.createService();
this.createFormComponent();
this.createModule();
this.checkDirValidity().then(success => {
this.prepareVariables();
this.createMainComponent();
this.createService();
this.createFormComponent();
this.createModule();
}, error => {
});
}

checkDirValidity() {
if (!fs.existsSync(this.path)) {
fs.mkdirSync(this.path);
} else {
throw new Error('Folder already exists in the provided path.')
}
return new Promise((resolve, reject) => {
if (!fs.existsSync(this.path)) {
fs.mkdirSync(this.path);
resolve();
} else {
(new Confirm("Folder already exists. Do you want to overwrite it ?")).run().then((answer) => {
if (!answer) {
reject()
} else {
GeneralHelper.emptyDir(this.path);
resolve();
}
});
}
});
}

prepareVariables() {
Expand Down

0 comments on commit b6d40f6

Please sign in to comment.