-
Notifications
You must be signed in to change notification settings - Fork 0
/
gradle-tasks-for-npm.gradle
146 lines (123 loc) · 3.87 KB
/
gradle-tasks-for-npm.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import groovy.json.JsonOutput
import groovy.json.JsonSlurper
def McmaVersion = "0.16.21"
task setMcmaVersion {
def packageJson = file("package.json")
enabled packageJson.exists()
inputs.file(packageJson)
inputs.property("VERSION", McmaVersion)
outputs.file(packageJson)
doLast {
def jsonSlurper = new JsonSlurper()
def object = jsonSlurper.parse(file("package.json"))
if (object.dependencies != null) {
object.dependencies.keySet().each {
object.dependencies[it] = it.startsWith("@mcma/") ? McmaVersion : object.dependencies[it]
}
}
if (object.peerDependencies != null) {
object.peerDependencies.keySet().each {
object.peerDependencies[it] = it.startsWith("@mcma/") ? McmaVersion : object.peerDependencies[it]
}
}
if (object.devDependencies != null) {
object.devDependencies.keySet().each {
object.devDependencies[it] = it.startsWith("@mcma/") ? McmaVersion : object.devDependencies[it]
}
}
def json = JsonOutput.toJson(object)
def jsonPretty = JsonOutput.prettyPrint(json) + "\n"
packageJson.write(jsonPretty)
}
}
task npmInstall(type: Exec) {
dependsOn ":verifyNodeJS"
inputs.file("package.json")
outputs.file("package-lock.json")
outputs.dir("node_modules")
commandLine npmExecutable
args "install"
def localLibraries = []
afterEvaluate {
dependsOn.collect().each {
if (it.endsWith(":npmPack")) {
def parts = it.toString().split(":")
def directory = "${project.rootDir}/"
for (def i = 1; i < parts.length - 1; i++) {
directory += parts[i] + "/"
}
def packageJson = file(directory + "package.json")
def jsonSlurper = new JsonSlurper()
def object = jsonSlurper.parse(packageJson)
def filename = directory + "/build/dist/" + object.name.replaceAll("@", "").replace("/", "-") + "-" + object.version + ".tgz"
inputs.file filename
localLibraries.push(filename)
}
}
}
doLast {
if (!localLibraries.empty) {
exec {
commandLine npmExecutable
args "install"
localLibraries.each { args it }
args "--no-save"
}
}
}
}
task npmUpdate(type: Exec) {
dependsOn ":verifyNodeJS"
inputs.file "package.json"
inputs.property("todaysDate", new Date().clearTime())
outputs.upToDateWhen { true }
commandLine npmExecutable
args "update"
}
task npmDedup(type: Exec) {
dependsOn ":verifyNodeJS"
inputs.file("package.json")
outputs.file("package-lock.json")
outputs.dir("node_modules")
commandLine npmExecutable
args "dedup"
}
task tsc(type: Exec) {
dependsOn ":verifyNodeJS"
dependsOn ":verifyTsc"
dependsOn npmInstall
inputs.files fileTree(dir: '.', include: '**/*.ts')
inputs.file("package.json")
inputs.file("tsconfig.json")
inputs.file "${project.rootDir}/tsconfig.json"
outputs.dir("build/staging")
commandLine tscExecutable
doFirst {
delete "build/staging"
}
}
task clean(type: Delete) {
delete "build"
delete "node_modules"
}
task cleanPackageLocks(type: Delete) {
delete "package-lock.json"
}
task npmAudit(type: Exec) {
dependsOn ":verifyNodeJS"
inputs.file("package.json")
commandLine npmExecutable
args "audit"
}
task npmAuditFix(type: Exec) {
dependsOn ":verifyNodeJS"
inputs.file("package.json")
commandLine npmExecutable
args "audit", "fix"
}
task npmForceAuditFix(type: Exec) {
dependsOn ":verifyNodeJS"
inputs.file("package.json")
commandLine npmExecutable
args "audit", "fix", "--force"
}