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:
Todd Bluhm 2019-08-29 23:39:32 -05:00
parent f5e2e33939
commit bbc4b78ad2
No known key found for this signature in database
GPG Key ID: 9CF312607477B8AB
28 changed files with 70 additions and 50 deletions

View File

@ -1,7 +0,0 @@
{
"extends": "standard-with-typescript",
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "./tsconfig.json"
}
}

1
.npmrc Normal file
View File

@ -0,0 +1 @@
package-lock = false

View File

@ -3,18 +3,22 @@
[![npm](https://img.shields.io/npm/v/env-cmd.svg?maxAge=86400)](https://www.npmjs.com/package/env-cmd)
[![npm](https://img.shields.io/npm/dm/env-cmd.svg?maxAge=86400)](https://www.npmjs.com/package/env-cmd)
[![npm](https://img.shields.io/npm/l/env-cmd.svg?maxAge=2592000)](https://www.npmjs.com/package/env-cmd)
[![Standard - JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/) [![Greenkeeper badge](https://badges.greenkeeper.io/toddbluhm/env-cmd.svg)](https://greenkeeper.io/)
[![TS-Standard - Typescript Standard Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](https://github.com/toddbluhm/ts-standard)
[![Greenkeeper badge](https://badges.greenkeeper.io/toddbluhm/env-cmd.svg)](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:

View File

View File

View File

View File

View File

@ -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"
]
}
}

View File

@ -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)
})

View File

@ -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
View File

@ -0,0 +1,12 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"allowJs": true,
"checkJs": true
},
"include": [
"src/**/*",
"test/**/*",
"bin/**/*"
]
}

View File

@ -10,7 +10,6 @@
]
},
"include": [
"./src/**/*",
"./test/**/*"
"./src/**/*"
]
}