@xlameiro/env-typegen 0.1.2 → 0.1.3
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 +6 -0
- package/README.md +82 -1
- package/dist/cli.js +1241 -57
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +1513 -32
- 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 +1501 -33
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.1.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 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.
|
|
8
|
+
|
|
3
9
|
## 0.1.2
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -41,8 +41,22 @@ npx env-typegen -i .env.example -o src/env.ts --no-format
|
|
|
41
41
|
|
|
42
42
|
# Watch mode — regenerate on every change
|
|
43
43
|
npx env-typegen -i .env.example -o src/env.ts --watch
|
|
44
|
+
|
|
45
|
+
# Validate one env source against a contract (strict by default)
|
|
46
|
+
npx env-typegen check --env .env --contract env.contract.ts
|
|
47
|
+
|
|
48
|
+
# Compare drift across multiple env files
|
|
49
|
+
npx env-typegen diff --targets .env,.env.example,.env.production --contract env.contract.ts
|
|
50
|
+
|
|
51
|
+
# Full diagnostics (check + diff + recommendations)
|
|
52
|
+
npx env-typegen doctor --env .env --targets .env,.env.example,.env.production --contract env.contract.ts
|
|
53
|
+
|
|
54
|
+
# Machine-readable report for CI pipelines
|
|
55
|
+
npx env-typegen check --env .env --json --output-file reports/env-check.json
|
|
44
56
|
```
|
|
45
57
|
|
|
58
|
+
All paths (`--env`, `--contract`, `--targets`, and `--output-file`) are resolved from your current working directory.
|
|
59
|
+
|
|
46
60
|
## Generator formats
|
|
47
61
|
|
|
48
62
|
Use `-f` / `--format` (or `-g` / `--generator` alias):
|
|
@@ -54,10 +68,58 @@ Use `-f` / `--format` (or `-g` / `--generator` alias):
|
|
|
54
68
|
| `t3` | Generate `@t3-oss/env-nextjs` config |
|
|
55
69
|
| `declaration` | Generate `.d.ts` declaration |
|
|
56
70
|
|
|
71
|
+
## Validation commands
|
|
72
|
+
|
|
73
|
+
`env-typegen` also includes governance-focused commands:
|
|
74
|
+
|
|
75
|
+
- `check` — validates one env source against the contract
|
|
76
|
+
- `diff` — compares env sources and detects configuration drift
|
|
77
|
+
- `doctor` — aggregates findings and prints remediation suggestions
|
|
78
|
+
|
|
79
|
+
### Strict mode
|
|
80
|
+
|
|
81
|
+
- Strict mode is enabled by default for validation commands.
|
|
82
|
+
- Use `--no-strict` to downgrade undeclared variables to warnings.
|
|
83
|
+
|
|
84
|
+
### JSON output
|
|
85
|
+
|
|
86
|
+
- `--json` outputs compact JSON
|
|
87
|
+
- `--json=pretty` outputs formatted JSON
|
|
88
|
+
- `--output-file <path>` writes the JSON report to disk
|
|
89
|
+
|
|
90
|
+
### Cloud snapshots
|
|
91
|
+
|
|
92
|
+
Validation commands can include cloud snapshot files as additional sources:
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
npx env-typegen check --cloud-provider vercel --cloud-file vercel-env.json --contract env.contract.ts
|
|
96
|
+
npx env-typegen diff --cloud-provider cloudflare --cloud-file cloudflare-env.json --contract env.contract.ts
|
|
97
|
+
npx env-typegen doctor --cloud-provider aws --cloud-file aws-env.json --contract env.contract.ts
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Supported providers: `vercel`, `cloudflare`, `aws`.
|
|
101
|
+
|
|
102
|
+
### Plugins
|
|
103
|
+
|
|
104
|
+
Use plugins to extend validation behavior:
|
|
105
|
+
|
|
106
|
+
- `transformContract` — mutate the loaded contract before validation
|
|
107
|
+
- `transformSource` — mutate environment values per source
|
|
108
|
+
- `transformReport` — enrich final validation reports
|
|
109
|
+
|
|
110
|
+
Load plugins with repeated `--plugin` flags or from `env-typegen.config.ts` (`plugins` field).
|
|
111
|
+
|
|
57
112
|
## Programmatic API
|
|
58
113
|
|
|
59
114
|
```ts
|
|
60
|
-
import {
|
|
115
|
+
import {
|
|
116
|
+
runGenerate,
|
|
117
|
+
runValidationCommand,
|
|
118
|
+
parseEnvFile,
|
|
119
|
+
generateTypeScriptTypes,
|
|
120
|
+
loadCloudSource,
|
|
121
|
+
loadPlugins,
|
|
122
|
+
} from "@xlameiro/env-typegen";
|
|
61
123
|
|
|
62
124
|
// High-level: full pipeline
|
|
63
125
|
await runGenerate({
|
|
@@ -70,6 +132,16 @@ await runGenerate({
|
|
|
70
132
|
// Low-level: parse then generate individually
|
|
71
133
|
const parsed = parseEnvFile(".env.example");
|
|
72
134
|
const ts = generateTypeScriptTypes(parsed);
|
|
135
|
+
|
|
136
|
+
// Run validation commands programmatically
|
|
137
|
+
const exitCode = await runValidationCommand({
|
|
138
|
+
command: "check",
|
|
139
|
+
argv: ["--env", ".env", "--contract", "env.contract.ts", "--json"],
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
// Load cloud snapshots and plugins in custom integrations
|
|
143
|
+
const cloudValues = await loadCloudSource({ provider: "vercel", filePath: "vercel-env.json" });
|
|
144
|
+
const plugins = await loadPlugins({ pluginPaths: ["./plugins/custom.mjs"] });
|
|
73
145
|
```
|
|
74
146
|
|
|
75
147
|
## Configuration
|
|
@@ -84,9 +156,18 @@ export default defineConfig({
|
|
|
84
156
|
output: "src/env.generated.ts",
|
|
85
157
|
generators: ["typescript", "zod"],
|
|
86
158
|
format: true,
|
|
159
|
+
schemaFile: "env.contract.ts",
|
|
160
|
+
strict: true,
|
|
161
|
+
diffTargets: [".env", ".env.example", ".env.production"],
|
|
162
|
+
plugins: ["./plugins/custom-validator.mjs"],
|
|
87
163
|
});
|
|
88
164
|
```
|
|
89
165
|
|
|
166
|
+
## Documentation
|
|
167
|
+
|
|
168
|
+
- Fumadocs source in repo: [`/content/docs`](../../content/docs)
|
|
169
|
+
- Package markdown docs: [`/packages/env-typegen/docs`](./docs)
|
|
170
|
+
|
|
90
171
|
## Status
|
|
91
172
|
|
|
92
173
|
`env-typegen` is actively maintained and published on npm.
|