在我做一个小的发布和标记它之前,我想更新这个包。Json来反映程序的新版本。

是否有编辑文件包的方法。json自动吗?

使用git预发布钩子会有帮助吗?


当前回答

我知道这是一个老问题,但我希望这种方法可以帮助某人,以防你想自动更新两个包。Json放在不同的位置,以便使用相同的版本。

首先,把这些线添加到你的主包中。Json脚本部分:

"new-version": "npm version --git-tag-version=false",
"version": "echo 'starting postversion script'",
"postversion": "LAST_VERSION=$(npm pkg get version | sed 's/\"//g') && echo $LAST_VERSION && cd projects/ngx-timeline && sed -i.bak \"s/\\\"version\\\": \\\"[0-9]\\.[0-9]\\.[0-9]\\\"/\\\"version\\\": \\\"$LAST_VERSION\\\"/g\" package.json && rm package.json.bak && git commit -am \"Release $LAST_VERSION\" && git tag v$LAST_VERSION"

然后运行npm run new-version minor,

第一个脚本将运行带有minor和避免标记的选项的NPM版本 版本脚本将在默认命令(在我的例子中只是一个echo)之后运行您需要的命令。 在带有sed的后版本脚本中,我可以覆盖子包中的版本。Json,修改提交(默认情况下版本脚本已经创建了一个提交),然后创建一个标签。

其他回答

首先,您需要了解升级版本号的规则。你可以在这里阅读更多关于语义版本的信息。

每个版本都有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"

如果你用的是纱线,你可以用

yarn version patch

这将增加包。Json版本由补丁(0.0.x),提交,并标记它的格式为v0.0.0

同样,你可以使用——minor或——major来碰撞minor或major版本

在推到git时,确保你也推了带有——follow-tags的标签

git push --follow-tags

您还可以为它创建一个脚本

    "release-it": "yarn version --patch && git push --follow-tags"

只需输入yarn release-it即可运行

提供一个最新的方法。

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版本可能是正确的答案。为了给大家一个替代的选择,我建议你用咕噜撞。它是由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,这可能是最简单的解决方案。

以防万一,如果你想用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运行版本大

去回购