-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change inline configuration format (#21)
- Loading branch information
Showing
6 changed files
with
72 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Extracted from degit | ||
// TODO: Export from degitto instead | ||
const supported = new Set(['github', 'gitlab', 'bitbucket', 'git.sr.ht']); | ||
|
||
class DegitError extends Error { | ||
constructor(message, options) { | ||
super(message); | ||
Object.assign(this, options); | ||
} | ||
} | ||
|
||
module.exports = src => { | ||
const match = /^(?:(?:https:\/\/)?([^:/]+\.[^:/]+)\/|git@([^:/]+)[:/]|([^/]+):)?([^/\s]+)\/([^/\s#]+)(?:((?:\/[^/\s#]+)+))?\/?(?:#(.+))?/.exec( | ||
src | ||
); | ||
if (!match) { | ||
throw new DegitError(`could not parse ${src}`, { | ||
code: 'BAD_SRC' | ||
}); | ||
} | ||
|
||
const site = (match[1] || match[2] || match[3] || 'github').replace( | ||
/\.(com|org)$/, | ||
'' | ||
); | ||
if (!supported.has(site)) { | ||
throw new DegitError( | ||
'degit supports GitHub, GitLab, Sourcehut and BitBucket', | ||
{ | ||
code: 'UNSUPPORTED_HOST' | ||
} | ||
); | ||
} | ||
|
||
const user = match[4]; | ||
const name = match[5].replace(/\.git$/, ''); | ||
const subdir = match[6]; | ||
const ref = match[7] || 'HEAD'; | ||
|
||
const domain = `${site}.${ | ||
site === 'bitbucket' ? 'org' : (site === 'git.sr.ht' ? '' : 'com') | ||
}`; | ||
const url = `https://${domain}/${user}/${name}`; | ||
const ssh = `git@${domain}:${user}/${name}`; | ||
|
||
const mode = supported.has(site) ? 'tar' : 'git'; | ||
|
||
return {site, user, name, ref, url, ssh, subdir, mode}; | ||
}; |