I have in my npm package the following scripts property:
"scripts": {
"test": "jasmine-node spec/",
"install": "browserify api-client.js -o ../www/components/global/api-client.js"
}
How can I do something like
npm run install --param differentOutput
so as not to hardcode the '../www/components/global/api-client.js' path
You can use option --:
npm run install -- --param differentOutput
Related
I created a tool and registered it on npmjs.com named Yattex. It script looks something like this
`
"scripts": {
"clean:reports": "rm -R -f cypress/reports && mkdir cypress/reports && mkdir cypress/reports/mochareports ",
"pretest": "npm run clean:reports",
"scripts": "cypress run",
"combine-reports": "mochawesome-merge cypress/reports/mocha/*.json > cypress/reports/mochareports/report.json",
"generate-report": "marge cypress/reports/mochareports/report.json -f report -o cypress/reports/mochareports -- inline",
"posttest": "npm run combine-reports && npm run generate-report",
"yattex-tool": "node yattex-tool",
"decorator": "node yattex-tool/test-decorators",
"test": "npm run decorator && npm run scripts || npm run posttest || npm run yattex-tool"
},
`
Now, in another project i installed the package and now i dont know what to write in scrips(test) to run the above test command which is in the node_modules/yattex/package.json file
I tried yattex and node node_modules/yattex/package.json
But it doesn't work. I'm a newbie and i cant find any solution...
If you add a property
"workspaces": ["./node_modules/yattex"]
to the package.json file in your other project, then npm test --workspaces will execute the tests both in your other project and in the yattex project (which is a "workspace" as explained on the npm help run page).
If you want to run only the tests for yattex, use npm test --workspace=./node_modules/yattex.
NODE_ENV=development : The term 'NODE_ENV=development' is not recognized as the name of a cmdlet, function, script file, or operable program. Check
the spelling of the name, or if a path was included, verify that the path is correct and try again.
Need win-node-env module
npm install -g win-node-env
For Windows
SET NODE_ENV=development
node app.js
For setting environment variables like that on Windows you can use package called cross-env.
You can install it by: npm install --save-dev cross-env. And then you have almost exact example from their docs:
{
"scripts": {
"build": "cross-env NODE_ENV=production webpack --config build/webpack.config.js"
}
}
I have setup webpack using npm. I installed jshint using npm install jshint --save-dev.
Now if I run command jshint assets/js/index.js i get errors.
I want to check the errors on npm run build
You can change your build script in the package.json in the way to run lint and then if it successful run build. See example
{
...
"scripts": {
"build": "npm run lint && your_build_command",
"lint": "jshint assets/js/index.js"
}
...
}
I know it has been covered in different questions but mine is a bit different:
Sorry in advance if it sounds really noob.
this is the script in package.json:
"start": "nodemon ./index.js --exec \"node -r babel-register\"",
I replaced that with:
"start": "node scripts/start.js",
and in start.js, I do:
const { execSync } = require('child_process')
execSync('nodemon ../index.js --exec \"node -r babel-register\"')
which throws an error:
/bin/sh: nodemon: command not found
Am I right with "execSync"?
I tried import nodemon in the file but it is obviously not helping.
What you're doing should work if nodemon is installed globally, i.e. with:
npm install -g nodemon
But if it's installed as a project dependency, i.e. with:
npm install --save-dev nodemon
Then you'll need to run it from the directory containing all the locally installed binaries: node_modules/.bin/
So something like this should work:
execSync('./node_modules/.bin/nodemon ../index.js --exec \"node -r babel-register\"')
Is there a way to use the babel client without installing it globally?
So rather than this
npm install -g babel-cli
I'd like to do this
npm install babel-cli --save-dev
Any local package's binary can be accessed inside npm scripts as if it was installed globally:
// package.json
{
"scripts": {
"build": "babel ..."
}
}
If you want to execute the binary on the command line, you can use a relative path to node_modules/.bin/:
$ node_modules/.bin/babel ...
This is related to first example: node_modules/.bin/ is simple added to the PATH of the environment the npm scripts are executed in.
you can put something like this:
{
"scripts": {
"start": "babel-node test.js"
}
}
in your package.json where test.js is a script which you want to run. Now you can run it with npm start command
Yes, you could install locally and run from node_modules:
./node_modules/.bin/babel
If you have a local package.json you could add an NPM script to simplify the command, since NPM scripts run with ./node_modules/.bin on the PATH:
"scripts": {
"babel": "babel ...",
}
To run from any directory under package.json:
$ npm run babel
If you just want to run test with command "npm test testFile.js". This is my package.json:
"scripts": {
"build": "babel-node",
"test": "node_modules/.bin/babel-node"
}