-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathbuild.gradle
530 lines (459 loc) · 17.7 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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
import com.amazonaws.services.s3.model.CannedAccessControlList
import com.neo4j.gradle.asciidoctor.AsciidoctorModuleDescriptorGenerateTask
import com.neo4j.gradle.asciidoctor.AsciidoctorModuleDescriptorPlugin
import com.neo4j.gradle.s3.S3Plugin
import com.neo4j.gradle.s3.S3UploadTask
import org.asciidoctor.gradle.jvm.AsciidoctorTask
import org.asciidoctor.gradle.jvm.pdf.AsciidoctorPdfTask
import org.asciidoctor.gradle.jvm.slides.AsciidoctorJRevealJSTask
import org.kordamp.gradle.livereload.LiveReloadTask
plugins {
id 'org.asciidoctor.jvm.gems' version '3.1.0' apply false
id 'org.asciidoctor.jvm.convert' version '3.1.0' apply false
id 'org.asciidoctor.jvm.pdf' version '3.1.0' apply false
id 'org.asciidoctor.jvm.revealjs' version '3.1.0' apply false
id 'org.kordamp.gradle.livereload' version '0.2.1' apply false
id 'com.neo4j.gradle.s3.S3Plugin' version '0.1.1' apply false
}
subprojects {
apply plugin: 'org.asciidoctor.jvm.gems'
apply plugin: 'org.asciidoctor.jvm.revealjs'
apply plugin: S3Plugin
apply plugin: AsciidoctorModuleDescriptorPlugin
configurations {
asciidoctorgoogleslides
}
repositories {
mavenCentral()
maven {
url "https://dl.bintray.com/mogztter/io.github.mogztter"
}
jcenter()
ruby {
gems()
}
}
dependencies {
asciidoctorGems 'rubygems:rouge:3.18.0'
asciidoctorGems 'rubygems:neo4j-asciidoctor-extensions:0.3.1'
asciidoctorGems 'rubygems:asciidoctor-include-ext:0.3.1'
asciidoctorgoogleslides("io.github.mogztter:asciidoctor-googleslides:0.0.31")
}
def stage = project.findProperty('stage')
s3 {
profile = project.hasProperty('s3-profile') ? project.property('s3-profile') : 'default'
region = project.hasProperty('s3-region') ? project.property('s3-region') : 'us-east-1'
}
asciidoctorj {
gemPaths "${rootProject.buildDir}/.asciidoctorGems"
attributes 'allow-uri-read': '',
'stage': stage != null ? stage : '',
'source-highlighter': 'rouge',
'rouge-style': 'neo.forest',
'presenter': 'Neo Technology',
'twitter': 'neo4j',
'email': '[email protected]',
'neo4j-version': '4.0',
'currentyear': '2020',
'experimental': '',
'manual': 'http://neo4j.com/docs/developer-manual/current',
'manual-cypher': '{manual}/cypher',
'document-metadata-attrs-include': 'author,slug,parent-path,categories*,tags*,taxonomies*<>',
'module-descriptor-path': "${projectDir}/build/online/asciidoctor-module-descriptor.yml"
}
asciidoctorGemsPrepare.with {
outputDir = "${rootProject.buildDir}/.asciidoctorGems"
}
revealjs {
version = '4.0.1'
templateGitHub {
organisation = 'hakimel'
repository = 'reveal.js'
tag = '3.9.2'
}
}
revealjsPlugins {
github 'denehyg', {
organisation = 'denehyg'
repository = 'reveal.js-menu'
branch = 'master'
}
github 'rajgoel', {
organisation = 'rajgoel'
repository = 'reveal.js-plugins'
branch = 'master'
}
}
afterEvaluate { Project project ->
def sourceImagesDirPath = project.hasProperty("antoraStructure") ? "${projectDir}/modules/ROOT/images" : "${projectDir}/images"
def sourceDocsRootPath = project.hasProperty("antoraStructure") ? "${projectDir}/modules/ROOT/pages" : "${projectDir}/docs"
task generateModuleDescriptor(type: AsciidoctorModuleDescriptorGenerateTask) {
source = fileTree(dir: sourceDocsRootPath, include: '**/*.adoc', excludes: ['enrollment.adoc', 'setup.adoc'])
outputDir "${projectDir}/build/online"
moduleName stage != 'production' ? "_testing_${project.name}" : project.name
}
// for debugging purpose
task convertStandaloneHtml(type: AsciidoctorTask) {
dependsOn asciidoctorGemsPrepare, generateModuleDescriptor
inputs.dir "${rootProject.projectDir}/resources/templates"
asciidoctorj {
options template_dirs: ["${rootProject.projectDir}/resources/templates"]
attributes 'imagesdir': 'images',
'sectanchors': ''
}
baseDir file(sourceDocsRootPath)
sourceDir file(sourceDocsRootPath)
sources {
excludes.addAll(['enrollment.adoc', 'setup.adoc'])
}
outputDir file("${projectDir}/build/standalone")
resources {
from("${rootProject.projectDir}/resources/images") {
include '**'
into 'images'
}
from(sourceImagesDirPath) {
include '**'
into 'images'
}
}
}
if (project.projectDir.parentFile.getName() == "browser-guides") {
task convertBrowserGuideHtml(type: AsciidoctorTask) {
dependsOn asciidoctorGemsPrepare
inputs.dir "${rootProject.projectDir}/resources/templates/browser-guide"
def baseUrl = {
switch (stage) {
case 'production':
return "https://guides.neo4j.com/${project.name}"
case 'preview':
return "http://localhost:35729/browser-guide"
default:
return "./${project.name}"
}
}
def imagesDir = {
switch (stage) {
case 'production':
return "https://guides.neo4j.com/${project.name}/images"
case 'preview':
return "http://localhost:35729/browser-guide/images"
default:
return "./${project.name}/images"
}
}
asciidoctorj {
requires "${rootProject.projectDir}/resources/extensions/antora_include_resolver.rb"
options template_dirs: ["${rootProject.projectDir}/resources/templates/browser-guide"]
attributes 'imagesdir': imagesDir,
'allow-uri-read': '',
'guides': baseUrl,
'icons': 'font',
'current': baseUrl,
'csv-url': baseUrl,
'leveloffset': '+1',
'env-guide': '',
'env-training': '',
'guide': '',
'sectanchors': ''
}
resources {
from(sourceImagesDirPath) {
include '**'
into 'images'
}
}
baseDir file(sourceDocsRootPath)
sourceDir file(sourceDocsRootPath)
outputDir file("${projectDir}/build/browser-guide")
}
if (new File(sourceImagesDirPath).exists()) {
if (stage == 'production') {
task s3UploadContent(type: S3UploadTask) {
dependsOn convertBrowserGuideHtml
// uncomment this if you want to replace files in guides.neo4j.com
overwrite = true
source = "${projectDir}/build/browser-guide"
bucket = "guides.neo4j.com/${project.name}"
destination = ""
acl.set(CannedAccessControlList.PublicRead)
}
}
}
}
task convertSetupHtml(type: AsciidoctorTask) {
dependsOn asciidoctorGemsPrepare
inputs.dir "${rootProject.projectDir}/resources/templates/setup"
asciidoctorj {
options template_dirs: ["${rootProject.projectDir}/resources/templates/setup"]
attributes 'parent-path': '/graphacademy/setup',
'imagesdir': "https://s3.amazonaws.com/dev.assets.neo4j.com/course/${project.name}/images/",
'document-metadata-attrs-include': 'author,slug,parent-path',
'module-id': stage != 'production' ? "_testing_${project.name}" : project.name
}
baseDir file("${projectDir}/docs")
sourceDir file("${projectDir}/docs")
sources {
include 'setup.adoc'
}
outputDir file("${projectDir}/build/setup")
doLast {
file("${projectDir}/build/setup/setup.html").renameTo("${projectDir}/build/setup/${project.name}.html")
}
}
task convertSlides(type: AsciidoctorJRevealJSTask) {
dependsOn asciidoctorGemsPrepare
revealjsOptions {
controls = false
progressBar = true
pushToHistory = true
overviewMode = true
touchMode = true
theme = 'white'
}
asciidoctorj {
requires "${rootProject.projectDir}/resources/extensions.rb"
options template_dirs: ["${rootProject.projectDir}/resources/templates/slide"]
// for no transition between slides add this line after imagesdir:
// 'revealjs_transition': 'none',
attributes 'revealjs_customtheme': 'themes/reveal.css',
'imagesdir': 'images',
'env-slides': '',
'revealjs_transition': 'none',
'revealjs_center': 'false',
'revealjs_width': '1280',
'revealjs_height': '720',
'revealjs_margin': '0.05',
'revealjs_fragmentinurl': 'true',
'revealjs_slidenumber': 'c',
'revealjs_minscale': '0.2',
'revealjs_maxscale': '2'
}
plugins 'denehyg/menu.js', 'rajgoel/chalkboard/chalkboard.js'
pluginConfigurationFile "${rootProject.projectDir}/resources/extensions/revealjs-extension-config.js"
baseDirFollowsSourceDir()
sourceDir file(sourceDocsRootPath)
sources {
excludes.addAll(['enrollment.adoc', 'setup.adoc'])
}
outputDir file("${projectDir}/build/slides")
resources {
from("${rootProject.projectDir}/resources/themes") {
include 'reveal.css'
into 'themes'
}
from("${rootProject.projectDir}/resources/extensions") {
include 'cypher-highlightjs.js'
into 'extensions'
}
from("${rootProject.projectDir}/resources/images") {
include '**'
into 'images'
}
from(sourceImagesDirPath) {
include '**'
into 'images'
}
}
}
task convertOnlinePdf(type: AsciidoctorPdfTask) {
dependsOn asciidoctorGemsPrepare
inputs.file "${rootProject.projectDir}/resources/themes/pdf-theme.yml"
asciidoctorj {
requires "${rootProject.projectDir}/resources/extensions.rb"
modules.pdf.version '1.5.2'
attributes 'pdf-style': "${rootProject.projectDir}/resources/themes/pdf-theme.yml",
'imagesdir': '../images'
}
baseDir file(sourceDocsRootPath)
sourceDir file(sourceDocsRootPath)
sources {
excludes.addAll(['enrollment.adoc', 'setup.adoc'])
}
outputDir file("${projectDir}/build/online")
}
/**
* Copy svg images to "build/images-pdf" before generating a PDF.
*/
task copySvgImagesPdf(type: Copy) {
doFirst {
mkdir "$buildDir/images-pdf"
}
from sourceImagesDirPath
include '*.svg'
into "$buildDir/images-pdf"
}
/**
* Prepare the images before generating a PDF.
*
* Since high-resolution images consume a *lot* of memory while generating a PDF with Asciidoctor,
* we downscale png and jpg/jpeg images using a max width and height in pixels.
*
* We rely on ImageMagick (more specifically `mogrify` command line) to downscale the images.
* https://imagemagick.org/
*
* We also copy svg images to "build/images-pdf".
*/
task prepareImagesPdf(type: Exec) {
dependsOn copySvgImagesPdf
inputs.dir sourceImagesDirPath
inputs.files "${projectDir}/images/**"
outputs.dir "$buildDir/images-pdf"
outputs.files "$buildDir/images-pdf/**"
workingDir sourceImagesDirPath
def commandsArgs = []
if (!fileTree(sourceImagesDirPath).filter { it.isFile() && it.getName().endsWith('.png') }.isEmpty()) {
commandsArgs.push(['mogrify', '-path', "$buildDir/images-pdf", '-thumbnail', '1024x768>', '*.png'])
}
if (!fileTree(sourceImagesDirPath).filter { it.isFile() && it.getName().endsWith('.jpeg') }.isEmpty()) {
commandsArgs.push(['mogrify', '-path', "$buildDir/images-pdf", '-thumbnail', '1024x768>', '*.jpeg'])
}
if (!fileTree(sourceImagesDirPath).filter { it.isFile() && it.getName().endsWith('.jpg') }.isEmpty()) {
commandsArgs.push(['mogrify', '-path', "$buildDir/images-pdf", '-thumbnail', '1024x768>', '*.jpg'])
}
commandsArgs.push(['echo'])
for (commandArgs in commandsArgs) {
commandLine commandArgs
}
}
/* single document */
task convertSinglePdf(type: AsciidoctorPdfTask) {
dependsOn asciidoctorGemsPrepare
dependsOn prepareImagesPdf
inputs.file "${rootProject.projectDir}/resources/themes/pdf-theme.yml"
asciidoctorj {
requires "${rootProject.projectDir}/resources/extensions.rb"
inProcess 'IN_PROCESS'
modules.pdf.version '1.5.2'
attributes 'pdf-style': "${rootProject.projectDir}/resources/themes/pdf-theme.yml",
'imagesdir': "${buildDir}/images-pdf"
}
baseDir file("${projectDir}/single-pdf")
sourceDir file("${projectDir}/single-pdf")
outputDir file("${projectDir}/build/single-pdf")
}
task convertSingleSlides(type: AsciidoctorJRevealJSTask) {
dependsOn asciidoctorGemsPrepare
revealjsOptions {
controls = false
progressBar = true
pushToHistory = true
overviewMode = true
touchMode = true
theme = 'white'
}
asciidoctorj {
requires "${rootProject.projectDir}/resources/extensions.rb"
options template_dirs: ["${rootProject.projectDir}/resources/templates/slide"]
attributes 'revealjs_customtheme': 'themes/reveal.css',
'imagesdir': 'images',
'env-slides': '',
'revealjs_center': 'false',
'revealjs_width': '1280',
'revealjs_height': '720',
'revealjs_margin': '0.05',
'revealjs_fragmentinurl': 'true',
'revealjs_slidenumber': 'c',
'revealjs_minscale': '0.2',
'revealjs_maxscale': '2'
}
plugins 'denehyg/menu.js', 'rajgoel/chalkboard/chalkboard.js'
pluginConfigurationFile "${rootProject.projectDir}/resources/extensions/revealjs-extension-config.js"
baseDirFollowsSourceDir()
sourceDir file("${projectDir}/single-slides")
outputDir file("${projectDir}/build/single-slides")
resources {
from("${rootProject.projectDir}/resources/themes") {
include 'reveal.css'
into 'themes'
}
from("${rootProject.projectDir}/resources/extensions") {
include 'cypher-highlightjs.js'
into 'extensions'
}
from("${rootProject.projectDir}/resources/images") {
include '**'
into 'images'
}
from(sourceImagesDirPath) {
include '**'
into 'images'
}
}
}
// beta!
task convertGoogleSlides(type: AsciidoctorTask) {
dependsOn asciidoctorGemsPrepare
// disable up-to-date
outputs.upToDateWhen { false }
asciidoctorj {
requires "${rootProject.projectDir}/resources/googleslides_extensions.rb"
// must be a web accessible location
attributes 'imagesdir': "https://s3.amazonaws.com/dev.assets.neo4j.com/course/${project.name}/images/",
'env-slides': '',
'experimental': '',
'google-slides-copy-id': '1aR6dlFmu6ssBuf1yQJm8I_cfTOOpSBHIfjqCQzuDsdQ',
'google-slides-credentials-path': "${rootProject.rootDir}/tokens/credentials.json",
'google-slides-layout-student-exercise': "CUSTOM_2", // Title gold with body
'google-slides-layout-quiz': "CUSTOM_1", // Title purple
'google-slides-layout-one-sixth-five-sixths-row': "CUSTOM_3", // one sixth + fix sixths row
'google-slides-layout-half-row': "CUSTOM_4", // half row
'google-slides-layout-half-column': "CUSTOM_5", // half column
'google-slides-layout-one-third-two-thirds-column': "CUSTOM_6", // one third + two thirds column
'google-slides-layout-five-sixths-one-sixth-row': "CUSTOM_7", // five sixths one sixth row
'google-slides-layout-two-thirds-one-third-column': "CUSTOM_8", // two thirds + one third column
'google-slides-layout-guided-exercise': "CUSTOM_9", // Title green with body
'google-slides-layout-section-break': "CUSTOM_11", // Title green
'google-slides-layout-slide-start-title': "TITLE" // Title slide
}
inProcess "IN_PROCESS"
baseDirFollowsSourceDir()
sourceDir file("${projectDir}/single-slides")
outputDir file("${projectDir}/build/google-slides")
outputOptions {
backends = ["googleslides"]
}
}
convertGoogleSlides.configurations 'asciidoctorgoogleslides'
task convert {
dependsOn convertSetupHtml
dependsOn convertOnlinePdf
dependsOn convertSlides
}
task liveReload(type: LiveReloadTask) {
docRoot "${projectDir}/build"
}
if (project.projectDir.parentFile.getName() != "browser-guides") {
if (new File(sourceImagesDirPath).exists()) {
if (stage == 'production') {
task s3UploadImages(type: S3UploadTask) {
overwrite = true
source = sourceImagesDirPath
bucket = "dev.assets.neo4j.com"
destination = "course/${project.name}/images"
acl.set(CannedAccessControlList.PublicRead)
}
} else if (stage == 'testing') {
task s3UploadImages(type: S3UploadTask) {
overwrite = true
source = sourceImagesDirPath
bucket = "dev.assets.neo4j.com"
destination = "test-course/${project.name}/images"
acl.set(CannedAccessControlList.PublicRead)
}
}
}
if (stage == 'production' || stage == 'testing') {
task s3UploadSetup(type: S3UploadTask) {
dependsOn convertSetupHtml
overwrite = true
source = "${projectDir}/build/setup"
bucket = "graphacademy.neo4j.com"
destination = "setup"
acl.set(CannedAccessControlList.PublicRead)
}
}
}
task s3Upload dependsOn(tasks.names.findAll { it.startsWith("s3Upload") && it != "s3Upload" })
}
}