add prepare command

This commit is contained in:
Philipp Kunz 2016-06-01 05:42:37 +02:00
parent 34f29bb4b4
commit 8fec378a53
6 changed files with 76 additions and 16 deletions

View File

@ -28,6 +28,7 @@
"q": "^1.4.1", "q": "^1.4.1",
"shelljs": "^0.7.0", "shelljs": "^0.7.0",
"smartfile": "^3.0.10", "smartfile": "^3.0.10",
"smartssh": "^1.0.4",
"typings-global": "^1.0.3" "typings-global": "^1.0.3"
} }
} }

View File

@ -34,9 +34,12 @@ switch (command){
break; break;
case "test": case "test":
test(commandOption); test(commandOption);
break;
case "prepare":
break; break;
case "publish": case "publish":
publish(); publish(commandOption);
break; break;
default: default:
break; break;

View File

@ -4,13 +4,15 @@ import {bash} from "./npmci.bash";
export let install = (versionArg) => { export let install = (versionArg) => {
let done = plugins.q.defer(); let done = plugins.q.defer();
plugins.beautylog.log("now installing " + "node ".green + ("version " + versionArg).yellow);
let version:string; let version:string;
if(versionArg == "lts"){ if(versionArg == "lts"){
version = "4"; version = "4";
} else if(versionArg = "legacy"){
version = "4.0.0"
} else { } else {
version = versionArg; version = versionArg;
}; };
plugins.beautylog.log("now installing " + "node ".green + ("version " + version).yellow);
bash( bash(
"nvm install " + version + "nvm install " + version +
" && nvm alias default " + version " && nvm alias default " + version

View File

@ -3,4 +3,5 @@ export import beautylog = require("beautylog");
export let commander = require("commander"); export let commander = require("commander");
export let q = require("q"); export let q = require("q");
export let shelljs = require("shelljs"); export let shelljs = require("shelljs");
export let smartssh = require("smartssh");
export import smartfile = require("smartfile"); export import smartfile = require("smartfile");

33
ts/npmci.prepare.ts Normal file
View File

@ -0,0 +1,33 @@
import "typings-global";
import * as plugins from "./npmci.plugins";
let docker = function(){
}
let npm = function(){
let done = plugins.q.defer();
let npmrcPrefix:string = "//registry.npmjs.org/:_authToken=";
let npmToken:string = process.env.NPMCITOKEN;
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();
}
}

View File

@ -1,22 +1,42 @@
import "typings-global"; import "typings-global";
import * as plugins from "./npmci.plugins"; import * as plugins from "./npmci.plugins";
import {prepare} from "./npmci.prepare";
import {bash} from "./npmci.bash"; import {bash} from "./npmci.bash";
let npmrcPrefix:string = "//registry.npmjs.org/:_authToken="; export let publish = (serviceArg:string = "npm") => {
let npmToken:string = process.env.NPMCITOKEN;
let npmrcFileString = npmrcPrefix + npmToken;
export let publish = () => {
let done = plugins.q.defer(); let done = plugins.q.defer();
if(npmToken){ switch (serviceArg){
plugins.beautylog.info("found access token"); case "npm":
} else { publishNpm()
plugins.beautylog.error("no access token found! Exiting!"); .then(function(){
process.exit(1); done.resolve();
});
break;
case "docker":
publishDocker()
.then(function(){
done.resolve();
});
} }
plugins.smartfile.memory.toFsSync(npmrcFileString,{fileName:".npmrc",filePath:"/root"}); return done.promise;
bash("npm publish"); };
plugins.beautylog.ok("Done!")
let publishNpm = function(){
let done = plugins.q.defer();
prepare("npm")
.then(function(){
bash("npm publish");
plugins.beautylog.ok("Done!") ;
done.resolve();
});
return done.promise;
}
let publishDocker = function(){
let done = plugins.q.defer();
prepare("docker")
.then(function(){
bash("docker push");
});
return done.promise; return done.promise;
}; };