[API reference](https://jsprismarine.dev/api/index.md) / [@jsprismarine/addon-tools](https://jsprismarine.dev/api/@jsprismarine/addon-tools/index.md) / build

# build

## Interfaces

### BuildAddonsOptions

Defined in: [build.ts:66](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/addon-tools/src/build.ts#L66)

Options for [buildAddons](#buildaddons).

#### Properties

##### addonsDirectory

> `readonly` **addonsDirectory**: `string`

Defined in: [build.ts:68](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/addon-tools/src/build.ts#L68)

The folder that holds one folder per addon.

##### baseUrl

> `readonly` **baseUrl**: `string`

Defined in: [build.ts:72](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/addon-tools/src/build.ts#L72)

Where the release serves its files from, an `https:` URL.

##### outDirectory

> `readonly` **outDirectory**: `string`

Defined in: [build.ts:70](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/addon-tools/src/build.ts#L70)

Where the packs and `index.json` are written.

##### published?

> `readonly` `optional` **published?**: [`AddonIndex`](https://jsprismarine.dev/api/@jsprismarine/addon-tools/addonIndex/index.md#addonindex)

Defined in: [build.ts:74](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/addon-tools/src/build.ts#L74)

The index already published, merged with the build's entries; none before a first release.

***

### BuildAddonsResult

Defined in: [build.ts:78](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/addon-tools/src/build.ts#L78)

What [buildAddons](#buildaddons) wrote.

#### Properties

##### added

> `readonly` **added**: readonly [`AddonIndexEntry`](https://jsprismarine.dev/api/@jsprismarine/addon-tools/addonIndex/index.md#addonindexentry)[]

Defined in: [build.ts:84](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/addon-tools/src/build.ts#L84)

The built entries the published index lacks: the packs a release has to upload.

##### addedListingFiles

> `readonly` **addedListingFiles**: readonly `string`[]

Defined in: [build.ts:86](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/addon-tools/src/build.ts#L86)

The listing files of the added entries, in index order: what a release uploads beside their packs.

##### built

> `readonly` **built**: readonly [`AddonIndexEntry`](https://jsprismarine.dev/api/@jsprismarine/addon-tools/addonIndex/index.md#addonindexentry)[]

Defined in: [build.ts:82](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/addon-tools/src/build.ts#L82)

One entry for each addon built, in name order.

##### index

> `readonly` **index**: [`AddonIndex`](https://jsprismarine.dev/api/@jsprismarine/addon-tools/addonIndex/index.md#addonindex)

Defined in: [build.ts:80](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/addon-tools/src/build.ts#L80)

The index written to `index.json`: the published one plus every addon built.

##### warnings

> `readonly` **warnings**: readonly `string`[]

Defined in: [build.ts:88](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/addon-tools/src/build.ts#L88)

Each addon whose commands could not be read, and why. Its listing goes without them.

## Functions

### buildAddons()

> **buildAddons**(`options`): `Promise`\<[`BuildAddonsResult`](#buildaddonsresult)\>

Defined in: [build.ts:135](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/addon-tools/src/build.ts#L135)

Builds every addon in a folder: compiles the TypeScript ones with [compileAddons](#compileaddons), reads
them with [readAddons](#readaddons), merges their entries into the published index, then writes each
pack into the output folder as `<name>-<version>.mcpack`, its listing files beside it, and
`index.json`. Each listing records the commands the addon's scripts register, read with
`readAddonCommands`; an addon whose commands cannot be read is built without them, and the
result's warnings say why. A build it refuses writes nothing to the output folder, so it keeps
the last good build.

#### Parameters

##### options

[`BuildAddonsOptions`](#buildaddonsoptions)

#### Returns

`Promise`\<[`BuildAddonsResult`](#buildaddonsresult)\>

#### Throws

When an addon is invalid or does not compile, or a built version is
published with other contents.

#### Throws

`InvalidBaseUrl` when the base URL is not an `https:` URL.

***

### compileAddons()

> **compileAddons**(`addonsDirectory`): `Promise`\<`void`\>

Defined in: [build.ts:110](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/addon-tools/src/build.ts#L110)

Compiles every TypeScript addon in a folder with `compileAddon`, in name order, so that
[readAddons](#readaddons) reads scripts built from the current sources.

#### Parameters

##### addonsDirectory

`string`

#### Returns

`Promise`\<`void`\>

#### Throws

`AddonCompileFailed` when an addon's scripts do not compile.

***

### fetchPublishedIndex()

> **fetchPublishedIndex**(`baseUrl`, `fetcher?`): `Promise`\<[`AddonIndex`](https://jsprismarine.dev/api/@jsprismarine/addon-tools/addonIndex/index.md#addonindex) \| `undefined`\>

Defined in: [build.ts:58](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/addon-tools/src/build.ts#L58)

Downloads the index a release publishes. When the release has no `index.json` but has the
[ADDON\_INDEX\_BACKUP\_FILE](https://jsprismarine.dev/api/@jsprismarine/addon-tools/addonIndex/index.md#addon_index_backup_file) a failed upload left, it reads that instead, so a build after
the failure keeps every published version.

#### Parameters

##### baseUrl

`string`

Where the release's files download from, as [releaseDownloadUrl](#releasedownloadurl) gives.

##### fetcher?

(`input`, `init?`) => `Promise`\<`Response`\>

What downloads it; the global `fetch` unless a caller routes requests itself.

#### Returns

`Promise`\<[`AddonIndex`](https://jsprismarine.dev/api/@jsprismarine/addon-tools/addonIndex/index.md#addonindex) \| `undefined`\>

The index, or undefined when the release has neither file yet.

#### Throws

When the index does not follow the schema.

***

### readAddons()

> **readAddons**(`addonsDirectory`): `Promise`\<[`Addon`](https://jsprismarine.dev/api/@jsprismarine/addon-tools/addon/index.md#addon)[]\>

Defined in: [build.ts:98](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/addon-tools/src/build.ts#L98)

Reads and checks every addon in a folder with `readAddon`, in name order. Every folder directly
under `addonsDirectory` is an addon, except those whose names start with a dot; files there,
such as a README, are skipped.

#### Parameters

##### addonsDirectory

`string`

#### Returns

`Promise`\<[`Addon`](https://jsprismarine.dev/api/@jsprismarine/addon-tools/addon/index.md#addon)[]\>

#### Throws

When an addon is invalid.

***

### releaseDownloadUrl()

> **releaseDownloadUrl**(`repository`): `string`

Defined in: [build.ts:25](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/addon-tools/src/build.ts#L25)

Where a GitHub repository's addon release serves its files from.

#### Parameters

##### repository

`string`

`<owner>/<repo>`.

#### Returns

`string`
