Monday 22 July 2019

How to run different postinstall script if environment is development/production

Hey! I'm trying to set up a postinstall script that would be slightly different in development vs. production. I'll probably use a bash script to do what I need to do, but I'm not sure how I would check whether we are in a production environment or not. It seems like there would be two ways to potentially do this:1) Run a different bash script based on the environment:``` ... (package.json, pseudocode)"scripts": {"postinstall": "if production 'sh setup-prod.sh' else 'sh setup-dev.sh'",...```2) Check the enviroment in the bash script:``` ... (package.json)"scripts": {"postinstall": "sh setup.sh",...(setup.sh, pseudocode) if (env === production) //do production stuff else // do development stuff ```Any ideas on how I could do this? Is there a way to access e.g. NODE_ENV in an npm script or in my .sh script?

Submitted July 22, 2019 at 09:35AM by sourtargets

No comments:

Post a Comment