-
Notifications
You must be signed in to change notification settings - Fork 6
/
process-turbo-build-log.cjs
36 lines (32 loc) · 1.09 KB
/
process-turbo-build-log.cjs
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
const path = require('path');
const fs = require('fs');
/** @param file string */
const processLogFile = ({ logPath, projectPath }) => {
const fileContent = fs.readFileSync(logPath, 'utf-8');
if (!fileContent.includes('> tsc -b')) {
return;
}
return fileContent.replace(/(.*)([(]\d+,\d+[)])/g, (_, localPath, carrot) => {
return `${path.join(projectPath, localPath)}${carrot}`;
});
}
function findLogFiles(startPath, filter) {
if (!fs.existsSync(startPath)) {
return [];
}
return fs.readdirSync(startPath).reduce((found, file) => {
const logPath = path.join(startPath, file);
const stat = fs.lstatSync(logPath);
if (stat.isDirectory()) {
return found.concat(findLogFiles(logPath, filter));
}
if (logPath.endsWith(filter)) {
const projectPath = logPath.replace(filter, '');
return found.concat({ logPath, projectPath });
}
return found;
}, []);
};
findLogFiles('./', '.turbo/turbo-build.log').forEach((entry) => {
console.log(processLogFile(entry));
});