gen-env-dts
v1.0.7
Published
Easily generate 'env.d.ts' files for '.env' files
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-dtsUsage 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-dtsOptions
--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/fileMultiple 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/file2NOTE: If multiple input files are set, you need to use
--outputoption 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/fileDefault 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.tsYou will get:
// ./env.d.ts
export interface MyEnv {
AK: string
SK: string
}