smartstring/dist/smartstring.git.js

52 lines
6.5 KiB
JavaScript
Raw Permalink Normal View History

"use strict";
2016-05-25 03:06:19 +00:00
require("typings-global");
2016-02-23 06:06:54 +00:00
var plugins = require("./smartstring.plugins");
/* ---------------------------------------------- *
* ------------------ classes ------------------- *
* ---------------------------------------------- */
2016-05-25 03:06:19 +00:00
var GitRepo = (function () {
function GitRepo(stringArg, tokenArg) {
2016-02-23 06:06:54 +00:00
var regexMatches = gitRegex(stringArg);
this.host = regexMatches[1];
this.user = regexMatches[2];
this.repo = regexMatches[3];
this.accessToken = tokenArg;
this.sshUrl = gitLink(this.host, this.user, this.repo, this.accessToken, "ssh");
this.httpsUrl = gitLink(this.host, this.user, this.repo, this.accessToken, "https");
}
;
2016-05-25 03:06:19 +00:00
return GitRepo;
}());
2016-05-25 03:06:19 +00:00
exports.GitRepo = GitRepo;
2016-02-23 06:06:54 +00:00
/* ---------------------------------------------- *
* ------------------ helpers ------------------- *
* ---------------------------------------------- */
var gitRegex = function (stringArg) {
2016-06-05 07:31:10 +00:00
var regexString = /([a-zA-Z0-9\-\.]*)(?:\/|\:)([a-zA-Z0-9\-]*)(?:\/)([a-zA-Z0-9\-]*)(?:\.git)/;
2016-02-23 06:06:54 +00:00
var regexMatches = regexString.exec(stringArg);
return regexMatches;
};
var gitLink = function (hostArg, userArg, repoArg, tokenArg, linkTypeArg) {
if (tokenArg === void 0) { tokenArg = ""; }
var returnString;
if (tokenArg !== "") {
tokenArg = tokenArg + "@";
}
switch (linkTypeArg) {
case "https":
returnString = "https://" +
tokenArg + hostArg + "/" + userArg + "/" + repoArg + ".git";
break;
case "ssh":
returnString = "git@" +
hostArg + ":" + userArg + "/" + repoArg + ".git";
break;
default:
plugins.beautylog.error("Link Type " + linkTypeArg + " not known");
break;
}
return returnString;
};
2016-06-05 07:31:10 +00:00
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0c3RyaW5nLmdpdC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