# suiteAppBuild

This step builds a frontend suite app by running `yarn build` in a nodejs prepared container.
By default it runs the [yarnRun](./yarnRun.md) step under the hood providing suite app defaults.
Alternatively, if `detectPackageManager` is enabled, it uses the package manager specified in `package.json` using the [packageManagerRun](./packageManagerRun.md) step. This allows you to use `pnpm` or `npm`.

## Parameters

| Name                 | Description                                          | Type           | Default | Required                          |
| -------------------- | ---------------------------------------------------- | -------------- | ------- | --------------------------------- |
| env                  | The environment [dev, qa, prod]                      | `String`       | n/a     | yes                               |
| envVars              | Map of environment variables                         | `Map`          | null    | no                                |
| scriptNames          | The scripts to run                                   | `List<String>` | null    | no                                |
| nodeVersion          | The node version to use.                             | `String`       | null    | yes, if no .nvmrc file in project |
| detectPackageManager | Auto-detect package manager from package.json        | `Boolean`      | false   | no                                |

## Usage

### Providing environment variables

Building a suite app depends on several environment variables. To provide them to the docker container, use the `envVars` parameter.
Note that environment that applies to all suite apps are already included. Refer to the [source code](./suiteAppBuild.groovy) for a full list of built in values.

```groovy
suiteAppBuild(
    env: 'qa',
    envVars: [
        AUTH0_CLIENT_ID: '1234',
        POEDITOR_PROJECT_ID: '1234'
    ]
)
```

### With specified node version

The step automatically picks up the node version from your .nvmrc file.
If you do not have a .nvmrc file or you want to override it, you can specify the version using the "nodeVersion" param.

```groovy
suiteAppBuild(
    env: 'qa',
    nodeVersion: '20.11.0',
    envVars: [
        AUTH0_CLIENT_ID: '1234',
        POEDITOR_PROJECT_ID: '1234'
    ]
)
```

### Overriding the yarn run script

By default, this step runs `yarn build`. If you want to override it, use the `scriptNames` parameter.

```groovy
suiteAppBuild(
    env: 'qa',
    scriptNames: ['i18n:sync', 'build'],
    envVars: [
        AUTH0_CLIENT_ID: '1234',
        POEDITOR_PROJECT_ID: '1234'
    ]
)
```

### Auto-detecting the package manager

By default, this step uses `yarn`. If your project uses `npm` or `pnpm`, you can enable auto-detection by setting `detectPackageManager: true`.
The step will read the `packageManager` field from your `package.json` and use the appropriate package manager.

```groovy
suiteAppBuild(
    env: 'qa',
    detectPackageManager: true,
    envVars: [
        AUTH0_CLIENT_ID: '1234',
        POEDITOR_PROJECT_ID: '1234'
    ]
)
```

To set the `packageManager` field in your `package.json`:

```json
{
  "name": "my-app",
  "packageManager": "npm@10.0.0"
}
```

If the `packageManager` field is missing or contains an unsupported package manager, the step will default to `yarn` for backward compatibility.
See [packageManagerRun](./packageManagerRun.md) for more details on package manager auto-detection.
