npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@mr.mikey/create-husky

v1.1.4

Published

自动为项目工程生成husky及git hook等配置,会创建commitlint对提交信息进行规范限制(angular commit规范)、汉化commitizen配置、lint-staged仅对commit文件做lint校验、release-it快速发布符合Semantic Version规范的版本和自动根据提交信息生成CHANGELOG。

Downloads

36

Readme

@mr.mikey/create-husky

功能说明

  • 做项目基建时需要对团队成员commit-msg进行规范化限制,一般采用业界公认的angular提交规范,为了避免繁琐无聊的配置,将这个过程做成了npm包,通过安装包执行命令即可一键在项目中生成配置,并通过husky来创建git hook限制提交msg格式。
  • 不会吧!不会还有人在手动维护CHANGELOG文档和管理版本吧!工具包集成了 release-it 和 auto-changelog 功能,你可以在初始化的时候选择是否需要它,它的主要作用是帮助我们快速生成符合 Semantic Versioning 规范的版本,自动打tag和修改package.json中的version字段,并且支持自动生成changelog功能,生成的CHANGELOG.md在项目根目录下。

请注意,使用release-it功能必须保证设置了远端仓库地址,否则将会失败。

初始化完成后输入 npm run commit 在cmder终端演示效果:

初始化完成后输入 npm run release:minor 在cmder终端的演示效果:

项目根目录下自动生成的changelog文档格式长这样:

为了偷懒,建议安装yarn,通过yarn commit来运行能少输几个字符

使用

环境

node: ^14.18.0 || >=16.0.0

安装依赖(用户名没取好,输入命令时记得加上引号)

npm install "@mr.mikey/create-husky" -D

初始化(用户名没取好,输入命令时记得加上引号)

npm init "@mr.mikey/husky"

或者

node ./node_modules/@mr.mikey/create-husky/index.mjs

初始化命令 npm init "@mr.mikey/husky" 或者 node ./node_modules/@mr.mikey/create-husky/index.mjs 演示效果:

自动生成&修改文件

package.json 会新增以下内容

"scripts": {
  "prepare": "husky install",
  "rehusky": "node ./node_modules/@mr.mikey/create-husky/index.mjs",
  "commit": "git add . && cz",
  "push": "git add . && cz && git push",

  // 如果你选择安装release-it
  "release:major": "release-it major",
  "release:minor": "release-it minor",
  "release:patch": "release-it patch"
},
"devDependencies": {
  "@commitlint/cli": "^17.6.7",
  "@commitlint/config-conventional": "^17.6.7",
  "commitizen": "^4.3.0",
  "commitlint-config-cz": "^0.13.3",
  "cz-customizable": "^7.0.0",
  "husky": "^8.0.3",
  "lint-staged": "^13.2.3",

  // 如果你选择安装release-it
  "@release-it/conventional-changelog": "^7.0.0",
  "auto-changelog": "^2.4.0",
  "release-it": "^16.0.0"
}
"config": {
  "commitizen": {
    "path": "./node_modules/cz-customizable"
  },
  "cz-customizable": {
    "config": "./.cz-config.js"
  }
}

scripts说明

| 命令 | 说明 | | ------------- | ------------------------------------------------------------------------------ | | prepare | npm install时自动触发husky安装,保证团队内成员在初次克隆仓库安装依赖后就能使用 | | rehusky | 重新执行本依赖包,创建配置文件 | | commit | 一键触发commit-msg交互选择工具并commit | | push | 一键触发commit-msg交互选择工具并push | | release:major | 一键发布major版本 | | release:minor | 一键发布minor版本 | | release:patch | 一键发布patch版本 |

devDependencies说明(commitlint功能安装的是(2023/07/28)最新稳定版,release-it功能安装的是(2023/08/10)最新稳定版,安装时会固定以下版本号,防止某个包断崖式更新导致无法使用该功能)

| 依赖 | 说明 | | ---------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------- | | @commitlint/[email protected] | commitlint基础,对commit-msg进行校验,不符合angular规范的commit信息将不允许提交 | | @commitlint/[email protected] | 用于commitlint验证msg是否符合angular规范 | | [email protected] | 友好的终端交互工具,输入命令即可自由选择符合angular规范的commit信息 | | [email protected] | 用于cz的commitlint可共享配置文件可自定义(用于常规提交和常规变更日志的可自定义Commitizen适配器) | | [email protected] | 自定义汉化commitizen,提供符合国人喜好的中文配置 | | [email protected] | git hook工具 | | [email protected] | 仅对commit的文件做lint校验工具 | | [email protected] | 使用release-it进行版本管理,并通过其多功能配置、强大的插件系统和挂钩发布到任何地方,以执行测试、构建和/或发布项目所需的任何命令 | | @release-it/[email protected] | 这个插件将提供推荐的bump来发布它,并更新变更日志文件例如changelog文件 | | [email protected] | 用于从git标记和提交历史生成变更日志 |

config说明

config中新增了commitizen的路径配置,默认配置为cz-customizable表示自定义commitizen,同时配置cz-customizable,让它读取生成的自定义配置文件.cz-config.js来实现汉化功能

根目录下新增文件

  • lint-staged.config.js:lint-staged配置模板,可自行修改
  • .cz-config.js:自定义终端汉化交互配置模板,可自行修改
  • .commitlintrc.js:commitlint配置模板,可自行修改
  • .release-it.json:release-it配置模板,可自行修改

试用步骤

  1. 新建文件夹,如husky-demo
  2. 打开终端进入husky-demo目录
  3. 输入 npm init -y 创建package.json
  4. 输入 git init 创建.git目录
  5. 输入 npm install "@mr.mikey/create-husky" -D 安装依赖
  6. 输入 npm init "@mr.mikey/husky" 执行依赖包
  7. 根目录下添加.gitignore,将node_modules放进去,否则文件太多啦
  8. 成功后即可体验输入 npm run commit 在终端选择规范的commit-msg

非前端项目如何使用?

其它语言有没有类似的这些工具包我不清楚,但你要想在非前端项目中使用的话也是可以的,只需要本地安装一个node环境,然后全局安装这个包即可

步骤:

  1. 安装 node:^14.18.0 || >=16.0.0 附上链接
  2. 终端输入命令全局安装工具包: npm install "@mr.mikey/create-husky" -g
  3. 终端输入命令运行工具包: npm init "@mr.mikey/husky"

完成后会在项目根目录下生成上述文件,但你可能并不想提交这些文件,所以你可以在.gitignore文件中忽略它们,配置我写好了直接cv就行

# 忽略create-husky生成文件 start
node_modules
.husky
package.json
package-lock.json
pnpm-lock.yaml # 如果你选择pnpm安装
yarn.lock # 如果你选择yarn安装
.commitlintrc.js
.cz-config.js
lint-staged.config.js
.release-it.json
# 忽略create-husky生成文件 end

然后你就可以愉快的体验交互式规范commit了

觉得好用不妨点个star呀🙋