-
-
Notifications
You must be signed in to change notification settings - Fork 10.7k
/
module_config.gradle
72 lines (63 loc) · 2.33 KB
/
module_config.gradle
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
63
64
65
66
67
68
69
70
71
72
import groovy.json.JsonSlurper
/**
* 在 module_config.json 中 根据 appConfig 和 pkgConfig 来 include 本地模块
* 可以考虑写成插件来更方便 apply
*/
def json = new JsonSlurper().parse(file("./module_config.json"))
for (def module in json.moduleConfig) {
String moduleName = module.name
if (moduleName == "feature_mock") {
if (json.pkgConfig.isEmpty()) {
module.isApply = false
}
} else if (moduleName.endsWith("_app")) {
if (!json.appConfig.contains(moduleName)) {
module.isApply = false
}
} else if (moduleName.endsWith("_pkg")) {
if (!json.pkgConfig.isEmpty()) {
if (!json.pkgConfig.contains(moduleName)) {
module.isApply = false
}
}
}
if (module.useLocal && module.isApply) {
include moduleName
project(":$moduleName").projectDir = file(module.localPath)
}
}
def ls = System.getProperty("line.separator")
List<String> modules = []
for (def module in json.moduleConfig) {
String name = module.name
boolean isApply = module.isApply
boolean useLocal = module.useLocal
String localPath = module.localPath
String remotePath = module.remotePath
if (localPath != null) localPath = "\"$localPath\""
if (remotePath != null) remotePath = "\"$remotePath\""
modules.add(String.format("%-12s%-27s: new ModuleConfig(isApply: %-5s, useLocal: %-5s, localPath: $localPath%s),",
"", name, isApply, useLocal, remotePath == null ? "" : ", remotePath: $remotePath"))
}
def configFile = file('./buildSrc/src/main/groovy/Config.groovy')
def lines = configFile.readLines("utf8")
def configContent = new StringBuilder()
boolean enterNeverFlag = false
for (def line : lines) {
if (enterNeverFlag) {
if (line.contains("/*Don't delete this line*/")) {
configContent.append(ls).append(line)
enterNeverFlag = false
}
continue
}
configContent.append(ls).append(line)
if (line.contains("/*Don't delete this line*/")) {
configContent.append(ls).append(String.format("%-12s/*Generated by \"module_config.json\"*/", ""))
enterNeverFlag = true
for (String m : modules) {
configContent.append(ls).append(m)
}
}
}
configFile.write(configContent.substring(ls.length()).toString())