我创建了一个以生成器工具命名generate-swap-project
的生成器插件。generate
我们先来看看:
- https://github.com/generate:一个新的命令行工具和开发人员框架,用于搭建 GitHub 项目。比 Yeoman 更强大、更可组合、更实用的替代品。
- https://github.com/generate/generate:一个新的命令行工具和开发者框架,用于搭建 GitHub 项目。Generate 提供了 Yeoman 的健壮性和可配置性,Slush 的表现力和简单性,以及比任何一个都更强大的流控制和可组合性。
- https://github.com/rbecheras/generate-swap-project SWAP 项目的生成器(我正在研究的生成器)
- https://github.com/rbecheras/generate-swap-project/tree/1-convert-to-standard-code-style:SWAP 项目的生成器(主分支上的自述文件)
- https://github.com/rbecheras/generate-swap-project/tree/1-convert-to-standard-code-style :(问题分支的自述文件)
主分支工作正常,测试通过 travis 和本地开发主机。测试由以下纱线脚本(在主服务器上)运行:
$ yarn test
但是在PR #2 Resolve #1 "Convert to ESNext/StandardJS code style"
中,我做了以下更改:
- 将代码库转换
ES5
为ESNext
- 将代码库移至
src/lib
和src/tests
- 在根级别添加了一个
generator.js
文件,只需要./dist/lib/generator.js
- 添加了纱线脚本:clear + lint + build + test(参见关于构建管道的自述部分)
测试由以下纱线脚本(在分支上1-convert-to-standard-code-style
)运行:
$ yarn travis
或(它的别名)
$ yarn pipeline
这是任务序列yarn clear && yarn lint && yarn build && yarn test
但是一项测试失败(14 次测试通过时 1 次测试失败)并出现一个奇怪的错误Error: expected file.path to export a function or instance
::
$ yarn pipeline
yarn run v1.3.2
$ yarn clear && yarn lint && yarn build && yarn test
$ yarn rimraf build dist
$ /home/remi/d/dev/generate-swap-project/node_modules/.bin/rimraf build dist
$ yarn lint:esnext
$ yarn standard src/*.js src/**/*.js
$ /home/remi/d/dev/generate-swap-project/node_modules/.bin/standard 'src/*.js' src/lib/generator.js src/tests/plugin.js src/tests/test.js
$ yarn build:lib && yarn build:tests && yarn build:docs
$ yarn babel src/lib/ --out-dir dist/lib --source-maps
$ /home/remi/d/dev/generate-swap-project/node_modules/.bin/babel src/lib/ --out-dir dist/lib --source-maps
src/lib/generator.js -> dist/lib/generator.js
$ yarn babel src/tests/ --out-dir dist/tests --source-maps
$ /home/remi/d/dev/generate-swap-project/node_modules/.bin/babel src/tests/ --out-dir dist/tests --source-maps
src/tests/plugin.js -> dist/tests/plugin.js
src/tests/test.js -> dist/tests/test.js
$ echo WARNING: No documentation build available yet
WARNING: No documentation build available yet
$ yarn mocha dist/tests/**/*.js
$ /home/remi/d/dev/generate-swap-project/node_modules/.bin/mocha 'dist/tests/**/*.js'
generate-swap-project
plugin
✓ should add tasks to the instance (80ms)
✓ should only register the plugin once
generate-swap-project
tasks
✓ should extend tasks onto the instance
✓ should run the `default` task with .build (186ms)
✓ should run the `default` task with .generate
swap-project (CLI)
X => 1) should run the default task using the `generate-swap-project` name (global install)
✓ should run the default task using the `swap-project` generator alias (local generator.js)
swap-project (API)
✓ should run the default task on the generator
✓ should run the `swap-project` task
✓ should run the `default` task when defined explicitly
sub-generator
✓ should work as a sub-generator
✓ should run the `default` task by default
✓ should run the `generator:default` task when defined explicitly
✓ should run the `generator:swap-project` task
✓ should work with nested sub-generators
✓ should run tasks as a sub-generator
15 passing (1s)
1 failing
1) generate-swap-project
swap-project (CLI)
should run the default task using the `generate-swap-project` name (global install):
Error: expected file.path to export a function or instance
at Env.get (node_modules/base-env/lib/file.js:256:11)
at Env.invoke (node_modules/base-env/lib/env.js:117:19)
at Generate.<anonymous> (node_modules/base-generators/lib/generator.js:62:30)
at Generate.getGenerator (node_modules/base-generators/index.js:157:22)
at Object.exports.process (node_modules/base-generators/lib/tasks.js:127:24)
at node_modules/base-generators/lib/tasks.js:86:23
at Array.reduce (<anonymous>)
at exports.parse (node_modules/base-generators/lib/tasks.js:85:15)
at Generate.generate (node_modules/base-generators/index.js:490:21)
at Generate.generate (node_modules/base-generators/index.js:463:23)
at Context.<anonymous> (dist/tests/test.js:87:11)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
这是特拉维斯配置
{
"sudo": false,
"language": "node_js",
"node_js": "lts/carbon",
"script": [
"npm link",
"npm install --global generate .",
"yarn travis"
],
"group": "stable",
"dist": "trusty",
"os": "linux"
}
这里是:
我不明白为什么该测试(以 CLI 模式运行生成器的测试)在 ESNext 转换和 babel 转译之后失败。
我的 PR 有什么问题?