Skip to content

feat: add env commands#227

Open
angeloashmore wants to merge 3 commits into
mainfrom
aa/env-dot-env
Open

feat: add env commands#227
angeloashmore wants to merge 3 commits into
mainfrom
aa/env-dot-env

Conversation

@angeloashmore

@angeloashmore angeloashmore commented Jul 16, 2026

Copy link
Copy Markdown
Member

Resolves:

Description

Adds prismic env commands to manage a project's active environment.

prismic env set <environment>   # Set the active environment
prismic env unset               # Reset to the production environment
prismic env active              # Print the active environment
prismic env list                # List available environments (--json, --repo)

The active environment is written to .env.local under a framework-specific
variable name, so the running site picks it up automatically:

# Next.js
NEXT_PUBLIC_PRISMIC_ENVIRONMENT=my-environment

Checklist

  • A comprehensive Linear ticket, providing sufficient context and details to facilitate the review of the PR, is linked to the PR.
  • If my changes require tests, I added them.
  • If my changes affect backward compatibility, it has been discussed.
  • If my changes require an update to the CONTRIBUTING.md guide, I updated it.

Preview

How to QA 1

npx prismic@pr-227 env list
npx prismic@pr-227 env set my-environment
npx prismic@pr-227 env active
npx prismic@pr-227 env unset

Note

Medium Risk
Changes which Prismic repository the dev site queries via .env.local edits and client bootstrap; mistakes could point local builds at the wrong environment, though production defaults remain when unset.

Overview
Adds prismic env so developers can list, set, unset, and print the active Prismic environment for a project. The choice is persisted in .env.local via a framework-specific public env var (NEXT_PUBLIC_PRISMIC_ENVIRONMENT, NUXT_PUBLIC_PRISMIC_ENVIRONMENT, PUBLIC_PRISMIC_ENVIRONMENT).

env set validates the domain against environments the logged-in user can access (prod/stage), writes or updates the var, and treats the production repo domain as “unset” (remove override). env list supports table or --json and marks the active env when listing the project repo; --repo lists another repo without an active marker.

Generated Next.js and SvelteKit prismicio templates now resolve repositoryName from that env var, falling back to prismic.config.json. Shared .env.local read/write helpers back the adapter getEnvironment / setEnvironment / unsetEnvironment APIs.

Reviewed by Cursor Bugbot for commit c74abb3. Bugbot is set up for automated code reviews on this repo. Configure here.

Footnotes

  1. Please use these labels when submitting a review:
    ❓ #ask: Ask a question.
    💡 #idea: Suggest an idea.
    ⚠️ #issue: Strongly suggest a change.
    🎉 #nice: Share a compliment.

angeloashmore and others added 2 commits July 16, 2026 19:13
Add `prismic env` commands to manage a project's active environment.
The active environment is stored in .env.local under a framework-specific
variable name (e.g. NEXT_PUBLIC_PRISMIC_ENVIRONMENT), so the running site
reads it automatically.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Register `prismic env` in the command router and update the generated
prismic.io client templates to resolve repositoryName from the active
environment variable, falling back to the configured repository name.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@angeloashmore angeloashmore changed the title feat: add prismic env commands backed by .env.local feat: persist environment selection Jul 16, 2026
@angeloashmore angeloashmore changed the title feat: persist environment selection feat: add env commands Jul 16, 2026
@angeloashmore
angeloashmore marked this pull request as ready for review July 16, 2026 20:34

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 6 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit a222150. Configure here.

Comment thread src/adapters/nuxt.ts
Comment thread src/commands/env-list.ts Outdated
Comment thread src/lib/prismic/environments.ts
Comment thread src/adapters/index.ts
Comment thread src/adapters/nextjs.templates.ts
Comment thread src/lib/file.ts
- getEnvironment surfaces corrupt .env.local instead of treating it as unset
- env list marks the active environment only for the project's own repo
- setEnvFileVar/unsetEnvFileVar update every occurrence of a key

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

@lihbr lihbr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, tiny suggestion

Comment thread src/lib/file.ts
if (!hasFile) return;

let contents = await readFile(path, "utf8");
parseEnv(contents); // Verify the format

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 #idea: do you think adding a test covering the behavior when this throws (malformed env) would be useful?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants