smartstring/dist/smartstring.git.js

59 lines
7.5 KiB
JavaScript
Raw Normal View History

"use strict";
2016-02-23 06:06:54 +00:00
/// <reference path="./typings/main.d.ts" />
var plugins = require("./smartstring.plugins");
/* ---------------------------------------------- *
* ------------------ classes ------------------- *
* ---------------------------------------------- */
var gitRepo = (function () {
function gitRepo(stringArg, tokenArg) {
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");
}
;
return gitRepo;
}());
2016-05-01 12:02:48 +00:00
exports.gitRepo = gitRepo;
2016-02-23 06:06:54 +00:00
/* ---------------------------------------------- *
* ------------------ helpers ------------------- *
* ---------------------------------------------- */
var gitRegex = function (stringArg) {
var regexString = /(?:git\+|git\@|https\:\/\/|)(?:https\:\/\/|)([^\/|\:]*)(?:\/|:)([^\/]+)*(?:\/|:)([^\.]+)/;
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;
};
/* ---------------------------------------------- *
* ------------------ exports ------------------- *
* ---------------------------------------------- */
2016-05-01 12:02:48 +00:00
exports.git = function (stringArg, tokenArg) {
2016-02-23 06:06:54 +00:00
var localGitRepo = new gitRepo(stringArg, tokenArg);
return localGitRepo;
};
2016-05-01 12:02:48 +00:00
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozL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