Skip to content

feat: add prismic env commands and CLI-owned active environment#211

Draft
angeloashmore wants to merge 5 commits into
mainfrom
feat/env-commands
Draft

feat: add prismic env commands and CLI-owned active environment#211
angeloashmore wants to merge 5 commits into
mainfrom
feat/env-commands

Conversation

@angeloashmore

Copy link
Copy Markdown
Member

Resolves: #209

Description

Adds prismic env set/unset/active/list to pick a project's active environment. The choice lives in CLI-owned state keyed by project, so nothing lands in the repo. getRepositoryName resolves it, so every command honors it (--env/--repo still override).

Sites read the active environment at build time via two exports:

  • prismic/env — a sync getActiveEnvironment()
  • prismic/env/register — a side-effect import that sets the framework's environment variable

prismic init wires the register import into the framework config and updates the generated prismicio file for Next.js and SvelteKit, and adds prismic as a project dependency. Nuxt is out of scope here — @nuxtjs/prismic will read the state itself.

This implements the approach from the last comment on #209 (CLI-owned state), not the .env.local approach from #210.

Not included, by design: stripping the stale Slice Machine NEXT_PUBLIC_PRISMIC_ENVIRONMENT from existing projects' .env.local.

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

In a Next.js or SvelteKit project:

  1. prismic env list shows the environments; production is marked (active).
  2. prismic env set <staging-domain> then prismic env active prints the staging domain, and CLI commands (e.g. prismic pull) target it.
  3. Start the dev server — the site resolves the staging repository via the generated prismicio file.
  4. prismic env unset returns everything to production.

🤖 Generated with Claude Code

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 3, 2026 01:41
Add `prismic env set/unset/active/list` to pick a project's active
environment. The choice lives in CLI state keyed by project, so nothing
lands in the repo. `getRepositoryName` resolves it, so every command
honors it.

Sites read it at build time via the `prismic/env` and
`prismic/env/register` exports; `prismic init` wires the register import
into the framework config and generated `prismicio` file for Next.js and
SvelteKit.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

@angeloashmore angeloashmore left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It looks like we're missing the update-notifier message change where if we detect the user has the prismic cli installed as a dependency, we print instructions on how to update it. If it's being used via npx without an installation instead, we keep the current message.

Comment thread src/commands/env-list.ts Outdated
Comment thread src/commands/env-set.ts
Comment thread src/active-environment.ts
angeloashmore and others added 3 commits July 3, 2026 02:19
- update-notifier: when the CLI is installed as a project dependency,
  suggest the package manager's add command instead of the npx message
- rename `listAvailableEnvironments` to `getEnvironments`
- reuse a shared `findUpwardSync` helper in `active-environment`

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Makes it clear at the call site that the function returns the prod/stage
environments the logged-in user can access, not the raw client list.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Rename addRegisterImport to addEnvRegisterImport and activeDomain to
activeEnvironment.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.

feat: better environment support

1 participant