prismicio / prismic-ts-codegen

A Prismic model-to-TypeScript-type generator.
Apache License 2.0
18 stars 6 forks source link

Automatically load .env files #15

Open angeloashmore opened 2 years ago

angeloashmore commented 2 years ago

Is your feature request related to a problem? Please describe.

Private tokens, like a Prismic repository's access token or Custom Types API token, should generally not be committed to a Git repository. Using .env files is a common practice to exclude private data from committed code.

Currently, prismic-ts-codegen requires an access token and/or Custom Types API token for certain configurations, but does not provide a straightforward way to do so securely.

Describe the solution you'd like

prismic-ts-codegen could automatically load .env files from the working directory. Loading a .env file populates the global process.env object with arbitrary data, which could be used to load private tokens.

The dotenv package is the most commonly used package to load .env files. While that exact package does not need to be used, its .env loading practices are industry-standard.

Something to consider: some frameworks have .env naming conventions. For example, .env.local (as seen in Next.js) and .env.development are common conventions. Which .env file is loaded can be a prismic-ts-codegen configuration property, but good defaults results in a smoother experience.

Describe alternatives you've considered

Because prismic-ts-codegen's config is written in a TypeScript or JavaScript file (prismicCodegen.config.{ts|js}), the dotenv package could be used manually. It is easy to set up, but ultimately is more friction than having that functionality built in to the tool.

Additional context

Thanks to @a-trost for prompting this feature request. šŸ“