if-prod

1.0.1 • Public • Published

if-prod

Build Status NPM version Dependencies status

Description

This tiny script allows to simplify conditional statements which check for the current environment from $NODE_ENV. Consider the following package.json:

"scripts"{
  "start": "if [[ \"${NODE_ENV}\" == \"production\" ]]; then node dist/server.js; else webpack --watch; fi",
}

The following code is hard for reading and doesn't work on Windows. It can be simplified using this package:

"scripts"{
  "start": "if-prod && node dist/server.js || webpack --watch",
}

Installation

Install with npm:

npm install if-prod

Usage

There are the following commands in this package:

  • if-prod
  • if-dev
  • if-env-is ENVIRONMENT NAME
  • if-not-prod
  • if-not-dev
  • if-not-env-is ENVIRONMENT NAME

Examples

  • if/then/else if-prod && node dist/server.js || webpack --watch

  • single if if-prod && node dist/server.js || true - without || true this command returns status code 1 if the current environment is not "production"

  • if not if-not-prod && rm -rf dist || true - run in all environment except "production"

  • custom environment if-env-is test && rm -rf coverage || true

Related projects

ericclemmons/if-env - almost the same approach but can check for any environment variables, not only $NODE_ENV

ericclemmons/per-env - environment-driven npm scripting

License

Licensed under MIT.

/if-prod/

    Package Sidebar

    Install

    npm i if-prod

    Weekly Downloads

    4

    Version

    1.0.1

    License

    MIT

    Unpacked Size

    2.99 kB

    Total Files

    3

    Last publish

    Collaborators

    • megahertz