Skip to content

Commit

Permalink
build(process): improved build process
Browse files Browse the repository at this point in the history
BREAKING CHANGE: module export directory
  • Loading branch information
Ahmad Nassri committed Dec 13, 2016
1 parent a5a912a commit fc5bb60
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 72 deletions.
19 changes: 8 additions & 11 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -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"]
}
}
}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*.log
/lib
/build
/node_modules
/.nyc_output
29 changes: 15 additions & 14 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
language: node_js

node_js:
- 4
- 6
- 7

env:
- BABEL_ENV=test
- 6
- 4

matrix:
fast_finish: true
Expand All @@ -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:
Expand Down
43 changes: 18 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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])`
Expand Down Expand Up @@ -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

Expand Down
33 changes: 12 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
14 changes: 14 additions & 0 deletions test/build.js
Original file line number Diff line number Diff line change
@@ -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)
}
})

0 comments on commit fc5bb60

Please sign in to comment.