# core/coordinators/chapter.coordinator.ts

> 26 lines of code and 7 definitions.

Tree: Bane's Lab Build Scripts
Language: typescript
Layer: application
Canonical: https://banes-lab.com/anatomy/build-scripts#file-build-scripts-core-coordinators-chapter-coordinator-ts
Source text: https://banes-lab.com/source/build-scripts/core/coordinators/chapter.coordinator.ts.txt

Listed in [core/coordinators](https://banes-lab.com/api/source/build-scripts/core/coordinators.md), after [core/coordinators/catalog.index.coordinator.ts](https://banes-lab.com/source/build-scripts/core/coordinators/catalog.index.coordinator.ts.md) and before [core/coordinators/config.coordinator.ts](https://banes-lab.com/source/build-scripts/core/coordinators/config.coordinator.ts.md).

## Definitions

- `renderShape` (lexical_declaration, line 17)
- `renderSurfaces` (lexical_declaration, line 25, exported)
- `surfacesKey` (lexical_declaration, line 11, exported)
- `SOURCE_EXTENSION` (lexical_declaration, line 9)
- `inputs` (lexical_declaration, line 12, exported)
- `code` (lexical_declaration, line 13, exported)
- `result` (lexical_declaration, line 18)

## Contained in

- [core/coordinators](https://banes-lab.com/anatomy/build-scripts/folder-build-scripts-core-coordinators.md)

## Uses

- [configuration/strings/chapter.strings.ts](https://banes-lab.com/source/build-scripts/configuration/strings/chapter.strings.ts.md)
- [core/converters/route.converter.ts](https://banes-lab.com/source/build-scripts/core/converters/route.converter.ts.md)

## Used by

- [core/steps/chapter.step.ts](https://banes-lab.com/source/build-scripts/core/steps/chapter.step.ts.md)

## Linked from

- [configuration/strings](https://banes-lab.com/anatomy/build-scripts/folder-build-scripts-configuration-strings.md)
- [core/converters](https://banes-lab.com/anatomy/build-scripts/folder-build-scripts-core-converters.md)
- [core/coordinators](https://banes-lab.com/anatomy/build-scripts/folder-build-scripts-core-coordinators.md)
- [core/steps](https://banes-lab.com/anatomy/build-scripts/folder-build-scripts-core-steps.md)

## Source

```typescript
import { attributionOf, surfaceInputFiles } from "@banes-lab/content/core/loaders/chapter.loader.ts";
import { chapterRefused, chaptersLine } from "#configuration/strings/chapter.strings";
import { collectFiles, fingerprint, fingerprintOf } from "@govlab/content-fingerprint";
import { CHAPTER_SHAPES } from "@banes-lab/content/configuration/constants/chapter.constants.ts";
import type { ChapterShape } from "@banes-lab/content/types/chapter.types.ts";
import { absolutePath } from "@ssot/paths";
import { renderSurface } from "@banes-lab/content/core/coordinators/chapter.coordinator.ts";

const SOURCE_EXTENSION = ".ts";

export const surfacesKey = function surfacesKey(): string {
    const inputs = [...new Set(CHAPTER_SHAPES.flatMap(surfaceInputFiles))];
    const code = collectFiles(absolutePath("app.content"), { include: (name) => name.endsWith(SOURCE_EXTENSION) });
    return fingerprintOf([fingerprint(inputs), fingerprint(code), JSON.stringify(attributionOf())]);
};

const renderShape = async function renderShape(shape: ChapterShape): Promise<string> {
    const result = await renderSurface(shape);
    if (!result.ok) {
        throw new Error(chapterRefused(shape, result.reason));
    }
    return chaptersLine(shape, result.chapters.length, result.removed.length, result.out);
};

export const renderSurfaces = async function renderSurfaces(): Promise<string> {
    return CHAPTER_SHAPES.reduce(
        async (previous, shape) => (await previous) + (await renderShape(shape)),
        Promise.resolve(""),
    );
};
```
