0.4.0 • Published 6 years ago
@southfarm/es-dev-tools v0.4.0
es-dev-tools
south.farm 的 ES6/7 项目,将用到的基本工具集,集中放在这个工程里管理。
只使用最有价值的工具
- babel
- commitlint
- eslint
- flow
- husky
- jest
- prettier
- standard-version
安装方法
首先在 ES6/7 工程里,安装这个依赖包,并保存到 package.json 中
// 安装工具集
npm install --save-dev @southfarm/es-dev-tools@latest
// 添加相关配置文件
touch .flowconfig
在你的 package.json 中添加如下配置 :
"babel": {
"presets": [
"env",
"stage-0"
],
"plugins": [
"transform-flow-strip-types",
[
"transform-builtin-extend",
{
"globals": [
"Error",
"Array"
]
}
]
]
},
"commitlint": {
"extends": [
"@commitlint/config-conventional"
]
},
"eslintConfig": {
"extends": "southfarm"
},
"jest": {
"testEnvironment": "node"
},
相关配置
- babel: 设置编译的语言集
- commitlint:设置 Commit 规范
- eslintConfig:设置 Eslint 规范
- jest:测试环境选择 node,如果是 web 工程,请改成 browser
在你的 package.json 中添加 scripts:
"scripts": {
"build": "rm -rf dist && babel ./src -d ./dist --ignore test.js",
"flow": "flow; test $? -eq 0 -o $? -eq 2",
"commitmsg": "commitlint -e $GIT_PARAMS",
"lint": "eslint src && . -qfo",
"prepare": "npm run build",
"release": "standard-version --no-verify && git push --follow-tags origin master",
"start": "npm test -- --watch",
"test": "npm run flow && npm run lint && jest"
},
- build: 用 Babel 把 code 编译到标准 es5
- flow: Facebook 出品的类型校验器,类似 Typescript,但是不强奸
- commitmsg: 规范 Commit message 的工具
- lint: 代码格式检查
- prepare: 发布前需要跑
- release: 发布,已经 push 到远端,剩下需要自己执行 npm publish
- start: 写代码前跑起来
- test: 测试
为什么要规范 Commit
- 其他组员看得懂
- 机器人看得懂,自动生成相关报表
commit 规范是 type: message, <#issue close>, 详细参 考白皮书, 或者我们使用的规则样 例@commitlint/config-conventional