当前位置: 首页 > news >正文

nodejs child_process 操作git 提交记录 提取git commit信息

/*** 记录发布时的commit信息,用于区分内网版本包之间的差异*/import path from 'path';import {writeFileSync} from 'fs';import {execSync} from 'child_process';let outputFileName = process.argv[2];if (!outputFileName) {outputFileName = 'revision.json';}try {const rootDir = execSync('git rev-parse --show-toplevel').toString().trim();// 分支const branch = execSync('git rev-parse --abbrev-ref HEAD').toString().trim();// commit idconst SHA1 = execSync('git rev-parse --short HEAD').toString().trim();// commit bodyconst commit = execSync(`git log -n 1 --date=format:'%Y-%m-%d %H:%M:%S' --format="%s%n%an%n%cd"`).toString().trim();const [message, author, date] = commit.split('\n');const content = JSON.stringify({branch, SHA1, message, author, date},undefined,2);writeFileSync(path.join(rootDir, outputFileName), content, {encoding: 'utf8'});console.log('\x1b[32m%s\x1b[0m','✨ [amis] revision.json generated successfully!');process.exit();} catch (error) {console.log('\x1b[31m%s\x1b[0m', '❌ [amis] revision.json failed to write!');process.exit(1);}

http://www.mrgr.cn/news/30217.html

相关文章:

  • Vue:加载本地视频
  • C++和OpenGL实现3D游戏编程【连载9】——纹理的镂空显示
  • 电子书号和纸质书号的ISBN 号有什么不同?
  • 《高等代数》行列式转置(应用)
  • 如何让零售巨头在营销拓客中旗开得胜?新增企业API自动输出客户名单!
  • git 压栈存储当前分支修改,出栈使用保存
  • Fiddler 工具使用教程
  • platform
  • Linux系统查看硬件配置教程
  • Android U 多任务启动分屏——Launcher流程(下分屏 更新中)
  • 电力电容器、电子电容器的区别
  • shell脚本中的if语句、shell脚本中的if条件语句介绍和使用案例(非常全面)
  • DDoS对策是什么?详细解说DDoS攻击难以防御的理由和对策方法
  • 高等数学 3.3 泰勒公式
  • SpringCloud微服务实现服务降级的最佳实践
  • 数据结构-排序(冒泡,选择,插入,希尔,快排,归并,堆排)
  • 人工智能时代,程序员如何保持核心竞争力?
  • 制作一个rabbitmq-sdk
  • 组态软件之万维组态介绍(web组态、html组态、vue2/vue3组态)
  • 文献分享: SIGMOD-24论文集概览