我刚看了Kent C. Dodds的video,他在那里解释了他的.bash_profile
.
他为yarn
和npm
使用以下别名:
## npm aliases
alias ni="npm install";
alias nrs="npm run start -s --";
alias nrb="npm run build -s --";
alias nrd="npm run dev -s --";
alias nrt="npm run test -s --";
alias nrtw="npm run test:watch -s --";
alias nrv="npm run validate -s --";
alias rmn="rm -rf node_modules";
alias flush-npm="rm -rf node_modules && npm i && say NPM is done";
alias nicache="npm install --prefer-offline";
alias nioff="npm install --offline";
## yarn aliases
alias yar="yarn run";
alias yas="yarn run start -s --";
alias yab="yarn run build -s --";
alias yat="yarn run test -s --";
alias yav="yarn run validate -s --";
alias yoff="yarn add --offline";
alias ypm="echo \"Installing deps without lockfile and ignoring engines\" && yarn install --no-lockfile --ignore-engines"
我想知道,-s --
旗是做什么的?肯特没有在视频中解释它,我在旗帜上找不到任何info。
选项-s
使得yarn
不会在标准输出上输出任何内容,即。让它沉默。
--
来自posix utility conventions,在命令行linux工具中非常常见:
Guideline 10:
The first -- argument that is not an option-argument should be accepted as a delimiter indicating the end of options. Any following arguments should be treated as operands, even if they begin with the '-' character.
所以:
> printf "%s" -n
-n
好吧,它会打印-n
。但:
> printf -n
bash: printf: -n: invalid option
printf: usage: printf [-v var] format [arguments]
允许传递-n
,即。选项以领先的-
作为printf的第一个参数开始,可以使用--
:
> printf -- -n
-n
所以:
alias yas="yarn run start -s";
yas -package
将通过纱线抛出未知选项,因为它将尝试解析-p
作为选项。这样做:
alias yas="yarn run start -s --";
yas -package
将由yarn
抛出未知的包,因为没有名为-package
的包。通过使用--
,作者有效地阻止用户(他自己)将任何其他选项传递给yarn,因为所有后面的参数将仅被解释为包名。
-s
相当于--silent
。
--
是常见的Unix惯例,表示选项的结束。在那之后,即使参数看起来像一个选项,它也将被视为位置参数。
它意味着命令选项的结束。因此,双击后不能使用命令选项(如-s
)。但是,您可以列出要按命令处理的文件。
-s
选项本身相当于--loglevel=silent
,它禁用了日志输出。