-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwork-java.js
More file actions
50 lines (44 loc) · 1.4 KB
/
work-java.js
File metadata and controls
50 lines (44 loc) · 1.4 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
const fs = require('fs');
const path = require('path');
function processFile(filePath) {
const content = fs.readFileSync(filePath, 'utf-8');
return `## ${filePath}\n\n\`\`\`\n${content}\n\`\`\`\n`;
}
function processDirectory(directory) {
let output = '';
const ignoreDirs = [
'target', 'build', '.git', 'coverage', '__tests__', '__mocks__'
];
const ignoreFiles = [
'.gitignore', 'pom.xml'
];
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 (extension === 'java' && !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/gitee/MicroCommunity";
const outputFile = "Java-MicroCommunity.md";
convertRepoToText(repoPath, outputFile);