forked from micronaut-projects/micronaut-guides
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
146 lines (129 loc) · 4.17 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
import io.micronaut.guides.GuidesPlugin
import io.micronaut.guides.IndexGenerator
import io.micronaut.guides.TestScriptGenerator
import io.micronaut.guides.ThemeProcessor
import io.micronaut.guides.GitDiffUtils
plugins {
id 'groovy'
id("org.asciidoctor.jvm.convert") version "4.0.0-alpha.1"
}
apply from: "gradle/asciidoc.gradle"
version '0.0.1'
repositories {
mavenCentral()
jcenter()
}
ext {
codeDir = new File(buildDir, 'code')
distDir = new File(buildDir, 'dist')
guidesDir = new File(projectDir, 'guides')
metadataConfigName = 'metadata.json'
micronautVersion = new File(projectDir, 'version.txt').text.trim()
}
task cleanAsciidoctorFolder(type: Delete) {
group 'guides'
description 'Cleans src/docs/asciidoc directory'
delete fileTree('src/docs/asciidoc') {
include '*.adoc'
}
}
apply plugin: GuidesPlugin
task copyImagesToDist(type: Copy) {
group 'guides'
description 'Copies images from src/docs/images to build/dist/images directory'
from 'src/docs/images'
into "$distDir/images"
include '**/*.png',
'**/*.jpg',
'**/*.svg',
'**/*.gif'
}
task copyStylesheetsToDist(type: Copy) {
group 'guides'
description 'Copies CSS files from assets/stylesheets to build/dist directory'
from 'assets/stylesheets'
into distDir
include '*.css'
}
task copyJavaScriptToDist(type: Copy) {
group 'guides'
description 'Copies JS files from assets/js to build/dist directory'
from 'assets/js'
into distDir
include '*.js'
}
task copyHtmlToDist(type: Copy) {
group 'guides'
description 'Copies HTML generated from Asciidoc from build/docs/asciidoc to build/dist'
from "$buildDir/docs/asciidoc"
into distDir
exclude 'common-*.html'
}
task createDist {
group 'guides'
description 'Creates build/dist directory with static assets'
dependsOn 'copyImagesToDist',
'copyStylesheetsToDist',
'copyJavaScriptToDist'
}
clean.dependsOn 'cleanAsciidoctorFolder'
build.dependsOn 'generateCodeZip'
build.dependsOn 'asciidoctor'
asciidoctor {
inputs.dir(project.layout.projectDirectory.dir("src/docs/asciidoc"))
// Pick up changes to included code
inputs.dir(project.layout.projectDirectory.dir("guides"))
mustRunAfter 'generateCodeZip'
finalizedBy 'copyHtmlToDist'
}
task generateTestScript {
group 'guides'
description 'Generates a test.sh to run every guide test at build/code'
doLast {
codeDir.mkdirs()
File testScript = new File(codeDir, "test.sh")
testScript.createNewFile()
List<String> changedFiles = []
boolean generateTestScript = true
if (System.getenv('GITHUB_WORKFLOW')) {
changedFiles = GitDiffUtils.filesChanged()
generateTestScript = !GitDiffUtils.onlyImagesOrMarkdownOrAsciidocChanged(changedFiles)
}
testScript.text = generateTestScript
? TestScriptGenerator.generateScript(guidesDir, metadataConfigName, false, changedFiles)
: TestScriptGenerator.EMPTY_SCRIPT
testScript.executable = true
}
}
task generateGuidesIndex {
group 'guides'
description 'Generates an index.html with all the guides'
doLast {
if (!distDir.exists()) {
distDir.mkdirs()
}
File template = new File(projectDir, "assets/template.html")
IndexGenerator.generateGuidesIndex(template, guidesDir, distDir, metadataConfigName)
}
}
task generateGuidesJsonMetadata {
group 'guides'
description 'Generates a guides.json with the metadata for all the guides'
doLast {
if (!distDir.exists()) {
distDir.mkdirs()
}
File guidesJson = new File(distDir, 'guides.json')
guidesJson.createNewFile()
guidesJson.text = IndexGenerator.generateGuidesJsonIndex(guidesDir, metadataConfigName)
}
}
task themeGuides {
group 'guides'
description 'Generates an index.html with all the guides'
doLast {
File template = new File(projectDir, "assets/template.html")
ThemeProcessor.applyThemes(template, distDir, guidesDir, metadataConfigName)
}
mustRunAfter('copyHtmlToDist')
}