@xlameiro/env-typegen 0.1.2 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.4
4
+
5
+ ### Patch Changes
6
+
7
+ - ad8f00d: Fix six QA-identified deficiencies in CLI behaviour and documentation
8
+ - **D1 (critical)**: Fix crash when `.ts` config file is present — `loadConfig()` now throws an actionable error with a code snippet instead of silently failing. `CONFIG_FILE_NAMES` load order changed to `.mjs → .js → .ts` to prefer simpler formats first.
9
+ - **D2**: Document multi-generator output suffix convention in `--output` / `-o` help text (e.g. `env.generated.typescript.ts`, `env.generated.zod.ts`).
10
+ - **D3**: Add "Config file:" section to `--help` describing auto-discovery order (`.mjs → .js → .ts`), CLI flag override, and `defineConfig()` tip.
11
+ - **D4**: Expand plugin load error to include the full expected interface shape (`name`, `transformSource?`, `transformReport?`, `transformContract?`) so users know exactly what to export.
12
+ - **D5**: Add "Exit codes:" section to all four help texts (`generate`, `check`, `diff`, `doctor`).
13
+ - **D6**: Fix `--watch` mode not propagating `output` path changes when config is reloaded — `handleConfigChange` now updates `runOptions.output` alongside `generators`, `format`, and `inferenceRules`.
14
+
15
+ ## 0.1.3
16
+
17
+ ### Patch Changes
18
+
19
+ - Refresh package and site documentation for the validation suite (`check`, `diff`, `doctor`), cloud snapshot sources, and plugin-based extension points. Expand public API examples to include `runValidationCommand`, `loadCloudSource`, and plugin loading helpers.
20
+
3
21
  ## 0.1.2
4
22
 
5
23
  ### Patch Changes
package/README.md CHANGED
@@ -1,22 +1,21 @@
1
1
  # env-typegen
2
2
 
3
- > From `.env.example` to TypeScript in one command.
3
+ > From `.env.example` to typed outputs and contract-based environment governance.
4
4
 
5
5
  [![npm version](https://badge.fury.io/js/%40xlameiro%2Fenv-typegen.svg)](https://npmjs.com/package/@xlameiro/env-typegen)
6
6
  [![CI](https://github.com/xlameiro/env-typegen/actions/workflows/ci.yml/badge.svg)](https://github.com/xlameiro/env-typegen/actions/workflows/ci.yml)
7
7
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
8
- [![TypeScript](https://img.shields.io/badge/TypeScript-5.x-blue)](https://www.typescriptlang.org/)
9
8
 
10
- ## What it does
9
+ ## What this package does
11
10
 
12
- `env-typegen` reads `.env.example` files and automatically generates:
11
+ `@xlameiro/env-typegen` reads `.env.example` and helps you:
13
12
 
14
- - TypeScript types (`type EnvVars = { PORT: number; DATABASE_URL: string }`)
15
- - Zod v4 schemas (`z.object({ PORT: z.coerce.number() })`)
16
- - `@t3-oss/env-nextjs` `createEnv` configuration
17
- - `.d.ts` declaration files that augment `NodeJS.ProcessEnv`
13
+ - generate TypeScript, Zod, t3-env, and declaration outputs
14
+ - validate real env files against explicit contracts
15
+ - detect drift across multiple targets
16
+ - produce CI-friendly JSON diagnostics
18
17
 
19
- ## Install
18
+ ## Installation
20
19
 
21
20
  ```bash
22
21
  pnpm add -D @xlameiro/env-typegen
@@ -27,73 +26,117 @@ npm install --save-dev @xlameiro/env-typegen
27
26
  ## Quick Start
28
27
 
29
28
  ```bash
30
- # Generate all outputs (default: typescript + zod + t3 + declaration)
29
+ # Generate all outputs by default
31
30
  npx env-typegen --input .env.example --output src/env.generated.ts
32
31
 
33
- # Generate only a Zod schema
32
+ # Generate only Zod schema
34
33
  npx env-typegen -i .env.example -o src/env.schema.ts -g zod
35
34
 
36
- # Generate multiple outputs explicitly
37
- npx env-typegen -i .env.example -o src/env.ts -f typescript -f zod
35
+ # Watch mode
36
+ npx env-typegen -i .env.example -o src/env.generated.ts --watch
37
+ ```
38
+
39
+ ## Generator formats
38
40
 
39
- # Generate without running Prettier
40
- npx env-typegen -i .env.example -o src/env.ts --no-format
41
+ | Value | Output |
42
+ | -------------------- | -------------------------------------------- |
43
+ | `ts` or `typescript` | TypeScript env types |
44
+ | `zod` | Zod v4 schema |
45
+ | `t3` | `@t3-oss/env-nextjs` `createEnv(...)` config |
46
+ | `declaration` | Ambient `.d.ts` env declaration |
41
47
 
42
- # Watch mode regenerate on every change
43
- npx env-typegen -i .env.example -o src/env.ts --watch
48
+ Multiple outputs in one run:
49
+
50
+ ```bash
51
+ npx env-typegen -i .env.example -o src/env.ts -f typescript -f zod -f declaration
44
52
  ```
45
53
 
46
- ## Generator formats
54
+ ## Validation and governance commands
47
55
 
48
- Use `-f` / `--format` (or `-g` / `--generator` alias):
56
+ ```bash
57
+ # Validate one source
58
+ npx env-typegen check --env .env --contract env.contract.ts
49
59
 
50
- | Value | Meaning |
51
- | -------------------- | ------------------------------------ |
52
- | `ts` or `typescript` | Generate TypeScript types |
53
- | `zod` | Generate Zod schema |
54
- | `t3` | Generate `@t3-oss/env-nextjs` config |
55
- | `declaration` | Generate `.d.ts` declaration |
60
+ # Compare drift across sources
61
+ npx env-typegen diff --targets .env,.env.example,.env.production --contract env.contract.ts
56
62
 
57
- ## Programmatic API
63
+ # Aggregated diagnostics
64
+ npx env-typegen doctor --env .env --targets .env,.env.example,.env.production --contract env.contract.ts
65
+ ```
58
66
 
59
- ```ts
60
- import { runGenerate, parseEnvFile, generateTypeScriptTypes } from "@xlameiro/env-typegen";
61
-
62
- // High-level: full pipeline
63
- await runGenerate({
64
- input: ".env.example",
65
- output: "src/env.generated.ts",
66
- generators: ["typescript"],
67
- format: true,
68
- });
69
-
70
- // Low-level: parse then generate individually
71
- const parsed = parseEnvFile(".env.example");
72
- const ts = generateTypeScriptTypes(parsed);
67
+ JSON output for CI:
68
+
69
+ ```bash
70
+ npx env-typegen check --env .env --json --output-file reports/env-check.json
71
+ ```
72
+
73
+ Strict mode is enabled by default. Use `--no-strict` to downgrade undeclared variables to warnings.
74
+
75
+ ## Cloud snapshots
76
+
77
+ Validation commands can include cloud snapshot sources:
78
+
79
+ ```bash
80
+ npx env-typegen check --cloud-provider vercel --cloud-file vercel-env.json --contract env.contract.ts
81
+ npx env-typegen diff --cloud-provider cloudflare --cloud-file cloudflare-env.json --contract env.contract.ts
82
+ npx env-typegen doctor --cloud-provider aws --cloud-file aws-env.json --contract env.contract.ts
73
83
  ```
74
84
 
75
- ## Configuration
85
+ Supported providers: `vercel`, `cloudflare`, `aws`.
76
86
 
77
- Create `env-typegen.config.ts` at your project root:
87
+ ## Plugin hooks
88
+
89
+ Use plugins to customize validation behavior:
90
+
91
+ - `transformContract`
92
+ - `transformSource`
93
+ - `transformReport`
94
+
95
+ Load plugins with repeated `--plugin` flags or via `plugins` in `env-typegen.config.ts`.
96
+
97
+ ## Programmatic API
78
98
 
79
99
  ```ts
80
- import { defineConfig } from "@xlameiro/env-typegen";
81
-
82
- export default defineConfig({
83
- input: ".env.example",
84
- output: "src/env.generated.ts",
85
- generators: ["typescript", "zod"],
86
- format: true,
87
- });
100
+ import {
101
+ runGenerate,
102
+ runValidationCommand,
103
+ parseEnvFile,
104
+ generateTypeScriptTypes,
105
+ loadCloudSource,
106
+ loadPlugins,
107
+ } from "@xlameiro/env-typegen";
88
108
  ```
89
109
 
90
- ## Status
110
+ ## Typical adoption path
91
111
 
92
- `env-typegen` is actively maintained and published on npm.
112
+ 1. Start with generation-only output (`ts`, `zod`).
113
+ 2. Add `check` in CI for contract enforcement.
114
+ 3. Add `diff` and `doctor` for drift prevention.
115
+ 4. Add cloud snapshots and plugins for advanced workflows.
116
+
117
+ ## FAQ
118
+
119
+ ### Is this package only for Next.js?
93
120
 
94
- ## Changelog
121
+ No. It is framework-agnostic. The `t3` generator is optional.
95
122
 
96
- See [`CHANGELOG.md`](./CHANGELOG.md) for release notes.
123
+ ### Can I use it without a contract file?
124
+
125
+ Yes, but explicit contracts are recommended for governance and CI reliability.
126
+
127
+ ### Which command should I run in CI?
128
+
129
+ Start with `check`. Add `diff` or `doctor` as your pipeline maturity grows.
130
+
131
+ ## Docs and references
132
+
133
+ - Website docs source: [`/content/docs`](../../content/docs)
134
+ - Package docs index: [`/packages/env-typegen/docs`](./docs)
135
+ - Changelog: [`CHANGELOG.md`](./CHANGELOG.md)
136
+
137
+ ## Status
138
+
139
+ `env-typegen` is actively maintained and published on npm.
97
140
 
98
141
  ## License
99
142