mirror of
https://github.com/toddbluhm/env-cmd.git
synced 2025-12-08 18:23:33 +00:00
Convert over to using ts-standard
- Removed all the various eslint dependencies and added ts-standard - Updated Readme file with some minor changes - Updated dist folder to have one level again
This commit is contained in:
parent
f5e2e33939
commit
bbc4b78ad2
@ -1,7 +0,0 @@
|
||||
{
|
||||
"extends": "standard-with-typescript",
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"parserOptions": {
|
||||
"project": "./tsconfig.json"
|
||||
}
|
||||
}
|
||||
64
README.md
64
README.md
@ -3,18 +3,22 @@
|
||||
[](https://www.npmjs.com/package/env-cmd)
|
||||
[](https://www.npmjs.com/package/env-cmd)
|
||||
[](https://www.npmjs.com/package/env-cmd)
|
||||
[](http://standardjs.com/) [](https://greenkeeper.io/)
|
||||
[](https://github.com/toddbluhm/ts-standard)
|
||||
[](https://greenkeeper.io/)
|
||||
|
||||
# env-cmd
|
||||
|
||||
A simple node program for executing commands using an environment from an env file.
|
||||
|
||||
## Install
|
||||
|
||||
`npm install env-cmd` or `npm install -g env-cmd`
|
||||
|
||||
## Basic Usage
|
||||
|
||||
**Environment file `./.env`**
|
||||
```
|
||||
|
||||
```text
|
||||
# This is a comment
|
||||
ENV1=THANKS
|
||||
ENV2=FOR ALL
|
||||
@ -22,6 +26,7 @@ ENV3=THE FISH
|
||||
```
|
||||
|
||||
**Package.json**
|
||||
|
||||
```json
|
||||
{
|
||||
"scripts": {
|
||||
@ -31,20 +36,24 @@ ENV3=THE FISH
|
||||
```
|
||||
|
||||
**Terminal**
|
||||
|
||||
```sh
|
||||
./node_modules/.bin/env-cmd node index.js
|
||||
```
|
||||
|
||||
## Using custom env file path
|
||||
|
||||
To use a custom env filename or path, pass the `-f` flag. This is a major breaking change from prior versions < 9.0.0
|
||||
|
||||
**Terminal**
|
||||
|
||||
```sh
|
||||
./node_modules/.bin/env-cmd -f ./custom/path/.env node index.js
|
||||
```
|
||||
|
||||
## 📜 Help
|
||||
```
|
||||
|
||||
```text
|
||||
Usage: _ [options] <command> [...args]
|
||||
|
||||
Options:
|
||||
@ -87,6 +96,7 @@ are found.
|
||||
```
|
||||
|
||||
**Terminal**
|
||||
|
||||
```sh
|
||||
./node_modules/.bin/env-cmd -e production node index.js
|
||||
# Or for multiple environments (where `production` vars override `test` vars,
|
||||
@ -110,6 +120,7 @@ Executes the command within a new shell environment. This is useful if you want
|
||||
commands together that share the same environment variables.
|
||||
|
||||
**Terminal**
|
||||
|
||||
```sh
|
||||
./node_modules/.bin/env-cmd -f ./test/.env --use-shell "npm run lint && npm test"
|
||||
```
|
||||
@ -122,6 +133,7 @@ files are also supported using `.js` file extension and resolving to an object w
|
||||
names (`{ production: { ENV_VAR_NAME: value, ... } }`).
|
||||
|
||||
**Terminal**
|
||||
|
||||
```sh
|
||||
./node_modules/.bin/env-cmd -f ./async-file.js node index.js
|
||||
```
|
||||
@ -134,6 +146,7 @@ the examples repo [env-cmd-examples](https://github.com/toddbluhm/env-cmd-exampl
|
||||
## Environment File Formats
|
||||
|
||||
These are the currently accepted environment file formats. If any other formats are desired please create an issue.
|
||||
|
||||
- `.env` as `key=value`
|
||||
- `.env.json` Key/value pairs as JSON
|
||||
- `.env.js` JavaScript file exporting an `object` or a `Promise` that resolves to an `object`
|
||||
@ -158,31 +171,35 @@ Working Directory = `/Users/test/Development/app`
|
||||
## ⚒ API Usage
|
||||
|
||||
### `EnvCmd`
|
||||
|
||||
A function that executes a given command in a new child process with the given environment and options
|
||||
|
||||
- **`options`** { `object` }
|
||||
- **`command`** { `string` }: The command to execute (`node`, `mocha`, ...)
|
||||
- **`commandArgs`** { `string[]` }: List of arguments to pass to the `command` (`['-R', 'Spec']`)
|
||||
- **`envFile`** { `object` }
|
||||
- **`filePath`** { `string` }: Custom path to .env file to read from (defaults to: `./.env`)
|
||||
- **`fallback`** { `boolean` }: Should fall back to default `./.env` file if custom path does not exist
|
||||
- **`rc`** { `object` }
|
||||
- **`environments`** { `string[]` }: List of environment to read from the `.rc` file
|
||||
- **`filePath`** { `string` }: Custom path to the `.rc` file (defaults to: `./.env-cmdrc(|.js|.json)`)
|
||||
- **`options`** { `object` }
|
||||
- **`command`** { `string` }: The command to execute (`node`, `mocha`, ...)
|
||||
- **`commandArgs`** { `string[]` }: List of arguments to pass to the `command` (`['-R', 'Spec']`)
|
||||
- **`envFile`** { `object` }
|
||||
- **`filePath`** { `string` }: Custom path to .env file to read from (defaults to: `./.env`)
|
||||
- **`fallback`** { `boolean` }: Should fall back to default `./.env` file if custom path does not exist
|
||||
- **`rc`** { `object` }
|
||||
- **`environments`** { `string[]` }: List of environment to read from the `.rc` file
|
||||
- **`filePath`** { `string` }: Custom path to the `.rc` file (defaults to: `./.env-cmdrc(|.js|.json)`)
|
||||
- **`options`** { `object` }
|
||||
- **`noOverride`** { `boolean` }: Prevent `.env` file vars from overriding existing `process.env` vars (default: `false`)
|
||||
- **`useShell`** { `boolean` }: Runs command inside a new shell instance (default: `false`)
|
||||
- **Returns** { `Promise<object>` }: key is env var name and value is the env var value
|
||||
- **`noOverride`** { `boolean` }: Prevent `.env` file vars from overriding existing `process.env` vars (default: `false`)
|
||||
- **`useShell`** { `boolean` }: Runs command inside a new shell instance (default: `false`)
|
||||
- **Returns** { `Promise<object>` }: key is env var name and value is the env var value
|
||||
|
||||
### `GetEnvVars`
|
||||
|
||||
A function that parses environment variables from a `.env` or a `.rc` file
|
||||
- **`options`** { `object` }
|
||||
- **`envFile`** { `object` }
|
||||
- **`filePath`** { `string` }: Custom path to .env file to read from (defaults to: `./.env`)
|
||||
- **`fallback`** { `boolean` }: Should fall back to default `./.env` file if custom path does not exist
|
||||
- **`rc`** { `object` }
|
||||
- **`environments`** { `string[]` }: List of environment to read from the `.rc` file
|
||||
- **`filePath`** { `string` }: Custom path to the `.rc` file (defaults to: `./.env-cmdrc(|.js|.json)`)
|
||||
- **Returns** { `Promise<object>` }: key is env var name and value is the env var value
|
||||
|
||||
- **`options`** { `object` }
|
||||
- **`envFile`** { `object` }
|
||||
- **`filePath`** { `string` }: Custom path to .env file to read from (defaults to: `./.env`)
|
||||
- **`fallback`** { `boolean` }: Should fall back to default `./.env` file if custom path does not exist
|
||||
- **`rc`** { `object` }
|
||||
- **`environments`** { `string[]` }: List of environment to read from the `.rc` file
|
||||
- **`filePath`** { `string` }: Custom path to the `.rc` file (defaults to: `./.env-cmdrc(|.js|.json)`)
|
||||
- **Returns** { `Promise<object>` }: key is env var name and value is the env var value
|
||||
|
||||
## Why
|
||||
|
||||
@ -208,6 +225,7 @@ same `cross-spawn` lib underneath too).
|
||||
- Anton Versal
|
||||
|
||||
## 📋 Contributing Guide
|
||||
|
||||
I welcome all pull requests. Please make sure you add appropriate test cases for any features
|
||||
added. Before opening a PR please make sure to run the following scripts:
|
||||
|
||||
|
||||
0
dist/src/env-cmd.js → dist/env-cmd.js
vendored
0
dist/src/env-cmd.js → dist/env-cmd.js
vendored
0
dist/src/index.d.ts → dist/index.d.ts
vendored
0
dist/src/index.d.ts → dist/index.d.ts
vendored
0
dist/src/index.js → dist/index.js
vendored
0
dist/src/index.js → dist/index.js
vendored
0
dist/src/spawn.d.ts → dist/spawn.d.ts
vendored
0
dist/src/spawn.d.ts → dist/spawn.d.ts
vendored
0
dist/src/spawn.js → dist/spawn.js
vendored
0
dist/src/spawn.js → dist/spawn.js
vendored
0
dist/src/types.d.ts → dist/types.d.ts
vendored
0
dist/src/types.d.ts → dist/types.d.ts
vendored
0
dist/src/types.js → dist/types.js
vendored
0
dist/src/types.js → dist/types.js
vendored
0
dist/src/utils.d.ts → dist/utils.d.ts
vendored
0
dist/src/utils.d.ts → dist/utils.d.ts
vendored
0
dist/src/utils.js → dist/utils.js
vendored
0
dist/src/utils.js → dist/utils.js
vendored
23
package.json
23
package.json
@ -2,8 +2,8 @@
|
||||
"name": "env-cmd",
|
||||
"version": "10.0.0",
|
||||
"description": "Executes a command using the environment variables in an env file",
|
||||
"main": "dist/src/index.js",
|
||||
"types": "dist/src/index.d.ts",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
"engines": {
|
||||
"node": ">=8.0.0"
|
||||
},
|
||||
@ -13,9 +13,8 @@
|
||||
"scripts": {
|
||||
"test": "mocha -r ts-node/register ./test/**/*.ts",
|
||||
"test-cover": "nyc --reporter=lcov --reporter=text npm test",
|
||||
"test-lint": "eslint ./src/**/*.ts ./test/**/*.ts",
|
||||
"coveralls": "coveralls < coverage/lcov.info",
|
||||
"lint": "eslint --fix ./src/**/*.ts ./test/**/*.ts && tsc --noEmit",
|
||||
"lint": "ts-standard --fix && tsc --noEmit",
|
||||
"build": "tsc",
|
||||
"watch": "tsc -w"
|
||||
},
|
||||
@ -57,21 +56,13 @@
|
||||
"@types/mocha": "^5.0.0",
|
||||
"@types/node": "^12.0.0",
|
||||
"@types/sinon": "^7.0.0",
|
||||
"@typescript-eslint/eslint-plugin": "^2.0.0",
|
||||
"@typescript-eslint/parser": "^2.0.0",
|
||||
"chai": "^4.0.0",
|
||||
"coveralls": "^3.0.0",
|
||||
"eslint": "^6.0.0",
|
||||
"eslint-config-standard": "^14.0.0",
|
||||
"eslint-config-standard-with-typescript": "toddbluhm/eslint-config-standard-with-typescript#compiled",
|
||||
"eslint-plugin-import": "^2.0.0",
|
||||
"eslint-plugin-node": "^9.0.0",
|
||||
"eslint-plugin-promise": "^4.0.0",
|
||||
"eslint-plugin-standard": "^4.0.0",
|
||||
"mocha": "^6.0.0",
|
||||
"nyc": "^14.0.0",
|
||||
"sinon": "^7.0.0",
|
||||
"ts-node": "^8.0.0",
|
||||
"ts-standard": "^1.0.0",
|
||||
"typescript": "^3.0.0"
|
||||
},
|
||||
"nyc": {
|
||||
@ -90,5 +81,11 @@
|
||||
],
|
||||
"sourceMap": true,
|
||||
"instrument": true
|
||||
},
|
||||
"ts-standard": {
|
||||
"project": "./tsconfig.eslint.json",
|
||||
"ignore": [
|
||||
"dist"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
module.exports = new Promise((resolve) => {
|
||||
setTimeout(() => {
|
||||
resolve({
|
||||
'THANKS': 'FOR ALL THE FISH',
|
||||
'ANSWER': 0
|
||||
THANKS: 'FOR ALL THE FISH',
|
||||
ANSWER: 0
|
||||
})
|
||||
}, 200)
|
||||
})
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
module.exports = {
|
||||
'THANKS': 'FOR ALL THE FISH',
|
||||
'ANSWER': 0,
|
||||
'GALAXY': 'hitch\nhiking'
|
||||
THANKS: 'FOR ALL THE FISH',
|
||||
ANSWER: 0,
|
||||
GALAXY: 'hitch\nhiking'
|
||||
}
|
||||
|
||||
12
tsconfig.eslint.json
Normal file
12
tsconfig.eslint.json
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"allowJs": true,
|
||||
"checkJs": true
|
||||
},
|
||||
"include": [
|
||||
"src/**/*",
|
||||
"test/**/*",
|
||||
"bin/**/*"
|
||||
]
|
||||
}
|
||||
@ -10,7 +10,6 @@
|
||||
]
|
||||
},
|
||||
"include": [
|
||||
"./src/**/*",
|
||||
"./test/**/*"
|
||||
"./src/**/*"
|
||||
]
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user