自动 git add/commit/push/打 tag,最后 publish npm 包,用的挺顺手的,一行命令解决很多事 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐关注
Meteor
JSLint - a Javascript code quality tool
jsFiddle
D3.js
WebStorm
推荐书目
Javascript 权威指南第 5 版
Closure: The Definitive Guide
hc990902
V2EX    Javascript

自动 git add/commit/push/打 tag,最后 publish npm 包,用的挺顺手的,一行命令解决很多事

  •  
  •   hc990902 2022-10-22 11:43:16 +08:00 3074 次点击
    这是一个创建于 1100 天前的主题,其中的信息可能已经有所发展或是发生改变。

    最近的时间一直投入concis组件库的开发工作,每次改完 bug 或者是新增完一些组件功能后都需要去发包、更新线上文档,这样一步步下来其实是比较麻烦的。

    发一个新的 NPM 包你可能需要这些步骤:

    • 手动修改package.json中的version.
    • git add .git commit -m "xxxx"生成一个提交.
    • git push origin master 推送到远端.
    • 在 github 中打一个新tag.
    • npm publish将代码提交到 NPM.

    是不是很麻烦?这就是cimi的由来。

    Cimi

    cimi是一款全自动 npm 发包工具,一行命令帮助你 git replase 、创建 git tag 、发布 npm 包。

    Cimi 自动生成新版本号,自动生成 commit message ,创建 tag ,push 到 github ,最后发布到 npm 中,整个过程只需要一行命令,解放你的双手!

    示例如下:

    image.png

    可以看到,通过一行cimi patch master,完成了手改版本号git add/commitgit pushgit tapsnpm publish所有任务。

    结合实际项目,你也可以像这样去配合cimi使用:

     "scripts": { "build": "rollup -c ./rollup.config.js", "replase": "npm run build && cimi patch master", } 

    自认为还是真香的

    使用

    安装cimi:

    # 全局安装 cimi npm i cimi -g # 本地安装 cimi npm i cimi -D 

    以下是cimi -h的输出:

    Usage: cimi [options] Options: -v, --version output the version number patch patch your new npm package minor minor your new npm package major major your new npm package -h, --help display help for command Tip: You should run this script in the root directory of you project or run by npm scripts. Examples: $ cimi patch [branch] (default: master) $ cimi minor [branch] (default: master) $ cimi major [branch] (default: master) 

    具体的介绍看 readme 吧,有建议或改善请留言。

    cimi github

    16 条回复    2022-10-23 10:14:07 +08:00
    learningman
        1
    learningman  
       2022-10-22 12:21:15 +08:00
    semantic-release 警告
    zbinlin
        2
    zbinlin  
       2022-10-22 12:55:34 +08:00   3
    npm 不是有命令生成新的版本吗?

    ```
    npm version {major,minor,patch}
    git push --follow-tags
    ```
    zbinlin
        3
    zbinlin  
       2022-10-22 12:56:02 +08:00
    npm pushlish
    zbinlin
        4
    zbinlin  
       2022-10-22 12:56:59 +08:00
    @zbinlin /pushlish/publish
    wonderfulcxm
        5
    wonderfulcxm  
       2022-10-22 12:58:18 +08:00 via iPhone
    不错,我尝试一下
    justan
        6
    justan  
       2022-10-22 13:03:10 +08:00
    有类似功能的有 lerna/changesets ,不知道有没特点
    masker
        7
    masker  
       2022-10-22 13:06:27 +08:00 via Android
    前端圈确实喜欢造轮子。
    Opportunity
        8
    Opportunity  
       2022-10-22 17:40:39 +08:00
    yarn 也自带这功能吧,yarn version 和 yarn publish 都可以自动改版本号和 git tag
    hc990902
        9
    hc990902  
    OP
       2022-10-22 22:43:11 +08:00
    @Opportunity 刚试了一下 yarn publish ,确实也挺方便,对比 cimi ,总结了区别:

    1.不能指定分支 commit 并推送;
    2.远程仓库没有 new version tag (可能需要其他命令辅助);

    yarn publish 可以直接指定新的版本,还是挺方便的。
    hc990902
        10
    hc990902  
    OP
       2022-10-22 22:44:27 +08:00
    @zbinlin npm publish 对比 yarn publish 就逊色很多了,你需要手动改 package.json 的 version ,再去 publish ,当然也需要去 git add/commit/push/打 tag ,帖子上的工具就是对于 npm publish 的不足才做的。
    hc990902
        11
    hc990902  
    OP
       2022-10-22 22:46:27 +08:00   1
    @zbinlin 嗯,帖子的工具原理也很简单,从我司业务方便自己而写的,只不过是一步步执行 npm version/add/commit/push/create tags ,仅此而已,在此基础上再多了一些交互,或者是原有的 patch 、major 、minor ,这些当然也都是基于版本协议的。
    hc990902
        12
    hc990902  
    OP
       2022-10-22 22:46:57 +08:00
    @wonderfulcxm 感谢支持,有意见请留言
    hc990902
        13
    hc990902  
    OP
       2022-10-22 22:47:46 +08:00
    @masker 有些人类确实抗拒创造,喜欢原地踏步躺平
    hc990902
        14
    hc990902  
    OP
       2022-10-22 22:49:09 +08:00
    @learningman 之前没听说过,看起来还不错
    masker
        15
    masker  
       2022-10-22 22:50:04 +08:00 via Android
    @hc990902 当然啦,相同的轮子重复造就是创造,所以说是前端圈
    alanhe421
        16
    alanhe421  
       2022-10-23 10:14:07 +08:00
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     2546 人在线   最高记录 6679       Select anguage
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 24ms UTC 08:09 PVG 16:09 LAX 01:09 JFK 04:09
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86