I'm using the scripts section inside the package.json file to store some commands I have to run regularly.
"scripts": {
"test": "./test/phantomjs ./test/js/run_jasmine_test.coffee ./test/index.html",
"rjs": "r.js -o ./js/app.build.js",
"less": "lessc -x ./css/app.less > ./css/app.css"
}
in every command I have got a ./ at the beginning of the path - this is why I can only call npm run-script rjs from the project's root directory.
is there a way to reference the project's root directory inside the package.json so that I can run e.g. npm test from anywhere in my project?
considered creating a shell file that runs?
for example create a .sh file make it executable (chmod 777 file.sh)
and then cd to your nodejs project root, run the npm command, and then cd back into the directory you have just left?
adding the script to your environment will make it executable from anywhere...
alternatively will hard coding the full path be ok? (so rather than using ./ - put /home/user/username/yourproject/phantomjs)
I have found a better option is to create a js script instead of the shell script. It seems to be easier to deal with with npm from my experience. you can then check for what environment you are in before running commands. We have people with both windows, macs and ubuntu and checking the environment or using the fs package makes life easier.