Skip to content

Commit

Permalink
feat: egg-bin check (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
atian25 authored Feb 24, 2018
1 parent e8de9e3 commit 92b1489
Show file tree
Hide file tree
Showing 11 changed files with 126 additions and 6 deletions.
3 changes: 2 additions & 1 deletion .autod.conf
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ module.exports = {
'intelli-espower-loader',
'power-assert',
'ypkgfiles',
'eslint-plugin-eggache',
'eslint',
],
devdep: [
'autod',
'eslint-config-egg',
'eslint',
'egg-ci',
],
keep: [
Expand Down
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules/
coverage/
test/fixtures/enzyme-example-mocha/
test/fixtures/check-eggache/
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,16 @@ Generate `pkg.dependencies` and `pkg.devDependencies` automatically, see [autod]
$ egg-bin autod
```

## check

Check egg project for collect useful infomation to report issue.

```bash
$ egg-bin check
```
### Rules:
- [eslint-plugin-eggache](https://github.com/eggjs/eslint-plugin-eggache)

## 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.
Expand Down
6 changes: 6 additions & 0 deletions lib/check-eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "plugin:eggache/recommended",
"parserOptions": {
"ecmaVersion": 6
}
}
41 changes: 41 additions & 0 deletions lib/cmd/check.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
'use strict';

const Command = require('../command');
const path = require('path');

class CheckCommand extends Command {
constructor(rawArgv) {
super(rawArgv);
this.usage = 'Usage: egg-bin check';
this.options = {
baseDir: {
description: 'directory of application, default to `process.cwd()`',
type: 'string',
},
};
}

get description() {
return 'Check egg project for collect useful infomation to report issue';
}

* run({ cwd, argv }) {
/* istanbul ignore next */
let baseDir = argv._[0] || argv.baseDir || cwd;
/* istanbul ignore next */
if (!path.isAbsolute(baseDir)) baseDir = path.join(cwd, baseDir);

// check eggache
const eslintBin = require.resolve('eslint/bin/eslint');
const eslintArgs = this.helper.unparseArgv({
_: [ '.' ],
config: require.resolve('../check-eslintrc'),
'no-eslintrc': true,
format: 'codeframe',
});
console.info('[egg-bin] run check: %s %s', eslintBin, eslintArgs.join(' '));
yield this.helper.forkNode(eslintBin, eslintArgs, { cwd: baseDir });
}
}

module.exports = CheckCommand;
13 changes: 8 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,32 @@
"debug": "^3.1.0",
"detect-port": "^1.2.2",
"egg-utils": "^2.3.0",
"eslint": "^4.17.0",
"eslint-plugin-eggache": "^1.0.0",
"globby": "^7.1.1",
"inspector-proxy": "^1.1.0",
"intelli-espower-loader": "^1.0.1",
"mocha": "^4.0.1",
"mocha": "^5.0.0",
"mz-modules": "^2.0.0",
"nyc": "^11.3.0",
"nyc": "^11.4.1",
"power-assert": "^1.4.4",
"semver": "^5.4.1",
"semver": "^5.5.0",
"test-exclude": "^4.1.1",
"ypkgfiles": "^1.5.0"
},
"devDependencies": {
"autod": "^3.0.1",
"babel": "^6.3.26",
"babel-preset-airbnb": "^1.0.1",
"babel-register": "^6.4.3",
"coffee": "^4.1.0",
"cross-env": "^3.1.3",
"egg": "^1.8.0",
"egg-ci": "^1.8.0",
"egg-mock": "^3.13.1",
"egg-mock": "^3.14.0",
"enzyme": "^2.0.0",
"eslint": "^4.12.1",
"eslint-config-egg": "^5.1.1",
"eslint-config-egg": "^6.0.0",
"jsdom": "^8.0.1",
"mm": "^2.2.0",
"mz": "^2.7.0",
Expand Down
9 changes: 9 additions & 0 deletions test/fixtures/check-eggache/config/config.default.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use strict';

module.exports = appInfo => {
const config = exports = {};
config.keys = appInfo.name;
return config;
};

exports.test = '12345';
7 changes: 7 additions & 0 deletions test/fixtures/check-eggache/config/plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

exports.view = {
enable: true,
package: '',
foo: 'bar',
};
7 changes: 7 additions & 0 deletions test/fixtures/check-eggache/other.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

module.exports = '';

exports.test = '12345';

let a;
3 changes: 3 additions & 0 deletions test/fixtures/check-eggache/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "check-eggache"
}
32 changes: 32 additions & 0 deletions test/lib/cmd/check.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
'use strict';

const path = require('path');
const coffee = require('coffee');

const eggBin = require.resolve('../../../bin/egg-bin.js');

describe('test/lib/cmd/check.test.js', () => {
it('should check eggache', function* () {
const cwd = path.join(__dirname, '../../fixtures/check-eggache');
yield coffee.fork(eggBin, [ 'check' ], { cwd })
// .debug()
.expect('stdout', /eggache\/no-override-exports/)
.expect('stdout', /eggache\/no-unexpected-plugin-keys/)
.notExpect('stdout', /no-unused-vars/)
.notExpect('stdout', /\/other.js/)
.expect('code', 1)
.end();
});

it('should check eggache with --baseDir', function* () {
const cwd = path.join(__dirname, '../../fixtures/check-eggache');
yield coffee.fork(eggBin, [ 'check', '--baseDir', cwd ])
// .debug()
.expect('stdout', /eggache\/no-override-exports/)
.expect('stdout', /eggache\/no-unexpected-plugin-keys/)
.notExpect('stdout', /no-unused-vars/)
.notExpect('stdout', /\/other.js/)
.expect('code', 1)
.end();
});
});

0 comments on commit 92b1489

Please sign in to comment.