npmci/dist/npmci.prepare.js
2016-06-05 04:48:39 +02:00

59 lines
7.5 KiB
JavaScript

"use strict";
require("typings-global");
var plugins = require("./npmci.plugins");
var env = require("./npmci.env");
var npm = function () {
var done = plugins.q.defer();
var npmrcPrefix = "//registry.npmjs.org/:_authToken=";
var npmToken = process.env.NPMCI_TOKEN_NPM;
var npmrcFileString = npmrcPrefix + npmToken;
if (npmToken) {
plugins.beautylog.info("found access token");
}
else {
plugins.beautylog.error("no access token found! Exiting!");
process.exit(1);
}
plugins.smartfile.memory.toFsSync(npmrcFileString, { fileName: ".npmrc", filePath: "/root" });
done.resolve();
return done.promise;
};
var docker = function () {
var done = plugins.q.defer();
env.dockerRegistry = "docker.io";
var dockerRegex = /^([a-zA-Z0-9\.]*)\|([a-zA-Z0-9\.]*)/;
if (!process.env.NPMCI_LOGIN_DOCKER) {
plugins.beautylog.error("You have to specify Login Data to the Docker Registry");
process.exit(1);
}
var dockerRegexResultArray = dockerRegex.exec(process.env.NPMCI_LOGIN_DOCKER);
var username = dockerRegexResultArray[1];
var password = dockerRegexResultArray[2];
plugins.shelljs.exec("docker login -u " + username + " -p " + password);
done.resolve();
return done.promise;
};
var dockerGitlab = function () {
var done = plugins.q.defer();
env.dockerRegistry = "registry.gitlab.com";
var ciBuildToken = process.env.CI_BUILD_TOKEN;
plugins.shelljs.exec("docker login -u gitlab-ci-token -p " + ciBuildToken + " " + env.dockerRegistry);
done.resolve();
return done.promise;
};
exports.prepare = function (serviceArg) {
switch (serviceArg) {
case "npm":
return npm();
case "docker":
return docker()
.then(dockerGitlab); // always also login to gitlab registry for tests
case "docker-gitlab":
return dockerGitlab();
default:
break;
}
};
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5wbWNpLnByZXBhcmUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sZ0JBQWdCLENBQUMsQ0FBQTtBQUN4QixJQUFZLE9BQU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