|
| 1 | +import fs from 'node:fs/promises'; |
| 2 | +import path from 'node:path'; |
| 3 | + |
| 4 | +const ROUTES = [ |
| 5 | + 'https://docs.apify.com/api/client/js', |
| 6 | + 'https://docs.apify.com/api/client/python', |
| 7 | + 'https://docs.apify.com/sdk/js', |
| 8 | + 'https://docs.apify.com/sdk/python', |
| 9 | + 'https://docs.apify.com/cli', |
| 10 | +]; |
| 11 | + |
| 12 | +const FILES = ['llms.txt', 'llms-full.txt']; |
| 13 | +const BUILD_DIR = path.resolve('build'); |
| 14 | + |
| 15 | +async function fetchFile(route, file) { |
| 16 | + const url = `${route}/${file}`; |
| 17 | + try { |
| 18 | + const res = await fetch(url); |
| 19 | + if (!res.ok) throw new Error(`Failed to fetch ${url}: ${res.status}`); |
| 20 | + return await res.text(); |
| 21 | + } catch (err) { |
| 22 | + console.error(`Error fetching ${url}:`, err.message); |
| 23 | + return ''; |
| 24 | + } |
| 25 | +} |
| 26 | + |
| 27 | +async function joinFiles() { |
| 28 | + await fs.mkdir(BUILD_DIR, { recursive: true }); |
| 29 | + for (const file of FILES) { |
| 30 | + const contents = await Promise.all( |
| 31 | + ROUTES.map((route) => fetchFile(route, file)), |
| 32 | + ); |
| 33 | + const joined = contents.filter(Boolean).join('\n\n'); |
| 34 | + await fs.writeFile(path.join(BUILD_DIR, file), joined, 'utf8'); |
| 35 | + console.log(`Wrote ${file} to build/`); |
| 36 | + } |
| 37 | +} |
| 38 | + |
| 39 | +joinFiles().catch((err) => { |
| 40 | + console.error('Failed to join LLMs files:', err); |
| 41 | + process.exit(1); |
| 42 | +}); |
0 commit comments