不带package.json的npm版本

时间:2019-03-13 10:55:18

标签: git npm git-tag

我有一个带有标签版本控制的npm项目,这意味着实际的项目版本仅存储在git标签上,而不存储在package.json上,后者始终保持为0.0.0

我需要使用npm工具维护此版本控制系统。

在Jenkins文件中:

npm version from-git // Obtain last Tag version from git and store it in package.json, it also does an automatic tag and commit for git (which I absolutely don't like)
npm version patch // Upgrade package.json to a +1 patch version, prepare Tag and Commit for git.
git push --tags // Push new Tag to git

以上所有方法显然都行不通,因为我知道npm版本不会创建带注释的标签,导致npm始终读取相同的标签,并且第一个标签为0.0.0,因此我按如下所示更改了Jenkinsfile上的代码:

    npm --no-git-tag-version version from-git // Same above without automatic git Tag
    TAG_VERSION = sh (
         script: 'npm --no-git-tag-version version patch',
         returnStdout: true
         ).trim() // Store the patch version in a temp variable without automatic git Tag
    git tag VERSION -a -m"New Tag Version: ${TAG_VERSION}" // Create the new Tag
    git push --tags // Push new annotated Tag to git

但是它也不起作用;在git show Tag v0.0.1的输出之后,npm正在做一些奇怪的事情:

$ git show v0.0.1
tag v0.0.1
Tagger: me
Date:  today
New Tag: %s
commit blablabla
Author: me
Date:   today
diff --git a/package-lock.json b/package-lock.json
index 
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,6 +1,6 @@
 {
   "name": "agency-vthp-frontend",
-  "version": "0.0.10",
+  "version": "0.0.0",
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "agency-vthp-frontend",
-  "version": "0.0.10",
+  "version": "0.0.0",
   "author": “me”,
   "license": "UNLICENSED",
   "repository": "myrepo"

和git显示Tag v0.0.2的输出:

$ git show v0.0.2
tag v0.0.2
Tagger: me
Date:   today
New Tag
commit blablabla2
Author: me
Date:  today
    Releasing 0.0.1
diff --git a/package-lock.json b/package-lock.json
index 
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,6 +1,6 @@
 {
   "name": "agency-vthp-frontend",
-  "version": "0.0.0",
+  "version": "0.0.1",
index 
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "agency-vthp-frontend",
-  "version": "0.0.0",
+  "version": "0.0.1",
   "author": "me
   "license": "UNLICENSED",
   "repository": "myrepo"

0 个答案:

没有答案