-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.js
62 lines (53 loc) · 1.73 KB
/
main.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
53
54
55
56
57
58
59
60
61
62
const fs = require('fs')
const path = require('path')
const {reorgGradleFileFromFilePath} = require("./sorter");
if (process.argv.length !== 3) {
console.error('Expected exactly one argument for a file path to the root directory!');
process.exit(1);
}
const projectPath = process.argv[2]
// grab all files in the given file path ending with gradle.kts
gradleKtsFiles = recFindByExt(projectPath, 'gradle.kts', null, null)
if (gradleKtsFiles.length !== 0) {
gradleKtsFiles.forEach(filePath => {
// we don't really support settings.gradle.kts
if (!filePath.endsWith("settings.gradle.kts")) {
reorgGradleFileFromFilePath(filePath)
}
})
}
// grab all files in the given file path ending with gradle
gradleGroovyFiles = recFindByExt(projectPath, 'gradle', null, null)
if (gradleGroovyFiles.length !== 0) {
gradleGroovyFiles.forEach(filePath => {
// we don't really support settings.gradle
if (!filePath.endsWith("settings.gradle")) {
reorgGradleFileFromFilePath(filePath)
}
})
}
/**
* Recursively find the files with a given extension
* @param base
* @param ext
* @param files
* @param result
* @returns {*[]}
*/
function recFindByExt(base, ext, files, result) {
files = files || fs.readdirSync(base)
result = result || []
files.forEach(
function (file) {
const newBase = path.join(base, file);
if (fs.statSync(newBase).isDirectory()) {
result = recFindByExt(newBase, ext, fs.readdirSync(newBase), result)
} else {
if (file.substr(-1 * (ext.length + 1)) === '.' + ext) {
result.push(newBase)
}
}
}
)
return result
}