rev error handling so error msg from hosted-git-info would be logged

This commit is contained in:
Michael Bradley, Jr 2018-09-25 09:20:59 -05:00
parent 7dd18db9d1
commit 36eabda506
2 changed files with 26 additions and 14 deletions

View File

@ -18,7 +18,14 @@ class TemplateGenerator {
const fspath = utils.joinPath(destinationFolder, name); const fspath = utils.joinPath(destinationFolder, name);
this.checkPathExists(fspath); this.checkPathExists(fspath);
const self = this; 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); let tmpFilePath = fs.tmpDir(filePath);
console.log(__('Installing template from ' + browse).green); console.log(__('Installing template from ' + browse).green);
console.log(__('Downloading template...').green); console.log(__('Downloading template...').green);
@ -91,20 +98,15 @@ class TemplateGenerator {
getExternalProject(uri) { getExternalProject(uri) {
let url, folder, hgi; let url, folder, hgi;
try { hgi = hostedGitInfo.fromUrl(uri);
hgi = hostedGitInfo.fromUrl(uri); if (!hgi || hgi.user.includes('#')) {
if (!hgi || hgi.user.includes('#')) { let templateAndBranch = uri.split('#');
let templateAndBranch = uri.split('#'); templateAndBranch[0] = `embark-framework/embark-${templateAndBranch[0]}-template`;
templateAndBranch[0] = `embark-framework/embark-${templateAndBranch[0]}-template`; hgi = hostedGitInfo.fromUrl(templateAndBranch.join('#'));
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);
} }
if(!hgi) { throw new Error('Unsupported template name or git host URL'); }
url = hgi.tarball();
folder = `${hgi.user}/${hgi.project}/${hgi.committish || 'master'}`;
return { return {
url, url,

View File

@ -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);
});
});
}); });
}); });