0

I want to npm run a command to generate a dynamic output file from the file name I pass in the command line. But I am not able to generate that from the below command

In my package.json in the script I have added the command:

scripts:{
"gen-out":"some_cmd src/app/parser/$npm_config_filene.st -o src/app/parser/$npm_config_filene.j"
}

and after running

npm run gen-out --filene=myfile 

it produces a file with the name $npm_config_filene.js instead of myfile.js

could anyone help, please?

Daksh Dutta
  • 163
  • 1
  • 1
  • 12
  • 1
    You're probably running this command on Windows, in which case npm utilizes `cmd` as the default shell for running npm scripts. Variables in `cmd` are referenced using the `%...%` notation (unlike `sh` on _*nix_ which utilizes the dollar (`$`) prefix). If you are on Windows try encasing the `npm_config_filene` variable in your npm script with `%...%`. For example: `"gen-out":"some_cmd src/app/parser/%npm_config_filene%.st -o src/app/parser/%npm_config_filene%.js"` – RobC Feb 15 '21 at 10:21
  • thanks it is working – Daksh Dutta Feb 15 '21 at 10:24
  • see https://stackoverflow.com/questions/47606901/can-i-put-a-variable-for-a-filename-in-the-scripts-property-of-package-json answer – Hamid Taebi Oct 20 '21 at 15:37

1 Answers1

1

for windows platform use this format:

scripts:{
"gen-out":"some_cmd src/app/parser/%npm_config_filene%.st -o src/app/parser/%npm_config_filene%.j"
}

npm run gen-out --filene=myfile 
Hamid Taebi
  • 357
  • 2
  • 12