forked from karanmalhi/mulesoft-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
248 lines (220 loc) · 7.4 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
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
import com.eriwen.gradle.css.tasks.CombineCssTask
import com.eriwen.gradle.css.tasks.MinifyCssTask
import java.nio.file.Files
import java.nio.file.Paths
// .TODO
// * add mode to run jetty in background
// * set outputs.dir for custom tasks
buildscript {
configurations.create('builder')
configurations.create('singlePageBuilder')
repositories {
if (project.hasProperty('useMavenLocal')) {
mavenLocal()
}
jcenter()
maven {
url 'https://repository-master.mulesoft.org/nexus/content/repositories/public'
}
}
dependencies {
classpath 'com.eriwen:gradle-css-plugin:2.12.0'
builder 'com.mulesoft.documentation.builder:mule-docs-builder:1.0.6'
singlePageBuilder 'com.mulesoft.documentation.builder:mule-docs-single-page-builder:1.0.6'
}
configurations.all {
resolutionStrategy {
// NOTE override JRuby version required by AsciidoctorJ to work around hang in CodeRay
// TODO Gradle does not honor JRuby version declared by docs builder since AsciidoctorJ specifies newer version
force 'org.jruby:jruby:9.0.5.0'
}
}
}
defaultTasks 'build'
group = 'com.mulesoft.documentation'
apply plugin: 'css'
apply from: 'gradle/git-helper.gradle'
ext {
dryRun = project.hasProperty('dryRun')
assetsDir = '_assets'
// TIP to test a remote branch, set assetsRepoBranchName = 'name' and assetsRepoCommit = "origin/$assetsRepoBranchName"
assetsRepoBranchName = 'dev-tag'
assetsRepoCommit = '5713283ac56798ff3a68298c0916a18cddd2b992'
assetsRepoUri = 'https://github.com/mulesoft/mulesoft-docs-site-assets'
builderMaxHeapSize = project.hasProperty('maxHeapSize') ? project.property('maxHeapSize') : '2500m'
builderJvmArgs = ['-Xverify:none', '-XX:+OptimizeStringConcat', '-XX:+UseFastAccessorMethods', '-Djava.net.preferIPv4Stack=true', '-Djava.awt.headless=true']
docsRepoBranchName = System.env.GIT_BRANCH ?
System.env.GIT_BRANCH.replaceFirst(/^origin\//, '') :
git('rev-parse --abbrev-ref HEAD', '.', true)
// NOTE we assume here that all branches reside in the upstream repository
docsRepoUri = 'https://github.com/mulesoft/mulesoft-docs'
profile = project.hasProperty('profile') ? project.property('profile') : 'dev'
profileBuildScript = "gradle/$profile-profile.gradle"
siteDir = '_site'
siteUri = 'http://localhost:8000'
tempDir = '_tmp'
templatesDir = '_templates'
srcTemplatesDir = "$assetsDir/_templates"
}
apply from: 'gradle/git-helper.gradle'
if (file(profileBuildScript).exists()) apply from: profileBuildScript
task cloneAssetsRepo {
outputs.dir(assetsDir).upToDateWhen { false }
onlyIf { !Files.isSymbolicLink(Paths.get(assetsDir)) && !file("$assetsDir/.gitkeep").file }
doLast {
if (file("$assetsDir/.git").directory) {
git "fetch -q origin", assetsDir
}
else {
git "clone -q -n $assetsRepoUri $assetsDir", file(assetsDir).parent
}
git "checkout -q -B $assetsRepoBranchName $assetsRepoCommit", assetsDir
}
}
task setup(group: 'Build', description: 'Prepares the build.') {
dependsOn cloneAssetsRepo
}
task cleanAssets(type: Delete) {
onlyIf { !Files.isSymbolicLink(Paths.get(assetsDir)) && !file("$assetsDir/.gitkeep").file }
delete assetsDir
}
task clean(type: Delete, group: 'Build', description: 'Deletes assets and site directories.') {
dependsOn cleanAssets
delete buildDir, siteDir, tempDir
}
// TODO site builder should accept a custom templates directory
task copyTemplates(type: Copy) {
dependsOn setup
onlyIf { file(srcTemplatesDir).directory }
from srcTemplatesDir
into templatesDir
}
task buildHtml(type: JavaExec, group: 'Build', description: 'Builds HTML pages.') {
dependsOn copyTemplates
mustRunAfter setup
classpath = buildscript.configurations.builder
main = 'com.mulesoft.documentation.builder.Client'
args = ['-s', projectDir.absolutePath, '-d', siteDir, '-ghr', docsRepoUri, '-ghb', docsRepoBranchName, '-url', siteUri]
maxHeapSize = builderMaxHeapSize
jvmArgs = builderJvmArgs
//outputs.dir siteDir
doFirst {
// NOTE revert residual changes to template(s), which may or may not be managed by git
if (!file(srcTemplatesDir).directory) {
if (git("status --porcelain $templatesDir", '.', true).startsWith('?? ')) {
file(templatesDir).deleteDir()
}
else {
git "checkout -- $templatesDir"
}
}
}
doLast {
// NOTE revert local changes to template(s), which may or may not be managed by git
if (file(srcTemplatesDir).directory) {
if (git("status --porcelain $templatesDir", '.', true).startsWith('?? ')) {
file(templatesDir).deleteDir()
}
else {
git "checkout -- $templatesDir"
}
}
}
}
// pass file to build using -Pfile=path/to/file.adoc
task buildHtmlSingle(type: JavaExec, group: 'Build', description: 'Builds a single HTML page.') {
classpath = buildscript.configurations.singlePageBuilder
main = 'com.mulesoft.documentation.builder.previewer.Client'
args = ['-s', file(project.hasProperty('file') ? project.property('file') : 'index.adoc').absolutePath, '-d', tempDir]
}
task copyAssets(type: Copy) {
dependsOn setup
mustRunAfter buildHtml
from(assetsDir) {
exclude 'README.md'
exclude '_*/**'
exclude 'css'
}
into siteDir
//outputs.dir siteDir
// preserve last modified times (futile since git clone doesn't preserve last modification times)
//def fileCopyDetails = []
//eachFile { fileCopyDetails << it }
//doLast {
// fileCopyDetails.each { new File(destinationDir, it.path).setLastModified(it.lastModified) }
//}
}
[csslint, combineCss, gzipCss, minifyCss].each { tasks.remove(it) }
css {
source {
standard {
css {
srcDir "$assetsDir/css"
include '*.css'
}
}
less {
css {
srcDir "$assetsDir/css"
include '*.less'
}
}
}
}
lesscss {
dependsOn setup
mustRunAfter copyAssets
// IMPORTANT must use asFileTree to delay resolution until after assets repo is cloned
source = css.source.less.css.asFileTree
dest = "${buildDir}/generated-css/mulesoft"
}
task combineMulesoftCss(type: CombineCssTask) {
source = lesscss
dest = "${buildDir}/css/mulesoft.css"
doFirst {
source = source.files.sort()
}
}
task combineVendorCss(type: CombineCssTask) {
dependsOn setup
mustRunAfter copyAssets
// IMPORTANT must use asFileTree to delay resolution until after assets repo is cloned
source = css.source.standard.css.asFileTree
dest = "${buildDir}/css/vendor.css"
doFirst {
source = source.files.sort()
}
}
task minifyMulesoftCss(type: MinifyCssTask) {
source = combineMulesoftCss
dest = "${buildDir}/css/mulesoft.min.css"
yuicompressor {
lineBreakPos = 500
}
}
task minifyVendorCss(type: MinifyCssTask) {
source = combineVendorCss
dest = "${buildDir}/css/vendor.min.css"
yuicompressor {
lineBreakPos = 500
}
}
task combineAndMinifyCss(type: Copy, group: 'Build', description: 'Combined and minifies CSS files after compiling LESS files to CSS.') {
dependsOn minifyMulesoftCss, minifyVendorCss
from("${buildDir}/css") {
include '*.min.css'
}
into "${siteDir}/css"
}
task build(group: 'Build', description: 'Builds site.') {
dependsOn setup, buildHtml, copyAssets, combineAndMinifyCss
mustRunAfter clean
}
task serve(type: JettyRun, group: 'Tools', description: 'Runs site in a local preview server.') {
mustRunAfter build
classpath = files()
contextPath ''
httpPort 8000
reload 'automatic'
webAppSourceDirectory file(siteDir)
}