egg-bin
egg developer tool
Last updated 7 months ago by fengmk2 .
Repository · Bugs · Original npm · Tarball · package.json
$ npm install egg-bin 
SYNC missed versions from official npm registry.

egg-bin

NPM version build status Test coverage 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 .",
    "ci": "npm run lint && 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

dev options

  • --framework egg web framework root path.
  • --baseDir application's root path, default to process.cwd().
  • --port server port, default to 7001.
  • --workers worker process number, default to 1 worker at local mode.
  • --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.
  • --declarations / --dts enable egg-ts-helper support, default to false. Also support read from package.json's egg.declarations.
  • --require will add to execArgv, support multiple. Also support read from package.json's egg.require

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

debug options

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

test

Using mocha to run test.

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

test options

You can pass any mocha argv.

  • --require require the given module
  • --grep only run tests matching <pattern>
  • --timeout milliseconds, default to 60000
  • --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))
  • --dry-run / -d whether dry-run the test command, just show the command
  • --parallel enable mocha parallel mode, default to false.
  • --auto-agent auto start agent in mocha master agent.
  • --jobs number of jobs to run in parallel, default to os.cpus().length - 1.
  • --mochawesome enable mochawesome reporter, default to false.
  • see more at https://mochajs.org/#usage

test 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 60000 ms.

TEST_TIMEOUT=2000 egg-bin test

node-test

Using node:test to run test.

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

node-test options

  • --test-only configures the test runner to only execute top level tests that have the only option set

TBD: TypeScript not support yet

node-test 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 node-test

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

TEST_REPORTER=doc egg-bin node-test

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

TEST_TIMEOUT=2000 egg-bin node-test

cov

Using mocha and [c8] to run code coverage, it support all test params above.

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

cov 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.

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

    • egg-bin have some default instruments passed to c8 like -r and --temp-directory
    • egg-bin cov --c8="-r teamcity -r text" --c8-report=true
  • --c8-report use c8 to report coverage, c8 uses native V8 coverage, default to false.

  • also support all test params above.

cov environment

You can set COV_EXCLUDES env to add dir ignore coverage.

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

node-test-cov

Using node:test and [c8] to run code coverage, it support all test params above.

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

node-test-cov options

You can pass any node:test 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.

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

    • egg-bin have some default instruments passed to c8 like -r and --temp-directory
    • egg-bin cov --c8="-r teamcity -r text" --c8-report=true
  • --c8-report use c8 to report coverage, c8 uses native V8 coverage, default to false.

  • also support all node-test params above.

node-test-cov environment

You can set COV_EXCLUDES env to add dir ignore coverage.

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

pkgfiles

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

egg-bin pkgfiles

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 {
  async 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 {}

dal

Generate code for @eggjs/tegg-dal-plugin

egg-bin dal gen

Dal document please read tegg doc.

License

MIT

Contributors


fengmk2


atian25


popomore


whxaxes


semantic-release-bot


dead-horse


killagu


hyj1991


mansonchor


ngot


waitingsong


onlylovermb


snyk-bot


BiosSun


luckydrq


stormslowly


snapre


ZYSzys


angleshe


ahungrynoob


yinseny


okoala

This project follows the git-contributor spec, auto updated at Wed Jan 18 2023 00:01:48 GMT+0800.

Current Tags

  • 6.10.0                                ...           latest (5 months ago)
  • 4.20.0                                ...           latest-4 (2 years ago)
  • 5.18.1                                ...           latest-5 (7 months ago)
  • 5.16.0                                ...           release-5.x (8 months ago)

178 Versions

  • 6.10.0                                ...           5 months ago
  • 6.9.0                                ...           6 months ago
  • 5.18.1                                ...           7 months ago
  • 5.18.0                                ...           7 months ago
  • 5.17.1                                ...           8 months ago
  • 5.17.0                                ...           8 months ago
  • 5.16.0                                ...           8 months ago
  • 6.8.1                                ...           8 months ago
  • 5.15.1                                ...           9 months ago
  • 5.15.0                                ...           9 months ago
  • 6.8.0                                ...           9 months ago
  • 6.7.0                                ...           10 months ago
  • 6.6.0                                ...           10 months ago
  • 6.5.2                                ...           a year ago
  • 6.5.1                                ...           a year ago
  • 6.5.0                                ...           a year ago
  • 5.14.2                                ...           a year ago
  • 5.14.1                                ...           a year ago
  • 6.4.2                                ...           a year ago
  • 6.4.1                                ...           a year ago
  • 6.4.0                                ...           2 years ago
  • 5.14.0                                ...           2 years ago
  • 6.3.0                                ...           2 years ago
  • 6.2.0                                ...           2 years ago
  • 6.1.2                                ...           2 years ago
  • 6.2.0-beta.0                                ...           2 years ago
  • 6.1.1                                ...           2 years ago
  • 6.1.0                                ...           2 years ago
  • 6.0.0                                ...           2 years ago
  • 6.0.0-beta.5                                ...           2 years ago
  • 6.0.0-beta.4                                ...           2 years ago
  • 6.0.0-beta.3                                ...           2 years ago
  • 6.0.0-beta.2                                ...           2 years ago
  • 6.0.0-beta.1                                ...           2 years ago
  • 6.0.0-beta.0                                ...           2 years ago
  • 5.13.4                                ...           2 years ago
  • 5.13.3                                ...           2 years ago
  • 5.13.2                                ...           2 years ago
  • 5.13.1                                ...           2 years ago
  • 5.13.0                                ...           2 years ago
  • 5.12.6                                ...           2 years ago
  • 5.12.5                                ...           2 years ago
  • 5.12.4                                ...           2 years ago
  • 5.12.3                                ...           2 years ago
  • 5.12.2                                ...           2 years ago
  • 5.12.1                                ...           2 years ago
  • 5.12.0                                ...           2 years ago
  • 5.11.3                                ...           2 years ago
  • 5.11.2                                ...           2 years ago
  • 5.11.1                                ...           2 years ago
  • 5.11.0                                ...           2 years ago
  • 5.10.0                                ...           2 years ago
  • 5.9.0                                ...           2 years ago
  • 5.8.1                                ...           2 years ago
  • 5.8.0                                ...           2 years ago
  • 5.7.0                                ...           2 years ago
  • 5.6.1                                ...           2 years ago
  • 5.6.0                                ...           2 years ago
  • 5.5.0                                ...           2 years ago
  • 5.4.1                                ...           2 years ago
  • 5.4.0                                ...           2 years ago
  • 5.3.3                                ...           2 years ago
  • 5.3.2                                ...           2 years ago
  • 5.3.1                                ...           2 years ago
  • 5.3.0                                ...           2 years ago
  • 4.20.0                                ...           2 years ago
  • 5.2.0                                ...           2 years ago
  • 4.19.2                                ...           2 years ago
  • 5.1.2                                ...           2 years ago
  • 4.19.1                                ...           2 years ago
  • 5.1.1                                ...           2 years ago
  • 5.1.0                                ...           2 years ago
  • 5.0.0                                ...           2 years ago
  • 4.19.0                                ...           3 years ago
  • 4.18.1                                ...           3 years ago
  • 4.18.0                                ...           3 years ago
  • 4.17.0                                ...           3 years ago
  • 4.17.0-beta2                                ...           3 years ago
  • 4.17.0-beta1                                ...           3 years ago
  • 4.16.4                                ...           3 years ago
  • 4.16.3                                ...           3 years ago
  • 4.16.2                                ...           4 years ago
  • 4.16.1                                ...           4 years ago
  • 4.16.0                                ...           4 years ago
  • 4.15.0                                ...           4 years ago
  • 4.14.1                                ...           5 years ago
  • 4.14.0                                ...           5 years ago
  • 4.13.2                                ...           5 years ago
  • 4.13.1                                ...           6 years ago
  • 4.13.0                                ...           6 years ago
  • 4.12.3                                ...           6 years ago
  • 4.12.2                                ...           6 years ago
  • 4.12.1                                ...           6 years ago
  • 4.12.0                                ...           6 years ago
  • 4.11.1                                ...           6 years ago
  • 4.11.0                                ...           6 years ago
  • 4.10.0                                ...           6 years ago
  • 4.9.0                                ...           6 years ago
  • 4.8.5                                ...           6 years ago
  • 4.8.4                                ...           6 years ago
  • 4.8.3                                ...           6 years ago
  • 4.8.2                                ...           6 years ago
  • 4.8.1                                ...           6 years ago
  • 4.8.0                                ...           6 years ago
  • 4.7.1                                ...           6 years ago
  • 4.7.0                                ...           7 years ago
  • 4.6.3                                ...           7 years ago
  • 4.6.2                                ...           7 years ago
  • 4.6.1                                ...           7 years ago
  • 4.6.0                                ...           7 years ago
  • 4.5.0                                ...           7 years ago
  • 4.4.1                                ...           7 years ago
  • 4.4.0                                ...           7 years ago
  • 4.3.7                                ...           7 years ago
  • 4.3.6                                ...           7 years ago
  • 4.3.5                                ...           7 years ago
  • 4.3.4                                ...           7 years ago
  • 4.3.3                                ...           7 years ago
  • 4.3.2                                ...           7 years ago
  • 4.3.1                                ...           7 years ago
  • 4.3.0                                ...           7 years ago
  • 4.2.0                                ...           7 years ago
  • 4.1.0                                ...           7 years ago
  • 4.0.5                                ...           7 years ago
  • 4.0.4                                ...           7 years ago
  • 4.0.3                                ...           7 years ago
  • 4.0.2                                ...           7 years ago
  • 4.0.1                                ...           7 years ago
  • 4.0.0                                ...           7 years ago
  • 3.7.0                                ...           7 years ago
  • 1.11.1                                ...           7 years ago
  • 3.6.0                                ...           7 years ago
  • 3.4.2                                ...           7 years ago
  • 3.4.1                                ...           7 years ago
  • 3.4.0                                ...           7 years ago
  • 3.3.2                                ...           8 years ago
  • 3.3.1                                ...           8 years ago
  • 3.3.0                                ...           8 years ago
  • 3.2.1                                ...           8 years ago
  • 3.2.0                                ...           8 years ago
  • 3.1.0                                ...           8 years ago
  • 3.0.1                                ...           8 years ago
  • 3.0.0                                ...           8 years ago
  • 2.4.0                                ...           8 years ago
  • 2.3.0                                ...           8 years ago
  • 2.2.3                                ...           8 years ago
  • 2.2.2                                ...           8 years ago
  • 2.2.1                                ...           8 years ago
  • 2.2.0                                ...           8 years ago
  • 2.1.0                                ...           8 years ago
  • 1.10.3                                ...           8 years ago
  • 2.0.2                                ...           8 years ago
  • 1.10.2                                ...           8 years ago
  • 2.0.1                                ...           8 years ago
  • 2.0.0                                ...           8 years ago
  • 1.10.1                                ...           8 years ago
  • 1.10.0                                ...           8 years ago
  • 1.9.1                                ...           8 years ago
  • 1.9.0                                ...           8 years ago
  • 1.8.1                                ...           8 years ago
  • 1.8.0-test                                ...           8 years ago
  • 1.8.0                                ...           8 years ago
  • 1.7.0                                ...           8 years ago
  • 1.6.0                                ...           8 years ago
  • 1.5.3                                ...           8 years ago
  • 1.5.2                                ...           8 years ago
  • 1.5.1                                ...           8 years ago
  • 1.5.0                                ...           8 years ago
  • 1.4.0                                ...           8 years ago
  • 1.3.0                                ...           8 years ago
  • 1.2.1                                ...           8 years ago
  • 1.2.0                                ...           8 years ago
  • 1.1.1                                ...           8 years ago
  • 1.1.0                                ...           8 years ago
  • 1.0.2                                ...           8 years ago
  • 1.0.1                                ...           8 years ago
  • 1.0.0                                ...           8 years ago
  • 0.0.1                                ...           8 years ago
Downloads
Total 0
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (16)
Dev Dependencies (15)
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE