-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.gradle
More file actions
110 lines (93 loc) · 3.54 KB
/
Copy pathbuild.gradle
File metadata and controls
110 lines (93 loc) · 3.54 KB
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
import java.util.regex.Pattern
import java.util.regex.Matcher
import groovy.json.JsonOutput
plugins {
// To run webpack-dev-server in the background
id 'com.github.psxpaul.execfork' version '0.2.2'
}
def replaceInTemplate(String templateFile, String destinationPath, Map<String, String> replacements) {
def content = file(templateFile).text
replacements.each { placeholder, newValue ->
def escapedPlaceholder = Pattern.quote("[[" + placeholder + "]]")
content = content.replaceAll(escapedPlaceholder, Matcher.quoteReplacement(newValue))
}
file(destinationPath).text = content
}
subprojects {
task clean {
delete "${projectDir}/assets"
delete "${projectDir}/node_modules"
}
task npmInstall(type: Exec) {
executable 'npm'
args 'i', '--no-audit', '--no-fund', '--loglevel=error'
}
task generateBuildConfig {
doLast {
mkdir "${projectDir}/assets"
// generate tsconfig.json for every plugin
replaceInTemplate(
"${rootDir}/config/tsconfig.json",
"${projectDir}/tsconfig.json",
['rsDir': project.properties['rsDir']]
)
// generate webpack config, we do this only if there are custom components
def componentsFile = file("${projectDir}/components.json");
if (componentsFile.exists()) {
// generate defaults.js
replaceInTemplate(
"${rootDir}/config/defaults.js",
"${projectDir}/defaults.js",
[
'extensionName': project.name,
'rsDir': project.properties['rsDir']
]
)
// generate webpack.config.js
replaceInTemplate(
"${rootDir}/config/webpack.config.js",
"${projectDir}/webpack.config.js",
[:]
)
// generate webpack.dev.config.js
replaceInTemplate(
"${rootDir}/config/webpack.dev.config.js",
"${projectDir}/webpack.dev.config.js",
[:]
)
// generate webpack.dev.config.js
replaceInTemplate(
"${rootDir}/config/webpack.prod.config.js",
"${projectDir}/webpack.prod.config.js",
[:]
)
}
}
}
tasks.generateBuildConfig.dependsOn npmInstall
task webpackProd(type: Exec) {
executable 'npx'
args 'webpack', '--bail', '--mode', 'production', '--config', "${projectDir}/webpack.prod.config.js"
}
tasks.webpackProd.dependsOn generateBuildConfig
}
if (project == gradle.rootProject) {
// define custom tasks exclusive to the root project
task generateProjectsConfig {
doLast {
def projectsJson = JsonOutput.toJson(subprojects.collect { "./plugins/${it.name}"})
file("${rootDir}/projects.json").text = projectsJson
}
}
// task to execute webpack in watch mode, see ./package.json
task startWebpack(type: com.github.psxpaul.task.ExecFork) {
dependsOn generateProjectsConfig
subprojects.each { dependsOn("${it.name}:generateBuildConfig") }
executable = 'npm'
args = [ 'run', 'dev' ]
timeout = Long.MAX_VALUE
forceKill = true
// wait for message produces by webpack in minimal log mode
waitForOutput = 'never happaens'
}
}