Skip to content

Commit

Permalink
Merge pull request #157 from KunalKapadia/develop-yarn
Browse files Browse the repository at this point in the history
Replace npm with yarn
  • Loading branch information
kunalkapadia authored Nov 23, 2016
2 parents 75338b7 + d52d19b commit fd49c9e
Show file tree
Hide file tree
Showing 4 changed files with 4,868 additions and 23 deletions.
6 changes: 2 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ language: node_js
node_js:
- "4.6"
- "6.9"
- "7.0"
- "7.2"
services:
- mongodb
cache:
directories:
- node_modules
git:
depth: 3
before_script:
- npm prune
after_script:
- npm run report-coverage
- yarn report-coverage
32 changes: 19 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ Heavily inspired from [Egghead.io - How to Write an Open Source JavaScript Libra
| Authentication via JsonWebToken | Supports authentication using [jsonwebtoken](https://www.npmjs.com/package/jsonwebtoken). |
| Code Linting | JavaScript code linting is done using [ESLint](http://eslint.org) - a pluggable linter tool for identifying and reporting on patterns in JavaScript. Uses ESLint with [eslint-config-airbnb](https://github.com/airbnb/javascript/tree/master/packages/eslint-config-airbnb), which tries to follow the Airbnb JavaScript style guide. |
| Auto server restart | Restart the server using [nodemon](https://github.com/remy/nodemon) in real-time anytime an edit is made, with babel compilation and eslint. |
| ES6 Code Coverage via [istanbul](https://www.npmjs.com/package/istanbul) | Supports code coverage of ES6 code using istanbul and mocha. Code coverage reports are saved in `coverage/` directory post `npm test` execution. Open `coverage/lcov-report/index.html` to view coverage report. `npm test` also displays code coverage summary on console. Code coverage can also be enforced overall and per file as well, configured via .istanbul.yml |
| ES6 Code Coverage via [istanbul](https://www.npmjs.com/package/istanbul) | Supports code coverage of ES6 code using istanbul and mocha. Code coverage reports are saved in `coverage/` directory post `yarn test` execution. Open `coverage/lcov-report/index.html` to view coverage report. `yarn test` also displays code coverage summary on console. Code coverage can also be enforced overall and per file as well, configured via .istanbul.yml |
| Debugging via [debug](https://www.npmjs.com/package/debug) | Instead of inserting and deleting console.log you can replace it with the debug function and just leave it there. You can then selectively debug portions of your code by setting DEBUG env variable. If DEBUG env variable is not set, nothing is displayed to the console. |
| Promisified Code via [bluebird](https://github.com/petkaantonov/bluebird) | We love promise, don't we ? All our code is promisified and even so our tests via [supertest-as-promised](https://www.npmjs.com/package/supertest-as-promised). |
| API parameter validation via [express-validation](https://www.npmjs.com/package/express-validation) | Validate body, params, query, headers and cookies of a request (via middleware) and return a response with errors; if any of the configured validation rules fail. You won't anymore need to make your route handler dirty with such validations. |
| Pre-commit hooks | Runs lint and tests before any commit is made locally, making sure that only tested and quality code is committed
| Secure app via [helmet](https://github.com/helmetjs/helmet) | Helmet helps secure Express apps by setting various HTTP headers. |
| Uses [yarn](https://yarnpkg.com) over npm | Uses new released yarn package manager by facebook. You can read more about it [here](https://code.facebook.com/posts/1840075619545360) |

- CORS support via [cors](https://github.com/expressjs/cors)
- Uses [http-status](https://www.npmjs.com/package/http-status) to set http status code. It is recommended to use `httpStatus.INTERNAL_SERVER_ERROR` instead of directly using `500` when setting status code.
Expand All @@ -44,41 +45,46 @@ git clone [email protected]:KunalKapadia/express-mongoose-es6-rest-api.git
cd express-mongoose-es6-rest-api
```

Install yarn:
```js
npm install -g yarn
```

Install dependencies:
```sh
npm install
yarn
```

Start server:
```sh
# Start server
npm start
yarn start

# Selectively set DEBUG env var to get logs
DEBUG=express-mongoose-es6-rest-api:* npm start
DEBUG=express-mongoose-es6-rest-api:* yarn start
```
Refer [debug](https://www.npmjs.com/package/debug) to know how to selectively turn on logs.


Tests:
```sh
# Run tests written in ES6 along with code coverage
npm test
yarn test

# Run tests on file change
npm run test:watch
yarn test:watch

# Run tests enforcing code coverage (configured via .istanbul.yml)
npm run test:check-coverage
yarn test:check-coverage
```

Lint:
```sh
# Lint code with ESLint
npm run lint
yarn lint

# Run lint on any file change
npm run lint:watch
yarn lint:watch
```

Other gulp tasks:
Expand All @@ -94,13 +100,13 @@ gulp

```sh
# compile to ES5
1. npm run build
1. yarn build

# upload dist/ to your server
2. scp -rp dist/ user@dest:/path

# install production dependencies only
3. npm i --production
3. yarn --production

# Use any process manager to start your services
4. pm2 start dist/index.js
Expand All @@ -122,10 +128,10 @@ Logs stacktrace of error to console along with other details. You should ideally
![Error logging](https://cloud.githubusercontent.com/assets/4172932/12563361/fb9ef108-c3cf-11e5-9a58-3c5c4936ae3e.JPG)

## Code Coverage
Get code coverage summary on executing `npm test`
Get code coverage summary on executing `yarn test`
![Code Coverage Text Summary](https://cloud.githubusercontent.com/assets/4172932/12827832/a0531e70-cba7-11e5-9b7c-9e7f833d8f9f.JPG)

`npm test` also generates HTML code coverage report in `coverage/` directory. Open `lcov-report/index.html` to view it.
`yarn test` also generates HTML code coverage report in `coverage/` directory. Open `lcov-report/index.html` to view it.
![Code coverage HTML report](https://cloud.githubusercontent.com/assets/4172932/12625331/571a48fe-c559-11e5-8aa0-f9aacfb8c1cb.jpg)

## A Boilerplate-only Option
Expand Down
13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@
"main": "index.js",
"private": false,
"engines": {
"node": ">=4.6.x",
"npm": ">=2.15.x"
"node": ">=4.6.0",
"npm": ">=2.15.9",
"yarn": ">=0.17.9"
},
"scripts": {
"start": "gulp serve",
"build": "gulp",
"lint": "esw *.js server config --color",
"lint:watch": "npm run lint -- --watch",
"lint:watch": "yarn lint -- --watch",
"test": "NODE_ENV=test babel-node node_modules/.bin/isparta cover _mocha -- --ui bdd --reporter spec --colors --compilers js:babel-core/register ./server/**/*.test.js",
"test:watch": "npm run test -- --watch",
"test:check-coverage": "npm run test && istanbul check-coverage",
"test:watch": "yarn test -- --watch",
"test:check-coverage": "yarn test && istanbul check-coverage",
"report-coverage": "coveralls < ./coverage/lcov.info"
},
"repository": {
Expand Down Expand Up @@ -89,7 +90,7 @@
"license": "MIT",
"config": {
"ghooks": {
"pre-commit": "npm run lint && npm test"
"pre-commit": "yarn lint && yarn test"
},
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
Expand Down
Loading

0 comments on commit fd49c9e

Please sign in to comment.