-
Notifications
You must be signed in to change notification settings - Fork 61
/
Gruntfile.coffee
executable file
·258 lines (232 loc) · 7 KB
/
Gruntfile.coffee
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
module.exports = (grunt) ->
grunt.util.linefeed = '\n'
importCSS = (filename) ->
"\"\"\"#{grunt.file.read("src/General/css/#{filename}.css").replace(/\s+/g, ' ').replace(/\r/g, '').trim()}\"\"\""
importHTML = (filename) ->
"(innerHTML: #{JSON.stringify(grunt.file.read("src/General/html/#{filename}.html").replace(/^ +| +$</gm, '').replace(/\r?\n/g, '')).replace(/\\\\u/g, '\\u')})"
html = (template) ->
parts = template.split /([\$&@]){([^}`]*)}/
parts2 = []
checkText = ''
for part, i in parts
switch i % 3
when 0
parts2.push JSON.stringify part unless part is ''
checkText += part
when 1
if /<[^>]*$/.test(checkText) and not (part is '$' and /\=['"][^"'<>]*$/.test checkText)
throw new Error "Illegal insertion into HTML template: #{template}"
parts2.push switch part
when '$' then "E(`#{parts[i+1]}`)"
when '&' then "`#{parts[i+1]}`.innerHTML"
when '@' then "`#{parts[i+1]}`.map((x) -> x.innerHTML).join('')"
unless /^(<\w+( [\w-]+(='[^"'<>]*'|="[^"'<>]*")?)*>|<\/\w+>|[^"'<>]*)*$/.test checkText
throw new Error "HTML template is ill-formed: #{template}"
output = if parts2.length is 0 then '""' else parts2.join ' + '
"(innerHTML: #{output})"
assert = (statement, objs...) ->
return '' unless grunt.config('pkg').tests_enabled
"throw new Error 'Assertion failed: ' + `#{JSON.stringify statement}` unless #{statement}"
# Project configuration.
grunt.initConfig
pkg: grunt.file.readJSON 'package.json'
concat:
options: process: Object.create(null, data:
get: ->
pkg = grunt.config 'pkg'
pkg.importHTML = importHTML
pkg.importCSS = importCSS
pkg.html = html
pkg.assert = assert
pkg.tests_enabled or= false
pkg
enumerable: true
)
coffee:
src: [
'src/General/Cheats.coffee'
'src/General/Config.coffee'
'src/General/Globals.coffee'
'src/General/Mascots.coffee'
'src/General/Themes.coffee'
'src/General/lib/*.coffee'
'src/General/Header.coffee'
'src/General/Index.coffee'
'src/General/Build.coffee'
'src/General/Get.coffee'
'src/General/UI.coffee'
'src/General/CrossOrigin.coffee'
'src/Filtering/**/*.coffee'
'src/Quotelinks/**/*.coffee'
'src/Posting/**/Captcha.coffee'
'src/Posting/**/Captcha.*.coffee'
'src/Posting/**/QR.coffee'
'src/Posting/**/QR.*.coffee'
'src/Images/**/*.coffee'
'src/Linkification/**/*.coffee'
'src/Menu/**/*.coffee'
'src/Monitoring/**/*.coffee'
'src/Archive/**/*.coffee'
'src/Miscellaneous/**/*.coffee'
'src/Theming/**/*.coffee'
'src/General/Navigate.coffee'
'src/General/Settings.coffee'
'src/General/Main.coffee'
]
dest: 'tmp-<%= pkg.type %>/script.coffee'
meta:
files:
'LICENSE': 'src/General/meta/banner.js'
crx:
files:
'builds/crx/manifest.json': 'src/General/meta/manifest.json'
'builds/crx/script.js': [
'src/General/meta/botproc.js'
'src/General/meta/banner.js'
'src/General/meta/usestrict.js'
'tmp-<%= pkg.type %>/script.js'
]
userscript:
files:
'builds/<%= pkg.name %>.meta.js': 'src/General/meta/metadata.js'
'builds/<%= pkg.name %>.user.js': [
'src/General/meta/botproc.js'
'src/General/meta/metadata.js'
'src/General/meta/banner.js'
'src/General/meta/usestrict.js'
'tmp-<%= pkg.type %>/script.js'
]
copy:
crx:
src: 'src/General/img/*.png'
dest: 'builds/crx/'
expand: true
flatten: true
coffee:
script:
src: 'tmp-<%= pkg.type %>/script.coffee'
dest: 'tmp-<%= pkg.type %>/script.js'
concurrent:
build: [
'concat:meta'
'build-crx'
'build-userscript'
]
bump:
options:
updateConfigs: [
'pkg'
]
commit: false
createTag: false
push: false
shell:
checkout:
command: 'git checkout <%= pkg.meta.mainBranch %>'
commit:
command: [
'git commit -am "Release <%= pkg.meta.name %> v<%= pkg.meta.version %>."'
'git tag -a <%= pkg.meta.version %> -m "<%= pkg.meta.name %> v<%= pkg.meta.version %>."'
'git tag -af stable -m "<%= pkg.meta.name %> v<%= pkg.meta.version %>."'
].join " && "
push:
command: 'git push origin --tags -f && git push origin --all'
watch:
options:
interrupt: true
all:
files: [
'Gruntfile.coffee'
'package.json'
'src/**/*'
]
tasks: 'build'
compress:
crx:
options:
archive: 'builds/<%= pkg.name %>.zip'
level: 9
pretty: true
expand: true
flatten: true
src: 'builds/crx/*'
dest: '/'
clean:
builds: 'builds'
tmpcrx: 'tmp-crx'
tmpuserscript: 'tmp-userscript'
require('load-grunt-tasks') grunt
grunt.registerTask 'default', [
'build'
]
grunt.registerTask 'set-build', 'Set the build type variable', (type) ->
pkg = grunt.config 'pkg'
pkg.type = type;
grunt.config 'pkg', pkg
[
pkg.filter
pkg.flex
pkg.order
pkg.align
pkg.justify
pkg.transform
] = if type is 'crx' then [
'-webkit-filter'
'-webkit-flex'
'-webkit-order'
'-webkit-align'
'-webkit-justify-content'
'-webkit-transform'
] else [
'filter'
'flex'
'order'
'align'
'justify-content'
'transform'
]
grunt.log.ok 'pkg.type = %s', type
grunt.registerTask 'build', [
'concurrent:build'
]
grunt.registerTask 'build-crx', [
'set-build:crx'
'concat:coffee'
'coffee:script'
'concat:crx'
'copy:crx'
'clean:tmpcrx'
]
grunt.registerTask 'build-userscript', [
'set-build:userscript'
'concat:coffee'
'coffee:script'
'concat:userscript'
'clean:tmpuserscript'
]
grunt.registerTask 'release', [
'build'
'compress:crx'
'shell:commit'
'shell:push'
]
grunt.registerTask 'patch', [
'bump'
'updcl:3'
]
grunt.registerTask 'minor', [
'bump:minor'
'updcl:2'
]
grunt.registerTask 'major', [
'bump:major'
'updcl:1'
]
grunt.registerTask 'updcl', 'Update the changelog', (headerLevel) ->
headerPrefix = new Array(+headerLevel + 1).join '#'
{meta} = grunt.config 'pkg'
{version} = meta
today = grunt.template.today 'yyyy-mm-dd'
changelog = grunt.file.read 'CHANGELOG.md'
grunt.file.write 'CHANGELOG.md', "#{headerPrefix} v#{version} \n*#{today}*\n\n#{changelog}"
grunt.log.ok "Changelog updated for v#{version}."