diff --git a/.eslintrc.json b/.eslintrc.json deleted file mode 100644 index afc4292..0000000 --- a/.eslintrc.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "extends": "standard-with-typescript", - "parser": "@typescript-eslint/parser", - "parserOptions": { - "project": "./tsconfig.json" - } -} \ No newline at end of file diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..c1ca392 --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +package-lock = false diff --git a/README.md b/README.md index 16c0775..a389cc4 100644 --- a/README.md +++ b/README.md @@ -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] [...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` }: 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` }: 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` }: 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` }: 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: diff --git a/dist/src/env-cmd.d.ts b/dist/env-cmd.d.ts similarity index 100% rename from dist/src/env-cmd.d.ts rename to dist/env-cmd.d.ts diff --git a/dist/src/env-cmd.js b/dist/env-cmd.js similarity index 100% rename from dist/src/env-cmd.js rename to dist/env-cmd.js diff --git a/dist/src/get-env-vars.d.ts b/dist/get-env-vars.d.ts similarity index 100% rename from dist/src/get-env-vars.d.ts rename to dist/get-env-vars.d.ts diff --git a/dist/src/get-env-vars.js b/dist/get-env-vars.js similarity index 100% rename from dist/src/get-env-vars.js rename to dist/get-env-vars.js diff --git a/dist/src/index.d.ts b/dist/index.d.ts similarity index 100% rename from dist/src/index.d.ts rename to dist/index.d.ts diff --git a/dist/src/index.js b/dist/index.js similarity index 100% rename from dist/src/index.js rename to dist/index.js diff --git a/dist/src/parse-args.d.ts b/dist/parse-args.d.ts similarity index 100% rename from dist/src/parse-args.d.ts rename to dist/parse-args.d.ts diff --git a/dist/src/parse-args.js b/dist/parse-args.js similarity index 100% rename from dist/src/parse-args.js rename to dist/parse-args.js diff --git a/dist/src/parse-env-file.d.ts b/dist/parse-env-file.d.ts similarity index 100% rename from dist/src/parse-env-file.d.ts rename to dist/parse-env-file.d.ts diff --git a/dist/src/parse-env-file.js b/dist/parse-env-file.js similarity index 100% rename from dist/src/parse-env-file.js rename to dist/parse-env-file.js diff --git a/dist/src/parse-rc-file.d.ts b/dist/parse-rc-file.d.ts similarity index 100% rename from dist/src/parse-rc-file.d.ts rename to dist/parse-rc-file.d.ts diff --git a/dist/src/parse-rc-file.js b/dist/parse-rc-file.js similarity index 100% rename from dist/src/parse-rc-file.js rename to dist/parse-rc-file.js diff --git a/dist/src/signal-termination.d.ts b/dist/signal-termination.d.ts similarity index 100% rename from dist/src/signal-termination.d.ts rename to dist/signal-termination.d.ts diff --git a/dist/src/signal-termination.js b/dist/signal-termination.js similarity index 100% rename from dist/src/signal-termination.js rename to dist/signal-termination.js diff --git a/dist/src/spawn.d.ts b/dist/spawn.d.ts similarity index 100% rename from dist/src/spawn.d.ts rename to dist/spawn.d.ts diff --git a/dist/src/spawn.js b/dist/spawn.js similarity index 100% rename from dist/src/spawn.js rename to dist/spawn.js diff --git a/dist/src/types.d.ts b/dist/types.d.ts similarity index 100% rename from dist/src/types.d.ts rename to dist/types.d.ts diff --git a/dist/src/types.js b/dist/types.js similarity index 100% rename from dist/src/types.js rename to dist/types.js diff --git a/dist/src/utils.d.ts b/dist/utils.d.ts similarity index 100% rename from dist/src/utils.d.ts rename to dist/utils.d.ts diff --git a/dist/src/utils.js b/dist/utils.js similarity index 100% rename from dist/src/utils.js rename to dist/utils.js diff --git a/package.json b/package.json index b1b4782..a1de49b 100644 --- a/package.json +++ b/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" + ] } } diff --git a/test/test-files/test-async.js b/test/test-files/test-async.js index b7ad8ae..ba95d4d 100644 --- a/test/test-files/test-async.js +++ b/test/test-files/test-async.js @@ -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) }) diff --git a/test/test-files/test.js b/test/test-files/test.js index 63d3f99..0ef99e6 100644 --- a/test/test-files/test.js +++ b/test/test-files/test.js @@ -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' } diff --git a/tsconfig.eslint.json b/tsconfig.eslint.json new file mode 100644 index 0000000..17ae7bb --- /dev/null +++ b/tsconfig.eslint.json @@ -0,0 +1,12 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "allowJs": true, + "checkJs": true + }, + "include": [ + "src/**/*", + "test/**/*", + "bin/**/*" + ] +} \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index bb3885c..3d0ff9b 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -10,7 +10,6 @@ ] }, "include": [ - "./src/**/*", - "./test/**/*" + "./src/**/*" ] } \ No newline at end of file