Skip to content

Automatically load .env files #15

@angeloashmore

Description

@angeloashmore

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. 🐴

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions