标准版本
用于使用版本的工具 铸造 和变换组发电 常规武器委员会。 。 。 .
有问题吗? 想贡献吗? 加入我们的行列 节点工具社区。 。 。 .
如何运作:
- 跟着 常规提交规格 在您的仓库.
- 当你准备好释放,跑
standard-version。 。 。 .
standard-version 然后将采取下列行动:
- 通过查看获取当前版本的仓库
bumpFiles[1] (中文(简体) ),倒回最后一个git tag。 。 。 . bump该版本在bumpFiles[1] (中文(简体) ) 基于你的承诺.- 生成 a
changelog基于您的承诺(使用) 常规变化日志 盖下. - 创建新
commit包括你bumpFiles[1] (中文(简体) ) 并更新了变换组. - 创建新
tag带有新版本编号.
bumpFiles, (中文(简体) ), packageFiles 财务报告和审定财务报表 updaters
standard-version 使用一些关键概念处理您的工程中出现的版本.
packageFiles- 用户定义的文件,可从其中读取版本 财务报告和审定财务报表 被"弹出".- 实例:
package.json, (中文(简体) ),manifest.json - 在大多数情况下(包括违约),
packageFiles属于bumpFiles。 。 。 .
- 实例:
bumpFiles– 用户定义的文件,其中版本应当"跳出",但没有明确读取.- 实例:
package-lock.json, (中文(简体) ),npm-shrinkwrap.json
- 实例:
updaters- 用于阅读的简单模块packageFiles并写信给bumpFiles。 。 。 .
默认, standard-version 假设你在基于节点JS的项目中工作... 因为这, 对于大多数的项目 你可能不需要与这些选项互动.
这么说,如果你发现自己问 我如何使用标准版本来获取更多元数据文件,语言或版本文件? - 这些配置选项会有所帮助!
Java 支持
从盒子里出来, standard-version 支持 Maven 工程, 只要提供路径到您 pom.xml 作为软件包和凸起文件:
standard-version --packageFiles pom.xml --bumpFiles pom.xml
如果你使用"格拉德",那就指向 build.gradle 档案!
standard-version --packageFiles build.gradle --bumpFiles build.gradle
安装 standard-version
作为当地人 npm run 脚本
安装并添加到 devDependencies数字 :
npm i --save-dev standard-version
添加一个 npm run 脚本 给您的 package.json数字 :
{
"scripts": {
"release": "standard-version"
}
}
现在你可以用 npm run release 替换 npm version。 。 。 .
这有利于使您的再集/包装更加便携,使其他开发者可以不需全球安装而剪切发布 standard-version 在他们的机器上.
作为全球 bin
全局安装( 添加到您的 PATH:
npm i -g standard-version
现在你可以用 standard-version 替换 npm version。 。 。 .
这可以让你使用 standard-version 在任何还原/包装上,不增加每件的依赖性.
使用 npx
截止 [email protected], (中文(简体) ), npx 安装在旁边 npm。使用 npx 您可以使用 standard-version 无需保留 package.json 运行时的文件 : npx standard-version。 。 。 .
这种方法在使用时特别有用 standard-version 在非贾瓦脚本项目中.
配置
您可以配置 standard-version 方法之一:
- 设置 a
standard-version在你身边package.json(假定 您的项目是 JavaScript . - 创建一个
.versionrc, (中文(简体) ),.versionrc.json或者说.versionrc.js。 。 。 .
- 如果你正在使用一个
.versionrc.js您的默认导出必须是配置对象,或者函数返回配置对象.
任意命令行参数 standard-version 可改为
通过配置提供。 请参看 常规变换log-配置- spec 以获取关于可用配置选项的详情.
自定义变换组
默认(截至 6.0.0, (中文(简体) ), standard-version 使用该 常规承诺预设。 。 。 .
此预设 :
有多种拨号和取号,可以转接与ChangGELOG生成相关.
例如,假设您使用GitLab,而不是GitHub,您可能会修改以下变量:
commitUrlFormat: 承诺消息中检测到的SHAs的URL格式.compareUrlFormat:用于比较两个标记的URL格式.issueUrlFormat: 用于链接问题的URL格式.
使这些URL符合GitLab的格式,而不是GitHub的格式.
CLI 使用量
注: 将嵌入式配置传递给 CLI 而不在
package.json使用标记作为参数e.g. --skip.changelog。 。 。 .
第一版发布
要生成您第一次发行的更改日志, 只需做:
# npm run script
npm run release -- --first-release
# global bin
standard-version --first-release
# npx
npx standard-version --first-release
这将标记释放 在不撞倒版本的情况下 bumpFiles1个。 。 。 .
等你准备好了,按下标记 npm publish 你的第一个释放。 \o/ (% 1)
剪接释放
如果您通常使用 npm version 切换到新版本,请这样做:
# npm run script
npm run release
# or global bin
standard-version
只要您的 git 承诺消息是常规的和准确的, 你不再需要指定 semver 类型 - 并且免费获得 ChangGELOG 生成 ! \o/ (% 1)
剪辑后,你可以推出新的git标签和 npm publish (或 npm publish --tag next当你准备好了.
作为释放前释放
使用旗帜 --prerelease 生成预放:
假设您的代码的最后版本是 1.0.0,而要执行的代码则补丁了修改。 运行 :
# npm run script
npm run release -- --prerelease
这将标记您的版本为: 1.0.1-0。 。 。 .
如果您想要指定发行前的名称,请通过 --prerelease <name>。 。 。 .
例如,假设你的预释应该包含 alpha 前缀 :
# npm run script
npm run release -- --prerelease alpha
这将标记该版本为: 1.0.1-alpha.0
作为目标类型的释放npm version- 喜欢)
放弃自动版本的凸起使用 --release-as 与论据 major, (中文(简体) ), minor 或者说 patch。 。 。 .
假设您的代码的最后版本是 1.0.0你只着陆了 fix: 承诺,但
你希望你的下次释放成为 minor。简单运行如下:
# npm run script
npm run release -- --release-as minor
# Or
npm run release -- --release-as 1.1.0
你会得到版本 1.1.0 而不是自动生成的版本 1.0.1。 。 。 .
注: 你可以结合
--release-as财务报告和审定财务报表--prerelease生成释放。 这在发布实验特性时是有用的.
防止金钩
如果像承诺前一样使用"git"钩子,在承诺前测试你的代码,可以防止在承诺步骤中通过"通过"来验证"钩子 --no-verify 选项 :
# npm run script
npm run release -- --no-verify
# or global bin
standard-version --no-verify
签名提交和标记
如果您设置了 GPG 密钥, 请添加 --sign 或者说 -s 标记为您的 standard-version 命令.
生命周期脚本
standard-version 支持生命周期脚本。 这些可以让你执行
拥有发布期间的补充命令。 以下内容:
钩子可用并按文件顺序执行:
prerelease: 在事发前被处决. 如果prerelease脚本返回 a 非零退出代码,版本将中止,但不会对 进程.prebump编号 :postbump: 版本被撞出前后执行. 如果prebump脚本返回一个版本 #, 它将被使用而不是 以standard-version。 。 。 .prechangelog编号 :postchangelog: 生成 ChangeGELOG 前后执行.precommit编号 :postcommit:在承诺步骤前后呼叫.pretag编号 :posttag:在标记步骤前后调用.
简单地在您的软件包中添加以下内容. json 来配置生命周期脚本 :
{
"standard-version": {
"scripts": {
"prebump": "echo 9.9.9"
}
}
}
作为从使用 GitHub 跟踪您的项目到使用您的项目的一个实例 Jira 使用 a
postchangelog 替换包含'https://github.com/'的url碎片的脚本myproject/问题/'
与您的 Jira 链接 - 假设您已经安装 替换
{
"standard-version": {
"scripts": {
"postchangelog": "replace 'https://github.com/myproject/issues/' 'https://myjira/browse/' CHANGELOG.md"
}
}
}
跳过生命周期步骤
你可以跳过任何生命周期步骤(bump, (中文(简体) ), changelog, (中文(简体) ), commit, (中文(简体) ), tag, (中文(简体) ),
在您的软件包中添加以下内容
{
"standard-version": {
"skip": {
"changelog": true
}
}
}
在释放命令中提交生成的艺术
如果您想在释放中承诺生成的文物(例如:. 96号),可以使用 --commit-all 或者说 -a 旗帜。 你将需要展示你想要的艺术品,所以你 release 命令可能像这样 :
"prerelease": "webpack -p --bail",
"release": "git add <file(s) to commit> && standard-version -a"
干运行模式
运行 standard-version 与旗帜 --dry-run 让你看到什么
命令将运行,而不承诺对文件进行配置或更新.
# npm run script
npm run release -- --dry-run
# or global bin
standard-version --dry-run
前缀标记
标记前缀为 v 默认。 如果你想用别的东西前缀标签,你可以用 -t 旗帜.
standard-version -t @scope/package\@
这将在标记前加个前缀, 以看起来像 @scope/[email protected]
如果您不想有任何标记前缀, 您可以使用 -t 无值的旗帜.
CLI 帮助
# npm run script
npm run release -- --help
# or global bin
standard-version --help
代码使用
const standardVersion = require('standard-version')
// Options are the same as command line, except camelCase
// standardVersion returns a Promise
standardVersion({
noVerify: true,
infile: 'docs/CHANGELOG.md',
silent: true
}).then(() => {
// standard-version is done
}).catch(err => {
console.error(`standard-version failed with message: ${err.message}`)
})
TIP: 使用 silent 选项 standard-version 从打印到打印 console。 。 。 .
财务问题
怎么样 standard-version 与 semantic-release? 吗?
semantic-release 描述为:
语义-放出将整个包放出工作流程自动化,包括:确定下个版本号,生成放出注释并发布包.
虽然两者都基于结构化承诺信息的同一基础, standard-version 通过处理版本、更改日志生成和为您指定标签, 采取了不同的方法 无 自动推( to GitHub) 或发布( to a npm register). 使用 standard-version 只影响您的本地 git repo - 它根本不影响远程资源。 跑完你再说 standard-version,你可以审查你的释放状态,纠正错误并遵循对你的代码库最有意义的释放策略.
我们鼓励人们使用 semantic-release 改为 standard-version 如果用起来合理的话.
公关合并时,我是否应该总是犯错?
当合并拉力请求时,壁球的指示假定: 一个公关最多等于一个特性或固定。 。 。 .
如果您拥有多个特性或固定在单个PR中着陆,并且每个承诺使用结构化消息,那么在接受PR时就可以进行标准合并. 这将保存承诺历史 从您的分支合并后.
尽管这将使每个承诺作为单独的条目列入您的变换组,但条目将 没有 能够引用调取更改的PR,因为保存的承诺信息不包括PR号码.
为此,我们建议将每项公关的范围保持在一个一般特征或固定。 在实践中,这允许您在每次小改动时使用无结构化的传输消息,然后在经过审查和接受后,用结构化的信息(参考PR号码)将其压入一个单一的承诺中.
我可以用吗 standard-version 用于额外的元数据文件、语言或版本文件?
截至版本 7.1.0 您可以配置多个 bumpFiles 财务报告和审定财务报表 packageFiles。 。 。 .
-
指定自定义
bumpFile" (中文(简体) )filename",这是路径到文件 你想"跳" -
指定
bumpFile" (中文(简体) )updater",这是 怎么样 文件会被撞倒.(单位:千美元) 如果使用普通类型,您可以使用其中的一种
standard-version内置updaters通过指定一个type。 。 。 .b. 如果您使用不太常用的版本文件, 您可以创建自己的文件
updater。 。 。 .
// .versionrc
{
"bumpFiles": [
{
"filename": "MY_VERSION_TRACKER.txt",
// The `plain-text` updater assumes the file contents represents the version.
"type": "plain-text"
},
{
"filename": "a/deep/package/dot/json/file/package.json",
// The `json` updater assumes the version is available under a `version` key in the provided JSON document.
"type": "json"
},
{
"filename": "VERSION_TRACKER.json",
// See "Custom `updater`s" for more details.
"updater": "standard-version-updater.js"
}
]
}
自定义 updater编号
一个 updater 的 Javascript 模块中 起码 两种方法曝光: readVersion 财务报告和审定财务报表 writeVersion。 。 。 .
readVersion(contents = string): string
这种方法用于从提供的文件内容读取版本.
返回值预计为语义版本字符串.
writeVersion(contents = string, version: string): string
这种方法用于将版本写入提供的内容.
返回值将直接写入(覆盖)提供的文件 .
假设我们 VERSION_TRACKER.json 有下列内容:
{
"tracker": {
"package": {
"version": "1.0.0"
}
}
}
一个可以接受的 standard-version-updater.js 将:
// standard-version-updater.js
const stringifyPackage = require('stringify-package')
const detectIndent = require('detect-indent')
const detectNewline = require('detect-newline')
module.exports.readVersion = function (contents) {
return JSON.parse(contents).tracker.package.version;
}
module.exports.writeVersion = function (contents, version) {
const json = JSON.parse(contents)
let indent = detectIndent(contents).indent
let newline = detectNewline(contents)
json.tracker.package.version = version
return stringifyPackage(json, indent, newline)
}
许可证
公务员制度委员会