Skip to Content
Grist Widgets

CLI reference

How create-grist-widget scaffolds a project, starts from a real example, and what the bundled GitHub Pages deploy pipeline does.

The CLI's commands, from scaffolding a widget to protecting its repository. Your first widget walks through them in order; to start from GitHub instead of a terminal, see Start from the template on GitHub: both give the same code.

npm create grist-widget

npm create grist-widget my-widget
cd my-widget
pnpm dev

Then open http://localhost:5173/demo/index.html: the widget in real Grist, running in the browser (no Docker, nothing saved), on the dev server's build, so edits reload in place. The scaffold ships that demo page (public/demo/) for its starting widget; pnpm demo --save regenerates it once the widget's columns change.

The template — and every starting example, and the logic that composes them — are embedded directly in the CLI. Nothing is fetched from GitHub or npm at scaffold time; the dependency install right after is the only network access any of this makes. Scaffolding via the CLI is the same starting point as grist-widget-template, so both paths converge on identical code.

Start from the template on GitHub

Instead of a terminal: open grist-widget-template, and check Include all branches on the next page, so the copy comes with its dev and gh-pages branches and GitHub Pages needs no setting. An AI coding agent (Claude, Codex, Cursor) works on the copy once its GitHub App is installed on it. From there, the widget is the same as a scaffolded one: Your first widget from step 3.

By default the scaffold is blank — a two-field editor — and its dependencies install automatically, with pnpm, whichever package manager runs the command: the widget's workflows install with pnpm and only read its lockfile. Without pnpm installed, nothing is installed and the CLI says how to get it. Run npm create grist-widget with no name for an interactive prompt instead, which asks for both a name and a starting example.

What you get

index.html
App.tsx
App.test.tsx
App.smoke.test.tsx
index.css
main.tsx
eslint.config.js
.prettierrc
package.json
  • index.html has the grist-plugin-api.js script tag wired in.
  • src/main.tsx is one call to mountGristWidget(): the widget inside Grist, a local-dev or release page anywhere else. It reads what src/app/App.tsx exports, so it is never edited.
  • src/app/ is the widget, and everything in it is yours. src/app/App.tsx declares the widget with defineGristWidget() (access, columns, title) and shows a typed read and write, with UI you can immediately replace. Put the widget's other files (components, hooks, helpers, assets) next to it.
  • src/app/App.test.tsx is a working test of that widget, using renderWithGrist(<App />, { widget, rows }) — run it, then edit it alongside App.tsx.
  • src/app/App.smoke.test.tsx checks that the widget renders inside an emulated Grist with every declared column mapped, whatever the widget does (Smoke test).
  • src/components/ui/ (shadcn primitives) and src/index.css (the theme) are yours too. src/main.tsx, the workflows and the build configuration belong to the template: their changes ship with new CLI releases (Upgrading a widget lists them).
  • Tailwind preconfigured for theme-aware widgets (light / dark / system).
  • Prettier + ESLint with project-wide rules.
  • tsconfig.app.json and tsconfig.node.json extend the TypeScript settings grist-widget-sdk ships, so compiler-setting changes arrive with SDK updates. Each keeps only the widget's own files, paths and types.
  • pnpm-lock.yaml in the first commit: the CLI installs with pnpm before committing, so dependency versions and their integrity hashes are pinned from the start. A widget scaffolded within a day of a release also gets age-check exceptions for the SDK and CLI versions it was made with, written by pnpm itself (see the template README).

After scaffolding, the first edit is typically src/app/App.tsx — replace the placeholder with the widget you want. For a pattern close to yours (drag and drop, writes, attachments, a map), read a catalog widget: each has its spec, its code and its tests in widgets/<slug>/.

The commands

This is what create-grist-widget --help prints, every command and option:

create-grist-widget — scaffold a Grist custom widget, offline

Usage:
  npm create grist-widget <name> [options]       Scaffold into ./<name>
  create-grist-widget create <name> [options]    Same as above, explicit
  create-grist-widget init [options]             Scaffold into the current directory
  create-grist-widget update [--dry-run] [--no-pr] [--branch <name>] [--min-age-days <n>] [--json] [--try]
                                                 At origin/dev: the newest create-grist-widget and
                                                 grist-widget-sdk at least 7 days old, installed exactly,
                                                 upgrade run, committed on a branch and opened as one pull
                                                 request into dev (with gh). --min-age-days only waits
                                                 longer. --try (sdk-update.yml): commits kept local,
                                                 no origin check, no push
  create-grist-widget upgrade [--force] [--json] Bring the template's files up to this CLI's
                                                 (run it on dev, in a widget: pnpm exec create-grist-widget upgrade);
                                                 --force overwrites a src/main.tsx or file of the widget's own;
                                                 --json prints its report as one JSON line
  create-grist-widget demo [--port <n>]          Open the widget in a real Grist on this machine
                                                 (needs Docker; in a widget: pnpm demo)
  create-grist-widget demo --save                Write public/demo/: the widget's demo page and
                                                 document, a real Grist from static files (Docker)
  create-grist-widget release <patch|minor|major> [--branch <name>] [--no-pr]
                                                 At origin/dev: bump the version, write CHANGELOG.md from
                                                 what dev has that main doesn't, commit on release/v<version>
                                                 and open its pull request into dev (with gh); merging it,
                                                 then dev into main, releases (in a widget: pnpm release minor)
  create-grist-widget protect [--dry-run]        After the first release: the repository's rulesets
                                                 (main, dev, tags), private vulnerability reporting
                                                 and GitHub Pages, with your gh CLI
  create-grist-widget check [<widget dir>...] [--axe] [--themes] [--strict-console] [--standard]
                           [--baseline <dir>] [--build] [--out <dir>]
                                                 The widget's build (dist/) in a real Grist (Docker):
                                                 it renders, with no uncaught error; --axe, --themes,
                                                 --strict-console and --standard add the catalog's
                                                 criteria, --baseline <gh-pages checkout> compares it
                                                 with its last release, pixel by pixel. Needs
                                                 playwright and axe-core in the widget's devDependencies
  create-grist-widget verify-release <version url> [--channel <url>]... [--version <x.y.z>] [--wait <s>]
                                                 After a deploy: the version's folder and the files it
                                                 references answer, each channel (/latest/) serves the
                                                 same build, and its metadata names --version
  create-grist-widget release-check [--site <gh-pages checkout>] [--head <sha>] [--base-ref <ref>]
                           [--repo <name>] [--owner-repo <owner/repo>]
                                                 On a pull request into main (ci.yml runs it): a build
                                                 that differs from the published v<version>/ needs a
                                                 new version, and the version's commit comes last
  create-grist-widget manifest --base <path> [--dist <dir>] [--owner-repo <owner/repo>]
                                                 Write <dist>/grist-widget.json (default dist/), the
                                                 widget's Grist manifest (run by the deploy workflow
                                                 after vite build; --owner-repo defaults to
                                                 $GITHUB_REPOSITORY)

Options (create / init):
  --yes            Skip interactive prompts, use defaults/flags only
  --no-install     Don't run the package manager install automatically
  --pm <name>      Install with this package manager instead of pnpm (the
                    widget's workflows use pnpm and only read its lockfile)
  --name <name>    (init only) Widget name — default: the current directory's name
  --force          (init only) Overwrite files that already exist and differ
                    from the template

  --help, -h       Show this help
  --version, -v    Show this CLI's version

Every widget starts from the template. For patterns (drag and drop, writes,
attachments, maps…), read a catalog widget's spec, code and tests:
https://gristwidgets.com/widgets/

Note: "create", "init", "upgrade", "demo", "release", "protect", "manifest",
"list" and "use" are themselves valid widget names: use
"create-grist-widget create <name>" for one of those.

demo and demo --save open the widget on sample rows from its declared columns. Export demo from src/app/demo.ts (a GristWidgetDemo from grist-widget-sdk) and they open your data instead: its tables with typed columns (references, lists of references and attachments included), the rows, the choices and their colours, which column each declared one maps to, and the widget's options. An attachments cell names files of src/app/demo/, which pnpm demo's document gets as attachments (the demo page's doesn't: grist-static has none).

init — scaffolding into an already-initialized directory

create refuses a non-empty target directory. init is the fix for the case that comes up constantly with cloud coding agents, which typically start from an already-cloned or already-git init'd repo rather than an empty one:

mkdir my-widget && cd my-widget
git init   # or: this is already a repo clone
npx create-grist-widget init

Files that already exist and are identical to the template are left untouched; the five identity-bearing files (package.json, README.md, CHANGELOG.md, index.html, src/app/App.tsx) get the usual name/title substitution even if present, and the README loses the template's own maintainer notes. Anything else that already exists and differs from the template's own copy stops the run and lists the conflicting paths — pass --force to overwrite anyway. If .git already exists, init never auto-commits; review and commit the result yourself. If it doesn't, init sets up main + dev and an initial commit exactly like create does.

upgrade — picking up template changes

git switch dev
pnpm exec create-grist-widget upgrade

Run inside a widget, on dev with nothing uncommitted, after updating its create-grist-widget dependency. It rewrites the template's files (src/main.tsx, the workflows, the build configuration) to this version's copies, deletes the ones earlier templates wrote that are gone now, and merges the template's scripts and dependency versions into package.json. Nothing of the widget's own is touched. It refuses to run on main, with uncommitted changes, or on a widget still in src/App.tsx, and to overwrite a src/main.tsx the widget changed (--force overrides). --json prints its report as one line of JSON for tools, which is what update reads: the files written and deleted, the package.json changes, the tsconfigs it couldn't read (tsconfigsUnreadable), the SDK names left to change by hand (sdkNamesLeft), and the printout (text). Upgrading a widget has the details.

demo — the widget in a real Grist on your machine

pnpm demo                 # in a widget; same as pnpm exec create-grist-widget demo
pnpm demo --port 9090  # Grist on another port than 8484

Needs Docker, for this command only. It starts the widget's Vite dev server and a Grist from a pinned Docker image, without authentication, then creates a document: the widget's demo data (src/app/demo.ts, below) when it has some, otherwise a table with a typed column per declared column and sample rows; and the widget's section with the access it requests, every column mapped and linked to the table. It prints the URL that opens that page, signed in as the local default user. Edits reload in place; Ctrl-C stops Grist and the dev server, and the next run starts from a fresh document. The widget gets the plugin API from that Grist rather than docs.getgrist.com, so the demo works offline.

It is real Grist, not the emulator, so it shows what pnpm test can't: the real handshake, column mapping and theme. It doesn't replace the dev branch's /dev/ preview in your own documents, with your data.

demo --save — a demo page anyone can open

pnpm demo --save          # writes public/demo/demo.grist and public/demo/index.html

Generates the same document as pnpm demo in the same Docker Grist, and writes it with a page that opens it in Grist running in the browser, from static files (grist-static, the pinned version gristwidgets.com serves). No server, no account, nothing saved: a link you can put in a README or the registry.

Commit both files. Vite copies public/ into every build, so each deployed channel serves its own demo next to the widget: …/latest/demo/, …/v1.2.0/demo/, …/dev/demo/. The document holds a placeholder widget URL that the page points at the build beside it (../) before Grist opens it, so one document serves every channel and host. Its widget section's title is a placeholder too, which the page replaces with the widget's title (the one in public/demo/index.html).

To change the demo data, open public/demo/demo.grist in any Grist (import it as a document), edit it, and download it back over the file; leave the widget section's URL and title as they are. Attachments and imports aren't available in grist-static.

manifest — the widget's Grist manifest

The deploy workflow's build job runs it after vite build:

pnpm exec create-grist-widget manifest --base "/<repo>/v<version>/"   # --owner-repo defaults to $GITHUB_REPOSITORY

It writes dist/grist-widget.json, served next to index.html on every channel (/v<version>/, /latest/, /dev/). The file is a Grist custom widget entry, the format of the widget lists a self-hosted Grist reads through GRIST_WIDGET_LIST_URL:

{
  "name": "World map",
  "widgetId": "@arthurblanchon/world-map",
  "url": "https://arthurblanchon.github.io/world-map/v0.2.0/",
  "published": true,
  "accessLevel": "read table",
  "columns": [{ "name": "CountryISO", "type": "Text" }, { "name": "Count", "type": "Numeric" }],
  "renderAfterReady": false,
  "description": "Choropleth of country counts from a table.",
  "authors": [{ "name": "ArthurBlanchon", "url": "https://github.com/ArthurBlanchon" }],
  "lastUpdatedAt": "2026-11-07T12:00:00.000Z",
  "gristWidgetSdk": {
    "schema": 1, "channel": "release", "version": "0.2.0", "license": "MIT",
    "repository": "https://github.com/ArthurBlanchon/world-map",
    "sdk": "0.3.27", "createGristWidget": "0.3.32"
  }
}

name, description, accessLevel and columns come from the widget's declaration, so the manifest always says what the widget declares. A /dev/ build is marked "published": false: listed, but not offered in Grist's widget picker. gristWidgetSdk holds what Grist doesn't read: the widget's version and license, and the SDK and CLI versions it was built with. The widget registry reads it from a widget's install URL.

create, init, upgrade, demo, release, protect, manifest, list and use are themselves valid widget names, but create-grist-widget <one of them> runs that command (list and use are retired, and say so). Use the explicit form (create-grist-widget create list) for a widget with one of these names.

The bundled deploy pipeline

Every scaffolded repo ships its own .github/workflows/deploy.yml, two channels from one workflow. It refuses a repository named <owner>.github.io: that one is the account's own Pages site, served at the domain's root, and the widget's root page would replace its home page. Give the widget a repository of its own.

  • Push to main → the release channel: an immutable /<repo>/v<version>/ plus a mutable /<repo>/latest/ (and the same build at the repo's Pages root). Re-pushing main without bumping package.json's version is a no-op — it only rebuilds when a new v<version> doesn't exist yet: pnpm release <patch|minor|major> at origin/dev makes the bump and the changelog entry, as a pull request into dev (Releasing a widget).
  • Push to dev → the dev channel: a mutable /<repo>/dev/, for live review inside Grist as you iterate.

Every channel also serves grist-widget.json, the widget's Grist manifest (see manifest), which the build job writes after vite build.

The deploy logic is the grist-widget-deploy command of create-grist-widget, a devDependency of every scaffold: fixes to it arrive as dependency updates, with no file to copy.

It builds in a job with a read-only token, and publishes in a separate job that installs with --ignore-scripts and runs only grist-widget-deploy, at the version the lockfile pins. So dependency code (Vite, its plugins, anything they pull in) never runs next to the token that can push to your repo and its gh-pages branch.

A "Use this template" copy is named after its repository by its first release, which commits the rename to main: package.json's name, the README and CHANGELOG headings and the page titles. That release still carries the template's name; the next one carries yours.

If you scaffolded via "Use this template" with Include all branches checked, GitHub Pages is already pointed at the copied gh-pages branch — nothing else to configure. Scaffolding a fresh, non-template repo yourself needs two one-time steps instead:

  1. Settings → Pages → Source: Deploy from a branch → gh-pages → / (the workflow creates the gh-pages branch itself, but Pages has to be pointed at it once — left on main, you'd see a blank page with a 404 for /src/main.tsx even though the workflow reports success).
  2. Settings → Actions → General → Workflow permissions → Read and write permissions.

After the first release, whichever way you scaffolded, protect the repository with one command. Not before: the first release itself commits to main and moves dev to it, which the rules would block.

pnpm exec create-grist-widget protect --dry-run   # what it would change
pnpm exec create-grist-widget protect

It uses your GitHub CLI (gh auth login first) and only adds what is missing:

  • The rulesets in .github/rulesets/, which "Use this template" doesn't copy:

    • main: a pull request and the check and release statuses from ci.yml, no force push, no deletion. A change then reaches main only through a green pull request.
    • dev: no force push, no deletion. The version bump before a release is pushed straight to dev, so no pull-request rule there.
    • tags: no tag moved or deleted.

    A ruleset that already exists under the same name is left as it is. Each file can also be imported by hand: Settings → Rules → Rulesets → New ruleset → Import a ruleset.

  • Private vulnerability reporting, turned on.

  • GitHub Pages from gh-pages: turned on if it is off (a copy with all branches has it already); if Pages serves another branch, it says so and leaves it.

The deploy workflow can't apply these itself: creating a ruleset takes the repository's Administration permission, which a workflow's token never has. It checks them instead. The first release opens an issue, "Protect this repository", with the command, and every release warns in its summary while the main, dev or tags ruleset is missing.

An AI agent working on the repo acts through your account, so the rules can't tell it from you: they guarantee nothing red reaches main, whoever merges.

Pull request checks and dependency updates

Two more files keep the repo current without any setup:

  • .github/workflows/ci.yml runs pnpm lint, pnpm test and pnpm build on every pull request. deploy.yml only builds, and only after a push.
  • .github/dependabot.yml opens weekly update pull requests, against dev, for your npm dependencies and the workflows' GitHub Actions.
  • .github/workflows/sdk-update.yml opens an issue when a new grist-widget-sdk is out, at least 7 days old, tried on dev's code. pnpm exec create-grist-widget update then opens its pull request.

Upgrading a widget covers the update loop, and how to pick up template changes in a widget scaffolded earlier.

Hand-rolled (no template)

If you want the bare minimum instead of the CLI:

mkdir my-widget && cd my-widget
pnpm init
pnpm add react react-dom grist-widget-sdk
pnpm add -D typescript @types/react @types/react-dom vite @vitejs/plugin-react

Then create index.html (with the plugin-api script tag), src/main.tsx (React root), and src/App.tsx (your widget) — see the SDK page for the smallest possible code, or a catalog widget for a working one. The template path saves about ten minutes of boilerplate and one or two configuration gotchas, but the SDK works fine without it.

On this page