Node.js .sh scripts Manager

敕令行也有苦恼

不知身为前端er的你是否是还在运用 Windows 开辟?横竖我是。运用 Git?运用 npm scripts?好吧,敕令行是少不了的吧?想必许多同砚和我一样,运用 Git Bash 作为敕令行终端吧。

但是每次都要敲,累不累?想一想一次简朴的 Git 提交须要几个步骤?

$ git add -A
$ git commit -m 'commit'
$ git push

图轻便的你能够会在 package.json 中如许设置:

{
    // ...
    "scripts": {
       // ...
       "push": "git add -A && git commit -m 'commit' && git push"
    }
}
// ...

然后再敲 npm run push。啊啊心好累。

用过 browser-sync cli 吗?横竖为了图轻便,我是经经常使用的。敲过最变态的是下面这一行:


browser-sync start --server --files "dist/*" --index "dist/index.html" --open "external" --reload-debounce --no-notify

.bat/.sh 的故事

敲过一次以后,宣誓不再这么玩了。干脆在桌面保留了一个 bs.bat 文件,把上面的内容放进去。每次都从桌面 copy 到事情目次中去,双击完事。

厥后玩 github 轻微勤了一些,commit、pull 的时刻,敕令行敲起来当然爽得不可,但是累啊。在上一家公司做 react-native 运用的时刻,对 react-native run start cd android && ./gradlew assembleRelease 也是切齿腐心。末了无不以 bat、sh文件扫尾。

nshm 的由来

前些时候接触到一个治理 npm registry 的 package,叫 nrm,用起来真是爽。nrm use taobao nrm add xx url简朴就能够处理题目。这让我萌生一个主意:能不能不要每次都从桌面 copy 那些简朴的剧本啊,来个简朴的敕令行本身把文件写目次不就 OK 了吗?

酝酿了一段时候。迟迟不愿着手。本日正午下楼吸烟,心血来潮,思绪来了,花了半下午时候,边写边重构,终究做出来一个略嫌大略但还能凑合用的东西,名之曰 “nshm”,取 “Node.js .sh scripts Manager” 的缩写,放在 Github 上了,https://github.com/AngusFu/nshm

运用起来很简朴,看文档就行。

装置

$ 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

Example 01

$ 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 

Example 02

# 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 的简朴反复,而是根据本身的明白来纪录。进修的生涯捡起来!

    原文作者:文蔺
    原文地址: https://segmentfault.com/a/1190000005947697
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞