Skip to content

The command line

bearminion ships a command line next to the library. It adds sections to a site that was created earlier, tells you which of a site’s files differ from the installed release, and adds a form handler, and keeps the list of a site’s sections in step with its directories. It runs in the folder of your site (or with --cwd) and needs nothing but the bearminion package you already have.

Add a section

A site is a copy of the starter, so it does not get new sections when the starter does. add copies a section, and the files it imports, from the installed bearminion into your site:

Terminal window
npx bearminion add --list # what can be added; * marks what the site already has
npx bearminion add gallery text # copy two sections
npx bearminion add gallery --dry-run # show what would be written, write nothing

Names are the section’s directory (logo-strip) or its type in content files (logoStrip). The files come from the same release as the bearminion you run, so what you get always matches the library, and nothing is fetched from the network. Sites created before sync existed list their sections by hand and cannot use add until they move over; see Add a section type in the template guide.

What happens to each file

A section is more than its own directory: it imports atoms, molecules and helpers that you may have changed. So add looks at every file it would write and decides one of four things:

It saysBecauseWhat add does
createThe site has no such fileWrites it
sameThe site’s file is this release’sLeaves it
updateThe site’s file is an earlier release’s and you did not change itReplaces it with this release’s
conflictThe site’s file is neither: you changed itStops. Nothing is written

It knows an earlier release’s file because bearminion carries the hash of every file of every release since add was introduced. That works on any site, with or without a lock file.

An update is the one to look at: other sections use the same shared file, and the new version may look a little different. add says so, and a git diff and your build show the rest. Commit before you add, so git is the undo.

When a file conflicts:

Terminal window
npx bearminion add gallery --diff # how your file differs from this release
npx bearminion add gallery --overwrite # replace your version with this release's

--overwrite is the only way add replaces a file you changed.

Everything that follows

After the files are written, add:

  1. Lists the new directories in definitions.gen.ts and components.gen.ts, the same as npx bearminion sync.
  2. Records the files in bearminion.lock.json.
  3. Prints the npm packages the sections import that your package.json does not list, with the command that installs them. --install runs it for you, with the package manager your lock file names.

It never edits definitions.ts, astro.config.ts or a content file.

Options

Option
--listList the sections that can be added
--dry-runShow the plan and write nothing
-y, --yesDo not ask before writing. Without it, a terminal asks; anything else (a script, CI) stops and tells you to pass --yes or --dry-run
--overwriteReplace files you changed
--diffShow how files you changed differ from this release
--installInstall the npm packages the sections need
--jsonPrint one JSON document instead of text. It needs --yes or --dry-run, and is made for scripts and AI agents
--cwd <dir>Run as if started in this folder

Exit code 0 is a section added, or already there. 1 is a conflict, an unknown section, a site add cannot work on, or a failed install. 2 is a command that was not understood.

With --json the document has ok, version, sections, files (each with its path and action), npm (what is missing), dirty (files to be overwritten that git shows as changed), and, after a write, written.

Add a form handler

The Contact form posts to /api/contact, and a handler in src/forms/contact.ts answers there. add form writes it, and the few lines of glue your host needs to run it. A new site has no Contact section: add form adds it too, so one command gives you the section, the handler and the glue. Then put the section on a page in the editor (Add section, Contact).

Terminal window
npx bearminion add form --list # what can be added
npx bearminion add form resend --host vercel # the handler and the glue
npx bearminion add form resend # the host is read from the project
npx bearminion add form --host vercel # glue only, for a handler you already have

Today that is one service, resend (email), and three hosts: vercel (api/contact.ts), netlify (netlify/functions/contact.mts) and cloudflare (a Worker: worker.ts and wrangler.jsonc, the second only when the site has no Wrangler config). A real message has gone through Resend on each of them. The other services are in Forms as files to copy by hand, and join the command one at a time, after a real message has gone through each.

Set the addresses in the environment. The handler reads the sender and the receiver from CONTACT_FROM and CONTACT_TO, so no address is written into your repository, and it refuses to send until both are set along with RESEND_API_KEY. CONTACT_FROM has to be on a domain you verified with Resend.

Without --host, the command looks for vercel.json, netlify.toml, wrangler.toml and an Astro server adapter. If it finds none or two, it asks which host you use when it runs in a terminal (a numbered list; Enter writes the handler only). Without a terminal, with --json, or for a host it has no glue for (an Astro server adapter, say), it writes the handler only and says so. A file that is already there and differs from the recipe stops the command; --overwrite replaces it. --dry-run, --yes and --json work as for sections. The files are noted in bearminion.lock.json, and the command prints the three values to set. Forms explains the handler.

Set up the hosted editor

The hosted editor is a second deployment of your site that signs people in with GitHub and edits the repository (Edit online is the full guide). add hosted prepares the repository for it:

Terminal window
npx bearminion add hosted --dry-run # look first
npx bearminion add hosted --install # write, and install the Vercel adapter

It writes three kinds of file:

  • The starter’s files the editor depends on, from this release, like a section’s files: src/lib/editing.ts, src/lib/image-url.ts, src/env.d.ts, the image components (Image.astro, MediaFrame.astro), Seo.astro, the page routes ([...slug].astro, 404.astro) and, for a site that has them, the Media and Logo strip sections. A file of an earlier release that you did not change is replaced; one you changed stops the command (--diff shows how, --overwrite replaces it). A site made before 1.9 or without a lock file is recognised by the release history, so an untouched file is replaced, not reported as yours. Page routes you customised are the usual stop: merge the lines that read Astro.locals.bearminion.
  • Two files that are yours from then on: src/editor.ts (the editor, reading its settings from the environment) and astro.editor.config.ts (the build of the editor deployment: your astro.config.ts merged with the adapter and the editor). A different file that is already there is kept, not overwritten, unless you pass --overwrite.
  • A build:editor script in package.json, added as one line without reformatting the file.

Your astro.config.ts is never edited. The editor build is a separate config, so the public site’s build cannot load any editor code. A site whose own config already adds bearminionHostedEditor (an environment-variable gate) is left as it is: the command writes the starter files and src/editor.ts and says so.

The command ends with what is left to do outside the repository: the GitHub App, a second Vercel project whose Build Command is npm run build:editor, and four environment variables. Today the only host is vercel (the default); for Cloudflare see the integration guide. --dry-run, -y, --overwrite, --install, --diff, --json and --cwd work as for sections.

Add a content type

Terminal window
npx bearminion add type # asks what the type is
npx bearminion add type news --field date:date --sort date:desc # or says it with flags
npx bearminion add blog # a ready blog, no questions

add type declares one content type: a blog, case studies, events, a fixed About page. In a terminal it asks for the id, many entries or one page, the address, the fields, a listing page and the order. Any of --kind, --path, --label, --field, --sort or --listing turns the questions off, so scripts and assistants can run it:

OptionWhat it does
--kind <kind>multi, many entries (the default), or single, one page at a fixed address
--path <path>/news/{slug} for entries, /about for a single. Default: from the id
--label <text>The name the editor shows. Default: from the id
--field <field>Once per field: name:kind, name?:kind when optional, name:choice=a|b|c. Kinds: text, long-text, date, number, switch, choice, image, list
--sort <field>The order of entries: date:desc. Default: title, A to Z
--listing <n>Entries on one listing page (default 10), or none
--files-onlyOnly bring the site’s own files up to date and declare nothing, for types you write by hand (below)

It writes the type to src/lib/types/<id>.ts, adds it to src/lib/types/index.ts, and the first time passes those to src/lib/content-model.ts with types: siteTypes. A content model that is not shaped like the starter’s, or declares types some other way, is left alone and gets the lines to add. Before writing, it checks the type the way astro dev would and that no page or other type has its address. It also updates the site’s own files first, as below. add blog is add type with the blog already answered: posts at /blog/<slug> with a date, an excerpt, a cover and a draft switch, newest first, listed at /blog. More in Content types.

--dry-run, -y, --overwrite, --diff, --json and --cwd work as for sections.

Update a site for content types

A site made before 1.21 has a route file that knows only pages. Content types need the starter’s current files. add type brings them in on its way; --files-only brings them in alone, for a site whose types you declare by hand:

Terminal window
npx bearminion add type --files-only --dry-run # look first
npx bearminion add type --files-only # write

It writes the starter’s own files, from this release, like a section’s files: the page route (src/pages/[...slug].astro), src/content.config.ts, src/lib/content.ts, src/lib/sitemap.ts, and the two components a listing page uses (EntryList.astro, Pagination.astro). A file of an earlier release that you did not change is replaced; one you changed stops the command (--diff shows how, --overwrite replaces it).

Your astro.config.ts and your content model are never edited. The command tells you when your config still builds the sitemap from pages only.

You only need this when you declare a type. A site with no types in its content model builds exactly as before with its old files, and astro build stops with the list of missing addresses if you declare a type without running it. --dry-run, -y, --overwrite, --diff, --json and --cwd work as for sections.

Add a language

Terminal window
npx bearminion add locale de # declare German, copy the home and 404 pages
npx bearminion add locale --files-only # only bring the site's files up to date

add locale adds one language: any lowercase tag, such as de, fr or pt-br. It declares the languages in src/lib/content-model.ts with defineLocales (the site’s own language first, from lang in content/site.json), copies the home page to content/<code>/pages/ as a draft and the 404 page next to it, and copies src/i18n/en.json to src/i18n/<code>.json to translate. A content model of another shape is left alone and gets the lines to add. Before writing, it checks that the code is a language tag Node knows (--force takes one it does not), is not the site’s language, and that no page or content type has its address (/de, content/de/).

First it brings the starter’s files that publish more than one language up to this release, as for content types: the page route, the content readers, Base.astro, the header, footer and mobile menu, Seo.astro, LanguageSwitcher.astro, src/lib/i18n.ts and src/i18n/en.json. --files-only does that alone. A site with no languages builds the same pages before and after. Your astro.config.ts is never edited; the command tells you when its sitemap has no alternates yet. status lists the declared languages. More in Locales.

--dry-run, -y, --overwrite, --diff, --json and --cwd work as for sections.

Check the form

When the Contact form does not deliver, start here:

Terminal window
npx bearminion check form # the host is read from the project
npx bearminion check form --host netlify
npx bearminion check form --json

It reads your files and writes nothing. It finds a missing handler or glue file; an import without .js (the error that stops a first Vercel deploy); a Netlify function in a folder Netlify does not read, or without path: '/api/contact'; a Wrangler config without main, with the placeholder Worker name, or without CONTACT_FROM and CONTACT_TO under vars. Each problem comes with the fix, and the exit code is 1 when there is one.

It cannot see the host’s own settings: the environment variables on Vercel and Netlify, the secrets on Cloudflare. It lists the names to set there. No problems found means the files are right, not that a message gets through; send one from the deployed site.

See what is out of date

status compares every file of the sections your site has with the installed release. It reads, and writes nothing:

Terminal window
npx bearminion status
npx bearminion status --json

Each file is in one of these states:

StateMeaningWhat add does
currentIt is this release’s fileNothing to do
outdatedYou did not change it, and the release hasReplaces it
editedYou changed it, and the release has not changed it since you got itLeaves it alone
conflictYou and the release both changed itStops
differsIt is not this release’s, and there is no lock file to say who changed itStops

status ends with the command that brings the outdated sections up to date. A section with a conflict or differs file is left out of that command, because add would stop on it: look at it with add <name> --diff.

Versions and updates

The starter and bearminion ship together, in one numbered release, and create-bearminion has the same number. A release is a package on npm; your site records nothing about it except the files and bearminion.lock.json.

  • A minor release (1.8 to 1.9) can bring a new section, a new form recipe or a changed shared file. Run npx bearminion@latest status to see what moved, then npx bearminion@latest add <name> for a new section or to update an outdated one.
  • A patch release fixes things inside the package. It does not change the files that add copies, unless the fix is in one of them.
  • A major release can change how sites are built. It comes with its own upgrade notes.

Update your site is the whole routine, step by step. Running npx bearminion@latest uses the latest release’s files, whatever your site started from. Run npm update bearminion as well when you want the library itself to move; the files add copies and the library are meant to match.

add never edits a file you changed, never edits definitions.ts, astro.config.ts or a content file, and there is no command that updates everything at once. Sections are copied, not linked: once a file is yours, it stays yours.

The lock file

bearminion.lock.json sits in the site’s root and is committed with it. For each file add handles it records the release the file came from and its hash. A new site starts with one. add keeps it up to date and creates it when a site has none; it is how add and status tell a file you left alone from one you changed, even when the release it came from is not in the history this version of bearminion carries.

Do not edit it by hand. Delete it and the next add writes a new one for the files it touches.

Keep the section list in step

sync rewrites definitions.gen.ts and components.gen.ts from the directories under src/components/sections/. Run it after you add, rename or remove a section directory by hand:

Terminal window
npx bearminion sync # rewrite
npx bearminion sync --check # write nothing; exit 1 when they are stale (for CI)

A section is a directory with a definition.ts that exports its definition under the camelCase name, and a component named after the directory. logo-strip/ exports logoStrip from definition.ts and has LogoStrip.astro. astro build, astro check and astro sync stop with a reminder when the generated files are stale, and astro dev warns.

How it knows

For people who want to check the reasoning: the registry is generated from the starter at release time, with each section’s import graph walked and its npm packages read from the starter’s package.json; the hash of every file of every release is kept in the repository’s packages/editor/registry-history.json. Nothing is downloaded when you run add.