# axle create

Create a new monorepo from a template, with Axle set up.

```sh
axle create [FOLDER] [--template NAME] [--package-manager NAME] [--linter NAME] [--formatter NAME] [--ci SERVICE] [--no-git] [--no-install] [--yes]
```

Creates a new monorepo from one of the [templates](https://axlers.dev/docs/getting-started/templates.md). Before Axle is installed, run it through your package manager:

```sh
pnpm create axle                                # pnpm
npm create axle@latest                          # npm
yarn create axle                                # Yarn
bun create axle                                 # Bun
nub dlx create-axle                             # nub
aube create axle                                # aube
```

In a terminal, running `axle` alone in a folder that isn't in a repository starts it too.

## The questions

It asks one question at a time, with the arrow keys to choose and Enter to answer:

1. **Where should the monorepo go?** A new or empty folder, whose name becomes the package name. The current folder is offered when it's empty.
2. **What are you building?** Empty, full-stack, frontend, backend, mobile or library. Empty is just the workspace and its [shared settings](https://axlers.dev/docs/getting-started/templates.md#shared-settings), for your own apps and packages.
3. **Which template?** The templates of that kind, when there's more than one.
4. **Which package manager?** pnpm, npm, Yarn, Bun, nub or aube. The one that ran the command is chosen to start with, and those not installed say so.
5. **Which linter?** Oxlint and ESLint, Oxlint, ESLint, Biome or none.
6. **Which formatter?** Prettier, Oxfmt or none. Not asked after Biome, which formats too.
7. **Which CI service?** GitHub Actions, GitLab CI, Bitbucket Pipelines or none. The workflow runs what each change [affects](https://axlers.dev/docs/reference/affected.md), as [`axle generate ci`](https://axlers.dev/docs/reference/generate.md#ci-workflows) writes it.
8. **Set up a Git repository?** It makes the first commit when Git knows your name and email.
9. **Install the dependencies?**

```text
✔ Where should the monorepo go? my-shop
✔ What are you building? Full-stack
✔ Which template? Next.js + Express
✔ Which package manager? pnpm
✔ Which linter? Oxlint and ESLint
✔ Which formatter? Prettier
✔ Which CI service? GitHub Actions
✔ Set up a Git repository? Yes
✔ Install the dependencies? Yes
✔ Created my-shop from the Next.js + Express template
✔ Added the next plugin
✔ Installed the dependencies
✔ Wrote .github/workflows/axle.yml
✔ Set up a Git repository and made the first commit

Next:
  cd my-shop
  pnpm dev
  pnpm build

Build again and Axle replays it from its cache.
```

Press Esc or Ctrl+C to stop before anything is written.

## Options

Each option answers a question, which is then not asked.

| Option                   | What it does                                                         |
| ------------------------ | -------------------------------------------------------------------- |
| `FOLDER`                 | the new or empty folder to create the monorepo in                    |
| `--template NAME`        | the template to start from, such as `next-express`                   |
| `--package-manager NAME` | `pnpm`, `npm`, `yarn`, `bun`, `nub` or `aube`; `--pm` for short      |
| `--linter NAME`          | `oxlint-eslint`, `oxlint`, `eslint`, `biome` or `none`               |
| `--formatter NAME`       | `prettier`, `oxfmt` or `none`; left out with `--linter biome`        |
| `--ci SERVICE`           | `github`, `gitlab`, `bitbucket` or `none`                            |
| `--no-git`               | doesn't set up a Git repository                                      |
| `--no-install`           | doesn't install the dependencies                                     |
| `--yes`, `-y`            | asks nothing, using the defaults for whatever the options don't give |

Outside an interactive terminal, such as in CI, nothing is asked either. The defaults are `my-monorepo`, the `empty` template, the package manager that ran the command (or pnpm when it's installed, and npm when it isn't), Oxlint and ESLint, Prettier, no CI workflow, a Git repository and installed dependencies:

```sh
axle create my-shop --template next-express --pm pnpm --linter biome --ci github --yes
```

## What it does

1. Downloads the templates from [`axle-rs/axle-templates`](https://github.com/axle-rs/axle-templates), at the tag of the running Axle's version.
2. Copies the template into the folder, naming the root package after it and adding `@axle-rs/axle` to its `devDependencies`. It writes an `axle.toml` with only the [`#:schema` line](https://axlers.dev/docs/reference/configuration.md#editor-support), as [`axle init`](https://axlers.dev/docs/reference/init.md) does, so your editor completes the settings you add later.
3. Sets the workspace up for the package manager: pnpm keeps `pnpm-workspace.yaml`, and the others get the `workspaces` field in `package.json`. `packageManager` records the version that's installed, and Yarn 2 and newer get a `.yarnrc.yml` that installs into `node_modules`.
4. Sets up the linter and formatter you chose: the template's `eslint-config` and `oxlint-config` packages stay when they're used, and a `prettier-config`, `oxfmt-config` or `biome-config` package is added. Every project gets the files that extend them, its `lint` and `format` scripts, and the dependencies. With npm and Yarn 1, which don't know `workspace:*`, the config packages are linked with `*`.
5. [Adds the official plugins](https://axlers.dev/docs/reference/plugins.md) for the template's tools to `axle.toml`, so their tasks are cached from the first run.
6. Installs the dependencies, writes the CI workflow and makes the first commit.

A plugin that can't be downloaded, or an install that fails, doesn't stop it: the monorepo is created all the same, and the next steps list what's left to do.

## Errors

- A folder that has files in it, or whose name can't be a package name: [the new monorepo's folder can't be used](https://axlers.dev/docs/messages/create-folder-not-empty.md).
- A `--template` that doesn't exist: [there's no template by that name](https://axlers.dev/docs/messages/unknown-template.md).
- No connection to GitHub: [the templates couldn't be downloaded](https://axlers.dev/docs/messages/templates-unreachable.md).
- An install that stops with an error: [the dependencies didn't install](https://axlers.dev/docs/messages/install-failed.md).
