mirror of https://github.com/embarklabs/embark.git
rev error handling so error msg from hosted-git-info would be logged
This commit is contained in:
parent
7dd18db9d1
commit
36eabda506
|
@ -18,7 +18,14 @@ class TemplateGenerator {
|
|||
const fspath = utils.joinPath(destinationFolder, name);
|
||||
this.checkPathExists(fspath);
|
||||
const self = this;
|
||||
let {url, filePath, browse} = this.getExternalProject(uri);
|
||||
let ext;
|
||||
try {
|
||||
ext = this.getExternalProject(uri);
|
||||
} catch (e) {
|
||||
console.error(utils.errorMessage(e).red);
|
||||
process.exit(1);
|
||||
}
|
||||
let {url, filePath, browse} = ext;
|
||||
let tmpFilePath = fs.tmpDir(filePath);
|
||||
console.log(__('Installing template from ' + browse).green);
|
||||
console.log(__('Downloading template...').green);
|
||||
|
@ -91,20 +98,15 @@ class TemplateGenerator {
|
|||
|
||||
getExternalProject(uri) {
|
||||
let url, folder, hgi;
|
||||
try {
|
||||
hgi = hostedGitInfo.fromUrl(uri);
|
||||
if (!hgi || hgi.user.includes('#')) {
|
||||
let templateAndBranch = uri.split('#');
|
||||
templateAndBranch[0] = `embark-framework/embark-${templateAndBranch[0]}-template`;
|
||||
hgi = hostedGitInfo.fromUrl(templateAndBranch.join('#'));
|
||||
}
|
||||
if(!hgi) { throw new Error(); }
|
||||
url = hgi.tarball();
|
||||
folder = `${hgi.user}/${hgi.project}/${hgi.committish || 'master'}`;
|
||||
} catch (e) {
|
||||
console.error('Unsupported template name or git host URL'.red);
|
||||
process.exit(1);
|
||||
hgi = hostedGitInfo.fromUrl(uri);
|
||||
if (!hgi || hgi.user.includes('#')) {
|
||||
let templateAndBranch = uri.split('#');
|
||||
templateAndBranch[0] = `embark-framework/embark-${templateAndBranch[0]}-template`;
|
||||
hgi = hostedGitInfo.fromUrl(templateAndBranch.join('#'));
|
||||
}
|
||||
if(!hgi) { throw new Error('Unsupported template name or git host URL'); }
|
||||
url = hgi.tarball();
|
||||
folder = `${hgi.user}/${hgi.project}/${hgi.committish || 'master'}`;
|
||||
|
||||
return {
|
||||
url,
|
||||
|
|
|
@ -112,5 +112,15 @@ describe('TemplateGenerator', function () {
|
|||
|
||||
});
|
||||
|
||||
describe('with unsupported template specifier', function () {
|
||||
|
||||
it('raises an exception', function () {
|
||||
assert.throws(() => templateGenerator.getExternalProject("bad://format"), /Unsupported/);
|
||||
assert.throws(() => templateGenerator.getExternalProject("bad://format#/also/bad"), /Unsupported/);
|
||||
assert.throws(() => templateGenerator.getExternalProject(/force an error/), Error);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue