Skip to content

Commit

Permalink
feat: initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
KernelPanic92 committed Jun 4, 2024
1 parent f098938 commit 1b75b6f
Show file tree
Hide file tree
Showing 13 changed files with 10,337 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
bin
package.json
./node_modules/
.vscode
.idea
50 changes: 50 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"root": true,
"parserOptions": {
"ecmaVersion": "latest"
},
"env": {
"es6": true
},
"plugins": ["simple-import-sort"],
"overrides": [
{
"parserOptions": {
"project": "./tsconfig.json"
},
"files": [
"src/**/*.ts"
],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended"
],
"rules": {
"simple-import-sort/imports": "error",
"simple-import-sort/exports": "error",
"@typescript-eslint/ban-ts-comment": 0,
"max-lines-per-function": [
1,
{
"max": 40
}
],
"max-lines": [
1,
{
"max": 150
}
]
}
},
{
"parserOptions": {
"project": "./tsconfig.json"
},
"files": [
"src/**/*.ts"
]
}
]
}
36 changes: 36 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Release

on:
push:
branches:
- main

jobs:
release:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '20'

- name: Setup Corepack
run: |
corepack enable
corepack prepare [email protected] --activate
- name: Install dependencies
run: npm install

- name: Build project
run: npm run build

- name: Run Semantic Release
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npm run release
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
bin
13 changes: 13 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.idea/
.github
.gitignore
.prettierrc.json
.DS_Store
CONTRIBUTE.md

# configuration
renovate.json
tsconfig.json
/.vscode
.eslintrc.json
.eslintignore
6 changes: 6 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"singleQuote": true,
"trailingComma": "all",
"endOfLine": "auto",
"printWidth": 100
}
22 changes: 22 additions & 0 deletions .releaserc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* @type {import('semantic-release').GlobalConfig}
*/
const releaseConfig = {
branches: ["main"],
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
"@semantic-release/changelog",
"@semantic-release/npm",
"@semantic-release/github",
[
"@semantic-release/git",
{
"assets": ["package.json", "CHANGELOG.md"],
"message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
}
]
]
};

module.exports = releaseConfig;
52 changes: 52 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# @devmy/dotenv2shell - Load Environment Variables from .env File

This TypeScript CLI lets you easily load environment variables from a `.env` file into your current shell session with [@dotenv-run/core](https://www.npmjs.com/package/@dotenv-run/core). It provides flexibility through various options and supports both zsh and bash.

- ✅ Load environment variables from .env files
- ✅ Load environment variables from .env.vault files
- ✅ Expand environment variables API_URL=$API_BASE/users
- ✅ Define environment variables for a specific environment (e.g. .env.production)
- ✅ Load priorities of .env.* files (e.g. .env.production > .env)
- ✅ Hierarchical cascading configuration in monorepo projects (Nx, Turbo, etc.) apps/next-app/.env > apps/.env > .env

## Usage

```bash
npx @devmy/dotenv2shell [options]
```

### Options

* `-o, --override`: Override existing environment variables on your machine with values from the `.env` file (default: false).
* `-p, --prefix`: Prefix to filter environment variables to load (e.g., `MY_APP_`).
* `-r, --root`: Root directory to search for the `.env` file (default: current working directory).
* `-f, --files`: Comma-separated list of `.env` files to load (default: `.env`).
* `-d, --dotenv_key`: Manually specify the `DOTENV_KEY` for decryption (if using `.env.vault`).

### Examples

* Load the default `.env` file from the current directory:

```bash
eval $(npx @devmy/dotenv2shell)
```

* Load a specific `.env` file with a prefix and override existing variable:

```zsh
eval $(npx @devmy/dotenv2shell -f my-env.env -p MY_APP_ -o)
```

## Handling Backslash Escapes

In some cases, environment variables loaded from the `.env` file may contain special characters that require backslash escapes to be interpreted correctly by the shell. This is particularly relevant when dealing with paths, file names, ssh-keys or other strings that might contain characters like spaces, commas, or backslashes themselves.

If you encounter issues with environment variables not behaving as expected, check for any special characters in their values and consider using backslash escapes to ensure they are treated as literal characters. For example:

```bash
eval $(npx @devmy/dotenv2shell) &&
echo -e "$DEPLOY_GITHUB_SSH_KEY" | ssh-add -
```


Remember that the -e option in echo is used to enable backslash escapes when printing strings, but it's not necessary when loading environment variables. The shell will automatically handle backslash escapes when interpreting environment variable values.
Loading

0 comments on commit 1b75b6f

Please sign in to comment.