Skip to content

Commit

Permalink
🔖 Bump version to 1.1.0, upgrade to Babel 7
Browse files Browse the repository at this point in the history
  • Loading branch information
pranavpr committed Sep 30, 2018
1 parent 23cd662 commit 0fda42d
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 33 deletions.
21 changes: 13 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
[![Dependency Status](https://david-dm.org/pranavpr/koa-api-generator.svg?maxAge=43200)](https://david-dm.org/pranavpr/koa-api-generator)
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)


A mostly unopinionated generator for creating Rest APIs using Koa2 and ES2017+ features in a Node.js server environment as well as providing linting and testing support. It provides the setup for compiling, linting and testing your code but doesn't make any further assumptions on how your project should be structured.

Make sure you read the FAQ for more details and info.

### Features:

- [Koa](http://koajs.com/) as the web framework.
- ES2017+ support with [Babel](https://babeljs.io/).
- Automatic polyfill requires based on environment with [babel-preset-env](https://github.com/babel/babel-preset-env).
- Automatic polyfill requires based on environment with [@babel/preset-env](https://github.com/babel/babel/tree/master/packages/babel-preset-env).
- Linting with [ESLint](http://eslint.org/).
- Testing with [Jest](https://facebook.github.io/jest/).

Expand All @@ -28,18 +28,22 @@ yarn add global koa-api-generator
```

## Quick Start

Create the app:

```sh
koa-api /tmp/foo && cd /tmp/foo
```

Install dependencies:

```sh
npm install

# or if you're using Yarn
yarn
```

_If you don't use [Yarn](https://yarnpkg.com/) you can just replace `yarn` with `npm` in the commands that follow._

Then you can begin development:
Expand Down Expand Up @@ -68,7 +72,7 @@ yarn test --coverage

### Linting

Linting is set up using [ESLint](http://eslint.org/). It uses ESLint's default [eslint:recommended](https://github.com/eslint/eslint/blob/master/conf/eslint.json) rules. Feel free to use your own rules and/or extend another popular linting config (e.g. [airbnb's](https://www.npmjs.com/package/eslint-config-airbnb) or [standard](https://github.com/feross/eslint-config-standard)).
Linting is set up using [ESLint](http://eslint.org/). It uses ESLint's default [eslint:recommended](https://eslint.org/docs/rules/) rules. Feel free to use your own rules and/or extend another popular linting config (e.g. [airbnb's](https://www.npmjs.com/package/eslint-config-airbnb) or [standard](https://github.com/feross/eslint-config-standard)).

Begin linting in watch mode with:

Expand All @@ -78,7 +82,7 @@ yarn run lint

### Environmental variables in development

The project uses [dotenv](https://www.npmjs.com/package/dotenv) for setting environmental variables during development. Simply copy `.env.example`, rename it to `.env` and add your env vars as you see fit.
The project uses [dotenv](https://www.npmjs.com/package/dotenv) for setting environmental variables during development. Simply copy `.env.example`, rename it to `.env` and add your env vars as you see fit.

It is **strongly** recommended **never** to check in your .env file to version control. It should only include environment-specific values such as database passwords or API keys used in development. Your production env variables should be different and be set differently depending on your hosting solution. `dotenv` is only for development.

Expand All @@ -90,7 +94,7 @@ Deployment is specific to hosting platform/provider but generally:
yarn run build
```

will compile your src into `/dist`, and
will compile your src into `/dist`, and

```sh
yarn start
Expand All @@ -106,11 +110,12 @@ The last command is generally what most hosting providers use to start your appl

In `package.json`. Feel free to extract them in separate respective config files if you like.

**Why are you using `babel-register` instead of `babel-node`?**
**Why are you using `@babel/register` instead of `@babel/node`?**

`babel-node` contains a small "trap", it loads Babel's [polyfill](https://babeljs.io/docs/usage/polyfill/) by default. This means that if you use something that needs to be polyfilled, it'll work just fine in development (because `babel-node` polyfills it automatically) but it'll break in production because it needs to be explicitely included in Babel's CLI which handles the final build.
`@babel/node` contains a small "trap", it loads Babel's [polyfill](https://babeljs.io/docs/usage/polyfill/) by default. This means that if you use something that needs to be polyfilled, it'll work just fine in development (because `@babel/node` polyfills it automatically) but it'll break in production because it needs to be explicitely included in Babel's CLI which handles the final build.

In order to avoid such confusions, `babel-register` is a more sensible approach in keeping the development and production runtimes equal. By using [babel-preset-env](https://github.com/babel/babel-preset-env) only code that's not supported by the running environment is transpiled and any polyfills required are automatically inserted.
In order to avoid such confusions, `@babel/register` is a more sensible approach in keeping the development and production runtimes equal. By using [@babel/preset-env](https://github.com/babel/babel/tree/master/packages/babel-preset-env) only code that's not supported by the running environment is transpiled and any polyfills required are automatically inserted.

## License

MIT License. See the [LICENSE](LICENSE) file.
46 changes: 24 additions & 22 deletions bin/koa-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,55 +150,57 @@ function createApplication(name, path) {
private: true,
main: 'dist/index.js',
engines: {
node: '~8.5.0',
npm: '>=5.3.0'
node: '~8.12.0',
npm: '>=6.4.1'
},
scripts: {
prestart: 'npm run -s build',
start: 'node dist/index.js',
dev:
'nodemon src/index.js --exec "node -r dotenv/config -r babel-register"',
'nodemon src/index.js --exec "node -r dotenv/config -r @babel/register"',
clean: 'rimraf dist',
build: 'npm run clean && mkdir -p dist && babel src -s -D -d dist',
test: 'jest',
lint: 'esw -w src test'
},
dependencies: {
'@koa/cors': '2',
'babel-cli': '^6.26.0',
'babel-plugin-transform-object-rest-spread': '^6.26.0',
'babel-preset-env': '^1.6.0',
koa: '^2.3.0',
'koa-bodyparser': '^4.2.0',
'@babel/cli': '^7.1.0',
'@babel/core': '^7.1.0',
'@babel/plugin-proposal-object-rest-spread': '^7.0.0',
'@babel/preset-env': '^7.1.0',
koa: '^2.5.3',
'koa-bodyparser': '^4.2.1',
'koa-morgan': '^1.0.1',
'koa-router': '^7.2.1',
'koa-router': '^7.4.0',
rimraf: '^2.6.2'
},
devDependencies: {
'babel-eslint': '^8.0.0',
'babel-jest': '^21.0.2',
'babel-register': '^6.26.0',
dotenv: '^4.0.0',
eslint: '^4.7.2',
'eslint-plugin-import': '^2.7.0',
'eslint-plugin-jest': '^21.1.0',
'eslint-watch': '^3.1.2',
jest: '^21.1.0',
nodemon: '^1.12.1',
supertest: '^3.0.0'
'babel-eslint': '^10.0.1',
'babel-jest': '^23.6.0',
'@babel/register': '^7.0.0',
'babel-core': '7.0.0-bridge.0',
dotenv: '^6.0.0',
eslint: '^5.6.1',
'eslint-plugin-import': '^2.14.0',
'eslint-plugin-jest': '^21.23.0',
'eslint-watch': '^4.0.2',
jest: '^23.6.0',
nodemon: '^1.18.4',
supertest: '^3.3.0'
},
babel: {
presets: [
[
'env',
'@babel/preset-env',
{
targets: {
node: 'current'
}
}
]
],
plugins: ['transform-object-rest-spread'],
plugins: ['@babel/plugin-proposal-object-rest-spread'],
sourceMaps: true,
retainLines: true
},
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "koa-api-generator",
"version": "1.0.4",
"version": "1.1.0",
"description": "Koa API generator",
"main": "./bin/koa-api.js",
"preferGlobal": true,
Expand All @@ -14,7 +14,14 @@
"type": "git",
"url": "git+ssh://git@github.com/pranavpr/koa-api-generator.git"
},
"keywords": ["koa", "koa2", "api", "generator", "boilerplate", "jest"],
"keywords": [
"koa",
"koa2",
"api",
"generator",
"boilerplate",
"jest"
],
"author": "Pranav Prakash <pranav@pranavprakash.net>",
"license": "MIT",
"bugs": {
Expand Down

0 comments on commit 0fda42d

Please sign in to comment.