├── .editorconfig ├── .github ├── dependabot.yml └── workflows │ ├── linux-tests.yml │ └── windows-tests.yml ├── .gitignore ├── .husky └── commit-msg copy ├── .npmrc ├── LICENSE ├── README.md ├── examples ├── env-file-async-cjs │ ├── async-env.cjs │ ├── index.js │ └── package.json ├── env-file-async-mjs │ ├── async-env.mjs │ ├── index.js │ └── package.json ├── env-file-async │ ├── async-env.js │ ├── index.js │ └── package.json ├── env-file-custom-path │ ├── .env-file │ ├── index.js │ └── package.json ├── env-file-env-expansion │ ├── .env │ ├── index.js │ └── package.json ├── env-file-fallback │ ├── .env │ ├── .npmrc │ ├── index.js │ └── package.json ├── env-file-silent │ ├── .env │ ├── index.js │ └── package.json ├── env-file-use-shell │ ├── index.js │ ├── package.json │ └── use-shell.env ├── env-file │ ├── .env │ ├── index.js │ └── package.json ├── rc-file-async-cjs │ ├── async-rc.cjs │ ├── index.js │ └── package.json ├── rc-file-async-mjs │ ├── async-rc.mjs │ ├── index.js │ └── package.json ├── rc-file-async │ ├── async-rc.js │ ├── index.js │ └── package.json ├── rc-file-custom-path │ ├── .cmdrc.json │ ├── index.js │ └── package.json ├── rc-file-multiple-environments │ ├── .env-cmdrc │ ├── index.js │ └── package.json ├── rc-file-silent │ ├── index.js │ └── package.json └── rc-file │ ├── .env-cmdrc │ ├── index.js │ └── package.json ├── lerna.json └── package.json /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig is awesome: https://EditorConfig.org 2 | 3 | # top-most EditorConfig file 4 | root = true 5 | 6 | # Unix-style newlines with a newline ending every file 7 | [*] 8 | end_of_line = lf 9 | insert_final_newline = true 10 | charset = utf-8 11 | 12 | [*.{js*,ts*}] 13 | indent_style = space 14 | indent_size = 2 15 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # To get started with Dependabot version updates, you'll need to specify which 2 | # package ecosystems to update and where the package manifests are located. 3 | # Please see the documentation for all configuration options: 4 | # https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file 5 | 6 | version: 2 7 | updates: 8 | - package-ecosystem: "" # See documentation for possible values 9 | directory: "/" # Location of package manifests 10 | schedule: 11 | interval: "weekly" 12 | -------------------------------------------------------------------------------- /.github/workflows/linux-tests.yml: -------------------------------------------------------------------------------- 1 | name: linux tests 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | build: 7 | 8 | runs-on: ubuntu-latest 9 | 10 | env: 11 | HUSKY: 0 12 | 13 | strategy: 14 | matrix: 15 | node-version: [18.x, 20.x, 22.x] 16 | 17 | steps: 18 | - name: Checkout Project 19 | uses: actions/checkout@v4 20 | with: 21 | fetch-depth: 0 22 | 23 | - name: Lint the Commit Messages 24 | uses: wagoid/commitlint-github-action@v1 25 | env: 26 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 27 | 28 | - name: Use Node.js ${{ matrix.node-version }} 29 | uses: actions/setup-node@v4 30 | with: 31 | node-version: ${{ matrix.node-version }} 32 | 33 | - name: Install Dependencies 34 | run: npm install 35 | 36 | - name: Lint Files 37 | run: npm run lint 38 | 39 | - name: Run Tests 40 | env: 41 | CI: true 42 | run: npm test 43 | -------------------------------------------------------------------------------- /.github/workflows/windows-tests.yml: -------------------------------------------------------------------------------- 1 | name: windows tests 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | build: 7 | runs-on: windows-latest 8 | 9 | env: 10 | HUSKY: 0 11 | 12 | strategy: 13 | matrix: 14 | node-version: [18.x, 20.x, 22.x] 15 | 16 | steps: 17 | - name: Checkout Project 18 | uses: actions/checkout@v4 19 | with: 20 | fetch-depth: 0 21 | 22 | - name: Use Node.js ${{ matrix.node-version }} 23 | uses: actions/setup-node@v4 24 | with: 25 | node-version: ${{ matrix.node-version }} 26 | 27 | - name: Install Dependencies 28 | run: npm install 29 | 30 | - name: Lint Files 31 | run: npm run lint 32 | 33 | - name: Run Tests 34 | env: 35 | CI: true 36 | run: npm test 37 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | package-lock.json 3 | .idea 4 | -------------------------------------------------------------------------------- /.husky/commit-msg copy: -------------------------------------------------------------------------------- 1 | npx commitlint --edit 2 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | package-lock = false 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Todd Bluhm 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Linux Tests](https://github.com/toddbluhm/env-cmd-examples/workflows/linux%20tests/badge.svg)](https://github.com/toddbluhm/env-cmd-examples/actions?query=workflow%3A%22linux%20tests%22) 2 | [![Windows Tests](https://github.com/toddbluhm/env-cmd-examples/workflows/windows%20tests/badge.svg)](https://github.com/toddbluhm/env-cmd-examples/actions?query=workflow%3A%22windows%20tests%22) 3 | [![License](https://badgen.net/github/license/toddbluhm/env-cmd-examples)](https://github.com/toddbluhm/env-cmd-examples/blob/master/LICENSE) 4 | [![Standard - JavaScript Style Guide](https://badgen.net/badge/code%20style/standard/green?icon=javascript)](http://standardjs.com/) 5 | 6 | # Env-cmd-examples 7 | 8 | This repo contains various examples of how to use the npm package [env-cmd](https://github.com/toddbluhm/env-cmd). 9 | 10 | ## 💾 Installation 11 | 12 | Clone/fork/download a copy of this repo. Execute `npm install` at the top level. This will traverse each 13 | example subdirectory and install `node_modules` in each subdirectory. 14 | 15 | ## ⌨️ Usage 16 | To execute all examples simply run `npm test` from the top level directory. 17 | 18 | You can also run individual examples by entering into a directory and running `npm run script-name` where 19 | `script-name` is the name of a script found in the corresponding `package.json` file located in that directory. 20 | 21 | ## ❓ Questions/FAQ 22 | If you run into any issues using `env-cmd` please post them in the [env-cmd issues](https://github.com/toddbluhm/env-cmd/issues) 23 | github repo. This github repo is not frequently monitored. If you find an issue with this repo 24 | you are welcome to create a PR or submit an issue here, but expect possible delays on any response. 25 | -------------------------------------------------------------------------------- /examples/env-file-async-cjs/async-env.cjs: -------------------------------------------------------------------------------- 1 | module.exports = Promise.resolve({ 2 | TEST_NAME: 'Async File Test', 3 | NODE_ENV: 'env-file', 4 | ENVVAR: 'exists', 5 | ENV_PATH: './async-env.js' 6 | }) 7 | -------------------------------------------------------------------------------- /examples/env-file-async-cjs/index.js: -------------------------------------------------------------------------------- 1 | import assert from 'node:assert' 2 | import chalk from 'chalk' 3 | 4 | console.log(process.argv) 5 | console.log(chalk.cyan(`Test Name: ${process.env.TEST_NAME}`)) 6 | console.log(`Environment: ${process.env.NODE_ENV}`) 7 | console.log(`ENVVAR: ${process.env.ENVVAR}`) 8 | console.log(`ENV_PATH: ${process.env.ENV_PATH}`) 9 | 10 | assert(process.env.NODE_ENV === 'env-file') 11 | assert(process.env.ENVVAR === 'exists') 12 | assert(process.env.ENV_PATH === './async-env.js') 13 | 14 | console.log(chalk.green('Asserts Pass!')) 15 | -------------------------------------------------------------------------------- /examples/env-file-async-cjs/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "env-file-async-cjs", 3 | "version": "10.1.0", 4 | "description": "env-cmd async env file example", 5 | "type": "module", 6 | "scripts": { 7 | "test": "env-cmd --verbose -f async-env.cjs -- node index.js" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /examples/env-file-async-mjs/async-env.mjs: -------------------------------------------------------------------------------- 1 | export default Promise.resolve({ 2 | TEST_NAME: 'Async File Test', 3 | NODE_ENV: 'env-file', 4 | ENVVAR: 'exists', 5 | ENV_PATH: './async-env.js' 6 | }) 7 | -------------------------------------------------------------------------------- /examples/env-file-async-mjs/index.js: -------------------------------------------------------------------------------- 1 | import assert from 'node:assert' 2 | import chalk from 'chalk' 3 | 4 | console.log(process.argv) 5 | console.log(chalk.cyan(`Test Name: ${process.env.TEST_NAME}`)) 6 | console.log(`Environment: ${process.env.NODE_ENV}`) 7 | console.log(`ENVVAR: ${process.env.ENVVAR}`) 8 | console.log(`ENV_PATH: ${process.env.ENV_PATH}`) 9 | 10 | assert(process.env.NODE_ENV === 'env-file') 11 | assert(process.env.ENVVAR === 'exists') 12 | assert(process.env.ENV_PATH === './async-env.js') 13 | 14 | console.log(chalk.green('Asserts Pass!')) 15 | -------------------------------------------------------------------------------- /examples/env-file-async-mjs/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "env-file-async-mjs", 3 | "version": "10.1.0", 4 | "description": "env-cmd async env file example", 5 | "type": "module", 6 | "scripts": { 7 | "test": "env-cmd --verbose -f async-env.mjs -- node index.js" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /examples/env-file-async/async-env.js: -------------------------------------------------------------------------------- 1 | export default Promise.resolve({ 2 | TEST_NAME: 'Async File Test', 3 | NODE_ENV: 'env-file', 4 | ENVVAR: 'exists', 5 | ENV_PATH: './async-env.js' 6 | }) 7 | -------------------------------------------------------------------------------- /examples/env-file-async/index.js: -------------------------------------------------------------------------------- 1 | import assert from 'node:assert' 2 | import chalk from 'chalk' 3 | 4 | console.log(process.argv) 5 | console.log(chalk.cyan(`Test Name: ${process.env.TEST_NAME}`)) 6 | console.log(`Environment: ${process.env.NODE_ENV}`) 7 | console.log(`ENVVAR: ${process.env.ENVVAR}`) 8 | console.log(`ENV_PATH: ${process.env.ENV_PATH}`) 9 | 10 | assert(process.env.NODE_ENV === 'env-file') 11 | assert(process.env.ENVVAR === 'exists') 12 | assert(process.env.ENV_PATH === './async-env.js') 13 | 14 | console.log(chalk.green('Asserts Pass!')) 15 | -------------------------------------------------------------------------------- /examples/env-file-async/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "env-file-async", 3 | "version": "10.1.0", 4 | "description": "env-cmd async env file example", 5 | "type": "module", 6 | "scripts": { 7 | "test": "env-cmd --verbose -f async-env.js -- node index.js" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /examples/env-file-custom-path/.env-file: -------------------------------------------------------------------------------- 1 | TEST_NAME=Custom File Path Test 2 | NODE_ENV=env-file 3 | ENVVAR=exists 4 | ENV_PATH=./.env-file -------------------------------------------------------------------------------- /examples/env-file-custom-path/index.js: -------------------------------------------------------------------------------- 1 | import assert from 'node:assert' 2 | import chalk from 'chalk' 3 | 4 | console.log(process.argv) 5 | console.log(chalk.cyan(`Test Name: ${process.env.TEST_NAME}`)) 6 | console.log(`Environment: ${process.env.NODE_ENV}`) 7 | console.log(`ENVVAR: ${process.env.ENVVAR}`) 8 | console.log(`ENV_PATH: ${process.env.ENV_PATH}`) 9 | 10 | assert(process.env.NODE_ENV === 'env-file') 11 | assert(process.env.ENVVAR === 'exists') 12 | assert(process.env.ENV_PATH === './.env-file') 13 | 14 | console.log(chalk.green('Asserts Pass!')) 15 | -------------------------------------------------------------------------------- /examples/env-file-custom-path/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "env-file-custom-path", 3 | "version": "10.1.0", 4 | "description": "env-cmd custom env file path", 5 | "type": "module", 6 | "scripts": { 7 | "test": "env-cmd --verbose -f .env-file -- node index.js" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /examples/env-file-env-expansion/.env: -------------------------------------------------------------------------------- 1 | TEST_NAME=Default File Path Test 2 | NODE_ENV=env-file 3 | ENVVAR=exists 4 | ENV_PATH=./.env -------------------------------------------------------------------------------- /examples/env-file-env-expansion/index.js: -------------------------------------------------------------------------------- 1 | import assert from 'node:assert' 2 | import chalk from 'chalk' 3 | 4 | console.log(process.argv) 5 | console.log(chalk.cyan(`Test Name: ${process.env.TEST_NAME}`)) 6 | console.log(`Environment: ${process.env.NODE_ENV}`) 7 | console.log(`ENVVAR: ${process.env.ENVVAR}`) 8 | console.log(`ENV_PATH: ${process.env.ENV_PATH}`) 9 | 10 | assert(process.env.NODE_ENV === 'env-file') 11 | assert(process.env.ENVVAR === 'exists') 12 | assert(process.env.ENV_PATH === './.env') 13 | if (process.platform === 'win32') { 14 | const option = process.argv[process.argv.length - 1] 15 | if (option.includes('--pathWin32')) { 16 | assert(option.split('=')[1] === './.env') 17 | } 18 | } else { 19 | const option = process.argv[process.argv.length - 2] 20 | if (option.includes('--path')) { 21 | assert(option.split('=')[1] === './.env') 22 | } 23 | } 24 | 25 | console.log(chalk.green('Asserts Pass!')) 26 | -------------------------------------------------------------------------------- /examples/env-file-env-expansion/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "env-file-env-expansion", 3 | "version": "10.1.0", 4 | "description": "env-cmd env expansion example", 5 | "type": "module", 6 | "scripts": { 7 | "test": "env-cmd --verbose -x -- node index.js --path=\\$ENV_PATH --pathWin32=$ENV_PATH" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /examples/env-file-fallback/.env: -------------------------------------------------------------------------------- 1 | TEST_NAME=Fallback File Test 2 | NODE_ENV=fallback-file 3 | ENVVAR=exists -------------------------------------------------------------------------------- /examples/env-file-fallback/.npmrc: -------------------------------------------------------------------------------- 1 | package-lock = false 2 | -------------------------------------------------------------------------------- /examples/env-file-fallback/index.js: -------------------------------------------------------------------------------- 1 | import assert from 'node:assert' 2 | import chalk from 'chalk' 3 | 4 | console.log(chalk.cyan(`Test Name: ${process.env.TEST_NAME}`)) 5 | console.log(`Environment: ${process.env.NODE_ENV}`) 6 | console.log(`ENVVAR: ${process.env.ENVVAR}`) 7 | 8 | assert(process.env.NODE_ENV === 'fallback-file') 9 | assert(process.env.ENVVAR === 'exists') 10 | 11 | console.log(chalk.green('Asserts Pass!')) 12 | -------------------------------------------------------------------------------- /examples/env-file-fallback/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "env-file-fallback", 3 | "version": "10.1.0", 4 | "description": "env-cmd fallback file example", 5 | "type": "module", 6 | "scripts": { 7 | "test": "env-cmd --verbose --fallback -f ./non-existant-file -- node index.js" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /examples/env-file-silent/.env: -------------------------------------------------------------------------------- 1 | TEST_NAME=Default File Path Test 2 | NODE_ENV=env-file-silent 3 | ENVVAR=exists 4 | ENV_PATH=./.env 5 | -------------------------------------------------------------------------------- /examples/env-file-silent/index.js: -------------------------------------------------------------------------------- 1 | import assert from 'node:assert' 2 | import chalk from 'chalk' 3 | 4 | console.log(process.argv) 5 | console.log(chalk.cyan(`Test Name: ${process.env.TEST_NAME}`)) 6 | console.log(`Environment: ${process.env.NODE_ENV}`) 7 | console.log(`ENVVAR: ${process.env.ENVVAR}`) 8 | console.log(`ENV_PATH: ${process.env.ENV_PATH}`) 9 | 10 | assert(process.env.ENV_PATH === './non-existent') 11 | assert(process.env.NODE_ENV === undefined) 12 | assert(process.env.ENVVAR === undefined) 13 | 14 | console.log(chalk.green('Asserts Pass!')) 15 | -------------------------------------------------------------------------------- /examples/env-file-silent/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "env-file-silent", 3 | "version": "10.1.0", 4 | "description": "env-cmd silent flag example", 5 | "type": "module", 6 | "scripts": { 7 | "test": "cross-env ENV_PATH=./non-existent env-cmd --verbose --silent -f ./non-existent -- node index.js" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /examples/env-file-use-shell/index.js: -------------------------------------------------------------------------------- 1 | import assert from 'node:assert' 2 | import chalk from 'chalk' 3 | 4 | console.log(process.argv) 5 | console.log(chalk.cyan(`Test Name: ${process.env.TEST_NAME}`)) 6 | console.log(`Environment: ${process.env.NODE_ENV}`) 7 | console.log(`ENVVAR: ${process.env.ENVVAR}`) 8 | console.log(`ENV_PATH: ${process.env.ENV_PATH}`) 9 | 10 | assert(process.env.NODE_ENV === 'env-file') 11 | assert(process.env.ENVVAR === 'exists') 12 | assert(process.env.ENV_PATH === './use-shell.env') 13 | if (process.platform === 'win32') { 14 | const option = process.argv[process.argv.length - 1] 15 | if (option.includes('--pathWin32')) { 16 | assert(option.split('=')[1] === './use-shell.env') 17 | } 18 | } else { 19 | const option = process.argv[process.argv.length - 2] 20 | if (option.includes('--path')) { 21 | assert(option.split('=')[1] === './use-shell.env') 22 | } 23 | } 24 | 25 | console.log(chalk.green('Asserts Pass!')) 26 | -------------------------------------------------------------------------------- /examples/env-file-use-shell/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "env-file-use-shell", 3 | "version": "10.1.0", 4 | "description": "env-cmd use shell flag example", 5 | "type": "module", 6 | "scripts": { 7 | "test": "env-cmd --verbose -f use-shell.env --use-shell -- \"node index.js --path=\\$ENV_PATH --pathWin32=%ENV_PATH%\"" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /examples/env-file-use-shell/use-shell.env: -------------------------------------------------------------------------------- 1 | TEST_NAME=Use Shell Script Option Test 2 | NODE_ENV=env-file 3 | ENVVAR=exists 4 | ENV_PATH=./use-shell.env -------------------------------------------------------------------------------- /examples/env-file/.env: -------------------------------------------------------------------------------- 1 | TEST_NAME=Default File Path Test 2 | NODE_ENV=env-file 3 | ENVVAR=exists 4 | ENV_PATH=./.env -------------------------------------------------------------------------------- /examples/env-file/index.js: -------------------------------------------------------------------------------- 1 | import assert from 'node:assert' 2 | import chalk from 'chalk' 3 | 4 | console.log(process.argv) 5 | console.log(chalk.cyan(`Test Name: ${process.env.TEST_NAME}`)) 6 | console.log(`Environment: ${process.env.NODE_ENV}`) 7 | console.log(`ENVVAR: ${process.env.ENVVAR}`) 8 | console.log(`ENV_PATH: ${process.env.ENV_PATH}`) 9 | 10 | assert(process.env.NODE_ENV === 'env-file') 11 | assert(process.env.ENVVAR === 'exists') 12 | assert(process.env.ENV_PATH === './.env') 13 | 14 | console.log(chalk.green('Asserts Pass!')) 15 | -------------------------------------------------------------------------------- /examples/env-file/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "env-file", 3 | "version": "10.1.0", 4 | "description": "env-cmd basic env file example", 5 | "type": "module", 6 | "scripts": { 7 | "test": "env-cmd --verbose -- node index.js" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /examples/rc-file-async-cjs/async-rc.cjs: -------------------------------------------------------------------------------- 1 | module.exports = Promise.resolve({ 2 | prod: { 3 | TEST_NAME: 'Async RC File Test', 4 | NODE_ENV: 'production', 5 | ENVVAR: 'exists', 6 | ENV_PATH: './async-rc.js' 7 | }, 8 | test: { 9 | TEST_NAME: 'Async RC File Test', 10 | NODE_ENV: 'test', 11 | ENVVAR: 'exists', 12 | ENV_PATH: './async-rc.js' 13 | } 14 | }) 15 | -------------------------------------------------------------------------------- /examples/rc-file-async-cjs/index.js: -------------------------------------------------------------------------------- 1 | import assert from 'node:assert' 2 | import chalk from 'chalk' 3 | 4 | console.log(chalk.cyan(`Test Name: ${process.env.TEST_NAME}`)) 5 | console.log(`Environment: ${process.env.NODE_ENV}`) 6 | console.log(`ENVVAR: ${process.env.ENVVAR}`) 7 | console.log(`ENV_PATH: ${process.env.ENV_PATH}`) 8 | 9 | assert(process.env.NODE_ENV === 'test') 10 | assert(process.env.ENVVAR === 'exists') 11 | assert(process.env.ENV_PATH === './async-rc.js') 12 | 13 | console.log(chalk.green('Asserts Pass!')) 14 | -------------------------------------------------------------------------------- /examples/rc-file-async-cjs/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "rc-file-async-cjs", 3 | "version": "10.1.0", 4 | "description": "env-cmd async rc file", 5 | "type": "module", 6 | "scripts": { 7 | "test": "env-cmd --verbose -e test -r async-rc.cjs -- node index.js" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /examples/rc-file-async-mjs/async-rc.mjs: -------------------------------------------------------------------------------- 1 | export default Promise.resolve({ 2 | prod: { 3 | TEST_NAME: 'Async RC File Test', 4 | NODE_ENV: 'production', 5 | ENVVAR: 'exists', 6 | ENV_PATH: './async-rc.js' 7 | }, 8 | test: { 9 | TEST_NAME: 'Async RC File Test', 10 | NODE_ENV: 'test', 11 | ENVVAR: 'exists', 12 | ENV_PATH: './async-rc.js' 13 | } 14 | }) 15 | -------------------------------------------------------------------------------- /examples/rc-file-async-mjs/index.js: -------------------------------------------------------------------------------- 1 | import assert from 'node:assert' 2 | import chalk from 'chalk' 3 | 4 | console.log(chalk.cyan(`Test Name: ${process.env.TEST_NAME}`)) 5 | console.log(`Environment: ${process.env.NODE_ENV}`) 6 | console.log(`ENVVAR: ${process.env.ENVVAR}`) 7 | console.log(`ENV_PATH: ${process.env.ENV_PATH}`) 8 | 9 | assert(process.env.NODE_ENV === 'test') 10 | assert(process.env.ENVVAR === 'exists') 11 | assert(process.env.ENV_PATH === './async-rc.js') 12 | 13 | console.log(chalk.green('Asserts Pass!')) 14 | -------------------------------------------------------------------------------- /examples/rc-file-async-mjs/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "rc-file-async-mjs", 3 | "version": "10.1.0", 4 | "description": "env-cmd async rc file", 5 | "type": "module", 6 | "scripts": { 7 | "test": "env-cmd --verbose -e test -r async-rc.mjs -- node index.js" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /examples/rc-file-async/async-rc.js: -------------------------------------------------------------------------------- 1 | export default Promise.resolve({ 2 | prod: { 3 | TEST_NAME: 'Async RC File Test', 4 | NODE_ENV: 'production', 5 | ENVVAR: 'exists', 6 | ENV_PATH: './async-rc.js' 7 | }, 8 | test: { 9 | TEST_NAME: 'Async RC File Test', 10 | NODE_ENV: 'test', 11 | ENVVAR: 'exists', 12 | ENV_PATH: './async-rc.js' 13 | } 14 | }) 15 | -------------------------------------------------------------------------------- /examples/rc-file-async/index.js: -------------------------------------------------------------------------------- 1 | import assert from 'node:assert' 2 | import chalk from 'chalk' 3 | 4 | console.log(chalk.cyan(`Test Name: ${process.env.TEST_NAME}`)) 5 | console.log(`Environment: ${process.env.NODE_ENV}`) 6 | console.log(`ENVVAR: ${process.env.ENVVAR}`) 7 | console.log(`ENV_PATH: ${process.env.ENV_PATH}`) 8 | 9 | assert(process.env.NODE_ENV === 'test') 10 | assert(process.env.ENVVAR === 'exists') 11 | assert(process.env.ENV_PATH === './async-rc.js') 12 | 13 | console.log(chalk.green('Asserts Pass!')) 14 | -------------------------------------------------------------------------------- /examples/rc-file-async/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "rc-file-async", 3 | "version": "10.1.0", 4 | "description": "env-cmd async rc file", 5 | "type": "module", 6 | "scripts": { 7 | "test": "env-cmd --verbose -e test -r async-rc.js -- node index.js" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /examples/rc-file-custom-path/.cmdrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "prod": { 3 | "TEST_NAME": "Custom RC File Path Test", 4 | "NODE_ENV": "production", 5 | "ENVVAR": "exists", 6 | "ENV_PATH": "./.cmdrc.json" 7 | }, 8 | "test": { 9 | "TEST_NAME": "Custom RC File Path Test", 10 | "NODE_ENV": "test", 11 | "ENVVAR": "exists", 12 | "ENV_PATH": "./.cmdrc.json" 13 | } 14 | } -------------------------------------------------------------------------------- /examples/rc-file-custom-path/index.js: -------------------------------------------------------------------------------- 1 | import assert from 'node:assert' 2 | import chalk from 'chalk' 3 | 4 | console.log(chalk.cyan(`Test Name: ${process.env.TEST_NAME}`)) 5 | console.log(`Environment: ${process.env.NODE_ENV}`) 6 | console.log(`ENVVAR: ${process.env.ENVVAR}`) 7 | console.log(`ENV_PATH: ${process.env.ENV_PATH}`) 8 | 9 | assert(process.env.NODE_ENV === 'test') 10 | assert(process.env.ENVVAR === 'exists') 11 | assert(process.env.ENV_PATH === './.cmdrc.json') 12 | 13 | console.log(chalk.green('Asserts Pass!')) 14 | -------------------------------------------------------------------------------- /examples/rc-file-custom-path/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "rc-file-custom-path", 3 | "version": "10.1.0", 4 | "description": "env-cmd rc file with custom path", 5 | "type": "module", 6 | "scripts": { 7 | "test": "env-cmd --verbose -e test -r .cmdrc.json -- node index.js" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /examples/rc-file-multiple-environments/.env-cmdrc: -------------------------------------------------------------------------------- 1 | { 2 | "test": { 3 | "TEST_NAME": "Default RC File Path Test", 4 | "NODE_ENV": "test", 5 | "ENVVAR": "exists", 6 | "ENV_PATH": "./.env-cmdrc" 7 | }, 8 | "prod": { 9 | "TEST_NAME": "Multiple Environments RC File Test", 10 | "NODE_ENV": "production", 11 | "ENV_PATH": "./.env-cmdrc" 12 | } 13 | } -------------------------------------------------------------------------------- /examples/rc-file-multiple-environments/index.js: -------------------------------------------------------------------------------- 1 | import assert from 'node:assert' 2 | import chalk from 'chalk' 3 | 4 | console.log(chalk.cyan(`Test Name: ${process.env.TEST_NAME}`)) 5 | console.log(`Environment: ${process.env.NODE_ENV}`) 6 | console.log(`ENVVAR: ${process.env.ENVVAR}`) 7 | console.log(`ENV_PATH: ${process.env.ENV_PATH}`) 8 | 9 | assert(process.env.NODE_ENV === 'production') 10 | assert(process.env.ENVVAR === 'exists') 11 | assert(process.env.ENV_PATH === './.env-cmdrc') 12 | 13 | console.log(chalk.green('Asserts Pass!')) 14 | -------------------------------------------------------------------------------- /examples/rc-file-multiple-environments/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "rc-file-multiple-environments", 3 | "version": "10.1.0", 4 | "description": "env-cmd rc file using multiple environments", 5 | "type": "module", 6 | "scripts": { 7 | "test": "env-cmd --verbose -e test,prod -- node index.js" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /examples/rc-file-silent/index.js: -------------------------------------------------------------------------------- 1 | import assert from 'node:assert' 2 | import chalk from 'chalk' 3 | 4 | console.log(chalk.cyan(`Test Name: ${process.env.TEST_NAME}`)) 5 | console.log(`Environment: ${process.env.NODE_ENV}`) 6 | console.log(`ENVVAR: ${process.env.ENVVAR}`) 7 | console.log(`ENV_PATH: ${process.env.ENV_PATH}`) 8 | 9 | assert(process.env.NODE_ENV === undefined) 10 | assert(process.env.ENVVAR === undefined) 11 | assert(process.env.ENV_PATH === './non-existent') 12 | 13 | console.log(chalk.green('Asserts Pass!')) 14 | -------------------------------------------------------------------------------- /examples/rc-file-silent/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "rc-file-silent", 3 | "version": "10.1.0", 4 | "description": "env-cmd rc file silent flag example", 5 | "type": "module", 6 | "scripts": { 7 | "test": "cross-env ENV_PATH=./non-existent env-cmd --verbose --silent -e test -r ./non-existent -- node index.js" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /examples/rc-file/.env-cmdrc: -------------------------------------------------------------------------------- 1 | { 2 | "test": { 3 | "TEST_NAME": "Default RC File Path Test", 4 | "NODE_ENV": "test", 5 | "ENVVAR": "exists", 6 | "ENV_PATH": "./.env-cmdrc" 7 | }, 8 | "prod": { 9 | "TEST_NAME": "Multiple Environments RC File Test", 10 | "NODE_ENV": "production", 11 | "ENV_PATH": "./.env-cmdrc" 12 | } 13 | } -------------------------------------------------------------------------------- /examples/rc-file/index.js: -------------------------------------------------------------------------------- 1 | import assert from 'node:assert' 2 | import chalk from 'chalk' 3 | 4 | console.log(chalk.cyan(`Test Name: ${process.env.TEST_NAME}`)) 5 | console.log(`Environment: ${process.env.NODE_ENV}`) 6 | console.log(`ENVVAR: ${process.env.ENVVAR}`) 7 | console.log(`ENV_PATH: ${process.env.ENV_PATH}`) 8 | 9 | assert(process.env.NODE_ENV === 'test') 10 | assert(process.env.ENVVAR === 'exists') 11 | assert(process.env.ENV_PATH === './.env-cmdrc') 12 | 13 | console.log(chalk.green('Asserts Pass!')) 14 | -------------------------------------------------------------------------------- /examples/rc-file/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "rc-file", 3 | "version": "10.1.0", 4 | "description": "env-cmd rc file basic example", 5 | "type": "module", 6 | "scripts": { 7 | "test": "env-cmd --verbose -e test -- node index.js" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /lerna.json: -------------------------------------------------------------------------------- 1 | { 2 | "packages": [ 3 | "examples/*" 4 | ], 5 | "version": "10.1.0" 6 | } 7 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "env-cmd-test", 3 | "version": "10.1.0", 4 | "description": "Example/Test Project for env-cmd", 5 | "author": "Todd Bluhm", 6 | "type": "module", 7 | "license": "MIT", 8 | "scripts": { 9 | "prepare": "husky", 10 | "lint": "standard --fix", 11 | "test": "lerna run --load-env-files=false test" 12 | }, 13 | "devDependencies": { 14 | "@commitlint/cli": "^19.6.0", 15 | "@commitlint/config-conventional": "^19.6.0", 16 | "chalk": "^5.3.0", 17 | "cross-env": "^7.0.3", 18 | "env-cmd": "github:toddbluhm/env-cmd", 19 | "husky": "^9.1.7", 20 | "lerna": "^8.1.9", 21 | "standard": "^17.1.2" 22 | }, 23 | "commitlint": { 24 | "extends": [ 25 | "@commitlint/config-conventional" 26 | ] 27 | } 28 | } 29 | --------------------------------------------------------------------------------