akmur
akmur

Reputation: 1635

"No such file or directory" when running command from NPM script

I have a simple command I would like to use in my NPM scripts. The command is:

cat ./path/**/*.css > ./other/path/plugins.css

If I run this in my terminal, it works. If however I put it in an NPM script, like so:

"scripts" {
     "cat": "cat ./path/**/*.css > ./other/path/plugins.css"
}

I will get No such file or directory.

Any idea what might be the reason?

Thanks!

Upvotes: 1

Views: 752

Answers (1)

tpimh
tpimh

Reputation: 578

The reason it does not work is because cat accepts filenames as parameters and the asterisks (glob) is converted to the filenames by your shell (most probably, bash).

The reason it doesn't work with npm script is because it is not being run in the shell which supports the features you want to use (glob expansion, stdout redirect to file).

To solve it, just run it in an instance of bash:

"scripts" {
     "cat": "bash -c 'cat ./path/**/*.css > ./other/path/plugins.css'"
}

Upvotes: 1

Related Questions