use hosted-git-info pkg to process --template name/url
This commit is contained in:
parent
9a78301ac1
commit
1b7935678c
|
@ -1,4 +1,5 @@
|
||||||
let fs = require('../core/fs.js');
|
let fs = require('../core/fs.js');
|
||||||
|
let hostedGitInfo = require('hosted-git-info');
|
||||||
let utils = require('./utils.js');
|
let utils = require('./utils.js');
|
||||||
|
|
||||||
class TemplateGenerator {
|
class TemplateGenerator {
|
||||||
|
@ -76,72 +77,28 @@ class TemplateGenerator {
|
||||||
console.log(__('Installing packages...').green);
|
console.log(__('Installing packages...').green);
|
||||||
utils.runCmd('npm install');
|
utils.runCmd('npm install');
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(__('Init complete').green);
|
console.log(__('Init complete').green);
|
||||||
console.log('\n' + __('App ready at ').green + templatePath);
|
console.log('\n' + __('App ready at ').green + templatePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
extractGithubUrlAndFolder(uri){
|
|
||||||
|
|
||||||
/* first matching group is the url, second the repoPart and third the branch with a hash in the beginning (if existing)
|
|
||||||
e.g. (["git@github.com/status-im/dappcon-workshop-dapp#master", "status-im/dappcon-workshop-dapp", "#master" ])
|
|
||||||
should work with all formats of the following:
|
|
||||||
* git@github.com/status-im/dappcon-workshop-dapp#start-here
|
|
||||||
* git@github.com/status-im/dappcon-workshop-dapp
|
|
||||||
* http://www.github.com/status-im/dappcon-workshop-dapp
|
|
||||||
* https://www.github.com/status-im/dappcon-workshop-dapp
|
|
||||||
* github.com/status-im/dappcon-workshop-dapp#start-here
|
|
||||||
|
|
||||||
sadly it doesn't extract from http(s)://github.com/status-im/dappcon-workshop-dapp/tree/start-here
|
|
||||||
thats why we have a special case later
|
|
||||||
*/
|
|
||||||
const match = uri.match(/github\.com+\/(.+?)(#.*)?$/);
|
|
||||||
const githubPart = "https://github.com/";
|
|
||||||
let repoPart = match !== null? match[1] : null;
|
|
||||||
let branchName = match !== null? match[2] : null;
|
|
||||||
|
|
||||||
if (branchName && branchName !== '#'){
|
|
||||||
branchName = branchName.substring(1);
|
|
||||||
} else {
|
|
||||||
branchName = "master";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let url, folder;
|
|
||||||
if (uri.includes("/tree")){
|
|
||||||
//e.g http(s)://github.com/status-im/dappcon-workshop-dapp/tree/start-here
|
|
||||||
let repoPartAndBranch = repoPart.split("/tree/");
|
|
||||||
repoPart = repoPartAndBranch[0];
|
|
||||||
branchName = repoPartAndBranch[1];
|
|
||||||
url = "https://github.com/" + repoPart + "/archive/"+ branchName +".zip";
|
|
||||||
folder = repoPart + "/" + branchName;
|
|
||||||
} else if (repoPart !== undefined) {
|
|
||||||
url = githubPart + repoPart + "/archive/" + branchName + ".zip";
|
|
||||||
folder = repoPart + "/" + branchName;
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
'url': url,
|
|
||||||
'folder': folder
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getExternalProject(uri) {
|
getExternalProject(uri) {
|
||||||
let url, folder;
|
let url, folder, hgi;
|
||||||
const regex = /^((git@)?(www\.)?github\.com\/)|(https?:\/\/)/;
|
try {
|
||||||
if (!uri.match(regex) && uri.split('/').length >= 2) {
|
hgi = hostedGitInfo.fromUrl(uri);
|
||||||
//e.g embark-framework/embark, embark-framework/embark#branch, embark-framework/embark#features/branch
|
if (!hgi) {
|
||||||
let repoPartAndBranch = uri.split('#');
|
let x = uri.split('#');
|
||||||
let repoPart = repoPartAndBranch[0];
|
x[0] = `embark-framework/embark-${x[0]}-template`;
|
||||||
let branchName = (repoPartAndBranch.length === 2)? repoPartAndBranch[1] : "master";
|
hgi = hostedGitInfo.fromUrl(x.join('#'));
|
||||||
url = "https://github.com/" + repoPart + "/archive/"+ branchName + ".zip";
|
}
|
||||||
folder = repoPart + "/" + branchName;
|
if(!hgi) { throw new Error(); }
|
||||||
} else if (uri.indexOf('/') === -1) {
|
url = hgi.tarball();
|
||||||
url = "https://github.com/embark-framework/embark-" + uri + "-template/archive/master.zip";
|
folder = `${hgi.user}/${hgi.project}/${hgi.committish || 'master'}`;
|
||||||
folder = "embark-framework/embark-" + uri + "-template";
|
} catch (e) {
|
||||||
} else {
|
console.error('Unsupported template name or git host URL'.red);
|
||||||
let urlAndFolder = this.extractGithubUrlAndFolder(uri);
|
process.exit(1);
|
||||||
url = urlAndFolder.url;
|
|
||||||
folder = urlAndFolder.folder;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
Loading…
Reference in New Issue