应用 JS 就可以撰写能实行 shell 指令的脚本制作

lxf2023-12-17 09:00:02

太长不看:撰写 Git Commit Tool,请先看文中最终一节或是下边的 github。

Github: Hacker-C/zx-scripts

环境

对于 git commit message 的规范性,大家都很明白了,现在是用 Commitizen、commitlint、Husky hooks 来标准递交。在我们自身只是单纯递交 commit message 时,并没必要上 husky 这个工具,这时候就要撰写一个 commit tool,来设计自已的 commit message。

commitizen 还可以撰写一个 commit tool,但是它的自定并不是特别友善,最少我自己在使用的时候,文件格式不能满足我要求。

本文强烈推荐更为简单方便且个性化水平强的方式:一般用 zx 和 inquirer。

  • google/zx: A tool for writing better scripts
  • SBoudrias/Inquirer.js: A collection of common interactive command line user interfaces

zx

zx 是谷歌搜索推出的脚本编写库,应用 JS 就可以撰写能实行 shell 指令的脚本制作。

免费下载:

npm install zx -g

撰写 commit.js:

#!/usr/bin/env zx
const commitMessage = '