Platform Env Fetcher
A world-class CLI tool to fetch environment files for your app from a remote API and write them locally.
Features
- Fetches all environment files for a given app from a central API
- Writes each file (e.g.,
.env
,.env.production
) to your current directory - Prompts for API key and app name if not provided
- Supports
.env-fetcher.json
config file and environment variables - Colorful, clear output and error messages
- Prompts before overwriting existing files (unless
--force
) - Zero config, plug-and-play
- Helpful
--help
and--version
output
Quickstart
Install dependencies:
npm install
Run the CLI (no arguments needed):
npx platform-env-fetcher
Or, after installing globally:
npm install -g .
platform-env-fetcher
Options
--app, -a
(optional): App name to fetch env for. If not provided, you will be prompted or it will use config/env var.--force, -f
(optional): Overwrite existing files without prompting.--help, -h
: Show help.--version, -v
: Show version.
Configuration
You can set defaults in a .env-fetcher.json
file in your project root:
{
"appName": "servicepilot"
}
Or use environment variables:
ENV_API_KEY
: Your API keyENV_APP_NAME
: Your app name
How it works
- The tool fetches env files from the API endpoint:
https://mono.specvista.com/platform-eng/api/v1/ci-env/get-env?appName=<your-app-name>
- The API should return a JSON object where keys are filenames and values are file contents, e.g.:
{ ".env": "KEY=VALUE\nANOTHER=123", ".env.production": "KEY=PROD_VALUE" }
- Each file is written to your current working directory.
- If a file exists, you will be prompted before overwriting (unless
--force
is used).
Advanced Usage
- Use a config file for team-wide defaults.
- Use
--force
in CI/CD to avoid prompts. - Combine with npm scripts for automation.
Troubleshooting
- Ensure your API key is correct and has access to the app.
- Check your network connection if fetch fails.
- Use
--force
if you want to overwrite files without prompts.
Contributing
Pull requests and issues are welcome! See the GitHub repo for details.
License
MIT