82f2b76e25
We now use webpack instead of SystemJS, effectively bundling modules into one file (plus commons chunks) for every entry point. This results in a much smaller extension size (almost half). Furthermore we use yarn/npm even for extension run-time dependencies. This relieves us from manually vendoring and building dependencies. It's also easier to understand for new developers familiar with node.
115 lines
3.1 KiB
JavaScript
115 lines
3.1 KiB
JavaScript
'use strict'
|
|
var gitHosts = require('./git-host-info.js')
|
|
var extend = Object.assign || require('util')._extend
|
|
|
|
var GitHost = module.exports = function (type, user, auth, project, committish, defaultRepresentation, opts) {
|
|
var gitHostInfo = this
|
|
gitHostInfo.type = type
|
|
Object.keys(gitHosts[type]).forEach(function (key) {
|
|
gitHostInfo[key] = gitHosts[type][key]
|
|
})
|
|
gitHostInfo.user = user
|
|
gitHostInfo.auth = auth
|
|
gitHostInfo.project = project
|
|
gitHostInfo.committish = committish
|
|
gitHostInfo.default = defaultRepresentation
|
|
gitHostInfo.opts = opts || {}
|
|
}
|
|
GitHost.prototype = {}
|
|
|
|
GitHost.prototype.hash = function () {
|
|
return this.committish ? '#' + this.committish : ''
|
|
}
|
|
|
|
GitHost.prototype._fill = function (template, opts) {
|
|
if (!template) return
|
|
var vars = extend({}, opts)
|
|
opts = extend(extend({}, this.opts), opts)
|
|
var self = this
|
|
Object.keys(this).forEach(function (key) {
|
|
if (self[key] != null && vars[key] == null) vars[key] = self[key]
|
|
})
|
|
var rawAuth = vars.auth
|
|
var rawComittish = vars.committish
|
|
Object.keys(vars).forEach(function (key) {
|
|
vars[key] = encodeURIComponent(vars[key])
|
|
})
|
|
vars['auth@'] = rawAuth ? rawAuth + '@' : ''
|
|
if (opts.noCommittish) {
|
|
vars['#committish'] = ''
|
|
vars['/tree/committish'] = ''
|
|
vars['/comittish'] = ''
|
|
vars.comittish = ''
|
|
} else {
|
|
vars['#committish'] = rawComittish ? '#' + rawComittish : ''
|
|
vars['/tree/committish'] = vars.committish
|
|
? '/' + vars.treepath + '/' + vars.committish
|
|
: ''
|
|
vars['/committish'] = vars.committish ? '/' + vars.committish : ''
|
|
vars.committish = vars.committish || 'master'
|
|
}
|
|
var res = template
|
|
Object.keys(vars).forEach(function (key) {
|
|
res = res.replace(new RegExp('[{]' + key + '[}]', 'g'), vars[key])
|
|
})
|
|
if (opts.noGitPlus) {
|
|
return res.replace(/^git[+]/, '')
|
|
} else {
|
|
return res
|
|
}
|
|
}
|
|
|
|
GitHost.prototype.ssh = function (opts) {
|
|
return this._fill(this.sshtemplate, opts)
|
|
}
|
|
|
|
GitHost.prototype.sshurl = function (opts) {
|
|
return this._fill(this.sshurltemplate, opts)
|
|
}
|
|
|
|
GitHost.prototype.browse = function (opts) {
|
|
return this._fill(this.browsetemplate, opts)
|
|
}
|
|
|
|
GitHost.prototype.docs = function (opts) {
|
|
return this._fill(this.docstemplate, opts)
|
|
}
|
|
|
|
GitHost.prototype.bugs = function (opts) {
|
|
return this._fill(this.bugstemplate, opts)
|
|
}
|
|
|
|
GitHost.prototype.https = function (opts) {
|
|
return this._fill(this.httpstemplate, opts)
|
|
}
|
|
|
|
GitHost.prototype.git = function (opts) {
|
|
return this._fill(this.gittemplate, opts)
|
|
}
|
|
|
|
GitHost.prototype.shortcut = function (opts) {
|
|
return this._fill(this.shortcuttemplate, opts)
|
|
}
|
|
|
|
GitHost.prototype.path = function (opts) {
|
|
return this._fill(this.pathtemplate, opts)
|
|
}
|
|
|
|
GitHost.prototype.tarball = function (opts) {
|
|
return this._fill(this.tarballtemplate, opts)
|
|
}
|
|
|
|
GitHost.prototype.file = function (P, opts) {
|
|
return this._fill(this.filetemplate, extend({
|
|
path: P.replace(/^[/]+/g, '')
|
|
}, opts))
|
|
}
|
|
|
|
GitHost.prototype.getDefaultRepresentation = function () {
|
|
return this.default
|
|
}
|
|
|
|
GitHost.prototype.toString = function (opts) {
|
|
return (this[this.default] || this.sshurl).call(this, opts)
|
|
}
|