gen-env-dts
v1.0.7
Published
Easily generate 'env.d.ts' files for '.env' files
Downloads
11
Maintainers
Readme
gen-env-dts
Easily generate env.d.ts
files for .env
files
Output (Support custom template)
// ./env.d.ts
declare global {
namespace NodeJS {
interface ProcessEnv {
AK: string
SK: string
}
}
}
export {}
Usage 1
npx gen-env-dts
Usage 2
# npm
npm install --save-dev gen-env-dts
#yarn
yarn add --dev gen-env-dts
#pnpm
pnpm add --save-dev gen-env-dts
./package.json
{
"scripts": {
"env-dts": "gen-env-dts"
}
}
npm run env-dts
Options
--input
(or-i
)--output
(or-o
)--template
(or-t
)
--input
(or -i
)
Input file path, default: .env
npx gen-env-dts -i ./path/to/env/file
Multiple input files
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
npx gen-env-dts -o ./path/to/output/file
--template
(or -t
)
Custom template file path
npx gen-env-dts -t ./path/to/template/file
Default template:
// ./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:
// ./my-template.d.ts
export interface MyEnv {
// DON'T CHANGE NEXT LINE, this will be replaced by the env variables
TEMPLATE_REPLACE
}
npx gen-env-dts -t ./my-template.d.ts
You will get:
// ./env.d.ts
export interface MyEnv {
AK: string
SK: string
}