Skip to content

feat: add prismic init --new to create a repository and push local models#222

Open
angeloashmore wants to merge 1 commit into
mainfrom
aa/init-new
Open

feat: add prismic init --new to create a repository and push local models#222
angeloashmore wants to merge 1 commit into
mainfrom
aa/init-new

Conversation

@angeloashmore

@angeloashmore angeloashmore commented Jul 9, 2026

Copy link
Copy Markdown
Member

Resolves:

Description

Adds a --new flag to prismic init.

The default prismic init creates or connects to a repository and pulls its models. --new instead:

  • creates a new empty repository,
  • points prismic.config.json at it, preserving an existing config's libraries and routes,
  • pushes the project's local models to it,
  • skips framework scaffolding (the project already has it).

This enables a fast setup path from a template: clone a starter that already ships models and framework files, then run one command to get a matching repository — instead of scaffolding and modeling everything from scratch.

npx degit prismicio-community/nextjs-starter-prismic-minimal my-site
cd my-site && npm install
npx prismic init --new

--new cannot be combined with --repo (it always creates a repository).

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.

Additive flag only; existing init behavior is unchanged (all existing tests pass).

Preview

How to QA

Once this PR publishes its prismic@pr-<number> prerelease:

npx degit prismicio-community/nextjs-starter-prismic-minimal my-site
cd my-site && npm install
npx prismic@pr-222 init --new

Expected: a new repository is created, prismic.config.json's repositoryName is repointed (routes/libraries preserved), and the page type + RichText slice are pushed to the new repo. npx prismic@pr-<number> init --new --repo foo should error.

🤖 Generated with Claude Code


Note

Medium Risk
New remote-write path during init can publish local models to a fresh repo and repoint config; mistakes could target the wrong account/repo, though scope is limited to the newly created repository and default init is unchanged.

Overview
Adds prismic init --new, an alternate init path for template/starter workflows: it always creates a new empty repository, reads local custom types and slices from the adapter, and pushes them with insertSlice / insertCustomType instead of pulling remote models.

Init rules change so an existing prismic.config.json is allowed only with --new (to repoint a starter at a new repo); otherwise init still errors if a config exists. --new cannot be used with --repo. For starters, repositoryName (and optional CDN endpoint) is updated after a successful push so a failed push does not leave the config switched; greenfield projects get a new config before the push. Framework initProject scaffolding is skipped when a config already exists (unless --no-setup), while types generation and optional dependency install still run.

The default init flow (create/connect repo and sync models from remote) is unchanged in behavior; legacy Slice Machine migration and pull/sync logic are simply moved behind the non---new branch.

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

@angeloashmore angeloashmore marked this pull request as ready for review July 10, 2026 00:47

@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 4 potential issues.

Fix All in Cursor

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

Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 88359d1. Configure here.

Comment thread src/commands/init.ts
Comment thread src/commands/init.ts
Comment thread src/commands/init.ts
Comment thread src/commands/init.ts
`--new` creates a new empty repository, points prismic.config.json at it
(preserving an existing config's libraries and routes), and pushes the
project's local models instead of pulling. This enables a fast setup from a
template that already ships models and framework files.

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

@levimykel levimykel 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.

I left a couple of comments/questions and pre-approved.

Comment thread src/commands/init.ts
throw new CommandError(
"A prismic.config.json file exists. This project is already initialized.",
);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

❓ If I have a fully-initialized project pointing at a real repo and run init --new by accident, this would repoint my config at a fresh empty repo without asking, yeah? Is this low risk or should we guard against it?

Comment thread src/commands/init.ts
Comment on lines +167 to +170
await insertSlice(slice.model, { repo, token, host });
}
for (const customType of localCustomTypes) {
await insertCustomType(customType.model, { repo, token, host });

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

❓ What happens if an insert fails halfway? The config would point at the half-populated repo, so re-running init would say “already initialized” and re-running init --new would create a second repo. Is that acceptable for now, or should we catch and say something more helpful?

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