-
Notifications
You must be signed in to change notification settings - Fork 9
/
buildFiles.js
52 lines (40 loc) · 1.38 KB
/
buildFiles.js
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
import { existsSync } from "fs";
import { resolve } from "path";
import fs from "fs";
function getBuildFiles(externalFiles, debugLog) {
let buildFiles = [];
if (externalFiles && externalFiles.length) {
externalFiles.forEach((externalFile) => {
if (!existsSync(externalFile)) {
console.log(`Unable to find ${externalFile} file.`.bgRed);
return;
} else {
buildFiles.push(externalFile);
}
});
}
const directoryToSearchIn = process.cwd();
debugLog(`Recursively looking for build files in directory ${directoryToSearchIn}`);
const allRecursiveFiles = getAllBuildFiles(directoryToSearchIn);
const recursiveBuildFiles = allRecursiveFiles.filter((it) => it.endsWith("build.gradle") || it.endsWith("build.gradle.kts"));
buildFiles.push(...recursiveBuildFiles);
return buildFiles;
}
const getAllBuildFiles = function (dirPath, arrayOfFiles) {
const files = fs
.readdirSync(dirPath, {
withFileTypes: true,
})
.filter((it) => !it.name.startsWith(".") && !it.name.startsWith("node_modules"));
arrayOfFiles = arrayOfFiles || [];
files.forEach((dirent) => {
const resolvedFile = resolve(dirPath, dirent.name);
if (dirent.isDirectory()) {
arrayOfFiles = getAllBuildFiles(resolvedFile, arrayOfFiles);
} else {
arrayOfFiles.push(resolvedFile);
}
});
return arrayOfFiles;
};
export { getBuildFiles };