diff --git a/lib/utils/template_generator.js b/lib/utils/template_generator.js index 32262fe2..eaa41681 100644 --- a/lib/utils/template_generator.js +++ b/lib/utils/template_generator.js @@ -6,7 +6,16 @@ class TemplateGenerator { this.templateName = templateName; } + checkPathExists(fspath) { + if (fs.existsSync(fspath)) { + console.error(`${fspath} already exists, will not overwrite`.red); + process.exit(1); + } + } + downloadAndGenerate(uri, destinationFolder, name) { + const fspath = utils.joinPath(destinationFolder, name); + this.checkPathExists(fspath); const self = this; let {url, filePath} = this.getExternalProject(uri); let tmpFilePath = fs.tmpDir(filePath); @@ -14,8 +23,6 @@ class TemplateGenerator { fs.mkdirpSync(utils.dirname(tmpFilePath)); utils.downloadFile(url, tmpFilePath, () => { - let fspath = utils.joinPath(destinationFolder, name); - utils.extractZip(tmpFilePath, fspath, { map: file => { let fixed_path = file.path.split('/'); @@ -30,10 +37,11 @@ class TemplateGenerator { } generate(destinationFolder, name) { + const fspath = utils.joinPath(destinationFolder, name); + this.checkPathExists(fspath); console.log(__('Initializing Embark Template...').green); let templatePath = fs.embarkPath(utils.joinPath('templates', this.templateName)); - let fspath = utils.joinPath(destinationFolder, name); fs.copySync(templatePath, fspath); this.installTemplate(fspath, name, (name === 'embark_demo'));