-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathbuildPackage.ahk
116 lines (99 loc) · 2.75 KB
/
buildPackage.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
inputFile := "start.user.js"
saveAs := "sangupackage.user.js"
savePath :=
FileEncoding, UTF-8-RAW ; If it crashes here, you've got the wrong version of Autohotkey - see readme
workingDirectory = %A_WorkingDir%
SetWorkingDir, %A_ScriptDir%
; update version
versionFileName = version.txt
newVersion := GetNewVersion(versionFileName)
UpdateVersion(newVersion, versionFileName)
ParseAndSaveFile(inputFile, savePath, saveAs)
; Restore system state
SetWorkingDir, workingDirectory
; Below are functions etc
GetNewVersion(versionFileName)
{
currentVersion =
FileRead, currentVersion, %versionFileName%
StringSplit, versionNumber, currentVersion, .
versionNumber4 := versionNumber4 + 1
newVersion = %versionNumber1%.%versionNumber2%.%versionNumber3%.%versionNumber4%
return %newVersion%
}
UpdateVersion(newVersion, versionFileName)
{
FileDelete, %versionFileName%
FileAppend, %newVersion%, %versionFileName%
}
ParseFile(fileName, indentCount)
{
if not FileExist(fileName)
{
MsgBox Couldn't find: %fileName% - exitting
ExitApp
}
replacedFile =
Loop, Read, %fileName%
{
replacedFile .= ParseLine(A_LoopReadLine, indentCount) . "`r"
}
StringTrimRight, replacedFile, replacedFile, 1
return %replacedFile%
}
ParseLine(line, indentCount)
{
found =
FoundInclude := RegExMatch(line, "(^\s*)?//\<!--@@INCLUDE "".*"" INDENT=\d //--\>", found)
if FoundInclude
{
; //<!--@@INCLUDE "\importit.txt" INDENT=X //-->
toIncludeFileName := RegExReplace(found, "^\s*")
StringMid, toIncludeFileName, toIncludeFileName, 18 ; jump till filename
closingQuotePosition := InStr(toIncludeFileName, """")
StringMid, newIndent, toIncludeFileName, closingQuotePosition + 9 ; Jump to indent
StringMid, newIndent, newIndent, 1, 1 ; Get indent
StringMid, toIncludeFileName, toIncludeFileName, 1, closingQuotePosition - 1 ; Get filename
If toIncludeFileName
{
toIncludeContent := ParseFile(toIncludeFileName, newIndent)
StringReplace, line, line, %found%, %toIncludeContent%
}
else
{
StringReplace, line, line, %found%
}
}
else
{
currentDateReplacer := "//<!--@@INCLUDE CURRENTDATE //-->"
IfInString, line, %currentDateReplacer%
{
currentDate =
FormatTime, currentDate, , d MMMM yyyy
StringReplace, line, line, %currentDateReplacer%, %currentDate%
}
else if indentCount
{
Loop %indentCount%
{
;line := " " . line
line := A_TAB . line
}
}
}
return %line%
}
SaveFile(fileContent, savePath, saveFileName)
{
FileDelete, %savePath%%saveFileName%
FileAppend, %fileContent%, %savePath%%saveFileName%
}
ParseAndSaveFile(inputFile, savePath, saveFileName)
{
;MsgBox %inputFile%, %savePath%, %saveFileName%
formattedOutput := ParseFile(inputFile, 0)
SaveFile(formattedOutput, savePath, saveFileName)
return %formattedOutput%
}
return