-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
110 lines (98 loc) · 3.08 KB
/
build.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
def requiredVersionNodeJS = "12.19.0"
allprojects {
ext {
if (org.gradle.internal.os.OperatingSystem.current().isWindows()) {
nodeExecutable = Arrays.asList("node")
ngExecutable = Arrays.asList("cmd", "/c", "ng")
npmExecutable = Arrays.asList("cmd", "/c", "npm")
terraformExecutable = Arrays.asList("cmd", "/c", "terraform")
tscExecutable = Arrays.asList("cmd", "/c", "tsc")
} else {
nodeExecutable = Arrays.asList("node")
ngExecutable = Arrays.asList("ng")
npmExecutable = Arrays.asList("npm")
terraformExecutable = Arrays.asList("terraform")
tscExecutable = Arrays.asList("tsc")
}
}
}
def getVersionNodeJS = { ->
def stdout = new ByteArrayOutputStream()
def stderr = new ByteArrayOutputStream()
try {
exec {
commandLine nodeExecutable
args "--version"
standardOutput stdout
errorOutput stderr
}
} catch (Exception ignored) {
}
return stdout.toString().trim().replace("v", "")
}
task verifyNodeJS {
inputs.property("VERSION_NODE_JS", requiredVersionNodeJS)
outputs.upToDateWhen { getVersionNodeJS() == requiredVersionNodeJS }
doLast {
if (getVersionNodeJS() != requiredVersionNodeJS) {
throw new Exception("Required Node version " + requiredVersionNodeJS + " not installed")
}
}
}
subprojects {
task npmInstall(type: Exec) {
dependsOn verifyNodeJS
enabled file("package.json").exists()
inputs.file("package.json")
outputs.file("package-lock.json")
outputs.dir("node_modules")
commandLine npmExecutable
args "install"
}
task npmUpdate(type: Exec) {
dependsOn verifyNodeJS
enabled file("package.json").exists()
inputs.file "package.json"
inputs.property("todaysDate", new Date().clearTime())
outputs.upToDateWhen { true }
commandLine npmExecutable
args "update"
}
task npmDedup(type: Exec) {
dependsOn verifyNodeJS
enabled file("package.json").exists()
inputs.file("package.json")
outputs.file("package-lock.json")
outputs.dir("node_modules")
commandLine npmExecutable
args "dedup"
}
task clean(type: Delete) {
delete "build"
delete "dist"
delete "node_modules"
}
}
afterEvaluate {
// avoiding simultaneous connections to npmjs.com
def prevTask = null
project.subprojects.each {
def task = it.tasks.find { task -> task.name.contains('npmUpdate') }
if (task != null) {
if (prevTask != null) {
task.mustRunAfter(prevTask)
}
prevTask = task
}
}
prevTask = null
project.subprojects.each {
def task = it.tasks.find { task -> task.name.contains('npmInstall') }
if (task != null) {
if (prevTask != null) {
task.mustRunAfter(prevTask)
}
prevTask = task
}
}
}