Use command line arguments for scripts.
See original GitHub issueWhat?
I think it would be easier to specify npm run scripts with command line arguments rather, as it would allow greater diversity in scripts that are runnable.
Example:
As an example I will use a simple add method that take command line arguments in its script:
// add.js
// adds two integers received as command line arguments
function add(a, b) {
return parseInt(a)+parseInt(b);
}
if(!process.argv[2] || !process.argv[3]) {
console.log('Insufficient number of arguments! Give two numbers please!');
}
else {
console.log('The sum of', process.argv[2], 'and', process.argv[3], 'is', add(process.argv[2], process.argv[3]));
}
The script becomes:
"js-add": "node add.js"
To run the script:
npm run js-add 2 3
Giving an output of:
The sum of 2 and 3 is 5
Relevance to vue-cli-plugin-cordova?
Using this method:
npm run cordova-serve-ios
can be replace with:
npm run cordova serve ios
This would be ideal in my situation, as I can’t build my ios projects on the command line. So my typical build command would be cordova prepare ios
and then I would run the app through xcode. But because your cli commands don’t allow for cordova prepare ios
I can’t do this.
This way would also make adding commands like cordova prepare ios
easier.
Issue Analytics
- State:
- Created 5 years ago
- Comments:27 (11 by maintainers)
Top Results From Across the Web
How to Use Command Line Arguments in a Bash Script
Learn how to use command-line arguments inside the bash script.
Read more >Bash Script - How to use Command Line Arguments
In this article, let us see about Command Line Arguments usage in Bash script. Arguments are inputs that are necessary to process the...
Read more >How to Read Command Line Arguments in Shell Scripts?
Command -line arguments are parameters that are passed to a script while executing them in the bash shell. They are also known as...
Read more >Adding arguments and options to your Bash scripts - Red Hat
Bash uses a tool called positional parameters to provide a means of entering data into a Bash program when it is invoked from...
Read more >Command Line Arguments - Linux Hint
You can handle command-line arguments in a bash script in two ways. One is by using argument variables, and another is by using...
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
Any progress with adding build.json support 😃
ok, I’ll give build.json a try, and we can mention and explain this in the README for the “advanced” users