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/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/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) [![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 # env-cmd
A simple node program for executing commands using an environment from an env file. A simple node program for executing commands using an environment from an env file.
## Install ## Install
`npm install env-cmd` or `npm install -g env-cmd` `npm install env-cmd` or `npm install -g env-cmd`
## Basic Usage ## Basic Usage
**Environment file `./.env`** **Environment file `./.env`**
```
```text
# This is a comment # This is a comment
ENV1=THANKS ENV1=THANKS
ENV2=FOR ALL ENV2=FOR ALL
@ -22,6 +26,7 @@ ENV3=THE FISH
``` ```
**Package.json** **Package.json**
```json ```json
{ {
"scripts": { "scripts": {
@ -31,20 +36,24 @@ ENV3=THE FISH
``` ```
**Terminal** **Terminal**
```sh ```sh
./node_modules/.bin/env-cmd node index.js ./node_modules/.bin/env-cmd node index.js
``` ```
## Using custom env file path ## 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 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** **Terminal**
```sh ```sh
./node_modules/.bin/env-cmd -f ./custom/path/.env node index.js ./node_modules/.bin/env-cmd -f ./custom/path/.env node index.js
``` ```
## 📜 Help ## 📜 Help
```
```text
Usage: _ [options] <command> [...args] Usage: _ [options] <command> [...args]
Options: Options:
@ -87,6 +96,7 @@ are found.
``` ```
**Terminal** **Terminal**
```sh ```sh
./node_modules/.bin/env-cmd -e production node index.js ./node_modules/.bin/env-cmd -e production node index.js
# Or for multiple environments (where `production` vars override `test` vars, # 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. commands together that share the same environment variables.
**Terminal** **Terminal**
```sh ```sh
./node_modules/.bin/env-cmd -f ./test/.env --use-shell "npm run lint && npm test" ./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, ... } }`). names (`{ production: { ENV_VAR_NAME: value, ... } }`).
**Terminal** **Terminal**
```sh ```sh
./node_modules/.bin/env-cmd -f ./async-file.js node index.js ./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 ## Environment File Formats
These are the currently accepted environment file formats. If any other formats are desired please create an issue. These are the currently accepted environment file formats. If any other formats are desired please create an issue.
- `.env` as `key=value` - `.env` as `key=value`
- `.env.json` Key/value pairs as JSON - `.env.json` Key/value pairs as JSON
- `.env.js` JavaScript file exporting an `object` or a `Promise` that resolves to an `object` - `.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 ## ⚒ API Usage
### `EnvCmd` ### `EnvCmd`
A function that executes a given command in a new child process with the given environment and options 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` } - **`options`** { `object` }
- **`command`** { `string` }: The command to execute (`node`, `mocha`, ...) - **`noOverride`** { `boolean` }: Prevent `.env` file vars from overriding existing `process.env` vars (default: `false`)
- **`commandArgs`** { `string[]` }: List of arguments to pass to the `command` (`['-R', 'Spec']`) - **`useShell`** { `boolean` }: Runs command inside a new shell instance (default: `false`)
- **`envFile`** { `object` } - **Returns** { `Promise<object>` }: key is env var name and value is the env var value
- **`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
### `GetEnvVars` ### `GetEnvVars`
A function that parses environment variables from a `.env` or a `.rc` file A function that parses environment variables from a `.env` or a `.rc` file
- **`options`** { `object` }
- **`envFile`** { `object` } - **`options`** { `object` }
- **`filePath`** { `string` }: Custom path to .env file to read from (defaults to: `./.env`) - **`envFile`** { `object` }
- **`fallback`** { `boolean` }: Should fall back to default `./.env` file if custom path does not exist - **`filePath`** { `string` }: Custom path to .env file to read from (defaults to: `./.env`)
- **`rc`** { `object` } - **`fallback`** { `boolean` }: Should fall back to default `./.env` file if custom path does not exist
- **`environments`** { `string[]` }: List of environment to read from the `.rc` file - **`rc`** { `object` }
- **`filePath`** { `string` }: Custom path to the `.rc` file (defaults to: `./.env-cmdrc(|.js|.json)`) - **`environments`** { `string[]` }: List of environment to read from the `.rc` file
- **Returns** { `Promise<object>` }: key is env var name and value is the env var value - **`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 ## Why
@ -208,6 +225,7 @@ same `cross-spawn` lib underneath too).
- Anton Versal - Anton Versal
## 📋 Contributing Guide ## 📋 Contributing Guide
I welcome all pull requests. Please make sure you add appropriate test cases for any features 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: 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", "name": "env-cmd",
"version": "10.0.0", "version": "10.0.0",
"description": "Executes a command using the environment variables in an env file", "description": "Executes a command using the environment variables in an env file",
"main": "dist/src/index.js", "main": "dist/index.js",
"types": "dist/src/index.d.ts", "types": "dist/index.d.ts",
"engines": { "engines": {
"node": ">=8.0.0" "node": ">=8.0.0"
}, },
@ -13,9 +13,8 @@
"scripts": { "scripts": {
"test": "mocha -r ts-node/register ./test/**/*.ts", "test": "mocha -r ts-node/register ./test/**/*.ts",
"test-cover": "nyc --reporter=lcov --reporter=text npm test", "test-cover": "nyc --reporter=lcov --reporter=text npm test",
"test-lint": "eslint ./src/**/*.ts ./test/**/*.ts",
"coveralls": "coveralls < coverage/lcov.info", "coveralls": "coveralls < coverage/lcov.info",
"lint": "eslint --fix ./src/**/*.ts ./test/**/*.ts && tsc --noEmit", "lint": "ts-standard --fix && tsc --noEmit",
"build": "tsc", "build": "tsc",
"watch": "tsc -w" "watch": "tsc -w"
}, },
@ -57,21 +56,13 @@
"@types/mocha": "^5.0.0", "@types/mocha": "^5.0.0",
"@types/node": "^12.0.0", "@types/node": "^12.0.0",
"@types/sinon": "^7.0.0", "@types/sinon": "^7.0.0",
"@typescript-eslint/eslint-plugin": "^2.0.0",
"@typescript-eslint/parser": "^2.0.0",
"chai": "^4.0.0", "chai": "^4.0.0",
"coveralls": "^3.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", "mocha": "^6.0.0",
"nyc": "^14.0.0", "nyc": "^14.0.0",
"sinon": "^7.0.0", "sinon": "^7.0.0",
"ts-node": "^8.0.0", "ts-node": "^8.0.0",
"ts-standard": "^1.0.0",
"typescript": "^3.0.0" "typescript": "^3.0.0"
}, },
"nyc": { "nyc": {
@ -90,5 +81,11 @@
], ],
"sourceMap": true, "sourceMap": true,
"instrument": true "instrument": true
},
"ts-standard": {
"project": "./tsconfig.eslint.json",
"ignore": [
"dist"
]
} }
} }

View File

@ -1,8 +1,8 @@
module.exports = new Promise((resolve) => { module.exports = new Promise((resolve) => {
setTimeout(() => { setTimeout(() => {
resolve({ resolve({
'THANKS': 'FOR ALL THE FISH', THANKS: 'FOR ALL THE FISH',
'ANSWER': 0 ANSWER: 0
}) })
}, 200) }, 200)
}) })

View File

@ -1,5 +1,5 @@
module.exports = { module.exports = {
'THANKS': 'FOR ALL THE FISH', THANKS: 'FOR ALL THE FISH',
'ANSWER': 0, ANSWER: 0,
'GALAXY': 'hitch\nhiking' 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": [ "include": [
"./src/**/*", "./src/**/*"
"./test/**/*"
] ]
} }