在我做一个小的发布和标记它之前,我想更新这个包。Json来反映程序的新版本。
是否有编辑文件包的方法。json自动吗?
使用git预发布钩子会有帮助吗?
在我做一个小的发布和标记它之前,我想更新这个包。Json来反映程序的新版本。
是否有编辑文件包的方法。json自动吗?
使用git预发布钩子会有帮助吗?
当前回答
我创建了一个工具,可以根据提交消息中的标记(称为更改类型)完成自动语义版本控制。这紧跟Angular提交消息约定和语义版本规范。
您可以使用此工具自动更改包中的版本。json使用npm CLI(这里描述)。
此外,它可以从这些提交创建变更日志,还提供了一个菜单(带有提交消息的拼写检查器),用于根据更改类型创建提交。我强烈建议你检查一下,阅读一下文档,看看用它可以完成的所有事情。
我编写了这个工具,因为我找不到任何可以满足CICD Pipeline自动化语义版本控制需求的工具。我宁愿关注实际的更改是什么,而不是版本应该是什么,这就是我的工具解决问题的地方。
有关该工具基本原理的更多信息,请参见此。
其他回答
提供一个最新的方法。
package.json
"scripts": {
"eslint": "eslint index.js",
"pretest": "npm install",
"test": "npm run eslint",
"preversion": "npm run test",
"version": "",
"postversion": "git push && git push --tags && npm publish"
}
然后运行它:
npm version minor --force -m "Some message to commit"
将:
... 进行测试… 更换你的包裹。Json到下一个小版本(例如:1.8.1到1.9.0) 推动您的更改 创建一个新的git标签版本和 发布你的NPM包。
——武力就是要显示谁是老大!撇开笑话不谈,见https://github.com/npm/npm/issues/8620
以防万一,如果你想用npm package semver链接来做这件事
let fs = require('fs');
let semver = require('semver');
if (fs.existsSync('./package.json')) {
var package = require('./package.json');
let currentVersion = package.version;
let type = process.argv[2];
if (!['major', 'minor', 'patch'].includes(type)) {
type = 'patch';
}
let newVersion = semver.inc(package.version, type);
package.version = newVersion;
fs.writeFileSync('./package.json', JSON.stringify(package, null, 2));
console.log('Version updated', currentVersion, '=>', newVersion);
}
包中。Json应该是这样的,
{
"name": "versioning",
"version": "0.0.0",
"description": "Update version in package.json using npm script",
"main": "version.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"version": "node version.js"
},
"author": "Bhadresh Arya",
"license": "ISC",
"dependencies": {
"semver": "^7.3.2"
}
}
只需要将major, minor, patch参数传递给NPM运行版本。默认为补丁。
例子: NPM运行版本或NPM运行版本补丁或NPM运行版本小或NPM运行版本大
去回购
NPM版本可能是正确的答案。为了给大家一个替代的选择,我建议你用咕噜撞。它是由angular.js的一个人维护的。
用法:
grunt bump
>> Version bumped to 0.0.2
grunt bump:patch
>> Version bumped to 0.0.3
grunt bump:minor
>> Version bumped to 0.1.0
grunt bump
>> Version bumped to 0.1.1
grunt bump:major
>> Version bumped to 1.0.0
如果你使用grunt,这可能是最简单的解决方案。
我用的是husky和git-branch-is:
从哈士奇v1+开始:
// package.json
{
"husky": {
"hooks": {
"post-merge": "(git-branch-is master && npm version minor ||
(git-branch-is dev && npm --no-git-tag-version version patch)",
}
}
}
在husky V1之前:
"scripts": {
...
"postmerge": "(git-branch-is master && npm version minor ||
(git-branch-is dev && npm --no-git-tag-version version patch)",
...
},
阅读更多关于npm版本
Webpack或Vue.js
如果你正在使用webpack或Vue.js,你可以在UI中使用自动注入版本- webpack插件来显示它
NUXT
在nuxt.config.js:
var WebpackAutoInject = require('webpack-auto-inject-version');
module.exports = {
build: {
plugins: [
new WebpackAutoInject({
// options
// example:
components: {
InjectAsComment: false
},
}),
]
},
}
例如在模板的页脚中:
<p> All rights reserved © 2018 [v[AIV]{version}[/AIV]]</p>
首先,您需要了解升级版本号的规则。你可以在这里阅读更多关于语义版本的信息。
每个版本都有x.y.z版本,它为不同的目的定义,如下所示。
X大调,当你有很大的变化时 发生了不一致的变化。 Y小调,当你有 出现了新的功能或增强。 Z - patch, up this when 您修复了错误或恢复了早期版本上的更改。
要运行脚本,可以在package.json中定义它。
"script": {
"buildmajor": "npm version major && ng build --prod",
"buildminor": "npm version minor && ng build --prod",
"buildpatch": "npm version patch && ng build --prod"
}
在你的终端中,你只需要根据你的需要运行npm
npm run buildpatch
如果在git repo中运行它,默认的git-tag-version是true,如果你不希望这样做,你可以在你的脚本中添加以下命令:
--no-git-tag-version
例如:"npm -no-git-tag-version version major && ng build -prod"