https://github.com/emiyaaaaa/gen-env-dts
Easily generate 'env.d.ts' files for '.env' files
https://github.com/emiyaaaaa/gen-env-dts
declaration env env-d-ts typescript
Last synced: 16 days ago
JSON representation
Easily generate 'env.d.ts' files for '.env' files
- Host: GitHub
- URL: https://github.com/emiyaaaaa/gen-env-dts
- Owner: Emiyaaaaa
- Created: 2024-01-08T18:15:22.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-04-11T03:31:17.000Z (about 2 years ago)
- Last Synced: 2025-03-28T19:43:44.986Z (about 1 year ago)
- Topics: declaration, env, env-d-ts, typescript
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/gen-env-dts
- Size: 21.5 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# gen-env-dts
Easily generate `env.d.ts` files for `.env` files
### Output (Support custom template)
```ts
// ./env.d.ts
declare global {
namespace NodeJS {
interface ProcessEnv {
AK: string
SK: string
}
}
}
export {}
```

## Usage 1
```bash
npx gen-env-dts
```
## Usage 2
```bash
# npm
npm install --save-dev gen-env-dts
```
./package.json
```json
{
"scripts": {
"env-dts": "gen-env-dts"
}
}
```
```bash
npm run env-dts
```
## Options
- `--input` (or `-i`)
- `--output` (or `-o`)
- `--template` (or `-t`)
### `--input` (or `-i`)
Input file path, default: `.env`
```bash
npx gen-env-dts -i ./path/to/env/file
```
Multiple input files
```bash
npx gen-env-dts -i ./path/to/env/file1 -i ./path/to/env/file2 -o ./path/to/output/file1 -o ./path/to/output/file2
```
>NOTE: If multiple input files are set, you need to use `--output` option to specify all of output files path.
### `--output` (or `-o`)
Output file path, default: `./env.d.ts`
```bash
npx gen-env-dts -o ./path/to/output/file
```
### `--template` (or `-t`)
Custom template file path
```bash
npx gen-env-dts -t ./path/to/template/file
```
Default template:
```ts
// ./template.d.ts
declare global {
namespace NodeJS {
interface ProcessEnv {
// DON'T CHANGE NEXT LINE, this will be replaced by the env variables
TEMPLATE_REPLACE
}
}
}
export {}
```
Your custom template:
```ts
// ./my-template.d.ts
export interface MyEnv {
// DON'T CHANGE NEXT LINE, this will be replaced by the env variables
TEMPLATE_REPLACE
}
```
```bash
npx gen-env-dts -t ./my-template.d.ts
```
You will get:
```ts
// ./env.d.ts
export interface MyEnv {
AK: string
SK: string
}
```