axle generate
axle generateaxle generate package ui-kitaxle generate app web --with reactaxle generate ci --set provider=githubaxle generate move ui-kit --folder libs/ui-kitaxle generate remove old-adminaxle generate component Button --set package=webaxle generate creates new files from a generator: the built-in package, app, ci, move and remove generators, the repository’s own, listed in axle.toml, or one a plugin ships. Writing generators shows how to make your own.
For editors and scripts
Section titled “For editors and scripts”--json prints JSON and asks nothing. Without a generator, it lists each one with its variables, each with its prompt, default, choices and pattern, whether it takes a folder (required, optional or none), and for app and package the starters that --with takes. With a generator, it prints what was written, or with --dry-run what would be: each file’s diff under changes, the command or template that starts an app, or where move moves a package. The editor extensions build their generator form from it.
Listing generators
Section titled “Listing generators”axle generate with no generator lists them all, with where each comes from:
package A new package in the workspace, ready to build (built in)app A new app, from a framework's own tool, a copy, or empty (built in)ci A CI workflow that runs what each change affects (built in)move Move a package to another folder, and update the paths that point into it (built in)remove Remove a package that nothing depends on (built in)component A React component with a test (this repository)kit:service A service the kit plugin runs (plugin kit)
Run axle generate <generator> to use one.A plugin’s generators are named after the plugin, as <plugin>:<generator>.
Giving values
Section titled “Giving values”A generator asks for values, such as a component’s name. Give them on the command line:
| Option | What it does |
|---|---|
<NAME> |
the value of the generator’s name variable, so axle generate component Button sets name |
--set <variable>=<value> |
the value of any variable; repeat it for each one |
--folder <folder> |
writes the files into this folder, relative to the repository root, instead of the generator’s own |
--dry-run |
shows the files as a diff, and writes nothing |
In a terminal, Axle asks for each value you didn’t give, offering the generator’s choices as a numbered list and its default in parentheses. Anywhere else, such as in CI or from a script, a value with no default is the error generator-variable-missing. A value that doesn’t match the generator’s pattern or choices is refused before anything is written, and so is a value for a variable the generator doesn’t have.
What it writes
Section titled “What it writes”A generator that creates files never changes one that’s already there; only move and remove edit existing files. When any file it would write exists, it stops with generated-file-exists and writes nothing, so a generator can be run again with other values but never overwrites your work. Every file stays inside the repository, and nothing is written into .git.
It writes all of its files or none, and prints each one:
Created packages/web/src/components/button/button.test.tsxCreated packages/web/src/components/button/button.tsxNew packages
Section titled “New packages”axle generate package @acme/ui-kitaxle generate package admin --folder apps/adminThe package generator creates a package in packages/ when your workspace lists packages/*, and otherwise in the first folder it lists, named after the last part of the package’s name: @acme/ui-kit goes in packages/ui-kit. In a terminal it asks where it should go, with that folder as the answer to accept; elsewhere, give --folder to put it somewhere else. A repository whose workspace lists no such folder needs it. The folder has to be one the workspace lists, such as packages/admin for packages/*, since your package manager wouldn’t see a package anywhere else; add a new folder to the workspace first.
| File | What’s in it |
|---|---|
package.json |
the name, version 0.0.0, private, "type": "module", its exports and a build script |
src/index.ts |
an export to start from, or src/index.js when the repository doesn’t use TypeScript |
tsconfig.json |
with TypeScript only: compiles src into dist with declarations, and build runs tsc |
oxlint.config.mts |
with an oxlint-config package: extends it |
eslint.config.mjs |
with an eslint-config package: exports it |
prettier.config.mjs |
with a prettier-config package: exports it |
oxfmt.config.mts |
with an oxfmt-config package: extends it |
biome.json |
with a biome-config package: extends it |
For a library that’s built with tsdown and tested with Vitest, as in the library template, give --with library: the package is copied from that template and linked to the config packages as an app is. --copy copies any package, as it does for apps. In a terminal, without either, it asks which of the two it should be.
The package uses TypeScript when the workspace depends on typescript, and then on the same version. Without it, build checks the source with node --check, ready to be replaced by your real build.
It follows the config packages the workspace has, found by their names, such as @repo/eslint-config. The new package depends on each one, tsconfig.json extends typescript-config’s base.json, and it gets the lint and format scripts that run them, with the versions of oxlint, eslint, prettier, oxfmt or @biomejs/biome the workspace already uses. Add rules to its own files to override the shared ones. The name must be a valid npm package name that isn’t in the workspace yet.
Then install, so the package manager links the new package into the workspace:
pnpm installnpm installyarn installbun installnub installaube installNew apps
Section titled “New apps”axle generate app web --with reactaxle generate app admin --copy webaxle generate app docs --copy https://github.com/owner/repository/tree/main/apps/docsThe app generator creates an app in apps/ when your workspace lists apps/*, and otherwise in the first folder it lists, named after the last part of its name. Like package, it asks where it should go in a terminal, and takes --folder anywhere. It starts the app one of three ways:
| Option | What it does |
|---|---|
--with FRAMEWORK |
runs the framework’s own tool, with its default answers, so the app is exactly what that tool makes |
--copy SOURCE |
copies a workspace package, given by its name or folder, or a folder on GitHub, leaving out node_modules, build output and Git’s files |
| neither | in a terminal, asks for the framework; anywhere else, writes a package.json and a source file, as package does |
| Framework | Its tool |
|---|---|
next |
create-next-app |
react |
create-vite with its react-ts template |
react-router |
create-react-router |
vue |
create-vue, with TypeScript, Vue Router, Pinia and Vitest |
nuxt |
create-nuxt, with its minimal template |
sveltekit |
sv create, with its minimal template in TypeScript |
astro |
create-astro, with its minimal template |
angular |
the Angular CLI’s ng new |
express |
the Express API of the express template |
nestjs |
the Nest CLI’s nest new |
expo |
create-expo-app |
The names are the same as the templates’, so --template sveltekit and --with sveltekit start the same app. The tool runs in the folder the app goes in, such as apps, through your package manager, such as pnpm dlx create-vite@latest, so it’s always the latest version. express is copied from the templates of the Axle version you run, since Express has no tool of its own that writes a current app. --dry-run shows the command or the copy, and writes nothing.
Then the app is linked to the workspace’s config packages:
- Its name is set, and the lockfiles, workspace files and
.gitfolder the tool may have made inside it are removed. - Every
tsconfig.jsonwithcompilerOptionsextendstypescript-config’sbase.json, ahead of what it already extends. - It depends on the config packages and gets their files,
lintandformatscripts and tools, as a new package does. - When it uses Next.js, Nuxt, SvelteKit, Angular, Expo, Astro or React Router, its config files extend that framework’s export of the config package, such as
@repo/eslint-config/svelte-kit, which Axle adds the first time an app needs it. The export ignores the framework’s build output, and holds the rules its starter needs, such as allowingrequire()for Expo’s images. - The
.gitignorethe tool wrote is merged into the repository’s own and removed, so there’s one.gitignore, at the root. Its paths are rewritten to point into the app, and a Prettierformatscript reads it with--ignore-path. - A config file the framework wrote itself, such as
create-next-app’seslint.config.mjs, is kept, since it holds the framework’s rules. Axle says which, so you can extend the shared package there.
Then install, so the package manager links the new app into the workspace.
Moving a package
Section titled “Moving a package”axle generate move @acme/ui --folder libs/uiThe move generator moves a package’s folder, and rewrites every path that pointed into it or, from inside it, out of it, so the repository keeps building:
- the paths in each
tsconfig*.jsonandjsconfig*.json, such asreferences,pathsandextends, at the root and in every package; file:andlink:dependencies and other paths in eachpackage.json;- the paths in the root’s and each package’s
axle.toml; - relative imports, in the package’s own source files and in other packages’ that reach into it.
Imports by the package’s name don’t change, since its name stays the same. The new folder must be one the workspace lists, such as libs/ui with libs/* among its folders, and empty or not there yet. In a terminal, it asks for the package and the folder; anywhere else, give both. --dry-run shows every edit as a diff and moves nothing. Then install, so the lockfile follows the move.
Removing a package
Section titled “Removing a package”axle generate remove old-adminThe remove generator deletes a package’s folder, and takes it out of the references and paths of the tsconfig*.json files that point into it. It refuses while another package depends on it, and names them, so nothing is left importing a package that’s gone. When axle.toml still mentions the package, it says so, for you to take it out there. --dry-run shows the edits and removes nothing. Then install, so the lockfile forgets it.
CI workflows
Section titled “CI workflows”axle generate ci --set provider=githubaxle generate ci --set provider=gitlab --set tasks="build test"axle generate ci --set provider=github --set jobs=4The ci generator writes a workflow that runs the tasks a change affects, on every pull request and every push to main, or on GitLab to the default branch:
provider |
File |
|---|---|
github |
.github/workflows/axle.yml |
gitlab |
.gitlab-ci.yml |
bitbucket |
bitbucket-pipelines.yml |
tasks is the tasks to run, separated by spaces. Left out, it’s whichever of build, test and lint the repository’s packages have, or build when they have none.
jobs is how many parallel jobs share the tasks, 1 by default. With more, each job runs its shard through AXLE_SHARD: a matrix on GitHub, parallel on GitLab and parallel steps on Bitbucket, each job keeping its own cache.
The workflow:
- fetches the whole history, so
--affectedcan compare with the branch a pull request goes into, or with the commit before a push. When there is no such commit, as on the first push of a branch, after a force push or in a scheduled pipeline, it runs every task instead, from the cache where it can. Bitbucket doesn’t say which commit came before a push, so a push tomainalways runs every task; - sets up Node.js and the repository’s package manager, and installs with its lockfile, such as
pnpm install --frozen-lockfile,npm cioraube ci; - keeps Axle’s local cache between runs with the service’s own cache, in
.axle/cachethroughAXLE_CACHE_DIR; - runs Axle from the repository when the root
package.jsonlists@axle-rs/axle, and otherwise installs it first; - with a remote cache in
axle.toml, gives Axle its token and keys, theAWS_*keys of a bucket or theAZURE_STORAGE_KEYof a container, from the service’s secrets. Axle says which secrets to add.
It’s a starting point to commit and change: the branch is main on GitHub and Bitbucket, and the Node.js version is the latest LTS.