benoror / better-npm-run

🏃‍♂️ Better NPM scripts runner
MIT License
639 stars 56 forks source link

How to override env variables via cli? #38

Closed aqzhyi closed 8 years ago

aqzhyi commented 8 years ago

If I have

{
  "betterScripts": {
    "want:override": {
      "command": "echo $DEBUG",
      "env": {
        "DEBUG": "app:*"
      }
    }
  },
  "scripts": {
    "ov": "better-npm-run want:override"
  }
}

When I run sh$ npm run ov will output app:*

Can I do something like this, sh$ DEBUG=app:compile; npm run ov and expect output to be app:compile?

benoror commented 8 years ago

$ DEBUG=app:compile; npm run ov will set DEBUG env variable, but then it will be overwritten again by better-npm-run (if you set it on env object)

aqzhyi commented 8 years ago

Ok, thanks :)

Egor-Koldasov commented 8 years ago

So is there a way to override variables specified in betterScripts? I guess It would be very convenient because package.json is usually synchronized with repo and I see no way to override it in environment rather than in project, in a case when developing environment differs between developers at least a little bit.

benoror commented 8 years ago

@oeeq Sorry, didn't catch your point, can you illustrate it with an example?

Egor-Koldasov commented 8 years ago
{
  "scripts": {
    "dev": "better-npm-run start:dev",
    "prod": better-npm-run start:prod"
  },
  "betterScripts": {
    "start:dev": {
      "command": "./bin/run.js",
      "env": {
        "PORT": 3000,
        "DBPORT": 3306
      },
    "start:dev": {
      "command": "./bin/run.js",
      "env": {
        "NODE_ENV": "development",
        "PORT": 3000,
        "DBPORT": 3306
      }
    },
    "start:prod": {
      "command": "./bin/run.js",
      "env": {
        "NODE_ENV": "production",
        "PORT": 80,
        "DBPORT": 6603
      }
    }
  }
}

@benoror Here's a very simple example. I assume it's a pretty common use case, it simplifies configurations a lot. However, I'm losing a capability to override those parameters in environment (using .env file or specifying them before command PORT=3001 npm run dev). For example, if I don't have a 3000 port available, the only way to change it is to update package.json, which will affect other developers. So I'm searching the way to override parameters from environment, for example using some file that I could add to .gitignore. Probably it's not intended to be used this way, and this feature could add unnecessary complexity to better-npm-run, I'm just wondering if I didn't overlook this functionality.

benoror commented 8 years ago

@oeeq Yeah this definitely feels overengineered and out of scope for better-npm-run