有没有办法用 JavaScript 读取 Git 标签
Is there a way to read Git tags with JavaScript
我将开始使用 Git 标记来标记代码库,但我还想在我的应用程序中的某个位置显示此标记,以便测试人员知道他们正在测试哪个版本。
有没有办法使用 JavaScript 读取当前 Git 标签的内容?
仅供参考,我使用 Grunt.js 构建应用程序。但是,最好使用 vanilla JS 解决方案。
使用 git-rev-sync
package,您可以创建一个自定义任务来检索当前标签并将其存储为 grunt.option
以在您的 grunt 任务的其他地方使用:
var git = require('git-rev-sync');
function currentGitTag() {
var currentTag = git.tag();
grunt.option('tag', currentTag);
}
grunt.registerTask('gitTag', currentGitTag);
要访问 grunt 中的值:grunt.option('tag');
。
您还可以通过模板字符串访问值:<%= grunt.option('tag') %>
isomorphic-git has a listTags() function that does just that. The package is available as a npm package。从 API 文档复制的示例片段:
let tags = await git.listTags({ dir: '.' })
console.log(tags)
目前,isomorphic-git 不支持创建标签(在撰写本文时,该软件包的最新版本是 0.37.3 版)。不过有个GitHub issue表示已经开始工作,以后会补上
我将开始使用 Git 标记来标记代码库,但我还想在我的应用程序中的某个位置显示此标记,以便测试人员知道他们正在测试哪个版本。
有没有办法使用 JavaScript 读取当前 Git 标签的内容?
仅供参考,我使用 Grunt.js 构建应用程序。但是,最好使用 vanilla JS 解决方案。
使用 git-rev-sync
package,您可以创建一个自定义任务来检索当前标签并将其存储为 grunt.option
以在您的 grunt 任务的其他地方使用:
var git = require('git-rev-sync');
function currentGitTag() {
var currentTag = git.tag();
grunt.option('tag', currentTag);
}
grunt.registerTask('gitTag', currentGitTag);
要访问 grunt 中的值:grunt.option('tag');
。
您还可以通过模板字符串访问值:<%= grunt.option('tag') %>
isomorphic-git has a listTags() function that does just that. The package is available as a npm package。从 API 文档复制的示例片段:
let tags = await git.listTags({ dir: '.' })
console.log(tags)
目前,isomorphic-git 不支持创建标签(在撰写本文时,该软件包的最新版本是 0.37.3 版)。不过有个GitHub issue表示已经开始工作,以后会补上