# Azion CLI link

The Azion CLI `link` command sets up the project in the current directory so that the CLI can build, run, and deploy it as an [Application](/en/documentation/platform/applications/). It writes the `azion/azion.json` file and an [azion.config](/en/documentation/devtools/cli/azion-config-js/) file for the preset you choose, and it can add entries to `.gitignore` and a GitHub Actions workflow. The command creates no resource on Azion: every ID in `azion/azion.json` stays `0` until the first deploy. The options every command accepts, such as `--format`, `--out`, and `-y`, are on [Global options](/en/documentation/devtools/cli/globals/).

---

## Usage

Run `azion link` from the root folder of the project:

```bash
azion link [flags]
```

| Flag                     | Short | Type   | Default   | Description                                                                                                                                                                                                                |
| ------------------------ | ----- | ------ | --------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `--auto`                 | —     | —      | —         | Runs the whole command without stopping for a question. It adds the `.gitignore` entries and the GitHub Actions workflow, and it does not build or deploy the project.                                                     |
| `--config-dir`           | —     | string | `"azion"` | Relative path to the folder that holds your `azion.json` and `args.json` files.                                                                                                                                            |
| `--local`                | —     | —      | —         | Runs the build and the deploy on your machine when you deploy the project from this command.                                                                                                                               |
| `--name`                 | —     | string | —         | Name of the application. Without it, the command suggests a random name and asks you to accept it or type another.                                                                                                         |
| `--package-manager`      | —     | string | —         | Package manager to use, such as `npm`, `yarn`, or `pnpm`.                                                                                                                                                                  |
| `--preset`               | —     | string | —         | Preset the project builds with, such as `html` or `next`. The names are the ones [Azion CLI presets](/en/documentation/devtools/cli/resources/presets/) lists. Without it, the command opens a picker with the same names. |
| `--remote`               | —     | string | —         | URL of a Git repository to clone and link to an application.                                                                                                                                                               |
| `--skip-framework-build` | —     | —      | —         | Skips the framework build that runs before `azion build`.                                                                                                                                                                  |
| `--sync`                 | —     | —      | —         | Synchronizes the local `azion.json` file with the remote resources when you deploy the project from this command.                                                                                                          |

For a static HTML site, use the `html` preset. A project linked with `html` serves the files in its `www` folder, so move your files into `www` before you build or deploy. Files at the root of the project are not uploaded.

To run the command from a script, pass `--name`, `--preset`, and `--auto`. The command then asks no question.

---

## Examples

Each example shows the command and the output it prints.

### Link a static site without questions

This command links a static HTML site named `my-site` and asks no question:

```bash
azion link --name my-site --preset html --auto
```

The command writes the project files and reminds you to build the project:

```text
Project successfully configured
Sucessfully written to your .gitignore file
Successfully created GitHub Actions workflow file at .github/workflows/azion-deploy.yml
…
Please, remember to run azion build --preset [preset-name], in order to generate the necessary configuration files
```

The command adds `.edge/`, `.vulcan`, and `.open-next` to `.gitignore`, writes `azion.config.cjs`, and writes `azion/azion.json` with no resource IDs:

```json
{
  "name": "my-site",
  "bucket": "",
  "preset": "html",
  "env": "production",
  "prefix": "",
  "rotate-prefix": true,
  "function": [],
  "application": {
    "id": 0,
    "name": "__DEFAULT__"
  },
  "domain": {
    "id": 0,
    "name": "__DEFAULT__",
    "domain_name": "",
    "url": ""
  },
  "rt-purge": {
    "purge_on_publish": true
  },
  "origin": null,
  "rules-engine": {
    "created": false,
    "rules": null
  },
  "cache-settings": null,
  "workloads": {
    "id": 0,
    "name": "",
    "domains": null,
    "url": "",
    "deployment_id": null
  },
  "connectors": null
}
```

The workflow in `.github/workflows/azion-deploy.yml` runs `azion build` and `azion deploy --local` when you start it by hand in GitHub. It reads a personal token from the `AZION_PERSONAL_TOKEN` secret of the repository.

### Link a project with questions

This command links the same kind of site and asks a question at each step:

```bash
azion link --name my-site
```

The command asks you to confirm the folder, then opens the preset picker. This example answers yes to `.gitignore`, no to the workflow, yes to the build, and no to the dependencies, the local development server, and the deploy:

```text
🤔 Do you want to link <project-dir> to Azion? (y/N) y

Getting presets available (Some dependencies may need to be installed)
…
? Choose a preset: html
Project successfully configured
🤔 Azion CLI creates some files during the build process for internal use. Would you like to add these to your .gitignore file? (Y/n) Y
Sucessfully written to your .gitignore file
🤔 Would you like to add a GitHub Actions workflow for automated deployment? (Y/n) n
…
🤔 Do you allow Azion to build your project in order to generate configuration files? (Y/n) Y
🤔 Do you want to install project dependencies? This may be required to start local development server (Y/n) n


Building your Application. This process may take a few minutes
Running build step command:

$ npx --yes  @aziontech/bundler@1.1.4 build --preset html
…
[Azion] [Build] › ℹ  info      Using preset: html
[Azion] [Pre-Build] › ℹ  info      Starting pre-build...
[Azion] [Pre-Build] › ℹ  info      Pre-build completed successfully
[Azion] [Build] › ℹ  info      Using built-in handler from "html" preset.
[Azion] [Build] › ℹ  info      Starting build...
[Azion] [Build] › ✔  success   Build completed successfully
[Azion] [Post-Build] › ℹ  info      Starting post-build...
[Azion] [Post-Build] › ✔  success   Post-build completed successfully
[Azion] [Storage] › ℹ  info      Using provided prefix for storage '$BUCKET_NAME': $BUCKET_PREFIX
[Azion] [IaC] › ✔  success   Manifest generated successfully at <project-dir>/.edge/manifest.json
Your Application was built successfully
🤔 Do you want to start a local development server? (y/N) n
If you want to start a local development server later, run 'azion dev'
🤔 Do you want to deploy your project? (y/N) n
If you want to deploy your application later, run 'azion deploy'
Your application my-site was linked successfully
```

Without `--name`, the command asks for the name after the folder question and suggests a random one:

```text
? (Hit enter to accept the suggested name in parenthesis) Your application's name:  (affectionate-rainbow)
```

---

## Related resources

- [Azion CLI init](/en/documentation/devtools/cli/init.md): The command that creates a project from a template instead of linking an existing folder.
- [Azion CLI dev](/en/documentation/devtools/cli/dev-command.md): How to run the linked project on your machine before you deploy it.
- [Azion CLI deploy](/en/documentation/devtools/cli/deploy.md): The command that creates the resources the `azion` folder points to and deploys the project.
- [Azion CLI unlink](/en/documentation/devtools/cli/unlink-command.md): The command that removes the `azion` folder of the project and can also delete its remote resources.
