Coder Social home page Coder Social logo

egg-bin's Introduction

egg-bin

NPM version build status Test coverage Known Vulnerabilities npm download

egg developer tool, extends @artus-cli/artus-cli.


Install

npm i egg-bin --save-dev

Usage

Add egg-bin to package.json scripts:

{
  "scripts": {
    "dev": "egg-bin dev",
    "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 options:

  • --inspect
  • --inspect-brk
  • --typescript / --ts enable typescript support. Auto detect from package.json's pkg.egg.typescript, or pkg.dependencies.typescript/pkg.devDependencies.typescript.
  • --base / --baseDir application's root path, default to process.cwd().
  • --require will add to execArgv, support multiple. Also support read from package.json's pkg.egg.require
  • --dry-run / -d whether dry-run the test command, just show the command
egg-bin [command] --inspect
egg-bin [command] --inspect-brk
egg-bin [command] --typescript
egg-bin [command] --base /foo/bar

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.
  • --port server port. If not specified, the port is obtained in the following order: egg.js configuration config/config.*.js > process.env.EGG_BIN_DEFAULT_PORT > 7001 > other available ports.
  • --workers worker process number, default to 1 worker at local mode.
  • --sticky start a sticky cluster server, default to false.

debug/inspect on VSCode

Create .vscode/launch.json file:

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "launch",
      "name": "Egg Debug",
      "runtimeExecutable": "npm",
      "runtimeArgs": [
        "run",
        "dev",
        "--",
        "--inspect-brk"
      ],
      "console": "integratedTerminal",
      "restart": true,
      "protocol": "auto",
      "port": 9229,
      "autoAttachChildProcesses": true
    },
    {
      "type": "node",
      "request": "launch",
      "name": "Egg Test",
      "runtimeExecutable": "npm",
      "runtimeArgs": [
        "run",
        "test-local",
        "--",
        "--inspect-brk"
      ],
      "protocol": "auto",
      "port": 9229,
      "autoAttachChildProcesses": true
    }
  ]
}

test

Using mocha to run test.

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

auto require test/.setup.ts

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

test
  ├── .setup.ts
  └── foo.test.ts

test options

You can pass any mocha argv.

  • --timeout milliseconds, default to 60000
  • --changed / -c only test changed test files(test files means files that match ${pwd}/test/**/*.test.(js|ts))
  • --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 true.

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

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

Custom egg-bin for your team

See https://artus-cli.github.io

License

MIT

Contributors


fengmk2


atian25


popomore


whxaxes


semantic-release-bot


dead-horse


killagu


hyj1991


mansonchor


ngot


waitingsong


onlylovermb


snyk-bot


BiosSun


luckydrq


gxkl


stormslowly


Solais


snapre


ZYSzys


angleshe


ahungrynoob


yinseny


liuhanqu


okoala

This project follows the git-contributor spec, auto updated at Sat Jun 03 2023 16:58:54 GMT+0800.

egg-bin's People

Contributors

ahungrynoob avatar angleshe avatar atian25 avatar biossun avatar dead-horse avatar dxhuii avatar fengmk2 avatar gxkl avatar hyj1991 avatar jarrychung avatar killagu avatar liuhanqu avatar luckydrq avatar mansonchor avatar ngot avatar okoala avatar onlylovermb avatar popomore avatar semantic-release-bot avatar snapre avatar snyk-bot avatar solais avatar stormslowly avatar wai-dung avatar waitingsong avatar whxaxes avatar yinseny avatar zyszys avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

egg-bin's Issues

egg从2.x升级到3.17.5后,npm run debug不显示DevTools 地址

用到的模块版本,是不是egg-bin降级5.x能解决下述问题?

    "egg": "^3.17.5",
    "egg-cors": "^3.0.0",
    "egg-jwt": "^3.1.7",
    "egg-mongoose": "^4.0.1",
    "egg-multipart": "^3.3.0",
    "egg-redis": "^2.5.0",
    "egg-scripts": "^2.17.0",
    "egg-sequelize": "^6.0.0",
    "egg-session-redis": "^2.1.0",
    "egg-view-nunjucks": "^2.3.0",

    "egg-bin": "^6.5.2",
    "egg-ci": "^2.2.0",
    "egg-mock": "^5.10.9",

问题1

之前用egg 2.x版本是可以显示的,如官网截图一样:
image

但egg升级到3.17.5版本,其他egg模块升级最新版本后,npm run debug如下:
image

该如何显示出chrome-devtools地址呢?ws地址不能直接在浏览器新页签中打开,不方便使用。

问题2

升级egg 3.x之后,config.default.js中,指定端口的配置,npm run start生效,npm run dev、debug不生效,始终是7001,该如何调整?

  // 修改dev模式监听的端口,默认7001
  config.cluster = {
    listen: {
      path: '',
      port: 3003,
      hostname: '0.0.0.0'
    }
  };

Pick DAL Generation Feature to Master Branch

This issue tracks the request to pick the new DAL generation feature introduced in PR #257 to the master branch. The feature enhances the Egg.js framework's data access layer capabilities by automating the generation of DAL code, making development processes more efficient. Picking this feature to the master branch will ensure its availability for broader use.

'test-local-changed' won't work properly on Windows

Steps to Reproduce this issue:

If you change any test files (ending with 'test.js' in Egg project), and you run:

npm run test-local-changed

You'll always be told there's no file changed.

Reasons:

"globby" is referring "minimatch" for the global pattern searches.

In Windows, we can use either "/" or "\" as path seperators, however Only "/" is supported. Please read here: https://github.com/isaacs/minimatch#windows

Solutions:

To convert the "pattern" paths by replacing "" to "/".

6.x 版本egg dev没有集成ets

如题,6.x版本运行egg dev无法识别declarations配置,不会运行ets生成typings。这个符合预期吗,在changelog里没看到相关信息

egg-bin@6,默认端口覆盖了 config.default.js 中配置的端口

问题描述

img_v3_027i_493fd4d1-0b8a-4689-a7cb-631ef0d3f22g
如上图,egg-bin@4egg-bin@5 中,当 detect 到的端口与 defaultPort 一致时,将不会赋值给 argv.port,导致 argv.port 为空,进而用了 config.default.js 里面配置的 port

image
如上图,在 egg-bin@6 中,任何情况都会赋值 this.port,也就意味着不会使用到 config.default.js 中配置的 port

与 6 版本相比,4/5 看起来是 bug 逻辑,但表现上符合业务预期。6 是正常逻辑,但表现上不符合业务预期。

期望

  1. 麻烦帮忙确认下上述理解是否正确;
  2. 能否调整端口获取的优先级为:--port > config 文件 > EGG_BIN_DEFAULT_PORT > 7001;
  3. 建议以何种方式管理生产环境、开发环境的 port,分开管理还是集中管理?业务上,在不同环境的 port 是一样的。

致谢!

报错如何消除

os: windows 10
node: 16.20.0
egg-bin:6.4.2
cmd: cross-env EGG_SERVER_ENV=local egg-bin dev --port=8002 --workers=1

为什么有报错?Why are there errors reported?

1111

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.