From c13ab8e428c073c60c3ce3db64ea86207f62568c Mon Sep 17 00:00:00 2001 From: Phil Kunz Date: Mon, 30 May 2016 02:28:47 +0200 Subject: [PATCH] add functionality --- .gitlab-ci.yml | 32 ++++++++++++++++++++++++++++++++ alias.json | 1 + package.json | 1 + ts/index.ts | 23 +++++++++++++++++------ ts/npmci.install.ts | 21 ++++++++++++++++++++- ts/npmci.plugins.ts | 4 +++- ts/npmci.publish.ts | 11 ++++++++++- ts/npmci.test.ts | 15 +++++++++++++-- 8 files changed, 97 insertions(+), 11 deletions(-) create mode 100644 .gitlab-ci.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..a28dec0 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,32 @@ +image: hosttoday/ht-docker-node + +stages: +- test +- release + +testLTS: + stage: test + script: + - npmci install 4 + - npm install + - npm test + tags: + - docker + +testSTABLE: + stage: test + script: + - npmci install stable + - npm install + - npm test + tags: + - docker + +release: + stage: release + script: + - npm -v + only: + - tags + tags: + - docker \ No newline at end of file diff --git a/alias.json b/alias.json index e69de29..9e26dfe 100644 --- a/alias.json +++ b/alias.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/package.json b/package.json index 6be2312..b1d897c 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "dependencies": { "beautylog": "^5.0.6", "commander": "^2.9.0", + "q": "^1.4.1", "shelljs": "^0.7.0", "smartfile": "^3.0.10", "typings-global": "^1.0.3" diff --git a/ts/index.ts b/ts/index.ts index 005c756..bbc6c1f 100644 --- a/ts/index.ts +++ b/ts/index.ts @@ -2,6 +2,9 @@ import "typings-global"; import * as plugins from "./npmci.plugins"; +import {install} from "./npmci.install"; +import {test} from "./npmci.test"; +import {publish} from "./npmci.publish"; let command; @@ -9,10 +12,10 @@ let commandOption; plugins.commander .version('0.0.1') - .arguments(' [node]') - .action(function (commandArg, commandOptionArg) { - command = commandArg; - commandOption = commandOptionArg; + .arguments(' [commandoptionarg]') + .action(function (commandarg, commandoptionarg) { + command = commandarg; + commandOption = commandoptionarg; }); plugins.commander.parse(process.argv); @@ -24,7 +27,15 @@ if (typeof command === 'undefined') { switch (command){ case "install": - + install(commandOption); + break; + case "test": + test(commandOption); + break; + case "publish": + publish(); + break; + default: + break; } -shelljs.exec("bash -c \"source /usr/local/nvm/nvm.sh && nvm install "+ commandOption + " nvm alias default " + commandOption + "\""); \ No newline at end of file diff --git a/ts/npmci.install.ts b/ts/npmci.install.ts index a0261c0..560e700 100644 --- a/ts/npmci.install.ts +++ b/ts/npmci.install.ts @@ -1,3 +1,22 @@ +import "typings-global"; +import * as plugins from "./npmci.plugins"; export let install = (versionArg) => { - if(versionArg = ) + let done = plugins.q.defer(); + let version:string; + if(versionArg = "lts"){ + version = "4"; + } else { + version = versionArg; + }; + plugins.beautylog.log("now installing " + "node ".green + ("version " + version).yellow); + plugins.shelljs.exec( + "bash -c \"source /usr/local/nvm/nvm.sh && nvm install "+ + version + + " nvm alias default " + + version + + "\"" + ); + plugins.beautylog.success("Node version " + version + " successfully installed!"); + done.resolve(); + return done.promise; } \ No newline at end of file diff --git a/ts/npmci.plugins.ts b/ts/npmci.plugins.ts index b0ecd33..0de660d 100644 --- a/ts/npmci.plugins.ts +++ b/ts/npmci.plugins.ts @@ -1,4 +1,6 @@ import "typings-global"; export import beautylog = require("beautylog"); export let commander = require("commander"); -export let shelljs = require("shelljs"); \ No newline at end of file +export let q = require("q"); +export let shelljs = require("shelljs"); +export import smartfile = require("smartfile"); \ No newline at end of file diff --git a/ts/npmci.publish.ts b/ts/npmci.publish.ts index c59d563..7f94021 100644 --- a/ts/npmci.publish.ts +++ b/ts/npmci.publish.ts @@ -1,6 +1,15 @@ +import "typings-global"; +import * as plugins from "./npmci.plugins"; + let npmrcPrefix:string = "//registry.npmjs.org/:_authToken="; -let npmToken:string; +let npmToken:string = process.env.NPMCITOKEN; +let npmrcFileString = npmrcPrefix + npmToken; + export let publish = () => { + let done = plugins.q.defer(); + plugins.smartfile.memory.toFs(npmrcFileString,{fileName:".npmrc",filePath:"/root/"}); + plugins.shelljs.exec("npm publish"); + return done.promise; }; \ No newline at end of file diff --git a/ts/npmci.test.ts b/ts/npmci.test.ts index 485dec7..9102d08 100644 --- a/ts/npmci.test.ts +++ b/ts/npmci.test.ts @@ -1,3 +1,14 @@ -export let test = () => { - +import "typings-global"; +import * as plugins from "./npmci.plugins"; +import {install} from "./npmci.install"; +export let test = (versionArg) => { + let done = plugins.q.defer(); + install(versionArg) + .then(function(){ + plugins.beautylog.info("now starting tests:"); + plugins.shelljs.exec("npm test"); + plugins.beautylog.success("test finished"); + done.resolve(); + }) + return done.promise; } \ No newline at end of file