egg-bin
egg developer tool
Last updated a month ago by dead_horse .
Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install egg-bin 
SYNC missed versions from official npm registry.

egg-bin

NPM version build status Test coverage David deps Known Vulnerabilities npm download

egg developer tool, extends common-bin.


Install

$ npm i egg-bin --save-dev

Usage

Add egg-bin to package.json scripts:

{
  "scripts": {
    "dev": "egg-bin dev",
    "debug": "egg-bin debug",
    "test-local": "egg-bin test",
    "test": "npm run lint -- --fix && npm run test-local",
    "cov": "egg-bin cov",
    "lint": "eslint .",
    "pkgfiles": "egg-bin pkgfiles",
    "autod": "egg-bin autod",
    "ci": "npm run lint && npm run autod -- --check && npm run pkgfiles -- --check && npm run cov"
  }
}

Command

All the commands support these specific v8 options:

  • --debug
  • --inspect
  • --harmony*
  • --es_staging
$ egg-bin [command] --debug --es_staging

if process.env.NODE_DEBUG_OPTION is provided (WebStorm etc), will use it as debug options.

dev

Start dev cluster on local env, it will start a master, an agent and a worker.

$ egg-bin dev
options
  • --framework egg web framework root path.
  • --baseDir application's root path, default to process.cwd().
  • --port server port, default to 7001.
  • --cluster worker process number, skip this argvs will start only 1 worker, provide this without value will start cpu count worker.
  • --sticky start a sticky cluster server, default to false.
  • --typescript / --ts enable typescript support, default to false. Also support read from package.json's egg.typescript.
  • --require will add to execArgv, support multiple.

debug

Debug egg app with V8 Inspector Integration.

automatically detect the protocol, use the new inspector when the targeted runtime >=7.0.0 .

if running without VSCode or WebStorm, we will use inspector-proxy to proxy worker debug, so you don't need to worry about reload.

$ egg-bin debug --debug-port=9229 --proxy=9999
options
  • all egg-bin dev options is accepted.
  • --proxy=9999 worker debug proxy port.

test

Using mocha with co-mocha to run test.

power-assert is the default assert library, and intelli-espower-loader will be auto required.

$ egg-bin test [files] [options]
  • files is optional, default to test/**/*.test.js
  • test/fixtures, test/node_modules is always exclude.

auto require test/.setup.js

If test/.setup.js file exists, it will be auto require as the first test file.

test
  ├── .setup.js
  └── foo.test.js

options

You can pass any mocha argv.

  • --require require the given module
  • --grep only run tests matching <pattern>
  • --timeout milliseconds, default to 30000
  • --full-trace display the full stack trace, default to false.
  • --typescript / --ts enable typescript support, default to false.
  • --changed / -c only test changed test files(test files means files that match ${pwd}/test/**/*.test.(js|ts))
  • see more at https://mochajs.org/#usage

environment

Environment is also support, will use it if options not provide.

You can set TESTS env to set the tests directory, it support glob grammar.

TESTS=test/a.test.js egg-bin test

And the reporter can set by the TEST_REPORTER env, default is spec.

TEST_REPORTER=doc egg-bin test

The test timeout can set by TEST_TIMEOUT env, default is 30000 ms.

TEST_TIMEOUT=2000 egg-bin test

cov

Using [nyc] to run code coverage, it support all test params above.

Coverage reporter will output text-summary, json and lcov.

options

You can pass any mocha argv.

  • -x add dir ignore coverage, support multiple argv

  • --prerequire prerequire files for coverage instrument, you can use this options if load files slowly when call mm.app or mm.cluster

  • --typescript / --ts enable typescript support, default to false, if true, will auto add .ts extension and ignore typings and d.ts.

  • --nyc nyc instruments passthrough. you can use this to overwrite egg-bin's default nyc instruments and add additional ones.

    if you want to add addtional nyc reporters, you need to use this rather than add reporter key in .nycrc because:

    • when same key exists in .nycrc and cmd instruments, nyc prefers instrument.
    • egg-bin have some default instruments passed to nyc like -r and --temp-directory
    • egg-bin cov --nyc="-r teamcity -r text"
  • also support all test params above.

environment

You can set COV_EXCLUDES env to add dir ignore coverage.

$ COV_EXCLUDES="app/plugins/c*,app/autocreate/**" egg-bin cov

pkgfiles

Generate pkg.files automatically before npm publish, see ypkgfiles for detail

$ egg-bin pkgfiles

autod

Generate pkg.dependencies and pkg.devDependencies automatically, see autod for detail

$ egg-bin autod

Custom egg-bin for your team

You maybe need a custom egg-bin to implement more custom features if your team has develop a framework base on egg.

Now you can implement a Command sub class to do that. Or you can just override the exists command.

See more at common-bin.

Example: Add nsp for security scan

nsp has provide a useful security scan feature.

This example will show you how to add a new NspCommand to create a new egg-bin tool.

my-egg-bin

const EggBinCommand = require('egg-bin');

class MyEggBinCommand extends EggBinCommand {
  constructor(rawArgv) {
    super(rawArgv);
    this.usage = 'Usage: egg-bin [command] [options]';

    // load directory
    this.load(path.join(__dirname, 'lib/cmd'));
  }
}

module.exports = MyEggBinCommand;

NspCommand

const Command = require('egg-bin').Command;

class NspCommand extends Command {
  * run({ cwd, argv }) {
    console.log('run nsp check at %s with %j', cwd, argv);
  }

  description() {
    return 'nsp check';
  }
}

module.exports = NspCommand;

my-egg-bin.js

#!/usr/bin/env node

'use strict';
const Command = require('..');
new Command().start();

Run result

$ my-egg-bin nsp

run nsp check at /foo/bar with {}

License

MIT

Current Tags

  • 4.9.0                                ...           latest (a month ago)
  • 1.8.0-test                                ...           test (2 years ago)

81 Versions

  • 4.9.0                                ...           a month ago
  • 4.8.5                                ...           a month ago
  • 4.8.4                                ...           2 months ago
  • 4.8.3                                ...           2 months ago
  • 4.8.2                                ...           2 months ago
  • 4.8.1                                ...           3 months ago
  • 4.8.0                                ...           3 months ago
  • 4.7.1                                ...           4 months ago
  • 4.7.0                                ...           6 months ago
  • 4.6.3                                ...           7 months ago
  • 4.6.2                                ...           7 months ago
  • 4.6.1                                ...           7 months ago
  • 4.6.0                                ...           7 months ago
  • 4.5.0                                ...           7 months ago
  • 4.4.1                                ...           7 months ago
  • 4.4.0                                ...           8 months ago
  • 4.3.7                                ...           10 months ago
  • 4.3.6                                ...           a year ago
  • 4.3.5                                ...           a year ago
  • 4.3.4                                ...           a year ago
  • 4.3.3                                ...           a year ago
  • 4.3.2                                ...           a year ago
  • 4.3.1                                ...           a year ago
  • 4.3.0                                ...           a year ago
  • 4.2.0                                ...           a year ago
  • 4.1.0                                ...           a year ago
  • 4.0.5                                ...           a year ago
  • 4.0.4                                ...           a year ago
  • 4.0.3                                ...           a year ago
  • 4.0.2                                ...           a year ago
  • 4.0.1                                ...           a year ago
  • 4.0.0                                ...           a year ago
  • 3.7.0                                ...           a year ago
  • 1.11.1                                ...           a year ago
  • 3.6.0                                ...           a year ago
  • 3.4.2                                ...           a year ago
  • 3.4.1                                ...           a year ago
  • 3.4.0                                ...           a year ago
  • 3.3.2                                ...           a year ago
  • 3.3.1                                ...           a year ago
  • 3.3.0                                ...           2 years ago
  • 3.2.1                                ...           2 years ago
  • 3.2.0                                ...           2 years ago
  • 3.1.0                                ...           2 years ago
  • 3.0.1                                ...           2 years ago
  • 3.0.0                                ...           2 years ago
  • 2.4.0                                ...           2 years ago
  • 2.3.0                                ...           2 years ago
  • 2.2.3                                ...           2 years ago
  • 2.2.2                                ...           2 years ago
  • 2.2.1                                ...           2 years ago
  • 2.2.0                                ...           2 years ago
  • 2.1.0                                ...           2 years ago
  • 1.10.3                                ...           2 years ago
  • 2.0.2                                ...           2 years ago
  • 1.10.2                                ...           2 years ago
  • 2.0.1                                ...           2 years ago
  • 2.0.0                                ...           2 years ago
  • 1.10.1                                ...           2 years ago
  • 1.10.0                                ...           2 years ago
  • 1.9.1                                ...           2 years ago
  • 1.9.0                                ...           2 years ago
  • 1.8.1                                ...           2 years ago
  • 1.8.0-test                                ...           2 years ago
  • 1.8.0                                ...           2 years ago
  • 1.7.0                                ...           2 years ago
  • 1.6.0                                ...           2 years ago
  • 1.5.3                                ...           2 years ago
  • 1.5.2                                ...           2 years ago
  • 1.5.1                                ...           2 years ago
  • 1.5.0                                ...           2 years ago
  • 1.4.0                                ...           2 years ago
  • 1.3.0                                ...           2 years ago
  • 1.2.1                                ...           2 years ago
  • 1.2.0                                ...           2 years ago
  • 1.1.1                                ...           2 years ago
  • 1.1.0                                ...           2 years ago
  • 1.0.2                                ...           2 years ago
  • 1.0.1                                ...           2 years ago
  • 1.0.0                                ...           2 years ago
  • 0.0.1                                ...           2 years ago

Copyright 2014 - 2016 © taobao.org |