1.1.1 โข Published 2 years ago
@sensethenlove/env-write v1.1.1
๐ @sensethenlove/env-write
๐ Description
- Set keys & values in
.env
file w/bash
. - Helpful if using
.env
file in an environment whereprocess
is undefined. - If key is found in the
.env
file the new value is set. - If key is not found in the
.env
file the key & value are added @ the end of the file. - Only works if each key in
.env
file is on its own line.
โฏ๏ธ Install
pnpm add @sensethenlove/env-write
โค๏ธ Example: package.json w/o optional bash
{
"scripts": {
"localEnv": "node node_modules/@sensethenlove/env-write/lib/index.js ENVIRONMENT=local HOST=http://localhost:5173 API=https://dev-api.example.com",
"devEnv": "node node_modules/@sensethenlove/env-write/lib/index.js ENVIRONMENT=development HOST=https://dev.example.com API=https://dev-api.example.com",
"mainEnv": "node node_modules/@sensethenlove/env-write/lib/index.js ENVIRONMENT=production HOST=https://app.example.com API=https://api.example.com"
}
}
๐ Example: .env
file below based on mainEnv
script above
# foo here before
ENVIRONMENT='production'
HOST='https://app.example.com'
API='https://api.example.com'
# bar remains
๐งก Example: Bash script (optional) (env.sh)
#!/bin/bash
node node_modules/@sensethenlove/env-write/lib/index.js ENVIRONMENT=$env HOST=$host API=$api
๐ Example: package.json w/ optional bash
{
"scripts": {
"localEnv": "env=local host=http://localhost:5173 api=https://dev-api.example.com bash ./src/lib/scripts/env.sh",
"devEnv": "env=development host=https://dev.example.com api=https://dev-api.example.com bash ./src/lib/scripts/env.sh",
"mainEnv": "env=production host=https://app.example.com api=https://api.example.com bash ./src/lib/scripts/env.sh"
}
}