@zat-design/sisyphus-react 3.11.8 → 3.11.9-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,94 @@
1
+ /* eslint-disable @typescript-eslint/no-var-requires */
2
+ const fs = require('fs');
3
+ const path = require('path');
4
+
5
+ // 递归遍历目录,返回所有匹配的文件路径
6
+ function getFiles(dir, ext) {
7
+ let results = [];
8
+ const list = fs.readdirSync(dir);
9
+ list.forEach((file) => {
10
+ const filePath = path.join(dir, file);
11
+ const stat = fs.statSync(filePath);
12
+ if (stat && stat.isDirectory()) {
13
+ results = results.concat(getFiles(filePath, ext));
14
+ } else if (filePath.endsWith(ext)) {
15
+ results.push(filePath);
16
+ }
17
+ });
18
+ return results;
19
+ }
20
+
21
+ // 去除文件开头的日志相关信息(移除包含 '@' 的行),保留其他说明
22
+ function removeLogInfo(content) {
23
+ const headerRegex = /^\/\*[\s\S]*?\*\//;
24
+ const match = content.match(headerRegex);
25
+ if (match) {
26
+ const header = match[0];
27
+ // 过滤掉包含 '@' 的行
28
+ const cleanedHeader = header
29
+ .split('\n')
30
+ .filter((line) => !line.includes('@'))
31
+ .join('\n')
32
+ .trim();
33
+ // 移除 header 后剩余的内容
34
+ const rest = content.replace(headerRegex, '').trim();
35
+ return cleanedHeader ? `${cleanedHeader}
36
+
37
+ ${rest}` : rest;
38
+ }
39
+ return content;
40
+ }
41
+
42
+ // 聚合 docs 下所有 Markdown 文件内容
43
+ function aggregateDocsMarkdown() {
44
+ const docsDir = path.join(process.cwd(), 'docs');
45
+ const mdFiles = getFiles(docsDir, '.md');
46
+ let aggregated = '# API 描述\n\n';
47
+ mdFiles.forEach((filePath) => {
48
+ const relativePath = path.relative(process.cwd(), filePath);
49
+ const content = fs.readFileSync(filePath, 'utf-8');
50
+ aggregated += `## ${relativePath}\n\n`;
51
+ aggregated += `${content}\n\n`;
52
+ });
53
+ return aggregated;
54
+ }
55
+
56
+ // 按组件维度聚合 src 下各子目录的 demos 文件夹中 demo 文件的代码示例
57
+ function aggregateDemoDescriptions() {
58
+ const srcDir = path.join(process.cwd(), 'src');
59
+ let aggregated = '# Demo 示例\n\n';
60
+
61
+ // 遍历 src 目录的所有子目录,作为组件
62
+ const subDirs = fs.readdirSync(srcDir)
63
+ .map((name) => path.join(srcDir, name))
64
+ .filter((p) => fs.statSync(p).isDirectory());
65
+
66
+ subDirs.forEach((subDir) => {
67
+ const demosPath = path.join(subDir, 'demos');
68
+ if (fs.existsSync(demosPath) && fs.statSync(demosPath).isDirectory()) {
69
+ const componentName = path.basename(subDir);
70
+ aggregated += `## 组件: ${componentName}\n\n`;
71
+ const demoFiles = getFiles(demosPath, '.tsx');
72
+ demoFiles.forEach((demoFile) => {
73
+ const demoFileName = path.basename(demoFile);
74
+ const relativePath = path.relative(process.cwd(), demoFile);
75
+ let content = fs.readFileSync(demoFile, 'utf-8');
76
+ // 清洗日志相关信息
77
+ content = removeLogInfo(content);
78
+ aggregated += `### Demo: ${demoFileName} (${relativePath})\n\n`;
79
+ aggregated += `\`\`\`tsx\n${content}\n\`\`\`\n\n`;
80
+ });
81
+ }
82
+ });
83
+ return aggregated;
84
+ }
85
+
86
+ function main() {
87
+ const docsContent = aggregateDocsMarkdown();
88
+ const demoContent = aggregateDemoDescriptions();
89
+ const finalContent = `# 代码库上下文聚合\n\n${docsContent}\n${demoContent}`;
90
+ const outputPath = path.join(process.cwd(), 'aggregated_context.md');
91
+ fs.writeFileSync(outputPath, finalContent, 'utf-8');
92
+ }
93
+
94
+ main();