Skip to content

Commit 3cc476c

Browse files
authored
feat: include documents in npm package for ai agents (#960)
1 parent eac8d92 commit 3cc476c

3 files changed

Lines changed: 52 additions & 3 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ docs/.vitepress/theme/components/demoCode.json
1616
docs/zh/components
1717

1818
tsconfig.tsbuildinfo
19-
types
19+
types
20+
doc

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737
"es",
3838
"icon",
3939
"scripts",
40-
"types"
40+
"types",
41+
"doc"
4142
],
4243
"scripts": {
4344
"prepare": "husky install",
@@ -55,7 +56,8 @@
5556
"build:style": "node scripts/build-style.js",
5657
"build:type": "node scripts/build-types.js",
5758
"build:icon": "node scripts/build-icon.js",
58-
"build": "npm run build:version && npm run build:esm && npm run build:type && cp -rf es/icon . && npm run build:esm-browser && npm run build:umd && npm run build:style && npm run build:icon",
59+
"build:in-bundle-doc": "docs:build && node script/copyDocs.js",
60+
"build": "build:in-bundle-doc && npm run build:version && npm run build:esm && npm run build:type && cp -rf es/icon . && npm run build:esm-browser && npm run build:umd && npm run build:style && npm run build:icon",
5961
"release": "node scripts/release.js",
6062
"lint-staged": "lint-staged --allow-empty",
6163
"commitlint": "commitlint --config commitlint.config.cjs -e -V",

scripts/copyDocs.cjs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
const fs = require('node:fs');
2+
const path = require('node:path');
3+
4+
const SRC_DIR = path.resolve(__dirname, '../docs/.vitepress/dist');
5+
const DEST_DIR = path.resolve(__dirname, '../doc');
6+
7+
function collectMdFiles(dir, base = '') {
8+
const entries = fs.readdirSync(dir, { withFileTypes: true });
9+
const files = [];
10+
for (const entry of entries) {
11+
const relPath = base ? `${base}/${entry.name}` : entry.name;
12+
const fullPath = path.join(dir, entry.name);
13+
if (entry.isDirectory()) {
14+
files.push(...collectMdFiles(fullPath, relPath));
15+
} else if (entry.name.endsWith('.md')) {
16+
files.push({ relPath, fullPath, name: entry.name.replace('.md', '') });
17+
}
18+
}
19+
return files;
20+
}
21+
22+
if (!fs.existsSync(SRC_DIR)) {
23+
console.error(`Source directory not found: ${SRC_DIR}`);
24+
console.error('Please run "npm run docs:build" first.');
25+
// eslint-disable-next-line node/prefer-global/process
26+
process.exit(1);
27+
}
28+
29+
fs.rmSync(DEST_DIR, { recursive: true, force: true });
30+
fs.mkdirSync(DEST_DIR, { recursive: true });
31+
32+
const files = collectMdFiles(SRC_DIR);
33+
34+
const indexLines = ['# Document Index', ''];
35+
36+
for (const file of files) {
37+
const destSubDir = path.join(DEST_DIR, path.dirname(file.relPath));
38+
fs.mkdirSync(destSubDir, { recursive: true });
39+
fs.copyFileSync(file.fullPath, path.join(DEST_DIR, file.relPath));
40+
indexLines.push(`- [${file.name}](${file.relPath})`);
41+
}
42+
43+
fs.writeFileSync(path.join(DEST_DIR, 'index.md'), `${indexLines.join('\n')}\n`);
44+
45+
console.log(`Copied ${files.length} .md files to ${DEST_DIR}`);
46+
console.log(`Generated index.md with ${files.length} entries`);

0 commit comments

Comments
 (0)