Passing arguments within a script
See original GitHub issueAny idea how I’d replace all instances of breaknotes
in this script with a argument?
I’m very close to writing a build script to write build scripts for each of my components. (not a good idea)
`scripts`:{
"update:breaknotes": "cd ./generators/ && node component.js breaknotes && terminal-notifier -message 'breaknotes updated'",
}
sadly npm config set component "breaknotes
doesn’t update the local package config even without the --global flag. $npm_package_config_component
only pulls in the local
"config": {
"component": "breaknotes"
},
Is there a way to write to the local config with a command because then we could write
npm config set component "breaknotes" && npm run update:component
Issue Analytics
- State:
- Created 9 years ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
How to pass and use arguments in shell script - Educative.io
Inside the script, we can use the $ symbol followed by the integer to access the arguments passed. For example, $1 , $2...
Read more >How can I pass a command line argument into a shell script?
You can access passed arguments with $n where n is the argument number - 1, ...
Read more >How to Use Command Line Arguments in a Bash Script
Arguments passed to a script are processed in the same order in which they're sent. The indexing of the arguments starts at one,...
Read more >Passing Arguments to a Script - Micro Focus
In the Arguments field in the Run Test Case dialog box. · In Silk Central. Select the Properties tab of a Silk Test...
Read more >How to Pass Arguments to a Python Script from the Command ...
In Python, arguments are passed to a script from the command line using the sys package. The argv member of sys ( sys.argv...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
As I mentioned in the article you can override config vars using command line switches. So let’s say you had a package json something like:
You could run
npm run update --myproject:component=foo
and it would override the$npm_package_config_component
var to befoo
.The reason your permanent
npm config set
command isn’t working, is because it needs the project namespace (it needs to be prefixed with the project name, plus a colon). So given my above example, I’d run the commandnpm config set myproject:component "foo"
to set it permanently in my local~/.npmrc
Ah, unfortunately variables won’t work in Windows. You can use npm config still, but you have to use it inside of a Node.js script, so this will work:
Alternatively if you’re ONLY using windows for this project, you can use the Windows variable syntax of
%VAR%
. I haven’t tested this but it should work: