egg developer tool, extends common-bin.
npm i egg-bin --save-devAdd 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"
}
}All the commands support these specific v8 options:
--debug--inspect--harmony*--es_staging
egg-bin [command] --debug --es_stagingif process.env.NODE_DEBUG_OPTION is provided (WebStorm etc), will use it as debug options.
Start dev cluster on local env, it will start a master, an agent and a worker.
egg-bin dev--frameworkegg web framework root path.--baseDirapplication's root path, default toprocess.cwd().--portserver port, default to7001.--workersworker process number, default to1worker at local mode.--stickystart a sticky cluster server, default tofalse.--typescript/--tsenable typescript support, default tofalse. Also support read frompackage.json'segg.typescript.--declarations/--dtsenable egg-ts-helper support, default tofalse. Also support read frompackage.json'segg.declarations.--requirewill add toexecArgv, support multiple. Also support read frompackage.json'segg.require
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- all
egg-bin devoptions is accepted. --proxy=9999worker debug proxy port.
Using mocha to run test.
egg-bin test [files] [options]filesis optional, default totest/**/*.test.jstest/fixtures,test/node_modulesis always exclude.
If test/.setup.js file exists, it will be auto require as the first test file.
test
├── .setup.js
└── foo.test.jsYou can pass any mocha argv.
--requirerequire the given module--greponly run tests matching<pattern>--timeoutmilliseconds, default to 60000--full-tracedisplay the full stack trace, default to false.--typescript/--tsenable typescript support, default tofalse.--changed/-conly test changed test files(test files means files that match${pwd}/test/**/*.test.(js|ts))--dry-run/-dwhether dry-run the test command, just show the command--parallelenable mocha parallel mode, default tofalse.--auto-agentauto start agent in mocha master agent.--jobsnumber of jobs to run in parallel, default toos.cpus().length - 1.--mochawesomeenable mochawesome reporter, default tofalse.- see more at https://mochajs.org/#usage
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 testAnd the reporter can set by the TEST_REPORTER env, default is spec.
TEST_REPORTER=doc egg-bin testThe test timeout can set by TEST_TIMEOUT env, default is 60000 ms.
TEST_TIMEOUT=2000 egg-bin testUsing node:test to run test.
egg-bin node-test [files] [options]filesis optional, default totest/**/*.test.jstest/fixtures,test/node_modulesis always exclude.
--test-onlyconfigures the test runner to only execute top level tests that have the only option set
TBD: TypeScript not support yet
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-testAnd the reporter can set by the TEST_REPORTER env, default is tap.
TEST_REPORTER=doc egg-bin node-testThe test timeout can set by TEST_TIMEOUT env, default is 60000 ms.
TEST_TIMEOUT=2000 egg-bin node-testUsing mocha and [c8] to run code coverage, it support all test params above.
Coverage reporter will output text-summary, json and lcov.
You can pass any mocha argv.
-
-xadd dir ignore coverage, support multiple argv -
--prerequireprerequire files for coverage instrument, you can use this options if load files slowly when callmm.appormm.cluster -
--typescript/--tsenable typescript support, default tofalse, if true, will auto add.tsextension and ignoretypingsandd.ts. -
--c8c8 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
-rand--temp-directory egg-bin cov --c8="-r teamcity -r text" --c8-report=true
- egg-bin have some default instruments passed to c8 like
-
--c8-reportuse c8 to report coverage, c8 uses native V8 coverage, default tofalse. -
also support all test params above.
You can set COV_EXCLUDES env to add dir ignore coverage.
COV_EXCLUDES="app/plugins/c*,app/autocreate/**" egg-bin covUsing node:test and [c8] to run code coverage, it support all test params above.
Coverage reporter will output text-summary, json and lcov.
You can pass any node:test argv.
-
-xadd dir ignore coverage, support multiple argv -
--prerequireprerequire files for coverage instrument, you can use this options if load files slowly when callmm.appormm.cluster -
--typescript/--tsenable typescript support, default tofalse, if true, will auto add.tsextension and ignoretypingsandd.ts. -
--c8c8 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
-rand--temp-directory egg-bin cov --c8="-r teamcity -r text" --c8-report=true
- egg-bin have some default instruments passed to c8 like
-
--c8-reportuse c8 to report coverage, c8 uses native V8 coverage, default tofalse. -
also support all node-test params above.
You can set COV_EXCLUDES env to add dir ignore coverage.
COV_EXCLUDES="app/plugins/c*,app/autocreate/**" egg-bin node-test-covGenerate pkg.files automatically before npm publish, see ypkgfiles for detail
egg-bin pkgfilesYou 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.
- Full demo: 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;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;#!/usr/bin/env node
'use strict';
const Command = require('..');
new Command().start();$ my-egg-bin nsp
run nsp check at /foo/bar with {}This project follows the git-contributor spec, auto updated at Wed Jan 18 2023 00:01:48 GMT+0800.