-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwork-python.js
More file actions
59 lines (50 loc) · 1.78 KB
/
work-python.js
File metadata and controls
59 lines (50 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const fs = require('fs');
const path = require('path');
function processFile(filePath) {
const content = fs.readFileSync(filePath, 'utf-8');
return `## ${filePath}\n\n\`\`\`python\n${content}\n\`\`\`\n`;
}
function processDirectory(directory) {
let output = '';
const ignoreDirs = [
'__pycache__', 'venv', 'env', '.git', 'dist', 'build', 'tests', 'test',
'doc', 'docs', 'imgs', 'logs', 'resources', 'StyleText', 'configs','applications','configs'
];
const ignoreFiles = [
'.gitignore', 'requirements.txt', 'setup.py', 'LICENSE', 'README.md', 'Makefile',
'.clang-format', '.pre-commit-config.yaml', '.pylintrc', '.style.yapf',
'setup.cfg', 'train.sh', 'MANIFEST.in'
];
function traverseDirectory(currentDir) {
const files = fs.readdirSync(currentDir);
for (const file of files) {
const filePath = path.join(currentDir, file);
const stat = fs.statSync(filePath);
if (stat.isDirectory()) {
if (!ignoreDirs.includes(file)) {
traverseDirectory(filePath);
}
} else {
const extension = file.split('.').pop();
if (
['py', 'html', 'css', 'js', 'json', 'yml', 'yaml', 'txt', 'md'].includes(extension) &&
!ignoreFiles.includes(file)
) {
output += processFile(filePath);
}
}
}
}
traverseDirectory(directory);
return output;
}
function convertRepoToText(repoPath, outputFile) {
const text = `# 代码仓库: ${repoPath}\n\n`;
const output = text + processDirectory(repoPath);
fs.writeFileSync(outputFile, output, 'utf-8');
console.log(`转换完成,结果保存在: ${outputFile}`);
}
// 示例用法
const repoPath = "program/open-source/crewai-experiments";
const outputFile = "crewai-experiments.md";
convertRepoToText(repoPath, outputFile);