feat(@embark/cli): add --template option to embark demo cli command

Adds a --template option to the embark demo cli command so it is now possible to generate a demo project using an existing embark's template repository on Github with an existing demo branch (e.g. embark demo --template vue will use embark-framework/embark-vue-template#demo), or any other git URL repository. If no --template option is specified, the command  will generate a demo from default template in templates/demo
This commit is contained in:
Santiago Gonzalez Toral 2018-11-12 22:39:20 -05:00 committed by Iuri Matias
parent 58795ca7d2
commit 89e3eb6156
1 changed files with 10 additions and 1 deletions

View File

@ -92,10 +92,19 @@ class Cmd {
program
.command('demo')
.option('--locale [locale]', __('language to use (default: en)'))
.option('--template <name/url>', __('download a demo template using a known name or a git host URL'))
.description(__('create a working dapp with a SimpleStorage contract'))
.action(function(options) {
i18n.setOrDetectLocale(options.locale);
embark.generateTemplate('demo', './', 'embark_demo');
if(options.template) {
const hostedGitInfo = require('hosted-git-info');
const hgi = hostedGitInfo.fromUrl(options.template);
const url = !hgi ? `embark-framework/embark-${options.template}-template#demo`:options.template;
const folderName = !hgi ? `embark_${options.template}_demo`:'template_demo';
embark.generateTemplate('demo', './', folderName, url);
} else {
embark.generateTemplate('demo', './', 'embark_demo');
}
});
}