mu-kōän-generator 公案-ジェネレータ
Installation
$ npm i -g mu-koan-generator
Usage
To get started with a Koa 2.0.0+ REST JSON API use the command line executable mu-koan(1)
to generate an application as shown:
- Create the application:
$ mkdir my-awesome-api && cd my-awesome-api$ mu-koan info: [mu-koan] Creating project "my-awesome-api" into [/home/you/dev/my-awesome-api]info: [mu-koan] Created /home/you/dev/my-awesome-apiinfo: [mu-koan] Created /home/you/dev/my-awesome-api/.editorconfiginfo: [mu-koan] Created /home/you/dev/my-awesome-api/.eslintrcinfo: [mu-koan] Created /home/you/dev/my-awesome-api/.gitignoreinfo: [mu-koan] Created /home/you/dev/my-awesome-api/appinfo: [mu-koan] Created /home/you/dev/my-awesome-api/app.jsinfo: [mu-koan] Created /home/you/dev/my-awesome-api/app/configinfo: [mu-koan] Created /home/you/dev/my-awesome-api/app/config/index.jsinfo: [mu-koan] Created /home/you/dev/my-awesome-api/app/config/properties.jsoninfo: [mu-koan] Created /home/you/dev/my-awesome-api/app/logger.jsinfo: [mu-koan] Created /home/you/dev/my-awesome-api/app/routesinfo: [mu-koan] Created /home/you/dev/my-awesome-api/app/routes/status.jsinfo: [mu-koan] Created /home/you/dev/my-awesome-api/app/server.jsinfo: [mu-koan] Created /home/you/dev/my-awesome-api/build.jsoninfo: [mu-koan] Created /home/you/dev/my-awesome-api/gulpfile.js
This will run npm init
and npm install
after generating the initial scaffolding.
- Fire it up:
$ npm start [12:59:48] Using gulpfile ~/dev/js/my-awesome-api/gulpfile.js[12:59:48] Starting 'default'...[12:59:48] Starting 'eslint'...[12:59:49] Finished 'eslint' after 736 ms[12:59:49] Starting 'nodemon'......2016-07-22 12:59:49,648 - info: [my-awesome-api] Starting and configuring Koa server2016-07-22 12:59:49,662 - info: [my-awesome-api] Configuring routes
- Check everything's working as expected by requesting
/api/status
. In a new terminal session, run:
$ curl http://localhost:3000/api/status
You can change or remove the
/api
namespace by modifying"koa.routes.prefix"
option onapp/config/properties.json
or by starting the API withnpm start -- --koa.routes.prefix foo
.
Command line interface
Usage: mu-koan [-f --force] [-v] Options: -h, --help Show help [boolean] -v, --verbose Sets the verbosity level
Features
Along with a working webserver, the generator creates some common files that feature additional functionality or help you follow standard practices, such as:
- A gulpfile.js with some common tasks like
gulp eslint
for linting orgulp nodemon
to start a nodemon process. - Linting rules based on xo-space and semistandard ESLINT configurations.
- An
.editorconfig
file. - A
.gitignore
with many common entries (thanks to https://gitignore.io). - Includes mu-kōän as a dependency, so you get many helpful Koa middlewares out-of-the-box.
- Includes mu-kōän-router as a dependency for automatic controller discovery: just drop a
.js
file under/routes
. - A readily configured
winston
logger atapp/logger.js
. - A
routes/status.js
controller that prints out simple information on the running process onGET /api/status
. - Stores its configuration on an
nconf
instance, supporting command line arguments, environment variables and aconfig/properties.json
file as sources.
License
MIT