Skip to content

Commit

Permalink
Merge pull request #65 from nighca/version-check
Browse files Browse the repository at this point in the history
build-config 中添加字段指定 builder 版本号
  • Loading branch information
nighca authored Jan 24, 2018
2 parents 7168ed1 + 7aabcda commit 4e56624
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 10 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,24 @@ npm 包与 docker 镜像的对比,优点:

表示使用 `xxx`、`yyy` 分别作为 AccessKey 与 SecretKey,上传到名为 `zzz` 的 bucket。

* engines

配置对构建环境的要求。目前支持字段:`builder`

- builder 配置项目所要求的 fec-builder 版本范围,格式遵循 [node-semver range](https://github.com/npm/node-semver#ranges)

在统一的构建环境中,服务应依据该版本范围去选择合适的 builder 版本对项目进行构建;本地开发时,若本地使用的 builder 版本不匹配项目所配置的版本范围,会输出警告信息,但不影响使用

示例:

```json
{
"engines": {
"builder": "^1.5.0"
}
}
```

### transformer 的配置

对于不同的 transformer,我们可以通过与 `transformer` 平级的 `config` 字段对 transformer 的行为进行配置,这里是不同 transformer 支持的配置项:
Expand Down
6 changes: 5 additions & 1 deletion bin/fec-builder
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const _ = require('lodash')
const paths = require('../lib/utils/paths')
const buildEnv = require('../lib/utils/build-env')
const logger = require('../lib/utils/logger')
const prepare = require('../lib/prepare')
const clean = require('../lib/clean')
const generate = require('../lib/generate')
const upload = require('../lib/upload')
Expand Down Expand Up @@ -82,7 +83,10 @@ _.forEach(commands, ({ desc, handler, isDefault }, command) => {
command = isDefault ? [command, '*'] : command
yargs.command(command, desc, () => {}, args => {
applyArgv(args)
handler(args).catch(handleError)

prepare().then(
() => handler(args)
).catch(handleError)
})
})

Expand Down
21 changes: 21 additions & 0 deletions lib/prepare.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* @file prepare behaviors
* @author nighca <[email protected]>
*/

const semver = require('semver')
const logger = require('./utils/logger')
const findBuildConfig = require('./utils/build-conf').find
const packageInfo = require('../package.json')

module.exports = () => findBuildConfig().then(
buildConfig => {
const builderVersionRange = buildConfig.engines && buildConfig.engines.builder
if (typeof builderVersionRange === 'string') {
const builderVersion = packageInfo.version
if (!semver.satisfies(builderVersion, builderVersionRange)) {
logger.warn(`builder version not satisfied, which may causes error (expected \`${builderVersionRange}\`, got \`${builderVersion}\`)`)
}
}
}
)
7 changes: 7 additions & 0 deletions lib/utils/build-conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ const utils = require('./index')
const paths = require('./paths')
const logger = require('./logger')

/**
* The complete Triforce, or one or more components of the Triforce.
* @typedef {object} Engines
* @property {string} builder - required builder version range
*/

/**
* The complete Triforce, or one or more components of the Triforce.
* @typedef {object} BuildConfig
Expand All @@ -27,6 +33,7 @@ const logger = require('./logger')
* @property {object} optimization
* @property {object} devProxy
* @property {object} deploy
* @property {Engines} engines
*/

/**
Expand Down
25 changes: 16 additions & 9 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"raw-loader": "^0.5.1",
"react-hot-loader": "^3.1.3",
"sass-loader": "^6.0.6",
"semver": "^5.5.0",
"style-loader": "^0.19.0",
"stylus": "^0.54.5",
"stylus-loader": "^3.0.1",
Expand Down
3 changes: 3 additions & 0 deletions preset-configs/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,8 @@
"SecretKey": "",
"bucket": ""
}
},
"engines": {
"builder": "*"
}
}

0 comments on commit 4e56624

Please sign in to comment.