不知身为前端er的你是否是还在使用 Windows 开发?反正我是。使用 Git?使用 npm scripts?好吧,命令行是少不了的吧?想必不少同窗和我同样,使用 Git Bash 做为命令行终端吧。html
但是每次都要敲,累不累?想一想一次简单的 Git 提交须要几个步骤?前端
$ git add -A $ git commit -m 'commit' $ git push
图简便的你可能会在 package.json 中这样配置:react
{ // ... "scripts": { // ... "push": "git add -A && git commit -m 'commit' && git push" } } // ...
而后再敲 npm run push
。啊啊心好累。android
用过 browser-sync cli
吗?反正为了图简便,我是常常用的。敲过最变态的是下面这一行:git
browser-sync start --server --files "dist/*" --index "dist/index.html" --open "external" --reload-debounce --no-notify
敲过一次以后,发誓不再这么玩了。索性在桌面保存了一个 bs.bat
文件,把上面的内容放进去。每次都从桌面 copy 到工做目录中去,双击完事。github
后来玩 github 稍微勤了一些,commit、pull 的时候,命令行敲起来当然爽得不行,但是累啊。在上一家公司作 react-native 应用的时候,对 react-native run start
cd android && ./gradlew assembleRelease
也是深恶痛绝。最后无不以 bat、sh文件收尾。web
前些时间接触到一个管理 npm registry
的 package,叫 nrm
,用起来真是爽。nrm use taobao
nrm add xx url
简单就能解决问题。这让我萌生一个想法:能不能不要每次都从桌面 copy 那些简单的脚本啊,来个简单的命令行本身把文件写目录不就 OK 了吗?npm
酝酿了一段时间。迟迟不愿动手。今天中午下楼抽烟,灵机一动,思路来了,花了半下午时间,边写边重构,最终作出来一个略嫌简陋但还能凑合用的工具,名之曰 “nshm”,取 “Node.js .sh scripts Manager” 的缩写,放在 Github 上了,https://github.com/AngusFu/nshm。json
使用起来很简单,看文档就行。react-native
$ npm install nshm -g $ nshm <command> [args...]
$ nshm add <command_name> -[t|f] [text|path] # add file content $ nshm add commit --file ./my-commit.sh # or $ nshm add commit -f ./my-commit.sh # add text content $ nshm add pull --text "git pull" # or $ nshm add pull -t "git pull"
$ nshm co <command_name> [command|text] [command|text] [command|text] [...] $ nshm co git commit pull "git status"
$ nshm rm <command_name> <command_name> <...> $ nshm rm commit pull git
$ nshm clean
# view all names $ nshm ls # view all details $ nshm ls -a
$ nshm add add -t "git add -A" $ nshm add commit -t "git commit -m 'push'" $ nshm add pull -t "git push" $ nshm co git add commit pull # init my directory # then we'll get `add.sh` `commit.sh` `pull.sh` $ nshm git
# browserSync cli # here we use `${}` as placeholders # for necessary params $ nshm add bs -t "browser-sync start --server --files \"${files}\" --index \"${index}\" --open \"external\" --reload-debounce --no-notify" # now we get the `bs.sh` file under our working directory $ nshm bs --file '**' --index 'index.html'
工具默认自带了 Git 相关的 commit
pull
及集成二者的 git
命令,还有上面提到的 browser-sync
的命令(简称做bs
)。也能够使用 nshm add
的形式本身添加。
微不足道的工具,自娱自乐一下,虽然显得 low 了点,也能解决本身的一点问题。
That's all。
PS: 今晚开始看 WebRTC 的内容,小有收获,学习笔记会放在 https://github.com/AngusFu/webRTC-demo 这里,不是对书上 demo 的简单重复,而是按照本身的理解来记录。学习的生活捡起来!