Giter Site home page Giter Site logo

egg-bin's Introduction

egg-bin

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

egg developer tool


Install

$ npm i egg-bin --save-dev

Usage

Add egg-bin to package.json scripts:

{
  "devDependencies": {
    "egg-bin": "1"
  },
  "scripts": {
    "dev": "egg-bin dev",
    "debug": "egg-bin debug",
    "test": "egg-bin test",
    "cov": "egg-bin cov",
    "lint": "eslint .",
    "ci": "npm run lint && npm run cov"
  }
}

Command

dev

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

$ egg-bin dev

debug

Debug egg app with Chrome Developer Tools by iron-node.

$ egg-bin debug

test

Using mocha with thunk-mocha to run test.

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 istanbul to run code coverage, it support all test params above.

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

excludes

You can set COV_EXCLUDES env to add dir ignore coverage.

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

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 Program sub class, and Command sub class to do that. Or you can just override the exists command.

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 and MyProgram to create a new egg-bin tool.

MyProgram

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

class MyProgram extends Program {
  constructor() {
    super();
    this.version = require('../package.json').version;

    this.addCommand('nsp', path.join(__dirname, 'NspCommand.js'));
  }
}

module.exports = MyProgram;

NspCommand

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

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

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

module.exports = NspCommand;

my-egg-bin.js

#!/usr/bin/env node

'use strict';

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

run(require('../lib/my_program'));

Run result

$ my-egg-bin nsp

run nsp check at /foo/bar with []

License

MIT

egg-bin's People

Contributors

fengmk2 avatar popomore avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.