-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add egg-bin autod --check
command
#70
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
'use strict'; | ||
|
||
const Command = require('../command'); | ||
|
||
class AutodCommand extends Command { | ||
constructor(rawArgv) { | ||
super(rawArgv); | ||
this.usage = 'Usage: egg-bin autod'; | ||
this.options = { | ||
check: { | ||
description: 'dependencies checker', | ||
}, | ||
}; | ||
} | ||
|
||
get description() { | ||
return 'Generate pkg.dependencies and pkg.devDependencies automatically'; | ||
} | ||
|
||
* run({ cwd, argv }) { | ||
const args = []; | ||
if (argv.check) args.push('--check'); | ||
const autodBin = require.resolve('autod/bin/autod.js'); | ||
yield this.helper.forkNode(autodBin, args, { cwd }); | ||
} | ||
} | ||
|
||
module.exports = AutodCommand; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,6 @@ const debug = require('debug')('egg-bin:cov'); | |
const path = require('path'); | ||
const rimraf = require('mz-modules/rimraf'); | ||
const testExclude = require('test-exclude'); | ||
const fs = require('mz/fs'); | ||
|
||
const Command = require('./test'); | ||
const EXCLUDES = Symbol('cov#excludes'); | ||
|
@@ -77,15 +76,10 @@ class CovCommand extends Command { | |
env: Object.assign({ NODE_ENV: 'test' }, env), | ||
}; | ||
|
||
// FIXME: remove hotfix after https://github.com/tapjs/spawn-wrap/pull/57 merged | ||
yield hotfixSpawnWrap(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这个已经修复了 |
||
|
||
// save coverage-xxxx.json to $PWD/coverage | ||
const covArgs = this.getCovArgs(context); | ||
debug('covArgs: %j', covArgs); | ||
yield this.helper.forkNode(nycCli, covArgs, opt); | ||
|
||
yield rollbackSpawnWrap(); | ||
} | ||
|
||
/** | ||
|
@@ -123,36 +117,3 @@ class CovCommand extends Command { | |
} | ||
|
||
module.exports = CovCommand; | ||
|
||
const src = 'var command = path.basename(options.file, \'.exe\')'; | ||
const target = 'var command = path.basename(options.file).replace(/\.exe$/i, \'\')'; | ||
|
||
function* hotfixSpawnWrap() { | ||
if (process.platform === 'win32') { | ||
yield replaceSpawnWrap(src, target); | ||
} | ||
} | ||
|
||
function* rollbackSpawnWrap() { | ||
if (process.platform === 'win32') { | ||
yield replaceSpawnWrap(target, src); | ||
} | ||
} | ||
|
||
function* replaceSpawnWrap(src, target) { | ||
let spawnWrapPath; | ||
try { | ||
spawnWrapPath = require.resolve('spawn-wrap/index.js'); | ||
} catch (_) { | ||
spawnWrapPath = path.join(__dirname, '../../node_modules/nyc/node_modules/spawn-wrap/index.js'); | ||
} | ||
if (!(yield fs.exists(spawnWrapPath))) return; | ||
|
||
let content = yield fs.readFile(spawnWrapPath, 'utf8'); | ||
// https://github.com/tapjs/spawn-wrap/pull/57 | ||
if (content.includes(src)) { | ||
content = content.replace(src, target); | ||
console.warn('[egg-bin] hotfix spawn-wrap'); | ||
yield fs.writeFile(spawnWrapPath, content); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
"mocha": "bin/mocha.js" | ||
}, | ||
"dependencies": { | ||
"autod": "^2.9.0", | ||
"change-case": "^3.0.1", | ||
"co-mocha": "^1.2.0", | ||
"common-bin": "^2.4.0", | ||
|
@@ -16,32 +17,30 @@ | |
"egg-utils": "^2.2.0", | ||
"globby": "^6.1.0", | ||
"intelli-espower-loader": "^1.0.1", | ||
"mocha": "^3.4.2", | ||
"mz": "^2.6.0", | ||
"mocha": "^3.5.0", | ||
"mz-modules": "^1.0.0", | ||
"nyc": "^11.0.2", | ||
"nyc": "^11.1.0", | ||
"power-assert": "^1.4.4", | ||
"test-exclude": "^4.1.1", | ||
"ypkgfiles": "^1.4.0" | ||
}, | ||
"devDependencies": { | ||
"autod": "^2.8.0", | ||
"babel": "^6.3.26", | ||
"babel-preset-airbnb": "^1.0.1", | ||
"babel-register": "^6.4.3", | ||
"coffee": "^4.0.1", | ||
"coffee": "^4.1.0", | ||
"cross-env": "^3.1.3", | ||
"egg-ci": "^1.8.0", | ||
"enzyme": "^2.0.0", | ||
"eslint": "^3.0.0", | ||
"eslint-config-egg": "^4.2.1", | ||
"eslint": "^4.3.0", | ||
"eslint-config-egg": "^5.0.0", | ||
"jsdom": "^8.0.1", | ||
"mm": "^2.1.0", | ||
"mz": "^2.6.0", | ||
"react": "^0.14.7", | ||
"react-addons-test-utils": "^0.14.7", | ||
"react-dom": "^0.14.7", | ||
"semver": "^5.3.0" | ||
"semver": "^5.4.1" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
|
@@ -54,13 +53,13 @@ | |
"author": "fengmk2 <[email protected]> (https://fengmk2.com)", | ||
"scripts": { | ||
"lint": "eslint .", | ||
"pkgfiles": "node bin/egg-bin.js pkgfiles --check", | ||
"pkgfiles": "node bin/egg-bin.js pkgfiles", | ||
"test": "npm run lint -- --fix && npm run test-local", | ||
"test-local": "node bin/egg-bin.js test -t 3600000", | ||
"cov": "nyc -r lcov -r text-summary npm run test-local", | ||
"ci-test-only": "TESTS=test/lib/cmd/cov.test.js npm run test-local", | ||
"ci": "npm run lint && npm run pkgfiles && npm run ci-test-only && npm run cov", | ||
"autod": "autod" | ||
"ci": "npm run lint && npm run pkgfiles -- --check && npm run autod -- --check && npm run ci-test-only && npm run cov", | ||
"autod": "node bin/egg-bin.js autod" | ||
}, | ||
"engines": { | ||
"node": ">= 6.0.0" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
'use strict'; | ||
|
||
require('urllib'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"name": "autod-exists", | ||
"dependencies": { | ||
"urllib": "*" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
'use strict'; | ||
|
||
require('urllib'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"name": "autod-missing" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
'use strict'; | ||
|
||
const path = require('path'); | ||
const coffee = require('coffee'); | ||
|
||
const eggBin = require.resolve('../../../bin/egg-bin.js'); | ||
|
||
describe('test/lib/cmd/autod.test.js', () => { | ||
it('should autod check fail', function* () { | ||
const cwd = path.join(__dirname, '../../fixtures/autod-missing'); | ||
yield coffee.fork(eggBin, [ 'autod', '--check' ], { cwd }) | ||
.debug() | ||
.expect('code', 1) | ||
.expect('stderr', /\[ERROR\] Missing dependencies: \["urllib"\]/) | ||
.end(); | ||
}); | ||
|
||
it('should autod check pass', function* () { | ||
const cwd = path.join(__dirname, '../../fixtures/autod-exists'); | ||
yield coffee.fork(eggBin, [ 'autod', '--check' ], { cwd }) | ||
.debug() | ||
.expect('code', 0) | ||
.end(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
感觉直接把 rawArgs 给他就好了
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
usage 提示哪里怎么办?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
usage 可以放着,参数让 autod 提示?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果以后 autod 用了 common-bin,就可以继承了