用shell解释发布开源工具的git commit&git tag&npm publish&gh-pages流程

由于过程复杂和老忘记改版本号(╯‵□′)╯︵┻━┻,为简化本身提交开源工具而写的shell,记录一下。webpack

用alias写在了.zshrc里,直接用 command [version] [commit/tag message] [subtreeDir]使用,[version][message]必须。git

其中包含了自动修改版本号、git提交操做、tag操做、publish、提交gh-pages的subtree。github

个人drag-block目前在用,前期准备工做以下:web

  • 在github上建库
  • 使用webpack打包,设置dev和prod环境
  • build会把代码以及示例打包,分别放在lib/ 和 example/下
  • 须要一个npm帐号在登陆状态
  • 配置npm publish以前的ignore、files等
  • 创建gh-pages分支,并使用subtree将example/提交到该分支

会获得:shell

  • 一个github仓库
  • github releases,能够用代码包的方式下载
  • 能够直接在npm install的工具
  • 一个github page,内容是你作的示例页面

具体的能够从drag-block这里看。npm

#!/bin/sh                                                                                                                                                                                
if [ ! -n "$3" ];then
    subtreeDir="example/"
else
    subtreeDir=$3
fi

if [ ! -n "$1" ];then
    echo '请输入版本号';
else
    sed -i '' 's#\("version": "\).*#\1'"$1"'",#g' package.json # 修改package.json中的version
    npm run build
    git add .
    git commit -m "$2"
    git tag $1 -m "$2"
    git push
    git push --tags
    npm publish
    git subtree push --prefix=${subtreeDir} origin gh-pages  # 使用subtree的方式提交个人 example/ 目录为gh-pages分支内容,用以github pages。
fi
相关文章
相关标签/搜索