Skip to content

Commit

Permalink
feat: update pkg.files that if file exists (#37)
Browse files Browse the repository at this point in the history
Avoid missing files when publish to npm
  • Loading branch information
popomore authored Mar 3, 2017
1 parent 4542dee commit af5af6a
Show file tree
Hide file tree
Showing 16 changed files with 94 additions and 7 deletions.
1 change: 1 addition & 0 deletions .autod.conf
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module.exports = {
'co-mocha',
'intelli-espower-loader',
'power-assert',
'ypkgfiles',
],
devdep: [
'autod',
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@ You can set `COV_EXCLUDES` env to add dir ignore coverage.
$ COV_EXCLUDES="app/plugins/c*,app/autocreate/**" egg-bin cov
```

### pkgfiles

Generate `pkg.files` automatically before npm publish, see [ypkgfiles] for detail

```bash
$ egg-bin pkgfiles
```

### auto require `test/.setup.js`

If `test/.setup.js` file exists, it will be auto require on `test` and `cov` command.
Expand Down Expand Up @@ -221,3 +229,4 @@ run nsp check at /foo/bar with []
[iron-node]: https://github.com/s-a/iron-node
[intelli-espower-loader]: https://github.com/power-assert-js/intelli-espower-loader
[power-assert]: https://github.com/power-assert-js/power-assert
[ypkgfiles]: https://github.com/popomore/ypkgfiles
9 changes: 9 additions & 0 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@ TEST_TIMEOUT=2000 egg-bin test
$ COV_EXCLUDES="app/plugins/c*,app/autocreate/**" egg-bin cov
```

### pkgfiles

在 npm publish 之前使用 pkgfiles 自动生成 `pkg.files`, 更多查看 [ypkgfiles]

```bash
$ egg-bin pkgfiles
```

## 定制属于你团队的 egg-bin

如果你的团队已经基于 egg 开发了属于自己的框架,那么很可能你会需要在 egg-bin 上做更多自定义功能。
Expand Down Expand Up @@ -195,3 +203,4 @@ run nsp check at /foo/bar with []
[nsp]: https://npmjs.com/nsp
[intelli-espower-loader]: https://github.com/power-assert-js/intelli-espower-loader
[power-assert]: https://github.com/power-assert-js/power-assert
[ypkgfiles]: https://github.com/popomore/ypkgfiles
4 changes: 2 additions & 2 deletions lib/helper.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const fs = require('fs');
const existsSync = require('fs').existsSync;
const path = require('path');
const glob = require('glob');
const detect = require('detect-port');
Expand All @@ -23,7 +23,7 @@ exports.getTestFiles = () => {

exports.getTestSetupFile = () => {
const setupFile = path.join(process.cwd(), 'test/.setup.js');
if (fs.existsSync(setupFile)) {
if (existsSync(setupFile)) {
return setupFile;
}
return null;
Expand Down
21 changes: 21 additions & 0 deletions lib/pkgfiles_command.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict';

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

class PkgfilesCommand extends Command {
* run(cwd) {
const args = [
'--entry', 'app',
'--entry', 'config',
'--entry', '*.js',
];
const pkgfiles = require.resolve('ypkgfiles/bin/pkgfiles.js');
yield this.helper.forkNode(pkgfiles, args, { cwd });
}

help() {
return 'Generate pkg.files automatically';
}
}

module.exports = PkgfilesCommand;
1 change: 1 addition & 0 deletions lib/program.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Program extends BaseProgram {
} else {
this.addCommand('cov', path.join(__dirname, 'cov_command.js'));
}
this.addCommand('pkgfiles', path.join(__dirname, 'pkgfiles_command.js'));
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/test_command.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const Command = require('./command');

class TestCommand extends Command {
* run(_, args) {
* run(cwd, args) {
yield this.helper.checkDeps();

const newArgs = this.helper.formatTestArgs(args);
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"mocha": "^3.2.0",
"power-assert": "^1.4.2",
"rimraf": "^2.6.1",
"ypkgfiles": "^1.1.0",
"yargs": "^6.6.0"
},
"devDependencies": {
Expand Down
31 changes: 31 additions & 0 deletions test/egg-pkgfiles.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
'use strict';

const path = require('path');
const assert = require('assert');
const coffee = require('coffee');
const fs = require('mz/fs');

describe('egg-bin pkgfiles', () => {
const eggBin = require.resolve('../bin/egg-bin.js');

let cwd;
afterEach(() => fs.writeFile(path.join(cwd, 'package.json'), '{}'));

it('should update pkg.files', function* () {
cwd = path.join(__dirname, 'fixtures/pkgfiles');
yield fs.writeFile(path.join(cwd, 'package.json'), '{}');

yield coffee.fork(eggBin, [ 'pkgfiles' ], { cwd })
// .debug()
.expect('code', 0)
.end();

const body = yield fs.readFile(path.join(cwd, 'package.json'), 'utf8');
assert.deepEqual(JSON.parse(body).files, [
'app',
'config',
'app.js',
]);
});

});
5 changes: 3 additions & 2 deletions test/fixtures/enzyme-example-mocha/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@
"dependencies": {
"react": "^0.14.7",
"react-dom": "^0.14.7"
}
}
},
"files": []
}
3 changes: 3 additions & 0 deletions test/fixtures/pkgfiles/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';

module.exports = () => {};
3 changes: 3 additions & 0 deletions test/fixtures/pkgfiles/app/extend/context.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';

module.exports = {};
3 changes: 3 additions & 0 deletions test/fixtures/pkgfiles/config/config.default.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';

module.exports = {};
1 change: 1 addition & 0 deletions test/fixtures/pkgfiles/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Empty file.
7 changes: 5 additions & 2 deletions test/fixtures/test-files/package.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"name": "test-files"
}
"name": "test-files",
"files": [
"lib"
]
}

0 comments on commit af5af6a

Please sign in to comment.