<commit_before><p align="center">
  <a href="#">
    <img alt="MOKY" src="https://dn-getlink.qbox.me/0oxtp9ie44vq7m7b7kqpvi.png"/>
  </a>
</p>

# moky = mock + proxy

[![JavaScript Style Guide](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard)

[![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url]  [![Downloads][downloads-image]][npm-url]

A proxy server with mock

## How to use

If you have experience in [webpack](https://github.com/webpack/webpack), it'll be a piece of cake!

Here comes the quick start:

 - Install as a global command, `npm i moky -g`
 - Create a file named `moky.config.js` in your project
 - Run `moky` in the same directory with `moky.config.js`

...Yeah, it'll not work actually :-) You need edit `moky.config.js` at first.

## Quick start

If you really want to have a try, clone the project to disk

 - `cd moky/example`
 - Run `moky`
 - Open `http://localhost:3000` & `http://localhost:3000/page` (default to mock mode)
 - Exit and **re**run `moky -e dev`, refresh two pages (async request is pass to proxy)

## Configure

The following is just a example, edit as your ways.

`cat moky.config.js`

```javascript
var path = require('path');

module.exports = {
  /* Listen port for moky server, OPTIONAL */
  localPort: 3000,
  /* Show detail log, OPTIONAL(default false) */
  verbose: false,
  /* Asnyc api mock data, OPTIONAL */
  asyncMockPath: path.join(__dirname, 'mock'),
  /* Template mock data, OPTIONAL */
  viewsMockPath: path.join(__dirname, 'tplMock'),
  /* Root directory for template rendering, REQUIRED */
  viewsPath: path.join(__dirname, 'views'),
  /* Path of favicon.ico, OPTIONAL */
  faviconPath: path.join(__dirname, 'public', 'favicon.ico'),
  /* Static router, OPTIONAL but usually required */
  publicPaths: {
    '/css': path.join(__dirname, 'public', 'css'),
    '/js': path.join(__dirname, 'public', 'js'),
  },
  /* Template engine settings, the same as koa-views, REQUIRED */
  viewConfig: {
    extension: 'html',
    map: { html: 'nunjucks' },
  },
  /* Host name of proxy, works for `virtual hosts`, OPTIONAL */
  hostName: 'hacker-news.firebaseio.com',
  /* Settings for proxy, OPTIONAL */
  proxyMaps: {
    dev: 'https://hacker-news.firebaseio.com',
    local: 'http://localhost:8080',
  },
  /* No show logs if url is in the list, OPTIONAL */
  filteredUrls: [],
  /* Settings for template page routing, REQUIRED */
  urlMaps: {
    '/': 'index',
    '/page': 'page/index',
  },
}
```

## Template engine

The `moky` has integrated some major template engines, if your template is one of the following type, your don't need to do anything, it works well.

  - freemarker (`JAVA_HOME` should set correctly)
  - handlebars
  - nunjucks
  - ejs

**BUT**, for we use [koa-views](https://github.com/queckezz/koa-views) and koa-views use [consolidate.js](https://github.com/tj/consolidate.js), it's quite easy to enable a template engine, if you use a template engine we don't include, issues welcome :-)

## More

`moky -h`
```text
Usage: moky [options]

Options:
  -c, --config  Configure file path                  [default: "moky.config.js"]
  -e, --env     Debug env, see <proxyMaps> in configure file     [default: "mock"]
  -h, --help    Show help                                              [boolean]
```

## Integrate in your app

It's easy to integrate moky in your own cli app.

 - Install as dependencies: `npm i moky -S`
 - In the entry of your app:
 ```javascript
 import path from 'path'
 import { moky, parseConfig } from 'moky'

 // get path of moky.config.js and env
 // you can use commander.js or yargs

 const options = parseConfig(path.resolve(config))
 options.env = env

 moky(options)
 ```

## Tips<commit_msg>docs: update options & helps<commit_after><p align="center">
  <a href="#">
    <img alt="MOKY" src="https://dn-getlink.qbox.me/0oxtp9ie44vq7m7b7kqpvi.png"/>
  </a>
</p>

# moky = mock + proxy

[![JavaScript Style Guide](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard)

[![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url]  [![Downloads][downloads-image]][npm-url]

A proxy server with mock

## How to use

If you have experience in [webpack](https://github.com/webpack/webpack), it'll be a piece of cake!

Here comes the quick start:

 - Install as a global command, `npm i moky -g`
 - Create a file named `moky.config.js` in your project
 - Run `moky` in the same directory with `moky.config.js`

...Yeah, it'll not work actually :-) You need edit `moky.config.js` at first.

## Quick start

If you really want to have a try, clone the project to disk

 - `cd moky/example`
 - Run `moky`
 - Open `http://localhost:3000` & `http://localhost:3000/page` (default to mock mode)
 - Exit and **re**run `moky -e dev`, refresh two pages (async request is pass to proxy)

## Configure

The following is just a example, edit as your ways.

`cat moky.config.js`

```javascript
var path = require('path');

module.exports = {
  /* Listen port for moky server, OPTIONAL */
  localPort: 3000,
  /* Show detail log, OPTIONAL(default false) */
  verbose: false,
  /* Auto create mock file if not exists, OPTIONAL */
  autoGenMock: false,
  /* Asnyc api mock data, OPTIONAL */
  asyncMockPath: path.join(__dirname, 'mock'),
  /* Template mock data, OPTIONAL */
  viewsMockPath: path.join(__dirname, 'tplMock'),
  /* Root directory for template rendering, REQUIRED */
  viewsPath: path.join(__dirname, 'views'),
  /* Path of favicon.ico, OPTIONAL */
  faviconPath: path.join(__dirname, 'public', 'favicon.ico'),
  /* Static router, OPTIONAL but usually required */
  publicPaths: {
    '/css': path.join(__dirname, 'public', 'css'),
    '/js': path.join(__dirname, 'public', 'js'),
  },
  /* Template engine settings, the same as koa-views, REQUIRED */
  viewConfig: {
    extension: 'html',
    map: { html: 'nunjucks' },
  },
  /* Host name of proxy, works for `virtual hosts`, OPTIONAL */
  hostName: 'hacker-news.firebaseio.com',
  /* Settings for proxy, OPTIONAL */
  proxyMaps: {
    dev: 'https://hacker-news.firebaseio.com',
    local: 'http://localhost:8080',
  },
  /* Not show logs if url is in the list, OPTIONAL */
  filteredUrls: [],
  /* Settings for template page routing, REQUIRED */
  urlMaps: {
    '/': 'index',
    '/page': 'page/index',
  },
}
```

## Template engine

The `moky` has integrated some major template engines, if your template is one of the following type, your don't need to do anything, it works well.

  - freemarker (`JAVA_HOME` should set correctly)
  - handlebars
  - nunjucks
  - ejs

**BUT**, for we use [koa-views](https://github.com/queckezz/koa-views) and koa-views use [consolidate.js](https://github.com/tj/consolidate.js), it's quite easy to enable a template engine, if you use a template engine we don't include, issues welcome :-)

## More

`moky -h`
```text
Usage: moky [options]

Options:
  -c, --config   Configure file path                 [default: "moky.config.js"]
  -e, --env      Debug env, see <proxyMaps> in configure file  [default: "mock"]
  -h, --help     Show help                                             [boolean]
  -V, --verbose  Show detail log
  -n, --new      Auto create mock file if not exists
  -v, --version  Show version number                                   [boolean]
```

## Integrate in your app

It's easy to integrate moky in your own cli app.

 - Install as dependencies: `npm i moky -S`
 - In the entry of your app:
 ```javascript
 import path from 'path'
 import { moky, parseConfig } from 'moky'

 // get path of moky.config.js and env
 // you can use commander.js or yargs

 const options = parseConfig(path.resolve(config))
 options.env = env

 moky(options)
 ```
For more, see `src/cli.js`

## Tips
{'fraction_non_alphanumeric': 0.14548708770135516, 'fraction_numerical': 0.005880848887752493, 'mean_word_length': 3.221802482460874, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 14, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 9, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2906620', 'n_tokens_mistral': 2685, 'n_tokens_neox': 2544, 'n_words': 852}