diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml index d1a8fe8..e40dc65 100644 --- a/.github/workflows/npm-publish.yml +++ b/.github/workflows/npm-publish.yml @@ -110,6 +110,9 @@ jobs: run: | echo "VERSION: ${{ env.PACKAGE_VERSION }}" + # --------------------------------------------------------------------------------------- + # JOB > PUBLISH > NPMJS + # --------------------------------------------------------------------------------------- job-publish-npm: name: >- @@ -131,6 +134,17 @@ jobs: always-auth: true scope: '@aetherinox' + - name: "📦 NPM Actions" + run: | + npm ci + npm publish + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + + # --------------------------------------------------------------------------------------- + # JOB > PUBLISH > GITHUB PACKAGE + # --------------------------------------------------------------------------------------- + job-publish-gpr: name: >- 📦 Package › Github @@ -150,6 +164,12 @@ jobs: registry-url: https://npm.pkg.github.com/ scope: '@aetherinox' + - name: "📦 NPM Actions" + run: | + npm ci + npm publish + env: + NODE_AUTH_TOKEN: ${{ secrets.SELF_TOKEN_CL }} # --------------------------------------------------------------------------------------- # Job > Release > Github diff --git a/README.md b/README.md index ff5a73b..77bc7fe 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,19 @@
+- [About](#about) +- [Installation](#installation) +- [Usage](#usage) +- [`noxenv` \& `noxenv-shell`](#noxenv--noxenv-shell) +- [Windows Issues](#windows-issues) +- [Contributors ✨](#contributors-) + +
+ +--- + +
+ ## About Most Windows-based command prompts / terminals will have issues when you attempt to set env variables utilizing `NODE_ENV=production`; unless you are using [Bash on Windows][win-bash]. Coupled with the issue that Windows and *NIX have different ways of utilizing env variables such as @@ -32,21 +45,7 @@ Most Windows-based command prompts / terminals will have issues when you attempt
> [!NOTE] -> `noxenv` only supports Node.js v10 and higher. - -
- - - - -- [About](#about) -- [Installation](#installation) -- [Usage](#usage) -- [`noxenv` vs `noxenv-shell`](#noxenv-vs-noxenv-shell) -- [Windows Issues](#windows-issues) -- [Contributors ✨](#contributors-) - - +> `noxenv` only supports Node.js v14 and higher.
@@ -56,11 +55,20 @@ Most Windows-based command prompts / terminals will have issues when you attempt ## Installation -This module is distributed via [npm][npm] which is bundled with [node][node] and -should be installed as one of your project's `devDependencies`: +This module is distributed via [npm][npm] which is bundled with [node][node]. To utilize this moduke, add it to your project's `package.json` -> `devDependencies`: + +```json +"devDependencies": { + "@aetherinox/noxenv": "^1.0.0" +}, +``` + +To install it via the npm command-line as a `devDependency`: + +
``` -npm install --save-dev @aetherinox/noxenv +npm i --save-dev @aetherinox/noxenv ```
@@ -70,31 +78,52 @@ npm install --save-dev @aetherinox/noxenv
## Usage +Some examples have been provided below to show various ways of using noxenv: + +
```json { "scripts": { - "build": "noxenv NODE_ENV=production webpack --config build/webpack.config.js" + "build": "noxenv NODE_ENV=production webpack --config build/webpack.config.js", + "build-rollup": "noxenv NODE_ENV=production rollup -c", + "development": "noxenv NODE_ENV=development npm start", + "production": "noxenv NODE_ENV=production SERVER_IP=http://127.0.0.1 npm start", + "test": "noxenv BABEL_ENV=test jest test/app", + "start-dev": "noxenv NODE_ENV=development PORT_ENV=2350 npm run build && node dist/src/main.js", + "openssl-legacy": "noxenv NODE_OPTIONS=\"--openssl-legacy-provider\" tsc -p tsconfig.json" } } ```
-The command that is executed (using [`cross-spawn`][cross-spawn]) is: +Inside your module, you can call these env variables with something similar to the below example: -``` -webpack --config build/webpack.config.js +```javascript +const TEST = { api: "f4dcc990-f8f7-4343-b852-a2065b4445d5" }; +const PROD = { api: "d1ac1eb8-7194-4095-8976-04be09378611" }; + +let target; +if (process.env.BABEL_ENV === "test") { + target = TEST; +} else if (process.env.BABEL_ENV === "prod") { + target = PROD; +} + +console.log(`Your API key is ${target} in ${process.env.BABEL_ENV} mode`); ``` -The `NODE_ENV` environment variable will be set by `noxenv`. +
+ +In the above example, variables such as `BABEL_ENV` will be set by `noxenv`. You can also set multiple environment variables at a time: ```json { "scripts": { - "build": "noxenv ENV_ONE=alpha ENV_TWO=bravo ENV_THREE=charlie node ./my-program" + "release-beta": "noxenv RELEASE=beta ENV=dev PORT=7732 npm run release && npm run start", } } ``` @@ -106,24 +135,26 @@ Additionally; you can split the command into several, or separate the env variab ```json { "scripts": { - "parentScript": "noxenv USER_NAME=\"Joe\" npm run childScript", - "childScript": "noxenv-shell \"echo Hello $USER_NAME\"" + "parentCmd": "noxenv USER_NAME=\"Joe\" npm run childCmd", + "childCmd": "noxenv-shell \"echo Hello $USER_NAME\"" } } ```
-In the above example, `childScript` stores the actual command to execute, and `parentScript` sets the env variable that is going to be used. In this case, `Joe` is the user we want to say hello to, so we store Joe's name in within the env variable `USER_NAME`, and then at the end of `parentScript`, we call `childScript` which does the actual greeting. +In the above example, `childCmd` stores the actual command to execute, and `parentCmd` sets the env variable that is going to be used. In this case, `Joe` is the user we want to say hello to, so we store Joe's name in within the env variable `USER_NAME`, and then at the end of `parentCmd`, we call `childCmd` which does the actual greeting. -This means that you only need to call `parentScript`, and both will be ran. Additionally, it also means that you can also call the env variable using `$USER_NAME` on Windows, even though the typical Windows syntax is `%USER_NAME%`. +This means that you only need to call `parentCmd`, and both will be ran. Additionally, it also means that you can also call the env variable using `$USER_NAME` on Windows, even though the typical Windows syntax is `%USER_NAME%`. If you wish to pass a JSON string (such as when using [ts-loader]), you may do the following: +
+ ```json { "scripts": { - "test": "noxenv TS_NODE_COMPILER_OPTIONS={\\\"module\\\":\\\"commonjs\\\"} node my_file.test.ts" + "test": "noxenv TS_NODE_COMPILER_OPTIONS={\\\"module\\\":\\\"commonjs\\\"} mocha --config ./test.js" } } ``` @@ -138,7 +169,7 @@ Pay attention to the **triple backslash** `(\\\)` **before** the **double quotes
-## `noxenv` vs `noxenv-shell` +## `noxenv` & `noxenv-shell` The `noxenv` module exposes two bins: `noxenv` and `noxenv-shell`. The first one executes commands using [`cross-spawn`][cross-spawn], while the second one uses the `shell` option from Node's `spawn`.