Skip to content
Gx
GitHub

The gx command

Each command of gx, with its arguments.

Run a command with gx <command>. In a project with a cmd/gx, the installed gx builds that command and runs it. The command then has the Gx version of go.mod and the plugins of the project. go run ./cmd/gx <command> does the same with no installed command. A command that takes an app directory uses the current directory when you give none.

gx init

gx init [--template app|docs] [--adapter datastar|htmx] [--module <path>] [dir]

Writes a new app into dir. It asks for the adapter when you give no --adapter. It does not write into a directory that has a go.mod or a gx.toml.

Flag Meaning
--template app is an app with one example slice. docs is a docs site with the docs shell and the docs kit.
--adapter datastar is the default. htmx gives an app with no signals. Read Adapters.
--module The Go module path. The default is the directory name.
--registry The component registry for gx.toml.

gx new

gx new page|action|form|component|slice <name> [app]

Adds typed code. A page, an action and a form take <slice>/<Name>. A component takes <dir>/<Name>. A slice takes a package name.

The command writes each file or none, adds the new value to the route list of its slice, and generates the code.

gx dev

gx dev [--addr 127.0.0.1:3333] [--main <package>] [app]

Runs the app with build, restart, page morph and the error overlay.

gx check

gx check [--json] [--external-links] [--dead] [app]

Checks each .gx file, the routes, the actions, the forms and the content. It fails when a generated file is stale. It type-checks each island with the pinned TypeScript compiler. --json prints the diagnostics for a tool. --external-links also requests each link to a different site.

It also checks the content model of the markup:

  • an image with no alt
  • a form control with no label
  • an interactive element inside a link or a button
  • one id on two elements of a component
  • an element in a parent where a browser moves it

A hint or a warning does not fail the check.

With a [budget] table in gx.toml, it runs the app and fails for a page route that loads more JS or CSS than its budget.

--dead also prints a report of code that nothing uses: components with no caller, page routes with no typed link, and classes of app/theme.css that no file uses. The report does not change the exit code. With --json, the output is one object with diagnostics and dead.

gx generate

gx generate [app]

Writes the generated Go files. Commit them.

gx api

gx api [app]

Writes api/openapi.json and api/client.ts for the actions with .API(). Commit them. gx check fails when one of them is stale, and it type-checks the client.

gx fmt

gx fmt [--check] [file ...]

Formats .gx files in place. With no file, it formats standard input. --check fails on a file that is not formatted.

gx lint

gx lint [--json] [app]

Runs go vet and the Gx analyzers on each package.

gx build

gx build [-o <file>] [--main <package>] [app]

Generates the code, builds the stylesheet and builds the app. The default output is bin/<name of the main package>.

gx export

gx export [--out dist] [--site <url>] [--main <package>] [app]

Renders each GET page to a static file. It stops when the app has a feature that needs a server.

gx routes

gx routes [--json] [app]

Prints each route with its type, its page, its fields, its prefix, its layouts and its middleware.

gx describe

gx describe [--json] [--schema] [app]

Prints the app model. --schema prints the JSON Schema of the JSON output.

gx add

gx add [--registry <source>] [--dir <dir>] <item>[@version] [app]

Installs a registry item and the items that it needs. @name/item reads from a named registry.

gx add theme:<name> writes a theme of a plugin of the project as app/theme.css. When the app changed its theme, the command writes app/theme.<name>.css and leaves the theme of the app.

gx diff

gx diff [--registry <source>] <item> [app]

Shows what changed in your copy of an item and in the registry.

gx update

gx update [--registry <source>] <item>[@version] [app]

Merges the registry version of an item with your copy.

gx registry

gx registry build [--out <dir>] <source>
gx registry lint <source>

build writes a registry that you can publish. lint fails an item that lacks a required part.

gx icons

gx icons pin <set>@<version> [app]

Pins an icon set and writes one component for each icon.

gx pin

gx pin [--cdn <url>] <package>@<version> [app]

Stores the bundled ES module of an npm package in js/vendor, with each module that it imports. gx.lock records the hash of each file. An island then imports the package by its name. A changed file stops the build.

gx wc

gx wc pin [--as <name>] [--out <dir>] [--element <tag>] [--cdn <url>] <package>@<version> [app]

Reads the custom elements manifest of an npm package and writes a Go package with one typed tag for each element. It pins the module of each element as gx pin does. --element limits the import to one tag; give it again for more tags.

gx wc build [--server <origin>] [--base <path>] [--out <dir>] [app or package]

Writes the files of each widget for a host page into dist/widgets: the element file, a .d.ts file, a file with the JSX types for React, and one custom-elements.json. With a package directory it writes the widgets of that package only. --server is the origin of the Gx server and --base the base path of the app; each has the key of the same name in [widgets] of gx.toml as its default. With no server the element calls the origin of its host page.

gx wc check [--update] [app]

Compares the contract of the widgets with the baseline in .gx/base/widgets.json, and prints each change. A removed or retyped attribute, event, event detail field or CSS variable needs a major bump of the version in [widgets]. An addition needs a minor bump. The command fails when the version does not have the bump. With no baseline each version passes. --update records the contract of now as the baseline after the check passes.

gx wc pack [--server <origin>] [--base <path>] [--out <dir>] [app]

Writes the npm tarball of the widgets into dist/widgets: the files of gx wc build and a package.json. [widgets] of gx.toml gives the name and the version of the package.

gx wc publish [--server <origin>] [--base <path>] [--registry <url>] [--tag <name>] [app]

Runs the check of gx wc check, then publishes the package through the HTTP API of the npm registry. The environment variable NPM_TOKEN holds the token of the registry. The keys registry and access of [widgets] set the registry and public or restricted. After the registry takes the version, the command writes the baseline. No node runs.

gx vendor

gx vendor [app]

Stores the pinned downloads in .gx/vendor, for a build with no network: Tailwind, Pagefind, the TypeScript compiler and the icon packs.

gx import

gx import starlight --out <dir> <source>

Converts a Starlight project into Gx content.

gx agents

gx agents --update [app]

Writes the current text into the managed section of AGENTS.md.

gx lsp

gx lsp [--root <dir>]

Runs the language server on standard input and output.

gx mcp

gx mcp [--main <package>] [--registry <source>] [app]

Runs the dev MCP server on standard input and output.

gx fuzz

gx fuzz [--seed <n>] [--sets <n>] [--json] [--main <package>] [--app <dir>] [component]

Renders each component of the app with random props, and checks each render. The command needs Chrome or Chromium. It needs no node.

The command builds the app as gx dev does and makes prop sets from the prop types of each component. The first set is the empty value of each prop. The second set has a long string in each string prop. The third set has markup characters in each string prop. Each later set is random.

A prop set fails when one of these checks fails:

  • The render does not panic.
  • The HTML parser gives the same tree that the render wrote.
  • axe finds no accessibility violation in headless Chrome. The page has prefers-reduced-motion: reduce, so axe measures the colours at the end of each transition.

Two inputs are not inputs of a caller, and the command does not report them:

  • A component has a required prop of a type that the command cannot make, for example an interface or a function. The command does not render the component and prints skipped with the name of the prop.
  • A slot takes only some elements, for example the cells of a table row. Text in such a slot is not a defect of the component.

The audit is for the component and not for a page.

A prop set has no caller. Two markers tell the command that a part of the component comes from the caller. Put a marker line in the props block, above a prop or at the top of the block. Each marker has its own line. A component can have the two markers:

props {
  // gx:fuzz name-from-caller
  // gx:fuzz context-from-caller
  // Children is the label of the item.
  Children gx.Node
}

// gx:fuzz name-from-caller is for a component that gets its accessible name from the caller. Examples are a button with the label in Children and a heading with the text in Title. The command then does not run these axe rules on the component: button-name, link-name, label, input-button-name, select-name, aria-input-field-name, summary-name, aria-dialog-name, aria-progressbar-name, aria-command-name, aria-toggle-field-name, aria-tooltip-name, aria-meter-name, aria-tab-name, aria-treeitem-name, svg-img-alt and empty-heading.

// gx:fuzz context-from-caller is for a part that is valid only in the structure of its caller. Examples are a list item for a list, a group for a menu, and a tab list with the tabs in Children. The command then does not run these axe rules on the component: list, listitem, definition-list, dlitem, aria-required-children and aria-required-parent.

Each other rule runs. A marker with another value is an error. A marker is not a part of the description of a prop. gx describe --json shows the markers as nameFromCaller and contextFromCaller on the component. The registry components have the markers.

Each axe finding names its rule and the CSS selector of the element. A color-contrast finding also names the foreground colour, the background colour and their contrast ratio. With --json, the findings of a failure hold the same values.

For each prop set that fails, the command prints an entry for the fixtures file of the component. Add the entry to <Name>.fixtures.go to see the defect in the gallery.

The last line of the output shows the seed. Give the same seed with --seed to get the same prop sets again. --sets is the number of prop sets for each component; the default is 20. A component name selects one component: Card, or ui.Card when two packages have the name.

The exit code is 1 when a prop set fails. --json prints machine output.

gx help

gx help

Prints the list of commands.