-
Notifications
You must be signed in to change notification settings - Fork 14
/
prepare-docs.ahk
160 lines (129 loc) · 4.48 KB
/
prepare-docs.ahk
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
PrepareDocsBegin(last_tag, version)
{
global TempDir, DocDir, Editor, ChangeLogFile
global PrepareDocsLog := TempDir "\ChangeLogEntry.htm"
global PrepareDocsVersion := version
global PrepareDocsEditor := 0
if (ChangeLogFile = "")
{
D("- No change log to update")
return
}
if !FileExist(ChangeLogFile)
{
Prompt("Change log file does not exist, so will not be updated:`n" ChangeLogFile, 0)
return
}
D("! Edit change log entry")
; Get all commit messages since the last tag.
log := git("log --format=format:%s%n%n%b --reverse " last_tag "..HEAD")
if FileExist(InstDataDir "\UX")
log .= git("log --format=format:%s%n%n%b --reverse " last_tag "..HEAD", InstDataDir "\UX")
; Unwrap. | Remove empty lines.
log := RegExReplace(log, "`n (?= \S)|`n(?=`n|$)")
; Encode < > &
log := StrReplace(StrReplace(StrReplace(log, "&", "&"), "<", "<"), ">", ">")
; `code`
log := RegExReplace(log, "``(.*?)``", "<code>$1</code>")
; Paragraph formatting.
log := RegExReplace(log, "`n).+", "<p>$0</p>")
; Header for previewing file.
header := "<head>"
. "<base href=""file:///" DocDir "/docs/"" target=""_blank"">"
. "<link href=""file:///" DocDir "/docs/static/theme.css"" rel=""stylesheet"" type=""text/css"" />"
. "</head>"
; Add header and heading.
FormatTime, date,, MMMM d, yyyy
log := "<!--temp-->" header "<!--/temp-->`n`n"
. "<h2 id=""v" version """>" version " - " date "</h2>`n"
. log "`n"
; Run editor for confirmation/editing.
FileOpen(PrepareDocsLog, "w`n", "UTF-8").Write(log)
Run, %Editor% "%PrepareDocsLog%",,, PrepareDocsEditor
}
_PrepareDocsEndEdit()
{
global ChangeLogFile
global PrepareDocsEditor, PrepareDocsLog
Process, Exist, %PrepareDocsEditor%
if ErrorLevel
{
D("! Waiting for editor to close")
; Wait until user finishes editing the entry.
Process, WaitClose, %PrepareDocsEditor%
}
FileRead, log, %PrepareDocsLog%
; Remove preview header and leading/trailing whitespace.
log := Trim(RegExReplace(log, "s)<!--temp.*?/temp-->"), " `t`r`n")
if (log = "")
{
Prompt("Change log entry is blank. Continue without updating change log?", 0)
return
}
D("! Updating change log")
; Insert log entry into docs.
FileRead, html, %ChangeLogFile%
html := RegExReplace(html, "(?=\R<h2)", "`n" log "`n", replaced, 1)
if replaced
FileOpen(ChangeLogFile, "w`n").Write(html)
}
PrepareDocsEnd()
{
global DocDir
global PrepareDocsEditor, PrepareDocsVersion
pullRes := git("pull --ff-only", DocDir)
if ErrorLevel
Prompt("Failed to pull docs (exit code " ErrorLevel "):`n" pullRes, 0)
if (PrepareDocsEditor != 0)
_PrepareDocsEndEdit()
version := PrepareDocsVersion
; Update version number in docs.
FileRead, html, % DocDir "\docs\index.htm"
html := RegExReplace(html, "(?<=<!--ver-->).*(?=<!--/ver-->)", version, replaced, 1)
if replaced
FileOpen(DocDir "\docs\index.htm", "w").Write(html)
else
Prompt("index.htm not updated!", 0)
PrepareSearchIndex()
git("commit -a -m v" version, DocDir)
if ErrorLevel
Prompt("Failed to commit docs!", 0)
git("push", DocDir)
}
PrepareDocsCHM()
{
global InstDir, DocDir, InstDataDir
D("! Updating AutoHotkey.chm")
Loop {
FileDelete %DocDir%\AutoHotkey.chm
if !FileExist(DocDir "\AutoHotkey.chm")
break
D("- AutoHotkey.chm locked; prompting user")
MsgBox 0x35,, AutoHotkey.chm appears to be locked. Ensure it is closed`, then click OK.
IfMsgBox Cancel
{
D("- User cancelled")
ExitApp 1
}
}
RunWait "%A_AhkPath%\..\AutoHotkeyU32.exe" compile_chm.ahk, %DocDir%
FileCopy %DocDir%\AutoHotkey.chm, %InstDataDir%, 1
}
PrepareSearchIndex(commit:=false)
{
global DocDir
; Update search index.
try
{
RunWait "%A_AhkPath%\..\v2\AutoHotkey32.exe" "%DocDir%\docs\static\source\build_search.ahk"
if ErrorLevel
throw Exception("AutoHotkey exited with code " ErrorLevel)
if commit
git("commit docs/static/source/data_search.js -m ""Update search index""", DocDir)
}
catch e
{
Prompt("Failed to build search index`n`n" e.message, 0)
}
}