I have a Node/React project and in my package.json if I want to run some simple scripts I might do something like this:
{
"scripts": {
"prep": "cp -r this/sub-directory/path another/sub-directory/path"
},
}
And then yarn prep to execute it.
However in this case I have a lot of commands, say 5-6 and to put them all on one line in a package.json file would make it difficult to read.
What I would like to do is put them in a separate file and then just call that file. Something like a file named run-script:
#!/bin/bash
echo 'test'
and then in package.json:
{
"scripts": {
"prep": "run-script"
},
}
But that gives me errors obviously, I don't know how to tell it to run the file, what extension it should be, etc. (I'm aware that I can do "prep": "node run-script.js" but in this case I want to do simple things like copy directories and such, not JavaScript things.)
Update [SOLVED]
Both of @roadowl’s solutions were needed.
- Run
chmod ug+x run-scriptto set the permissions, and then - Add the current working directory variable (
$PWD) in front of where the file is called in package.json:
{
"scripts": {
"prep": "$PWD/run-script"
},
}