This repository has been archived by the owner on May 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathupdaters.gradle
135 lines (114 loc) · 5.31 KB
/
updaters.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
// Adds optional dev convenience: the 'updateReadme' gradle task,
// which generates README .md and .adoc files at root, from docs/README.src.md,
// inserting values on placeholders.
import groovy.json.JsonOutput
import groovy.json.JsonSlurper
////////////////////////////////////////////////// Auto-update current version in docs and package.json:
def PACKAGE_JSON = new JsonSlurper().parseText(file('package.json').text)
def NPM_BUNDLE_VERSION = PACKAGE_JSON.dependencies.react4xp
def STARTER_VERSION = "${project.version}"
def XP_VERSION = "${xpVersion}"
def PREVIOUS_VERSION = "${PACKAGE_JSON.version}"
def README_SOURCE = "README.src.md"
def TARGET_COMMENT = "USE THIS FILE TO EDIT THE ROOT's README.md! This will generate the actual README.md and README.adoc with placeholder values inserted. Run gradle task before commit: updateReadme - this should autorun when building. Version placeholders: 0.6.3, 7.0.0, 1.0.0 and 0.2.1. Leave this line in place - and if you edit it, remember to also update it in the search/replace target in build.gradle!"
def NEW_COMMENT = " Autogenerated from source docs/${README_SOURCE} by the 'updateReadme' task in readme.gradle."
task makeAdoc(type: Copy) {
from("./docs/")
into("./")
include(README_SOURCE)
rename(README_SOURCE, "README.adoc")
doFirst {
new File('README.adoc').delete()
}
filter {
String line ->
line
// PLACEHOLDERS
.replaceAll(TARGET_COMMENT, NEW_COMMENT)
.replaceAll("###LIB_REACT4XP_VERSION###", rootProject.ext.LIB_REACT4XP_VERSION)
.replaceAll("###XP_VERSION###", XP_VERSION)
.replaceAll("###STARTER_VERSION###", STARTER_VERSION)
.replaceAll("###NPM_BUNDLE_VERSION###", NPM_BUNDLE_VERSION)
// MD --> ADOC
.replaceAll(/\[\/\/\]: <> \((.*?)\)/, "// \$1") // Top comment
.replaceAll(/^# (.*?)$/, "= \$1\n:toc: right") // Main header, adding auto ToC
.replaceAll(/^## (.*?)$/, "== \$1") // H2-H5
.replaceAll(/^### (.*?)$/, "=== \$1")
.replaceAll(/^#### (.*?)$/, "==== \$1")
.replaceAll(/^##### (.*?)$/, "===== \$1")
.replaceAll(/<a name="(.*?)"><\/a>/, "\n[[\$1]]") // Explicit anchor IDs
.replaceAll(/\[(.*?)\]\((.*?)\)/, "link:\$2[\$1]") // Links
.replaceAll(/^ +```\s*$/, "----") // Indented code block end (inside numbered list)
.replaceAll(/^ +```(.*?)$/, "+\n[source,\$1,options=\"nowrap\"]\n----") // Indented code block start (inside numbered list)
.replaceAll(/^```$/, "----") // Source code end
.replaceAll(/^```(.*?)$/, "[source,\$1,options=\"nowrap\"]\n----") // Source code start
.replaceAll(/^(\| ?\*?\*?Version \/ tag\*?\*?[\n \|])(.*?)\|$/, "[%header,cols=3]\n|===\n\$1\$2") // Version table header
.replaceAll(/^\| ?-.*?- ?\|$/, "")
.replaceAll(/^(\| ?0\.2\.8.*?) ?\|$/, "\$1\n|===") // Version table last line (starts with "0.2.8")
.replaceAll(/^(\| ?.*?)\|$/, "\$1") // Version table cells
.replaceAll(/<br\/>/, "{zwsp} +") // Empty lines
.replaceAll(/<img src="(.*?)" .*? title="(.*?)" width="(.*?)">/, "image:\$1[title=\"\$2\",width=\$3]") // images
}
doLast {
File fh1 = new File('README.adoc')
def text = fh1.getText('UTF-8')
text = text.replaceAll(/\n== Table of Contents\n( *- link:.*?\]\n)*\n/, "")
fh1.delete()
fh1.write text
println "Updated README.adoc from docs/$README_SOURCE"
}
inputs.file("./docs/" + README_SOURCE)
outputs.file('README.adoc')
}
task updateReadme(type: Copy) {
group('Documentation')
description('Automatically build/update README (both .md and .adoc) from the readme source: docs/README.src.md and insert values into placeholders, e.g. versions. Will OVERWRITE existing readme files at root.')
from("./docs/")
into("./")
include(README_SOURCE)
rename(README_SOURCE, "README.md")
doFirst {
new File('README.md').delete()
}
filter {
String line ->
line
// PLACEHOLDERS
.replaceAll(TARGET_COMMENT, NEW_COMMENT)
.replaceAll("###LIB_REACT4XP_VERSION###", rootProject.ext.LIB_REACT4XP_VERSION)
.replaceAll("###XP_VERSION###", XP_VERSION)
.replaceAll("###STARTER_VERSION###", STARTER_VERSION)
.replaceAll("###NPM_BUNDLE_VERSION###", NPM_BUNDLE_VERSION)
}
doLast {
println "Updated README.md from docs/$README_SOURCE"
}
inputs.file("./docs/" + README_SOURCE)
outputs.file('README.md')
}
updateReadme.dependsOn makeAdoc
def readmeUnstaged() {
def command = "git diff --name-only HEAD"
// println "Process: ${command}"
def proc = command.execute()
proc.waitFor()
if (proc.exitValue() != 0) {
throw new GradleException(proc.err.text)
}
def stdout = proc.in.text
def unstagedSource = stdout.split('\n').findAll { it == "docs/README.md" || it == "docs\\README.md" }
return unstagedSource.size() > 0
}
updateReadme.enabled = true // rootProject.ext.LIB_REACT4XP_VERSION != PREVIOUS_VERSION || readmeUnstaged()
task updatePackageJson() {
doLast {
PACKAGE_JSON.version = "$version"
def pkgJsonFile = new File('package.json')
// new File('package.json').delete()
pkgJsonFile.write(JsonOutput.prettyPrint(JsonOutput.toJson(PACKAGE_JSON)) + "\n")
println "Updated package.json: version --> ${PACKAGE_JSON.version}"
}
}
task updateVersions() {}
updateVersions.dependsOn += updateReadme
updateVersions.dependsOn += updatePackageJson