From 8fec378a53e8ac3370e5ce4743f61005659a3997 Mon Sep 17 00:00:00 2001 From: Phil Kunz Date: Wed, 1 Jun 2016 05:42:37 +0200 Subject: [PATCH] add prepare command --- package.json | 1 + ts/index.ts | 5 ++++- ts/npmci.install.ts | 4 +++- ts/npmci.plugins.ts | 1 + ts/npmci.prepare.ts | 33 +++++++++++++++++++++++++++++++ ts/npmci.publish.ts | 48 ++++++++++++++++++++++++++++++++------------- 6 files changed, 76 insertions(+), 16 deletions(-) create mode 100644 ts/npmci.prepare.ts diff --git a/package.json b/package.json index 3a75697..068e93e 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "q": "^1.4.1", "shelljs": "^0.7.0", "smartfile": "^3.0.10", + "smartssh": "^1.0.4", "typings-global": "^1.0.3" } } diff --git a/ts/index.ts b/ts/index.ts index 6b838fe..62baa0d 100644 --- a/ts/index.ts +++ b/ts/index.ts @@ -34,9 +34,12 @@ switch (command){ break; case "test": test(commandOption); + break; + case "prepare": + break; case "publish": - publish(); + publish(commandOption); break; default: break; diff --git a/ts/npmci.install.ts b/ts/npmci.install.ts index 2c753ac..878ec9b 100644 --- a/ts/npmci.install.ts +++ b/ts/npmci.install.ts @@ -4,13 +4,15 @@ import {bash} from "./npmci.bash"; export let install = (versionArg) => { let done = plugins.q.defer(); + plugins.beautylog.log("now installing " + "node ".green + ("version " + versionArg).yellow); let version:string; if(versionArg == "lts"){ version = "4"; + } else if(versionArg = "legacy"){ + version = "4.0.0" } else { version = versionArg; }; - plugins.beautylog.log("now installing " + "node ".green + ("version " + version).yellow); bash( "nvm install " + version + " && nvm alias default " + version diff --git a/ts/npmci.plugins.ts b/ts/npmci.plugins.ts index 0de660d..3ccf11f 100644 --- a/ts/npmci.plugins.ts +++ b/ts/npmci.plugins.ts @@ -3,4 +3,5 @@ export import beautylog = require("beautylog"); export let commander = require("commander"); export let q = require("q"); export let shelljs = require("shelljs"); +export let smartssh = require("smartssh"); export import smartfile = require("smartfile"); \ No newline at end of file diff --git a/ts/npmci.prepare.ts b/ts/npmci.prepare.ts new file mode 100644 index 0000000..bc7256f --- /dev/null +++ b/ts/npmci.prepare.ts @@ -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(); + } +} \ No newline at end of file diff --git a/ts/npmci.publish.ts b/ts/npmci.publish.ts index 80e1556..f50f4f2 100644 --- a/ts/npmci.publish.ts +++ b/ts/npmci.publish.ts @@ -1,22 +1,42 @@ import "typings-global"; import * as plugins from "./npmci.plugins"; +import {prepare} from "./npmci.prepare"; import {bash} from "./npmci.bash"; -let npmrcPrefix:string = "//registry.npmjs.org/:_authToken="; -let npmToken:string = process.env.NPMCITOKEN; -let npmrcFileString = npmrcPrefix + npmToken; - - -export let publish = () => { +export let publish = (serviceArg:string = "npm") => { let done = plugins.q.defer(); - if(npmToken){ - plugins.beautylog.info("found access token"); - } else { - plugins.beautylog.error("no access token found! Exiting!"); - process.exit(1); + switch (serviceArg){ + case "npm": + publishNpm() + .then(function(){ + done.resolve(); + }); + break; + case "docker": + publishDocker() + .then(function(){ + done.resolve(); + }); } - plugins.smartfile.memory.toFsSync(npmrcFileString,{fileName:".npmrc",filePath:"/root"}); - bash("npm publish"); - plugins.beautylog.ok("Done!") + return done.promise; +}; + +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; }; \ No newline at end of file