Skip to content

Commit f07a254

Browse files
committed
feat: merging script
1 parent 24e9192 commit f07a254

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@
4040
"lint:md:fix": "markdownlint '**/*.md' --fix",
4141
"lint:code": "eslint .",
4242
"lint:code:fix": "eslint . --fix",
43-
"postinstall": "patch-package"
43+
"postinstall": "patch-package",
44+
"postbuild": "node ./scripts/joinLlmsFiles.mjs"
4445
},
4546
"devDependencies": {
4647
"@apify/eslint-config": "^1.0.0",

scripts/joinLlmsFiles.mjs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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

Comments
 (0)