if-else on arguments in npm run script

荒凉一梦 提交于 2020-01-04 02:50:32

问题


I would like to call different other scripts, depending on whether a paramter is given or not:

"paramtest": "if [ -z $1 ]; then echo Foo $1; else echo Bar; fi",

npm run paramtest

should give "Bar".

npm run paramtest -- whatever

should give "Foo whatever".

However in practice I only get: (The parameter is added to the whole line, not 'passed in')

> if [ -z $1 ]; then echo Foo; else echo Bar; fi "whatever
  sh: 1: Syntax error: word unexpected

What can I do better?

Essentially I am after running full test suite / only individual test with the same command...

"test" : "if [ -z $1 ]; then mocha ./test/**/*.test.js; else mocha $1

来源:https://stackoverflow.com/questions/51401352/if-else-on-arguments-in-npm-run-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!