mirror of
https://github.com/status-im/embark-area-51.git
synced 2025-01-09 13:36:14 +00:00
refactor install template code
This commit is contained in:
parent
215799f2bd
commit
440baeb323
@ -7,8 +7,10 @@ class TemplateGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
downloadAndGenerate(uri, destinationFolder, name) {
|
downloadAndGenerate(uri, destinationFolder, name) {
|
||||||
|
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);
|
||||||
|
console.log(__('Installing Template from ' + uri + '....').green);
|
||||||
|
|
||||||
fs.mkdirpSync(utils.dirname(tmpFilePath));
|
fs.mkdirpSync(utils.dirname(tmpFilePath));
|
||||||
utils.downloadFile(url, tmpFilePath, () => {
|
utils.downloadFile(url, tmpFilePath, () => {
|
||||||
@ -22,26 +24,20 @@ class TemplateGenerator {
|
|||||||
file.path = utils.joinPath(...fixed_path);
|
file.path = utils.joinPath(...fixed_path);
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
|
}).then(() => {
|
||||||
|
self.installTemplate(fspath, name, true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
generate(destinationFolder, name) {
|
generate(destinationFolder, name) {
|
||||||
let templatePath = fs.embarkPath(utils.joinPath('templates', this.templateName));
|
|
||||||
console.log(__('Initializing Embark Template....').green);
|
console.log(__('Initializing Embark Template....').green);
|
||||||
|
|
||||||
|
let templatePath = fs.embarkPath(utils.joinPath('templates', this.templateName));
|
||||||
let fspath = utils.joinPath(destinationFolder, name);
|
let fspath = utils.joinPath(destinationFolder, name);
|
||||||
|
|
||||||
fs.copySync(templatePath, fspath);
|
fs.copySync(templatePath, fspath);
|
||||||
utils.cd(fspath);
|
|
||||||
utils.sed('package.json', '%APP_NAME%', name);
|
|
||||||
|
|
||||||
if (name === 'embark_demo') {
|
this.installTemplate(fspath, name, (name === 'embark_demo'));
|
||||||
console.log(__('Installing packages...').green);
|
|
||||||
utils.runCmd('npm install');
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log(__('Init complete').green);
|
|
||||||
console.log('\n' + __('App ready at ').green + fspath);
|
|
||||||
|
|
||||||
if (name === 'embark_demo') {
|
if (name === 'embark_demo') {
|
||||||
console.log('-------------------'.yellow);
|
console.log('-------------------'.yellow);
|
||||||
@ -52,6 +48,19 @@ class TemplateGenerator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
installTemplate(templatePath, name, installPackages) {
|
||||||
|
utils.cd(templatePath);
|
||||||
|
utils.sed('package.json', '%APP_NAME%', name);
|
||||||
|
|
||||||
|
if (installPackages) {
|
||||||
|
console.log(__('Installing packages...').green);
|
||||||
|
utils.runCmd('npm install');
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(__('Init complete').green);
|
||||||
|
console.log('\n' + __('App ready at ').green + templatePath);
|
||||||
|
}
|
||||||
|
|
||||||
getExternalProject(uri) {
|
getExternalProject(uri) {
|
||||||
let match = uri.match(
|
let match = uri.match(
|
||||||
/\.[a-z]+\/([-a-zA-Z0-9@:%_+.~#?&\/=]+)/
|
/\.[a-z]+\/([-a-zA-Z0-9@:%_+.~#?&\/=]+)/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user