@xlameiro/env-typegen 0.1.0
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 +57 -0
- package/LICENSE +21 -0
- package/README.md +83 -0
- package/dist/cli.js +768 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.cjs +539 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +271 -0
- package/dist/index.d.ts +271 -0
- package/dist/index.js +518 -0
- package/dist/index.js.map +1 -0
- package/package.json +107 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
This project adheres to [Semantic Versioning](https://semver.org/) and uses
|
|
6
|
+
[Changesets](https://github.com/changesets/changesets) for release management.
|
|
7
|
+
|
|
8
|
+
<!-- Releases are added automatically by `changeset version` -->
|
|
9
|
+
|
|
10
|
+
## [0.1.0] — 2026-03-16
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
#### Foundation (Phase 1)
|
|
15
|
+
|
|
16
|
+
- TypeScript 5 strict mode with `exactOptionalPropertyTypes` and `noUncheckedIndexedAccess`
|
|
17
|
+
- Dual CJS + ESM build via tsup with full type declarations (`dist/index.d.ts`)
|
|
18
|
+
- Vitest test infrastructure with v8 coverage (thresholds: 85% lines, 80% branches)
|
|
19
|
+
- ESLint v9 flat config with `@typescript-eslint/recommended`
|
|
20
|
+
|
|
21
|
+
#### Parser (Phase 2)
|
|
22
|
+
|
|
23
|
+
- `parseEnvFile(path)` — reads a `.env.example` file from disk and returns a structured `ParsedEnvFile`
|
|
24
|
+
- `parseEnvFileContent(content)` — parses raw string content; useful in tests or pipelines
|
|
25
|
+
- `parseCommentBlock(block)` — extracts JSDoc-style annotations (`@type`, `@description`, `@example`, `@optional`) from comment lines above env var assignments
|
|
26
|
+
- `inferType(value)` — infers `EnvVarType` (`string` | `number` | `boolean` | `url` | `email`) from a raw env value
|
|
27
|
+
|
|
28
|
+
#### Generators (Phases 3 & 4)
|
|
29
|
+
|
|
30
|
+
- `generateTypeScriptTypes(parsed)` — produces a `type Env = { ... }` TypeScript declaration with inferred types
|
|
31
|
+
- `generateEnvValidation(parsed)` — produces a runtime validation helper alongside the type
|
|
32
|
+
- `generateZodSchema(parsed)` — produces a Zod v4 `z.object({ ... })` schema; numbers use `z.coerce.number()`, booleans `z.coerce.boolean()`
|
|
33
|
+
- `generateT3Env(parsed)` — produces a `@t3-oss/env-nextjs` `createEnv(...)` call; splits vars into `server` and `client` (`NEXT_PUBLIC_*`) buckets automatically
|
|
34
|
+
- `generateDeclaration(parsed)` — produces a `.d.ts` file that augments `NodeJS.ProcessEnv` with the parsed var names and types
|
|
35
|
+
|
|
36
|
+
#### Config & Utils (Phase 5)
|
|
37
|
+
|
|
38
|
+
- `defineConfig(config)` — type-safe config factory (identity function for editor inference)
|
|
39
|
+
- `loadConfig(cwd)` — discovers and loads `env-typegen.config.ts` / `env-typegen.config.js` / `env-typegen.config.mjs` starting from a given directory
|
|
40
|
+
- `readEnvFile(path)` / `writeOutput(path, content)` — file I/O utilities
|
|
41
|
+
- `formatOutput(content)` — formats generated source with Prettier
|
|
42
|
+
- `log()`, `error()`, `success()`, `warn()` — colourised logger helpers
|
|
43
|
+
|
|
44
|
+
#### CLI (Phase 6)
|
|
45
|
+
|
|
46
|
+
- `env-typegen` binary via `dist/cli.js`
|
|
47
|
+
- Flags: `--input` / `-i`, `--output` / `-o`, `--generator` / `-g` (repeatable), `--format` / `-f`, `--watch` / `-w`, `--config` / `-c`, `--version` / `-v`, `--help` / `-h`
|
|
48
|
+
- Multiple generators produce separate output files with the generator name inserted before the extension (e.g. `env.generated.typescript.ts`, `env.generated.zod.ts`)
|
|
49
|
+
- Watch mode via chokidar v4 — regenerates on every file change; SIGINT-safe
|
|
50
|
+
- `runGenerate(options)` — programmatic pipeline API; runs without a CLI process
|
|
51
|
+
|
|
52
|
+
#### Quality & Docs (Phase 7)
|
|
53
|
+
|
|
54
|
+
- Full TSDoc on every public export in `src/index.ts`
|
|
55
|
+
- README with Quick Start (CLI examples), Programmatic API, and Configuration sections
|
|
56
|
+
|
|
57
|
+
[0.1.0]: https://github.com/YOUR_USERNAME/env-typegen/releases/tag/v0.1.0
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 env-typegen contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# env-typegen
|
|
2
|
+
|
|
3
|
+
> From `.env.example` to TypeScript in one command.
|
|
4
|
+
|
|
5
|
+
[](https://npmjs.com/package/env-typegen)
|
|
6
|
+
[](https://github.com/YOUR_USERNAME/env-typegen/actions/workflows/ci.yml)
|
|
7
|
+
[](LICENSE)
|
|
8
|
+
[](https://www.typescriptlang.org/)
|
|
9
|
+
|
|
10
|
+
## What it does
|
|
11
|
+
|
|
12
|
+
`env-typegen` reads `.env.example` files and automatically generates:
|
|
13
|
+
|
|
14
|
+
- TypeScript types (`type Env = { 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`
|
|
18
|
+
|
|
19
|
+
## Quick Start
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
# Generate TypeScript types (default)
|
|
23
|
+
npx env-typegen --input .env.example --output src/env.generated.ts
|
|
24
|
+
|
|
25
|
+
# Generate a Zod schema
|
|
26
|
+
npx env-typegen -i .env.example -o src/env.schema.ts -g zod
|
|
27
|
+
|
|
28
|
+
# Generate multiple outputs and format with Prettier
|
|
29
|
+
npx env-typegen -i .env.example -o src/env.ts -g typescript -g zod --format
|
|
30
|
+
|
|
31
|
+
# Watch mode — regenerate on every change
|
|
32
|
+
npx env-typegen -i .env.example -o src/env.ts --watch
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Programmatic API
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
import { runGenerate, parseEnvFile, generateTypeScriptTypes } from "env-typegen";
|
|
39
|
+
|
|
40
|
+
// High-level: full pipeline
|
|
41
|
+
await runGenerate({
|
|
42
|
+
input: ".env.example",
|
|
43
|
+
output: "src/env.generated.ts",
|
|
44
|
+
generators: ["typescript"],
|
|
45
|
+
format: true,
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
// Low-level: parse then generate individually
|
|
49
|
+
const parsed = await parseEnvFile(".env.example");
|
|
50
|
+
const ts = generateTypeScriptTypes(parsed);
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Configuration
|
|
54
|
+
|
|
55
|
+
Create `env-typegen.config.ts` at your project root:
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
import { defineConfig } from "env-typegen";
|
|
59
|
+
|
|
60
|
+
export default defineConfig({
|
|
61
|
+
input: ".env.example",
|
|
62
|
+
output: "src/env.generated.ts",
|
|
63
|
+
generators: ["typescript", "zod"],
|
|
64
|
+
format: true,
|
|
65
|
+
});
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Status
|
|
69
|
+
|
|
70
|
+
| Phase | Description | Status |
|
|
71
|
+
| ----- | -------------- | ------ |
|
|
72
|
+
| 1 | Foundation | ✅ |
|
|
73
|
+
| 2 | Parser | ✅ |
|
|
74
|
+
| 3 | Inferrer | ✅ |
|
|
75
|
+
| 4 | Generators | ✅ |
|
|
76
|
+
| 5 | Config & Utils | ✅ |
|
|
77
|
+
| 6 | CLI | ✅ |
|
|
78
|
+
| 7 | Quality & Docs | ✅ |
|
|
79
|
+
| 8 | Publishing | 🔜 |
|
|
80
|
+
|
|
81
|
+
## License
|
|
82
|
+
|
|
83
|
+
MIT
|