I plan to do something similar, like custom lodash assemblies. Therefore, in general, I want the user to write a command, for example:
lodash category=collection,function
Creating a custom module with only the specified category i
I read several tutorials on how to run scripts with npm bin. Just in case, I understand something wrong, I write it what I think.
So, if I have package.json with this part:
"main": "bin/index.js", "bin": { "snippet": "bin/index.js" },
and I npm install -g console should listen to the fragment of the command, and when I write it, it runs the script index.js in the bin folder.
This part looks correct to me. When I have something simple in my index.js ie console.log('It Works') .
In a standard situation, you want the user to pass parameters to the script. Therefore, I found out that all parameters should be in the variable process.argv .
The process.argv property returns an array containing the command line arguments passed when the Node.js process started. The first item will be process.execPath. The second element is the path to the JavaScript executable. The remaining elements will be any additional command line arguments.
So, I just console.log and run the script.
If I run the script using the snippet -f -a command Output: [ 'node', 'path/to/file' ]
If I run the script through node bin/index.js -f -a Exit: [ 'node', 'path/to/file', '-f', '-a' ]
I do not understand that this is the same script, but a different conclusion. However, I try to make it look like when I call the script through the bin command, it never passes parameters.
Is it someone who has experience? And advise me what am I doing wrong?
Or alternatively is there another way to do this?
Thanks for the consultation.