通过 npm 节点自动化 Git 提交 + 版本控制 + 标记 [英] Automate Git commit + versioning + tag by npm node

查看:8
本文介绍了通过 npm 节点自动化 Git 提交 + 版本控制 + 标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直试图得到的是,使用 npm version 更新 package.json 并创建一个标签,然后提交我的更改.这样,我将能够按版本进行标记,自动版本控制和提交信息.

What I have been trying to get is, work with npm version to update the package.json and create a tag and then commit my changes. In this way, I will be able to have tags by version, auto versioning and commit with the info.

我遇到的问题是,当我使用npm版本时,它会自动进行标记+提交,然后如果您之前有一些更改则无法完成,所以对我来说,增加没有意义您的项目的版本,在进行更改/实施/修复之前.

The problem I am having is, when I am using npm version, it's doing a tag + commit automatically and then it can not be done if you have previously some changes, So for me, it doesn't make sense to increase the version of your project, before to do the changes/implementation/fixes.

然后,我遇到的另一个问题是我首先将版本增加为补丁",然后我做了一些更改,我添加所有,我提交,然后我发布,最后,我有 2 个提交,1因为 npm 版本补丁,另一个是好的.

Then, another problem I was having is that I first increase the version as a 'patch', then I do some changes, I add all, I commit and then I publish, at the end, I have 2 commits, 1 because of the npm version patch, and the other one the good one.

我在 here 文档中看到有一个参数可以让您禁用此自动tag + commit,但是我真的很想在控制台中使用一个命令来更新包控制台并将该版本设置为标签.

I saw in the documentation here that there is a parameter that allow you to disable this auto tag + commit, but then I would really like to use a command in the console to be able to update the package console and get that version set up as a tag.

另一方面,我不确定我所说的是否有意义,因为据我所知,当您创建标签时,您可以在项目中回到那个点,所以我如何假装工作如果我禁用自动提交?

By another hand, not sure if this that I am saying it does make sense because as far as I know, when you create a tag, you can go back in your project to that point, So how I pretend to work like that if I am disabling the auto commit?

最后,我要明确的是我的目标,我真正想要达到的是由节点脚本处理一个半自动化的脚本能够要增加项目的版本,请使用新的标签创建版本,添加所有更改,提交和推送.

Finally, What I want to make clear is my goal, What I really want to reach is handle by node scripts a semi-automated script to be able to increase the version of the project, create a tag with the new version, add all changes, commit and push.

注意:我不想使用 gulp-git,因为我认为没有它可以解决这个问题.

不确定我是否足够清楚,如果没有,请询​​问并帮助我:)

Not sure if I was clear enough, if not, please ask and help me :)

推荐答案

好的,我明白了!我一直在寻找的是运行一个简单的命令并自动执行一些我们必须始终按照 Git 相同顺序执行的无聊任务.

Ok guys, I got it! What I was looking for is to run a simple command and automate some boring tasks we have to do always in the same order for Git.

所以,我在这里要做的是,首先我运行这个命令:

So, What I do here is, first I run this command:

$> npm run commit -- 'v.1.0.1: Fixes'

发生的情况是,我首先清理了我不需要/不想要的文件夹/文件,然后我运行:

What it happens is that I firstly clean of folders/files and I dont need/want, then I run:

$> npm version patch -no-git-tag-version --force

该命令增加我的 package.json 版本,而不是提交 &不是标签,所以然后我像往常一样添加所有更改,然后我提交我的更改,然后,我使用 tag:commit gulp 任务创建标签.

That command increase my package.json version, not commit & not tag, So Then I add all changes as normal, then I commit my changes and after this, I create the tag with the tag:commit gulp task.

在 gulp 任务(附在下面)中,我使用 require 获取包的版本并将其视为对象.

In the gulp task (attached bellow), I am getting the version of the package with require and treat it as a object.

"scripts": {
   "start": "gulp start",
   "initialize": "npm install & typings install",
   "clean": "gulp clean:folders",
   "commit:example": "echo 'npm run commit -- 'v.1.0.1: Fixes'",
   "commit:patch": "npm version patch --no-git-tag-version --force",
   "commit:minor": "npm version minor --no-git-tag-version --force",
   "commit:major": "npm version major --no-git-tag-version --force",
   "precommit": "npm run clean && npm run commit:patch && git add --all",
   "postcommit": "gulp tag:commit && git push origin master && git status && gulp commit:done",
   "commit": "git commit -m "
},

然后,我的 gulp 文件中有这个:

and then, I have this in my gulp file:

///// ***** GIT ***** /////


gulp.task('tag:commit', function () {
    var version = pjson.version;
    console.log(colors.bgWhite.black.bold(' 
Tagging the version ' + version + ' 
'));
    return run('git tag ' + version).exec();
});

我不想使用 gulp-git,因为我知道有办法做到这一点,如果我需要合并、创建早午餐或其他任何东西,我将运行控制台并修复它,但对于日常提交,它是记得标记,更新包版本,把它放在 git commit 中......

I didn't want to use gulp-git as I knew there was a way to do that, If I need to merge, create brunch or whatever, I will run the console and fix it, but for daily commits, it's painful to remember to tag, update the package version, put it in the git commit....

我希望这对其他人有用!

I hope that's useful for someone else!

干杯,

这篇关于通过 npm 节点自动化 Git 提交 + 版本控制 + 标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆