gen-env-dts
TypeScript icon, indicating that this package has built-in type declarations

1.0.7 • Public • Published

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 {}

image

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
}

Package Sidebar

Install

npm i gen-env-dts

Weekly Downloads

1

Version

1.0.7

License

none

Unpacked Size

5.57 kB

Total Files

7

Last publish

Collaborators

  • emiyaaaaa