{"id":31051763,"url":"https://github.com/ajay-develops/copy-env-keys-to-env-example","last_synced_at":"2026-02-14T18:02:33.583Z","repository":{"id":310328113,"uuid":"1039499960","full_name":"ajay-develops/copy-env-keys-to-env-example","owner":"ajay-develops","description":"Copies the environment variable keys from .env.local and .env to .env.example","archived":false,"fork":false,"pushed_at":"2025-08-17T16:14:05.000Z","size":11,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-09-15T00:54:28.211Z","etag":null,"topics":["copy","copy-environment-variables","environment-variables"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/copy-env-keys-to-env-example","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ajay-develops.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-08-17T11:24:17.000Z","updated_at":"2025-08-17T16:14:08.000Z","dependencies_parsed_at":null,"dependency_job_id":"580f58a2-f6bd-4bed-8a36-9da6c4dec9cc","html_url":"https://github.com/ajay-develops/copy-env-keys-to-env-example","commit_stats":null,"previous_names":["ajay-develops/copy-env-keys-to-env-example"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ajay-develops/copy-env-keys-to-env-example","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajay-develops%2Fcopy-env-keys-to-env-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajay-develops%2Fcopy-env-keys-to-env-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajay-develops%2Fcopy-env-keys-to-env-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajay-develops%2Fcopy-env-keys-to-env-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ajay-develops","download_url":"https://codeload.github.com/ajay-develops/copy-env-keys-to-env-example/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajay-develops%2Fcopy-env-keys-to-env-example/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29451930,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-14T15:52:44.973Z","status":"ssl_error","status_checked_at":"2026-02-14T15:52:11.208Z","response_time":53,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["copy","copy-environment-variables","environment-variables"],"created_at":"2025-09-15T00:54:26.536Z","updated_at":"2026-02-14T18:02:33.578Z","avatar_url":"https://github.com/ajay-develops.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## copy-env-keys-to-env-example\n\nCopies environment variable keys from `.env` and `.env.local` into an `.env.example` file.\n\n### Highlights\n\n- **Empty values** in output (`KEY=`)\n- **Preserves source order**: `.env` first, then new keys from `.env.local`\n- **Preserves standalone comments** and blank lines associated with keys\n- **Append-only overwrite**: if output exists, only missing keys are appended under a timestamped section\n- **Warns about unknown keys**: marks keys present only in `.env.example` with a comment\n- **Idempotent**: safe to run repeatedly\n- **Zero deps**, fast, tiny\n\n---\n\n## Quick start (no install)\n\nUse via npx without adding any dependency:\n\n```bash\nnpx copy-env-keys-to-env-example\n```\n\nPrint what would be written (no file changes):\n\n```bash\nnpx copy-env-keys-to-env-example --dry-run\n```\n\nCustom output path:\n\n```bash\nnpx copy-env-keys-to-env-example --output config/example.env\n# or\nnpx copy-env-keys-to-env-example -o config/example.env\n```\n\n---\n\n## Pre-commit hook (ensure .env.example stays up to date)\n\nKeep `.env.example` updated automatically before every commit. Two options are shown below; the first uses npx without installing the package.\n\n### Option A: Husky (recommended)\n\n```bash\n# Install husky (dev-only)\nnpm i -D husky\n\n# Initialize husky (creates .husky/ and git hook wiring)\nnpx husky init\n\n# Add a pre-commit hook that runs the tool via npx without installing it\nnpx husky add .husky/pre-commit \"npx -y copy-env-keys-to-env-example \u0026\u0026 git add .env.example\"\n\n# If you use a custom output path, update the hook accordingly, e.g.:\n# npx husky add .husky/pre-commit \"npx -y copy-env-keys-to-env-example -o config/example.env \u0026\u0026 git add config/example.env\"\n```\n\n### Option B: Native git hook (no extra deps)\n\n```bash\nmkdir -p .git/hooks\ncat \u003e .git/hooks/pre-commit \u003c\u003c'SH'\n#!/usr/bin/env sh\nset -e\n\n# Update .env.example using npx without installing locally\nnpx -y copy-env-keys-to-env-example\n\n# Stage the updated file\ngit add .env.example\nSH\nchmod +x .git/hooks/pre-commit\n```\n\nFor a custom output path, replace the command and the path in `git add` accordingly.\n\n---\n\n## Install (optional)\n\nIf you prefer adding the tool to devDependencies:\n\n```bash\nnpm install --save-dev copy-env-keys-to-env-example\n# or\nyarn add -D copy-env-keys-to-env-example\n```\n\nAdd a script for easy usage:\n\n```json\n{\n  \"scripts\": {\n    \"create:.env.example\": \"copy-env-keys-to-env-example\"\n  }\n}\n```\n\n---\n\n## Usage\n\n```bash\ncopy-env-keys-to-env-example [--dry-run] [--output \u003cpath\u003e]\n```\n\n### Flags\n\n- `--dry-run`: print the resulting content to stdout without writing a file\n- `-o, --output \u003cpath\u003e`: custom output file path (default: `./.env.example`)\n- `-h, --help`: show usage\n\n### Behavior\n\n- Reads keys from `.env` and `.env.local` if present. If neither exists, exits with an error.\n- When the output file does not exist, it is created from scratch with:\n  - Empty values for all keys: `KEY=`\n  - Preserved standalone comments and blank lines\n  - Keys ordered by appearance: `.env` first, then new keys from `.env.local`\n- When the output file exists, behavior is append-only:\n  - Missing keys are appended under a header: `# --- Added by copy-env-keys-to-env-example on YYYY-MM-DD HH:mm:ss ---`\n  - Keys already present are left intact\n  - Keys found only in the output (not in `.env` or `.env.local`) are annotated with:\n    `# NOTE: Key not found in .env or .env.local`\n- Duplicate top-of-file comments are avoided.\n\n---\n\n## Examples\n\n### Generate `.env.example` from scratch\n\n```bash\nnpx copy-env-keys-to-env-example\n```\n\n### Print the generated content without writing\n\n```bash\nnpx copy-env-keys-to-env-example --dry-run\n```\n\n### Use a custom output path\n\n```bash\nnpx copy-env-keys-to-env-example --output config/example.env\n# or\nnpx copy-env-keys-to-env-example -o config/example.env\n```\n\n### Typical workflow\n\n1. Update `.env` or `.env.local` with new keys\n2. Run the tool:\n   ```bash\n   npx copy-env-keys-to-env-example\n   ```\n3. Commit the updated `.env.example`\n\n---\n\n## Notes and limitations\n\n- Inline comments on the same line as assignments are not copied; standalone comments are preserved.\n- Keys are parsed with a tolerant parser that supports optional `export` prefixes and quoted values.\n- The tool does not remove keys from the output; it only appends and annotates unknown ones.\n\n---\n\n## Local development\n\n```bash\n# From this repo\nnpm link\n\n# In a test project\nnpm link copy-env-keys-to-env-example\ncopy-env-keys-to-env-example --dry-run\n```\n\n---\n\n## License\n\nISC © ajay-develops\n\nRepository: [GitHub](https://github.com/ajay-develops/copy-env-keys-to-env-example)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fajay-develops%2Fcopy-env-keys-to-env-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fajay-develops%2Fcopy-env-keys-to-env-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fajay-develops%2Fcopy-env-keys-to-env-example/lists"}