Reputation: 2129
I have the following NPM script in my package.json:
{
"scripts": {
"lint": "tslint -c tslint.json src/**/**?(.test).ts?(x)"
}
}
And after I run npm run lint
I get the following error:
> tslint -c tslint.json src/**/**?(.test).ts?(x)
sh: -c: line 0: syntax error near unexpected token `('
sh: -c: line 0: `tslint -c tslint.json src/**/**?(.test).ts?(x)'
It seems that I cannot use the character ( in my NPM script. How can I come around this? The script is a valid bash script.
I tried searching the issue but I couldn't find anything helpful.
Any help is appreciated.
Kind thanks!
Update:
It seems that running this command in my terminal (macOS) like so:
bash -c "tslint -c tslint.json src/**/**?(.test).ts?(x)"
I get the exact same error.
however if I run it like this:
bash -c "tslint -c tslint.json src/**/**?\(.test\).ts?\(x\)"
it seems to work in the terminal. But not in a NPM script.
Got it to work like so:
{
"scripts": {
"lint": "bash -c \"tslint -c tslint.json 'src/**/**?(.test).ts?(x)'\"",
}
}
or the more simpler version
{
"scripts": {
"lint": "tslint -c tslint.json 'src/**/**?(.test).ts?(x)'",
}
}
Credits go to @shellter.
Upvotes: 4
Views: 1552
Reputation: 1849
I once wrote this script to make a basic syntax check on my javascript files:
#!/usr/bin/env bash
if [ -x "$(command -v parallel)" ]; then
find src/js -name "*.js" | parallel --no-notice --jobs 4 --gnu nodejs -c
else
find src/js -name "*.js" | xargs -L1 -d '\n' nodejs -c
fi
This will lint every javascript file within src/js and utilize parallel if available. If you have a cpu with more threads, you might want to increase the jobs parameter to match your threads-count.
I hope this is of some help to you
Upvotes: 2