Git Product home page Git Product logo

if-env's Introduction

if-env

Simplify npm scripts with if-env ... && npm run this || npm run that


I recommend switching to per-env, which is much simpler and much more powerful!


Suppose you want to simplify development and be able to run npm start in all environments & run the correct scripts.

Your package.json might look like this:

"scripts": {
  "start": "if [[ ${NODE_ENV} == \"production\" ]]; then npm run start:prod; else npm run start:dev; fi",
  "start:dev": "webpack",
  "start:prod": "start-cluster"
}

The problem is, this doesn't work in all environments.

Instead, you can write:

"scripts": {
  "start": "if-env NODE_ENV=production && npm run start:prod || npm run start:dev",
  "start:dev": "webpack",
  "start:prod": "start-cluster"
}

Usage

1. Install

$ npm install if-env --save

2. Add to package.json

"scripts": {
  "start": "if-env SOME_ENV_VAR=some_val ANOTHER_ENV_VAR=another_val && npm run this || npm run that"
}

License

MIT © Eric Clemmons 2015

if-env's People

Contributors

ericclemmons avatar loris avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

if-env's Issues

Does it work with husky?

HI, I would like to implement this module in husky.

I am using a package called post-npm-install to automatically update dependencies on merge or rebase. I do not want to do it in PROD environment. This is what I have done.

"husky": { "hooks": { "pre-commit": "lint-staged", "post-merge": "if-env NODE_ENV != 'production' && post-npm-install", "post-rebase": "if-env NODE_ENV != 'production' && post-npm-install" } },

This doesnt work. Should I do something to make this work? Please advice.

Failed to work in docker

My npm script likes this:

"scripts": {
"start": "if-env NODE_ENV=production ?? npm run start:prod || npm run start:dev",
"start:dev": "DEBUG=dummy-app:* node --inspect ./bin/www",
"start:prod": "node ./bin/www"
}

Then I run NODE_ENV=production npm start but it did not work。

if-env NODE_ENV=production && npm run start:prod || npm start:dev

This command may play really bad joke with you, I learned it a hard way

if-env NODE_ENV=production && npm run start:prod || npm start:dev

if your app dies on unhandled exception then npm run start:prod returns no-zero code, then this expression proceeds to the npm start:dev and restarts your app in dev mode

Does not work with bash scripts?

The only difference from the example I see is not using nom run (and setting the env value) in:
"test" : "NODE_ENV='production' && if-env NODE_ENV==production && echo 'prod' $NODE_ENV || echo 'dev' $NODE_ENV",

The output I get (in Mac OS Sierra):
dev production

Do I use it wrongly or did I met a limitation?

Breaking - Don't use && and ||

Example:

if-env NODE_ENV=production && npm run webpack:prod || npm run webpack:dev

If webpack:prod fails, then webpack:dev runs. This isn't the desired behavior, as if-env only helps when everything works.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.