diff --git a/.babelrc b/.babelrc index 765ba8b..6a9c1d5 100644 --- a/.babelrc +++ b/.babelrc @@ -1,23 +1,20 @@ { - "env": { - "test": { - "presets": [ ["env", { "targets": { "node": "current" } }] ], - "plugins": [] - }, + "presets": [ ["env", { "targets": { "node": "current" } }] ], - "v4": { + "env": { + "node4": { "presets": [ ["env", { "targets": { "node": 4.0 } }] ], - "plugins": ["babel-plugin-add-module-exports"] + "plugins": ["add-module-exports"] }, - "v6": { + "node6": { "presets": [ ["env", { "targets": { "node": 6.0 } }] ], - "plugins": ["babel-plugin-add-module-exports"] + "plugins": ["add-module-exports"] }, - "v7": { + "node7": { "presets": [ ["env", { "targets": { "node": 7.0 } }] ], - "plugins": ["babel-plugin-add-module-exports"] + "plugins": ["add-module-exports"] } } } diff --git a/.gitignore b/.gitignore index 1bfd37a..6fd2ec3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ *.log -/lib +/build /node_modules /.nyc_output diff --git a/.travis.yml b/.travis.yml index cc70a14..38bc1f4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,12 +1,9 @@ language: node_js node_js: - - 4 - - 6 - 7 - -env: - - BABEL_ENV=test + - 6 + - 4 matrix: fast_finish: true @@ -15,16 +12,20 @@ cache: directories: - node_modules -before_script: - - npm prune - after_success: - - npm run coverage - - npm run codeclimate - - BABEL_ENV=v4 npm run compile -- -d lib - - BABEL_ENV=v6 npm run compile -- -d lib/node6 - - BABEL_ENV=v7 npm run compile -- -d lib/node7 - - npm run semantic-release + - npm install --only=production codeclimate-test-reporter semantic-release + +before_deploy: + - npm run coverage -- --coverage-report=text-lcov | codeclimate-test-reporter + +deploy: + skip_cleanup: true + provider: script + script: semantic-release pre && npm publish && semantic-release post || true + + on: + branch: master + node: 7 branches: except: diff --git a/README.md b/README.md index 08906fa..82a7610 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# api-problem [![version][npm-version]][npm-url] [![License][npm-license]][license-url] +# API Problem [![version][npm-version]][npm-url] [![License][license-image]][license-url] > [HTTP Problem](https://tools.ietf.org/html/draft-ietf-appsawg-http-problem) Utility @@ -15,28 +15,6 @@ npm install --only=production --save api-problem ``` -## Usage - -I recommend using an optimized build matching your Node.js environment version, otherwise, the standard `require` would work just fine with any version of Node `>= v4.0` . - -```js -/* - * Node 7 - */ -const Problem = require('api-problem/lib/node7') - -/* - * Node 6 - */ -const Problem = require('api-problem/lib/node6') - -/* - * Node 4 (Default) - * Note: additional ES2015 polyfills may be required - */ -var Problem = require('api-problem') -``` - ## API ### Constructor: `Problem(status[, title][, type][, members])` @@ -128,19 +106,34 @@ app.get('/', (req, res) => { app.use(Problem.Middleware) ``` ----- +## Targeted Builds + +an optimized build is made available for every major Node.js version marked as [Active LTS](https://github.com/nodejs/LTS). + +```js +// Node 7 +const api-problem = require('api-problem/build/node7') + +// Node 6 +const api-problem = require('api-problem/build/node6') + +// Node 4 (Default) +var api-problem = require('api-problem') +``` + +--- > :copyright: [ahmadnassri.com](https://www.ahmadnassri.com/)  ·  > License: [ISC][license-url]  ·  > Github: [@ahmadnassri](https://github.com/ahmadnassri)  ·  > Twitter: [@ahmadnassri](https://twitter.com/ahmadnassri) [license-url]: http://choosealicense.com/licenses/isc/ +[license-image]: https://img.shields.io/github/license/ahmadnassri/api-problem.svg?style=flat-square [travis-url]: https://travis-ci.org/ahmadnassri/api-problem [travis-image]: https://img.shields.io/travis/ahmadnassri/api-problem.svg?style=flat-square [npm-url]: https://www.npmjs.com/package/api-problem -[npm-license]: https://img.shields.io/npm/l/api-problem.svg?style=flat-square [npm-version]: https://img.shields.io/npm/v/api-problem.svg?style=flat-square [npm-downloads]: https://img.shields.io/npm/dm/api-problem.svg?style=flat-square diff --git a/package.json b/package.json index 2a9b297..73b396c 100644 --- a/package.json +++ b/package.json @@ -9,54 +9,45 @@ "url": "https://github.com/ahmadnassri/api-problem.git" }, "license": "ISC", - "main": "lib/index.js", + "main": "build/node4/index.js", "keywords": [ "api", "http", "problem" ], "engines": { - "node": ">= 4" + "node": ">=4" }, "files": [ - "lib", + "build", "src" ], "bugs": { "url": "https://github.com/ahmadnassri/api-problem/issues" }, "scripts": { - "compile": "babel -q src", - "test": "BABEL_ENV=test tap test/*.js --reporter spec --node-arg=--require --node-arg=babel-register", - "pretest": "snazzy && echint", - "coverage": "BABEL_ENV=test tap test/*.js --reporter silent --coverage --nyc-arg=--require --nyc-arg=babel-register", - "codeclimate": "BABEL_ENV=test tap --coverage-report=text-lcov | codeclimate-test-reporter", - "semantic-release": "semantic-release pre && npm publish && semantic-release post" + "build": "babel-build-all", + "lint": "snazzy && echint", + "pretest": "npm run lint && npm run build", + "test": "tap test --node-arg=--require --node-arg=babel-register", + "coverage": "tap test --reporter silent --coverage --nyc-arg=--require --nyc-arg=babel-register" }, "standard": { "ignore": [ - "lib/**" + "build/**" ] }, "echint": { "ignore": [ - "lib/**" + "build/**" ] }, - "config": { - "commitizen": { - "path": "./node_modules/cz-conventional-changelog" - } - }, "devDependencies": { - "babel-cli": "^6.18.0", + "@ahmadnassri/babel-build-all": "^1.3.0", "babel-plugin-add-module-exports": "^0.2.1", - "babel-preset-env": "1.0.2", + "babel-preset-env": "^1.0.2", "babel-register": "^6.18.0", - "codeclimate-test-reporter": "^0.4.0", - "cz-conventional-changelog": "^1.2.0", "echint": "^2.1.0", - "semantic-release": "^6.3.2", "snazzy": "^5.0.0", "tap": "^8.0.1" } diff --git a/test/build.js b/test/build.js new file mode 100644 index 0000000..7724dc1 --- /dev/null +++ b/test/build.js @@ -0,0 +1,14 @@ +'use strict' + +const tap = require('tap') + +tap.test('build', assert => { + assert.plan(1) + + try { + var module = require(`../build/node${process.version.slice(1, 2)}/`) + assert.type(module, 'function', 'should export a function') + } catch (e) { + assert.error(e) + } +})