Merge pull request #742 from embark-framework/bug_fix/template-destination

don't continue with template install if destination path exists
This commit is contained in:
Michael Bradley 2018-08-24 08:48:03 -05:00 committed by GitHub
commit 9311bf2d30
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 3 deletions

View File

@ -6,7 +6,16 @@ class TemplateGenerator {
this.templateName = templateName; 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) { downloadAndGenerate(uri, destinationFolder, name) {
const fspath = utils.joinPath(destinationFolder, name);
this.checkPathExists(fspath);
const self = this; const self = this;
let {url, filePath} = this.getExternalProject(uri); let {url, filePath} = this.getExternalProject(uri);
let tmpFilePath = fs.tmpDir(filePath); let tmpFilePath = fs.tmpDir(filePath);
@ -14,8 +23,6 @@ class TemplateGenerator {
fs.mkdirpSync(utils.dirname(tmpFilePath)); fs.mkdirpSync(utils.dirname(tmpFilePath));
utils.downloadFile(url, tmpFilePath, () => { utils.downloadFile(url, tmpFilePath, () => {
let fspath = utils.joinPath(destinationFolder, name);
utils.extractZip(tmpFilePath, fspath, { utils.extractZip(tmpFilePath, fspath, {
map: file => { map: file => {
let fixed_path = file.path.split('/'); let fixed_path = file.path.split('/');
@ -30,10 +37,11 @@ class TemplateGenerator {
} }
generate(destinationFolder, name) { generate(destinationFolder, name) {
const fspath = utils.joinPath(destinationFolder, name);
this.checkPathExists(fspath);
console.log(__('Initializing Embark Template...').green); console.log(__('Initializing Embark Template...').green);
let templatePath = fs.embarkPath(utils.joinPath('templates', this.templateName)); let templatePath = fs.embarkPath(utils.joinPath('templates', this.templateName));
let fspath = utils.joinPath(destinationFolder, name);
fs.copySync(templatePath, fspath); fs.copySync(templatePath, fspath);
this.installTemplate(fspath, name, (name === 'embark_demo')); this.installTemplate(fspath, name, (name === 'embark_demo'));