-
Notifications
You must be signed in to change notification settings - Fork 24
/
VersionDetemplater.moon
77 lines (70 loc) · 2.31 KB
/
VersionDetemplater.moon
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
versions = {
'src/ConfigHandler': '1.1.4'
'src/DataHandler': '1.0.5'
'src/DataWrapper': '1.0.2'
'src/Line': '1.5.3'
'src/LineCollection': '1.3.0'
'src/Log': '1.0.0'
'src/Math': '1.0.0'
'src/MotionHandler': '1.1.8'
'src/ShakeShapeHandler': '1.0.2'
'src/Statistics': '0.1.3'
'src/Tags': '1.3.4'
'src/Transform': '1.2.4'
'src/TrimHandler': '1.0.5'
'Aegisub-Motion': '1.0.9'
}
nameMap = {
CONFIGHANDLER: 'src/ConfigHandler'
DATAHANDLER: 'src/DataHandler'
DATAWRAPPER: 'src/DataWrapper'
LINE: 'src/Line'
LINECOLLECTION: 'src/LineCollection'
LOG: 'src/Log'
MATH: 'src/Math'
MOTIONHANDLER: 'src/MotionHandler'
SHAKESHAPEHANDLER: 'src/ShakeShapeHandler'
STATISTICS: 'src/Statistics'
TAGS: 'src/Tags'
TRANSFORM: 'src/Transform'
TRIMHANDLER: 'src/TrimHandler'
'AEGISUB-MOTION': 'Aegisub-Motion'
}
pathSep = package.config\sub( 1, 1 )
windows = pathSep == '\\'
for name, version in pairs versions
filename = name .. '.moon'
file = io.open filename
contents = file\read '*a'
file\close!
contents = contents\gsub '##__([A-Z-]+)_VERSION__##', ( template ) ->
print "#{filename}: replacing #{template}_VERSION with #{versions[nameMap[template]]}"
return versions[nameMap[template]]
file = io.open filename, 'wb'
file\write contents
file\close!
filename = 'DependencyControl.json'
file = io.open filename
contents = file\read '*a'
file\close!
contents = contents\gsub '##__([A-Z-]+)_VERSION__##', ( template ) ->
print "#{filename}: replacing #{template}_VERSION with #{versions[nameMap[template]]}"
return versions[nameMap[template]]
contents = contents\gsub '##__([A-Z-]+)_HASH__##', ( template ) ->
hashFilename = nameMap[template] .. '.moon'
local hashFile, hash
if windows
hashFile = io.popen 'CertUtil -hashfile ' .. hashFilename .. ' SHA1'
-- the hash itself is actually on the second line
hashFile\read '*l'
hash = hashFile\read( '*l' )\upper!
else
hashFile = io.popen 'shasum ' .. hashFilename
hash = hashFile\read '*a'
hash = hash\sub( 1, 40 )\upper!
hashFile\close!
print "#{filename}: replacing #{template}_HASH with #{hash}"
return hash
file = io.open filename, 'wb'
file\write contents
file\close!