Skip to content

Commit 045c2a1

Browse files
louis-preclaude
andcommitted
Centralize codegen path configuration
Add codegen/lib/config.ts as single source of truth for all paths: - apiReferenceRoot: site section root from repo root ('docs/api-reference') - guidesRoot: guides site section root ('docs/guides') - apiUrlPrefix: published URL prefix ('/api') - baseUrl, siteUrlPrefix: docs site URL constants Change Metalsmith destination from '../docs' to '../' (repo root) so file keys match the full path from repo root (docs/api-reference/...). Rename source directory from codegen/docs/ to codegen/source/ to avoid confusion with the output docs/ directory. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 29f4c35 commit 045c2a1

10 files changed

Lines changed: 44 additions & 22 deletions

File tree

codegen/lib/config.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { join } from 'node:path'
2+
3+
// Site section roots (paths from repo root)
4+
export const apiReferenceRoot = join('docs', 'api-reference')
5+
export const guidesRoot = join('docs', 'guides')
6+
7+
// The published URL prefix for the API Reference site section on docs.seam.co.
8+
export const apiUrlPrefix = '/api'
9+
10+
// The base URL for the published documentation site.
11+
export const baseUrl = 'https://docs.seam.co/latest/'
12+
13+
// The URL prefix to strip when resolving absolute URLs to file paths.
14+
export const siteUrlPrefix = '/latest'
15+
16+
// Derived paths
17+
export const apiSummaryPath = join(apiReferenceRoot, 'SUMMARY.md')

codegen/lib/postprocess.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ import { dirname, join, relative, sep } from 'node:path'
33

44
import type Metalsmith from 'metalsmith'
55

6-
const baseUrl = 'https://docs.seam.co/latest/'
7-
const urlPrefix = '/latest'
8-
const apiUrlPrefix = '/api'
9-
const apiReferenceRoot = join('docs', 'api-reference')
6+
import {
7+
apiReferenceRoot,
8+
apiUrlPrefix,
9+
baseUrl,
10+
siteUrlPrefix,
11+
} from './config.js'
1012

1113
export const postprocess = (
1214
files: Metalsmith.Files,
@@ -18,10 +20,10 @@ export const postprocess = (
1820
contents.replaceAll(new RegExp(`(${baseUrl}[^)]+)`, 'g'), ($1, $2) => {
1921
if (typeof $2 !== 'string') return $1
2022
const url = new URL($2)
21-
url.pathname = url.pathname.replace(urlPrefix, '')
23+
url.pathname = url.pathname.replace(siteUrlPrefix, '')
2224

2325
// Only relativize links to pages within the api-reference space.
24-
// The site section uses /api as its URL prefix.
26+
// The site section uses apiUrlPrefix as its URL prefix.
2527
// Cross-section links (to guides) stay as absolute URLs.
2628
if (!url.pathname.startsWith(apiUrlPrefix + '/')) return $1
2729
const apiPath = url.pathname.replace(apiUrlPrefix, '')

codegen/lib/reference.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
type ApiSummaryLayoutContext,
1616
setSummaryLayoutContext,
1717
} from './layout/summary.js'
18+
import { apiReferenceRoot } from './config.js'
1819
import { PathMetadataSchema } from './path-metadata.js'
1920

2021
interface Metadata {
@@ -27,7 +28,7 @@ type File = ApiEndpointLayoutContext &
2728
ApiNamespaceLayoutContext &
2829
ApiSummaryLayoutContext & { layout: string }
2930

30-
const rootPath = 'api-reference'
31+
const rootPath = apiReferenceRoot
3132
const indexFile = 'README.md'
3233

3334
export const reference = (

codegen/lib/report.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import type {
1212
import { openapi } from '@seamapi/types/connect'
1313
import type Metalsmith from 'metalsmith'
1414

15+
import { apiReferenceRoot } from './config.js'
16+
1517
const defaultDeprecatedMessage = 'No deprecated message provided'
1618
const defaultDraftMessage = 'No draft message provided'
1719
const defaultUndocumentedMessage = 'No undocumented message provided'
@@ -75,13 +77,13 @@ export const report = (
7577

7678
const reportData = generateReport(metadata)
7779

78-
files['api-reference/_report.md'] = {
80+
files[`${apiReferenceRoot}/_report.md`] = {
7981
contents: Buffer.from('\n'),
8082
layout: 'report.hbs',
8183
...reportData,
8284
}
8385

84-
files['api-reference/_blueprint.json'] = {
86+
files[`${apiReferenceRoot}/_blueprint.json`] = {
8587
contents: Buffer.from(JSON.stringify(metadata.blueprint, null, 2)),
8688
layout: 'default.hbs',
8789
}

codegen/lib/summary.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,28 @@
11
import { readFile } from 'node:fs/promises'
2-
import { join } from 'node:path'
32

43
import type Metalsmith from 'metalsmith'
54

6-
const summaryPath = join('docs', 'api-reference', 'SUMMARY.md')
5+
import { apiReferenceRoot, apiSummaryPath } from './config.js'
76

87
export const summary = async (
98
files: Metalsmith.Files,
109
_metalsmith: Metalsmith,
1110
): Promise<void> => {
12-
const apiSummary =
13-
files['api-reference/_summary.md']?.contents?.toString('utf-8')
11+
const summaryKey = `${apiReferenceRoot}/_summary.md`
12+
const apiSummary = files[summaryKey]?.contents?.toString('utf-8')
1413
if (apiSummary == null) {
15-
throw new Error('Missing api-reference/_summary.md')
14+
throw new Error(`Missing ${summaryKey}`)
1615
}
1716

18-
const k = 'api-reference/SUMMARY.md'
17+
const k = `${apiReferenceRoot}/SUMMARY.md`
1918
const summary = await readSummary()
2019
const contents = getUpdatedSummary(summary, apiSummary)
2120
files[k] = { contents: Buffer.from(`${contents}\n`) }
22-
delete files['api-reference/_summary.md']
21+
delete files[summaryKey]
2322
}
2423

2524
const readSummary = async (): Promise<string> => {
26-
const buf = await readFile(summaryPath)
25+
const buf = await readFile(apiSummaryPath)
2726
return buf.toString('utf-8')
2827
}
2928

codegen/smith.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import * as types from '@seamapi/types/connect'
99
import { deleteAsync } from 'del'
1010
import Metalsmith from 'metalsmith'
1111

12+
import { apiReferenceRoot } from './lib/config.js'
1213
import {
1314
formatCode,
1415
helpers,
@@ -22,17 +23,17 @@ const rootDir = dirname(fileURLToPath(import.meta.url))
2223

2324
await Promise.all([
2425
deleteAsync([
25-
'./docs/api-reference/**',
26-
'!./docs/api-reference/SUMMARY.md',
27-
'!./docs/api-reference/.gitbook.yaml',
26+
`./${apiReferenceRoot}/**`,
27+
`!./${apiReferenceRoot}/SUMMARY.md`,
28+
`!./${apiReferenceRoot}/.gitbook.yaml`,
2829
]),
2930
])
3031

3132
const partials = await getHandlebarsPartials(`${rootDir}/layouts/partials`)
3233

3334
Metalsmith(rootDir)
34-
.source('./docs')
35-
.destination('../docs')
35+
.source('./source')
36+
.destination('../')
3637
.clean(false)
3738
.use(
3839
metadata({
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)