|
5 | 5 | * the generated llms-full.txt files into: |
6 | 6 | * docs/angular-api/{package}/{version}/llms-full.txt |
7 | 7 | * |
8 | | - * Steps (handled here): |
9 | | - * 1. Verify common/api-docs submodule is present |
10 | | - * 2. npm install inside common/api-docs |
11 | | - * 3. (skipped) fetch:tools:angular — Angular TypeDoc JSONs are pre-bundled |
12 | | - * in common/api-docs/src/data/angular/ so no download is needed. |
13 | | - * 4. npm run build:angular:en — Astro SSG → dist/en/api/angular/** |
14 | | - * 5. Copy dist/en/api/angular/{pkg}/{ver}/llms-full.txt |
15 | | - * → docs/angular-api/{pkg}/{ver}/llms-full.txt |
| 8 | + * Angular TypeDoc JSONs are pre-bundled in common/api-docs/src/data/angular/, |
| 9 | + * so no fetch:tools step is needed before the Astro build. |
16 | 10 | */ |
17 | 11 |
|
18 | | -import { |
19 | | - existsSync, |
20 | | - mkdirSync, |
21 | | - copyFileSync, |
22 | | - readdirSync, |
23 | | - rmSync, |
24 | | - statSync, |
25 | | -} from 'fs'; |
26 | | -import { join, resolve } from 'path'; |
27 | | -import { execSync } from 'child_process'; |
28 | | -import { pickLatestVersionDir } from '../src/lib/version-picker.js'; |
| 12 | +import { exportApi } from './lib/export-api.js'; |
29 | 13 |
|
30 | | -const ROOT = resolve(import.meta.dirname, '..'); |
31 | | -const SUBMODULE_DIR = join(ROOT, 'common', 'api-docs'); |
32 | | -const ASTRO_DIST = join(SUBMODULE_DIR, 'dist', 'en', 'api', 'angular'); |
33 | | -const OUTPUT_DIR = join(ROOT, 'docs', 'angular-api'); |
34 | | - |
35 | | -function run(cmd: string, cwd: string): void { |
36 | | - console.log(`\n▶ ${cmd}`); |
37 | | - execSync(cmd, { cwd, stdio: 'inherit' }); |
38 | | -} |
39 | | - |
40 | | -// ── Step 1: verify submodule is present ─────────────────────────────────── |
41 | | -if (!existsSync(SUBMODULE_DIR)) { |
42 | | - console.error( |
43 | | - `❌ Submodule not found: ${SUBMODULE_DIR}\n` + |
44 | | - ` Run: git submodule update --init common/api-docs` |
45 | | - ); |
46 | | - process.exit(1); |
47 | | -} |
48 | | - |
49 | | -// ── Step 2: install deps in submodule ───────────────────────────────────── |
50 | | -console.log('📦 Installing api-docs dependencies...'); |
51 | | -run('npm install --silent', SUBMODULE_DIR); |
52 | | - |
53 | | -// ── Step 3: (skipped) fetch Angular tools ────────────────────────────── |
54 | | -// Angular TypeDoc JSONs are pre-bundled in common/api-docs/src/data/angular/. |
55 | | -// run('npm run fetch:tools:angular', SUBMODULE_DIR); |
56 | | - |
57 | | -// ── Step 4: Astro static build → dist/en/api/angular/** ────────────────── |
58 | | -console.log('\n🚀 Building Astro site for Angular (generates llms-full.txt files)...'); |
59 | | -run('npm run build:angular:en', SUBMODULE_DIR); |
60 | | - |
61 | | -// ── Step 5: copy llms-full.txt files to docs/angular-api/ ──────────────── |
62 | | -if (!existsSync(ASTRO_DIST)) { |
63 | | - console.error( |
64 | | - `❌ Astro build output not found: ${ASTRO_DIST}\n` + |
65 | | - ` The Astro build may have failed.` |
66 | | - ); |
67 | | - process.exit(1); |
68 | | -} |
69 | | - |
70 | | -console.log('\n📂 Exporting llms-full.txt files to docs/angular-api/...'); |
71 | | -mkdirSync(OUTPUT_DIR, { recursive: true }); |
72 | | - |
73 | | -let copied = 0; |
74 | | - |
75 | | -for (const pkgName of readdirSync(ASTRO_DIST)) { |
76 | | - const pkgSrc = join(ASTRO_DIST, pkgName); |
77 | | - if (!statSync(pkgSrc).isDirectory()) continue; |
78 | | - |
79 | | - const versions = readdirSync(pkgSrc) |
80 | | - .filter(n => statSync(join(pkgSrc, n)).isDirectory()); |
81 | | - if (versions.length === 0) continue; |
82 | | - |
83 | | - const latest = pickLatestVersionDir(versions); |
84 | | - const srcFile = join(pkgSrc, latest, 'llms-full.txt'); |
85 | | - if (!existsSync(srcFile)) continue; |
86 | | - |
87 | | - const pkgDest = join(OUTPUT_DIR, pkgName); |
88 | | - rmSync(pkgDest, { recursive: true, force: true }); |
89 | | - const destDir = join(pkgDest, latest); |
90 | | - mkdirSync(destDir, { recursive: true }); |
91 | | - |
92 | | - copyFileSync(srcFile, join(destDir, 'llms-full.txt')); |
93 | | - const note = versions.length > 1 ? ` (latest of ${versions.length})` : ''; |
94 | | - console.log(` ✓ ${pkgName}/${latest}/llms-full.txt${note}`); |
95 | | - copied++; |
96 | | -} |
97 | | - |
98 | | -if (copied === 0) { |
99 | | - console.error('❌ No llms-full.txt files were found in the Astro build output.'); |
100 | | - process.exit(1); |
101 | | -} |
102 | | - |
103 | | -console.log(`\n✅ Exported ${copied} llms-full.txt file(s) to docs/angular-api/`); |
| 14 | +exportApi({ |
| 15 | + platform: 'angular', |
| 16 | + displayName: 'Angular', |
| 17 | + astroDistSubdir: 'angular', |
| 18 | + outputDirName: 'angular-api', |
| 19 | + buildScript: 'build:angular:en', |
| 20 | +}); |
0 commit comments