@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 +18 -0
- package/README.md +97 -54
- package/dist/cli.js +1448 -169
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +1716 -150
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +537 -1
- package/dist/index.d.ts +537 -1
- package/dist/index.js +1704 -151
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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
|
|
3
|
+
> From `.env.example` to typed outputs and contract-based environment governance.
|
|
4
4
|
|
|
5
5
|
[](https://npmjs.com/package/@xlameiro/env-typegen)
|
|
6
6
|
[](https://github.com/xlameiro/env-typegen/actions/workflows/ci.yml)
|
|
7
7
|
[](LICENSE)
|
|
8
|
-
[](https://www.typescriptlang.org/)
|
|
9
8
|
|
|
10
|
-
## What
|
|
9
|
+
## What this package does
|
|
11
10
|
|
|
12
|
-
|
|
11
|
+
`@xlameiro/env-typegen` reads `.env.example` and helps you:
|
|
13
12
|
|
|
14
|
-
- TypeScript
|
|
15
|
-
-
|
|
16
|
-
-
|
|
17
|
-
-
|
|
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
|
-
##
|
|
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
|
|
29
|
+
# Generate all outputs by default
|
|
31
30
|
npx env-typegen --input .env.example --output src/env.generated.ts
|
|
32
31
|
|
|
33
|
-
# Generate only
|
|
32
|
+
# Generate only Zod schema
|
|
34
33
|
npx env-typegen -i .env.example -o src/env.schema.ts -g zod
|
|
35
34
|
|
|
36
|
-
#
|
|
37
|
-
npx env-typegen -i .env.example -o src/env.ts
|
|
35
|
+
# Watch mode
|
|
36
|
+
npx env-typegen -i .env.example -o src/env.generated.ts --watch
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Generator formats
|
|
38
40
|
|
|
39
|
-
|
|
40
|
-
|
|
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
|
-
|
|
43
|
-
|
|
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
|
-
##
|
|
54
|
+
## Validation and governance commands
|
|
47
55
|
|
|
48
|
-
|
|
56
|
+
```bash
|
|
57
|
+
# Validate one source
|
|
58
|
+
npx env-typegen check --env .env --contract env.contract.ts
|
|
49
59
|
|
|
50
|
-
|
|
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
|
-
|
|
63
|
+
# Aggregated diagnostics
|
|
64
|
+
npx env-typegen doctor --env .env --targets .env,.env.example,.env.production --contract env.contract.ts
|
|
65
|
+
```
|
|
58
66
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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
|
-
|
|
85
|
+
Supported providers: `vercel`, `cloudflare`, `aws`.
|
|
76
86
|
|
|
77
|
-
|
|
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 {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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
|
-
##
|
|
110
|
+
## Typical adoption path
|
|
91
111
|
|
|
92
|
-
|
|
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
|
-
|
|
121
|
+
No. It is framework-agnostic. The `t3` generator is optional.
|
|
95
122
|
|
|
96
|
-
|
|
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
|
|