Skip to content

Commit

Permalink
feat: Resolve saojs#107 install from git url
Browse files Browse the repository at this point in the history
  • Loading branch information
peng committed May 14, 2019
1 parent 7c8e469 commit 78bca3c
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion lib/parseGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module.exports = generator => {
}
}

const SPECIAL_PREFIX_RE = /^(npm|github|bitbucket|gitlab|alias):/
const SPECIAL_PREFIX_RE = /^(npm|github|bitbucket|gitlab|alias|direct):/

if (!SPECIAL_PREFIX_RE.test(generator) && !generator.includes('/')) {
generator = `npm:sao-${generator}`
Expand Down Expand Up @@ -90,6 +90,32 @@ module.exports = generator => {
path: path.join(paths.repoPath, hash)
}
}
// add direct git url
if (type === 'direct') {
const slug = 'direct:' + generator
let copyGenerator = generator
const protocolReg = /(http|https|ssh):(\/\/)/
const portReg = /:[1-9]\d*/
if (protocolReg.test(copyGenerator)) {
const fullProt = copyGenerator.match(protocolReg)[0]
copyGenerator = copyGenerator.split(fullProt)[1]
}
if (portReg.test(copyGenerator)) {
const fullPort = copyGenerator.match(portReg)[0]
copyGenerator = copyGenerator.split(fullPort)[1]
}

const hash = sum(`repo:${slug}`)
const hasSubGenerator = copyGenerator.indexOf(':') !== -1
return {
type: 'repo',
slug,
subGenerator:
hasSubGenerator && copyGenerator.slice(generator.indexOf(':') + 1),
hash,
path: path.join(paths.repoPath, hash)
}
}

const [
,
Expand Down

0 comments on commit 78bca3c

Please sign in to comment.