npmci/ts/npmci.prepare.ts

41 lines
1.2 KiB
TypeScript
Raw Normal View History

2016-06-01 03:42:37 +00:00
import "typings-global";
import * as plugins from "./npmci.plugins";
2016-06-02 11:39:03 +00:00
import {bash} from "./npmci.bash";
2016-06-01 03:42:37 +00:00
let docker = function(){
2016-06-02 11:08:15 +00:00
let done = plugins.q.defer();
let dockerRegex = /^([a-zA-Z0-9\.]*)\|([a-zA-Z0-9\.]*)/
let dockerRegexResultArray = dockerRegex.exec("process.env.NPMCI_LOGIN_DOCKER");
let username = dockerRegexResultArray[1];
let password = dockerRegexResultArray[2];
2016-06-02 11:39:03 +00:00
bash("docker login -u " + username + " -p " + password);
2016-06-02 11:08:15 +00:00
done.resolve();
return done.promise;
2016-06-01 03:42:37 +00:00
}
let npm = function(){
let done = plugins.q.defer();
let npmrcPrefix:string = "//registry.npmjs.org/:_authToken=";
2016-06-02 11:08:15 +00:00
let npmToken:string = process.env.NPMCI_TOKEN_NPM;
2016-06-01 03:42:37 +00:00
let 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;
};
export let prepare = function(serviceArg:string){
switch (serviceArg) {
case "npm":
return npm();
case "docker":
return docker();
}
}