From cc60549468bb61c444012ff61700c1e901df0bdb Mon Sep 17 00:00:00 2001 From: Khoa Tran Date: Wed, 16 Aug 2017 07:30:06 +1000 Subject: [PATCH] refactor and clean up --- .babelrc | 8 - .eslintrc.json | 12 + .gitignore | 2 + package.json | 22 +- src/gitlabci-variables.js | 12 - src/gitlabci.js | 12 - ...lab-ci-project-handler.js => gitlab-ci.js} | 143 +- src/lib/properties-file-handler.js | 21 - src/lib/properties-file.js | 22 + src/setAllVariables.js | 79 + test/fixtures/{gitlab.env.yml => test.yml} | 0 ...dler.test.js => gitlab-ci-project.test.js} | 140 +- test/lib/properties-file-handler.test.js | 17 - test/lib/properties-file.test.js | 17 + yarn.lock | 2580 +++++++++++++++++ 15 files changed, 2870 insertions(+), 217 deletions(-) create mode 100644 .eslintrc.json delete mode 100644 src/gitlabci-variables.js delete mode 100644 src/gitlabci.js rename src/lib/{gitlab-ci-project-handler.js => gitlab-ci.js} (52%) delete mode 100644 src/lib/properties-file-handler.js create mode 100644 src/lib/properties-file.js create mode 100644 src/setAllVariables.js rename test/fixtures/{gitlab.env.yml => test.yml} (100%) rename test/lib/{gitlab-ci-project-handler.test.js => gitlab-ci-project.test.js} (51%) delete mode 100644 test/lib/properties-file-handler.test.js create mode 100644 test/lib/properties-file.test.js create mode 100644 yarn.lock diff --git a/.babelrc b/.babelrc index 6148fe3..19fe773 100644 --- a/.babelrc +++ b/.babelrc @@ -18,14 +18,6 @@ [ "transform-async-to-module-method", { "module": "bluebird", "method": "coroutine" } - ], - [ - "babel-plugin-transform-builtin-extend", - { - "globals": [ - "Error" - ] - } ] ] } diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000..33e8c48 --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "parser": "babel-eslint", + "extends": "airbnb-base", + "root": true, + "env": { + "node": true, + "mocha": true + }, + "rules": { + "no-console": 0 + } +} diff --git a/.gitignore b/.gitignore index 3c3629e..4b6e500 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ node_modules +bin +gitlab.env.yml diff --git a/package.json b/package.json index 37d9b4f..04599ff 100644 --- a/package.json +++ b/package.json @@ -1,28 +1,40 @@ { "name": "gitlab-ci", "version": "0.0.1", - "description": "CLI tool to interact with gitlab CI", + "description": "CLI tool to handle gitlab CI project variables", "author": "Khoa Tran", + "bin": { + "setAllVars": "bin/setAllVariables.js" + }, + "main": "bin/setAllVariables.js", + "files": [ + "bin" + ], "scripts": { + "lint": "$(npm bin)/eslint src", "test": "NODE_ENV=test $(npm bin)/mocha --recursive --compilers js:babel-core/register test", - "test:watch": "npm run test -- --watch" + "test:watch": "npm run test -- --watch", + "build": "$(npm bin)/babel src --out-dir bin", + "preversion": "npm run build && npm run lint" }, "dependencies": { "axios": "^0.16.2", "commander": "^2.11.0", "js-yaml": "^3.9.1", - "url-parse": "^1.1.9", - "yaml-js": "^0.2.0" + "url-parse": "^1.1.9" }, "devDependencies": { "axios-mock-adapter": "^1.9.0", "babel-cli": "^6.24.1", + "babel-eslint": "^7.2.3", "babel-plugin-transform-async-to-module-method": "^6.24.1", - "babel-plugin-transform-builtin-extend": "^1.1.2", "babel-plugin-transform-runtime": "^6.23.0", "babel-preset-env": "^1.6.0", "bluebird": "^3.5.0", "chai": "^4.1.1", + "eslint": "^4.4.1", + "eslint-config-airbnb-base": "^11.3.1", + "eslint-plugin-import": "^2.7.0", "mocha": "^3.5.0" } } diff --git a/src/gitlabci-variables.js b/src/gitlabci-variables.js deleted file mode 100644 index cd8a5ec..0000000 --- a/src/gitlabci-variables.js +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env node - -import program from 'commander' - -program - .command('setAll') - .description('Read all key/value pairs under gitlab.env.yml on the current directory and sets them as environment variables on Gitlab CI') - .parse(process.argv) - -if (!process.argv.slice(2).length) { - program.outputHelp() -} diff --git a/src/gitlabci.js b/src/gitlabci.js deleted file mode 100644 index 0c5872e..0000000 --- a/src/gitlabci.js +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env node - -import program from 'commander' - -program - .version(require('../package.json').version) - .command('variables