-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
496 lines (481 loc) · 17.8 KB
/
Gruntfile.js
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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
/* GUIEasy Copyright (C) 2019-2020 Jimmy "Grovkillen" Westberg */
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
// minify js
uglify: {
options: {
//sourceMap: true,
compress: true,
comments: false
},
main_thread: {
files: {
'build/temp/gui.min.js': [
// THESE MUST BE IN CORRECT ORDER.... ADD NEW FILES HERE
'src/gui_easy_settings.js',
'src/gui_easy_default_settings.js',
'src/gui_easy_helper_bp.js',
'src/gui_easy_helper_server_specific.js',
'src/gui_easy_curly.js',
'src/gui_easy_curly_page.js',
'src/gui_easy_curly_icons.js',
'src/gui_easy_scrubber.js',
'src/gui_easy_popper_bp.js',
'src/gui_easy_popper_sign.js',
'src/gui_easy_pitcher.js',
'src/gui_easy_butler.js',
'src/gui_easy_tender.js',
'src/gui_easy_ini.js',
]
}
}
},
// minify html
htmlmin: {
dist: {
options: {
removeComments: true,
collapseWhitespace: true
},
files: {
'build/temp/index.min.html': 'build/temp/index.min.html'
}
},
},
// minify css
cssmin: {
options: {
mergeIntoShorthands: false,
roundingPrecision: -1
},
target: {
files: {
'build/temp/gui.min.css': ['src/gui_easy.css', 'src/bp.css']
}
}
},
// make one file of them all
processhtml: {
main: {
files: {'build/temp/index.min.html': ['src/index.html']}
}
},
// clean the release folder + nodash
clean: {
temp: {
src: ['build/temp']
},
version: {
src: ['build/<%= version %>']
},
test: {
src: ['build/0.0.0.0.0']
},
noDash: {
src: ['src/no-dash.index.html']
},
releaseInfo: {
src: ['release.txt']
},
tempFiles: {
src: ['build/temp/*.html', 'build/temp/*.js']
}
},
// zip source to temp folder + gzip the gui html single file
compress: {
source: {
options: {
archive: 'build/temp/src-<%= version %>.zip'
},
files: [
{
flatten: false,
src: ['src/*','src/forms/*','src/dash/*','Gruntfile.js','package.json'],
dest: '/',
filter: 'isFile'
}
]
},
main: {
options: {
mode: 'gzip',
level: 9 //default is 1, max is 9
},
files: [{
expand: false,
src: ['build/temp/index.min.html'],
dest: 'build/temp/main/index.htm.gz'
}]
}
},
// copyright
file_append: {
copyright: {
files: [
{
prepend: '/* GUIEasy Copyright (C) 2019-' + new Date().getFullYear() + ' Jimmy "Grovkillen" Westberg */',
input: 'build/temp/gui.min.js'
},
{
prepend: '/* GUIEasy Copyright (C) 2019-' + new Date().getFullYear() + ' Jimmy "Grovkillen" Westberg */',
input: 'build/temp/gui.min.css'
},
{
prepend: '<!-- GUIEasy Copyright (C) 2019-' + new Date().getFullYear() + ' Jimmy "Grovkillen" Westberg -->',
input: 'build/temp/index.min.html'
}
]
}
},
// rename the temp folder
rename: {
temp: {
files: [
{
src: ['build/temp'],
dest: 'build/<%= version %>'
}
]
},
test: {
files: [
{
src: ['build/temp'],
dest: 'build/0.0.0.0.0'
}
]
}
},
// file size report
size_report: {
source_files: {
options: {
header: 'source files:'
},
files: {
list: ['src/*']
}
},
release_files: {
options: {
header: 'release files:'
},
files: {
list: ['build/temp/*/*.gz']
}
}
},
// source report
folder_list : {
files :
{
src: ['**'],
dest: 'build/temp/info/source_files.json',
cwd: 'src/'
}
},
// release files
filesize: {
release: {
files: [
{
expand: true,
cwd: 'build/temp',
src: ['main/*.gz']
}
],
options: {
output: [
{
path: "build/release_sizes.txt",
format: "{filename}:{size}",
append: true
}
]
}
}
},
// copy release info
copy: {
releaseInfo : {
src: 'release.txt',
dest: 'build/temp/info/',
flatten: true,
filter: 'isFile',
},
package : {
src: 'package.json',
dest: 'build/temp/info/',
flatten: true,
filter: 'isFile',
}
}
});
// Load the plugin(s)
grunt.loadNpmTasks('grunt-contrib-uglify-es');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-rename');
grunt.loadNpmTasks('grunt-contrib-compress');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-htmlmin');
grunt.loadNpmTasks('grunt-processhtml');
grunt.loadNpmTasks('grunt-file-append');
grunt.loadNpmTasks('grunt-folder-list');
grunt.loadNpmTasks('grunt-size-report');
grunt.loadNpmTasks('grunt-filesize');
// the 'default' task can be run just by typing "grunt" on the command line
grunt.registerTask('default', [
'buildGuiEasy'
]);
grunt.registerTask('test', [
'buildGuiEasy:test'
]);
// build gui easy task
grunt.registerTask('buildGuiEasy', 'Will build the project',
function (type = "new") {
let settings = grunt.file.read('src/gui_easy_settings.js');
settings = settings.match(/--GRUNT-START--([\s\S]*?)\/\/--GRUNT-END--/)[1];
let guiEasy = "{" + settings + "}";
guiEasy = guiEasy.replace(/'/g,"\"");
guiEasy = JSON.parse(guiEasy);
let version;
if (guiEasy.development === true && guiEasy.releaseCandidate > 0) {
version = guiEasy.major + '.' + guiEasy.minor + '.rc' + guiEasy.releaseCandidate + '.' + guiEasy.revision;
} else if (guiEasy.development === true) {
version = guiEasy.major + '.' + guiEasy.minor + '.nightly.' + guiEasy.revision;
} else {
version = guiEasy.major + '.' + guiEasy.minor + '.' + guiEasy.revision;
}
let semVer = guiEasy.major + '.' + guiEasy.minor + '.' + guiEasy.revision;
// update the package.json
let packageJSON = grunt.file.read('package.json');
packageJSON = JSON.parse(packageJSON);
packageJSON.version = guiEasy.major + '.' + guiEasy.minor + '.' + guiEasy.revision;
packageJSON.versionName = version;
packageJSON.main = "build/" + version + "/main/index.html.gz";
if (type === "new") {
packageJSON.timestamp = Date.now();
grunt.file.write('package.json',
JSON.stringify(packageJSON,null,2)
);
// add version as a property for the grunt ini loop
grunt.config("version", version);
grunt.config("semVer", semVer);
grunt.log.ok('writing release info file');
grunt.file.write('release.txt',
'timestamp:' + packageJSON.timestamp + '\nmajor:' + guiEasy.major + '\nminor:' + guiEasy.minor + '\nrevision:' + guiEasy.revision + '\nrc:' + guiEasy.releaseCandidate + '\ndev:' + guiEasy.development
);
grunt.task.run(
'verifyCopyright',
'clean:temp',
'clean:version',
'uglify',
'cssmin',
'processhtml',
'htmlmin',
'file_append',
'compress',
'clean:tempFiles',
'folder_list',
'filesize',
'size_report',
'copy',
'clean:releaseInfo',
'rename',
'listBuilds',
'releaseFileSizes',
'gruntDone:' + version
);
} else {
let timestamp = Date.now();
grunt.config("version", version);
grunt.config("semVer", semVer);
grunt.task.run(
'testBuild:' + timestamp,
'verifyCopyright',
'clean:temp',
'clean:test',
'uglify',
'cssmin',
'processhtml',
'htmlmin',
'file_append',
'compress',
'clean:tempFiles',
'copy',
'rename:test',
'testBuild',
'gruntDone:' + version + "-test-" + timestamp
);
}
});
grunt.registerTask('gruntDone', function (version) {
grunt.log.ok(version + ' <--- this one is compiled');
grunt.log.ok('DONE!');
});
grunt.registerTask('testBuild', function (timestamp) {
let settings = grunt.file.read('src/gui_easy_settings.js');
if (timestamp > 0) {
grunt.log.ok('adding temporary test timestamp');
settings = settings.replace(/'test': null,/, "'test': " + timestamp + ",");
} else {
grunt.log.ok('removing temporary test timestamp');
settings = settings.replace(/'test': \d*,/, "'test': null,");
}
grunt.file.write( 'src/gui_easy_settings.js', settings);
});
grunt.registerTask('verifyCopyright', function () {
let fileRead, firstLine, counter = 0, fileExtension, commentWrapper;
let copyrightInfo = 'GUIEasy Copyright (C) 2019-' + new Date().getFullYear() + ' Jimmy "Grovkillen" Westberg';
//get file extension regex
let re = /(?:\.([^.]+))?$/;
grunt.log.writeln();
// read all subdirectories from your modules folder
grunt.file.expand(
{filter: 'isFile', cwd: 'src/'},
["**/*.js", ['**/*.html', ['**/*.css']]])
.forEach(function (dir) {
fileRead = grunt.file.read('src/' + dir).split('\n');
firstLine = fileRead[0];
let startIndex = 0;
//Deleting old copyright.
if (firstLine.search("Copyright") > -1) {
startIndex = 1;
}
//Start updating copyright.
counter++;
if (startIndex > 0) {
grunt.log.ok(dir + " --> updating copyright text");
} else {
grunt.log.ok(dir + " --> doesn't have copyright. Writing it.");
}
fileExtension = re.exec(dir)[1];
switch (fileExtension) {
case 'js':
commentWrapper = '/* ' + copyrightInfo + ' */';
break;
case 'html':
commentWrapper = '<!-- ' + copyrightInfo + ' -->';
break;
case 'css':
commentWrapper = '/* ' + copyrightInfo + ' */';
break;
default:
commentWrapper = null;
grunt.log.writeln('file extension not recognized');
break;
}
if (commentWrapper) {
fileRead = fileRead.slice(startIndex).join('\n');
grunt.file.write( 'src/' + dir, commentWrapper + '\n' + fileRead);
}
});
grunt.log.ok('Searched through', counter, 'files.');
});
grunt.registerTask('listBuilds', function () {
grunt.log.ok('looking for release folders...');
let folders = "";
grunt.file.expand(
{filter: 'isDirectory', cwd: 'build/'},
['*'])
.forEach(function (dir) {
if (dir !== "0.0.0.0.0") {
folders += dir + "\n";
}
});
grunt.log.ok((folders.split(/\n/).length - 1) + " releases found.");
grunt.file.write( 'build/releases.txt', folders);
});
grunt.registerTask('releaseFileSizes', function () {
grunt.log.ok('parsing release file sizes...');
let files = "files:[";
let packageJSON = grunt.file.read('package.json');
let version = JSON.parse(packageJSON).versionName;
let releaseInfo = grunt.file.read('build/' + version + '/info/release.txt');
let fileSizes = grunt.file.read('build/release_sizes.txt');
grunt.file.delete('build/release_sizes.txt');
fileSizes = fileSizes.split(/\n/);
fileSizes.forEach(function (file) {
if (file.length > 0) {
let build = file.split(":")[0].split(/[\\/]/);
build = build[(build.length - 2)];
let size = file.split(":")[1];
files += '{"build":"' + build + '","size":' + size + "}";
}
}
);
files += "]";
files = files.replace(/}{/g, "},{");
files = files.replace(/\r?\n|\r/g, "");
grunt.file.write( 'build/' + version + '/info/release.txt', releaseInfo + "\n" + files);
});
grunt.registerTask('bump', function(level) {
let settings_from = grunt.file.read('src/gui_easy_settings.js');
let settings = settings_from.match(/--GRUNT-START--([\s\S]*?)\/\/--GRUNT-END--/)[1];
let guiEasy = "{" + settings + "}";
guiEasy = guiEasy.replace(/'/g,"\"");
guiEasy = JSON.parse(guiEasy);
let version_from;
if (guiEasy.development === true && guiEasy.releaseCandidate > 0) {
version_from = guiEasy.major + '.' + guiEasy.minor + '.rc' + guiEasy.releaseCandidate + '.' + guiEasy.revision;
} else if (guiEasy.development === true) {
version_from = guiEasy.major + '.' + guiEasy.minor + '.nightly.' + guiEasy.revision;
} else {
version_from = guiEasy.major + '.' + guiEasy.minor + '.' + guiEasy.revision;
}
if (level === "revision") {
guiEasy.revision++;
guiEasy.development = true;
}
if (level === "minor") {
guiEasy.minor++;
guiEasy.revision = 0;
guiEasy.releaseCandidate = 0;
guiEasy.development = false;
}
if (level === "major") {
guiEasy.major++;
guiEasy.minor = 0;
guiEasy.revision = 0;
guiEasy.releaseCandidate = 0;
guiEasy.development = false;
}
if (level === "rc") {
guiEasy.revision++;
guiEasy.releaseCandidate++;
guiEasy.development = true;
}
if (level === "dev=true") {
guiEasy.development = true;
}
if (level === "dev=false") {
guiEasy.development = false;
}
let version_to;
if (guiEasy.development === true && guiEasy.releaseCandidate > 0) {
version_to = guiEasy.major + '.' + guiEasy.minor + '.rc' + guiEasy.releaseCandidate + '.' + guiEasy.revision;
} else if (guiEasy.development === true) {
version_to = guiEasy.major + '.' + guiEasy.minor + '.nightly.' + guiEasy.revision;
} else {
version_to = guiEasy.major + '.' + guiEasy.minor + '.' + guiEasy.revision;
}
if (version_from === version_to) {
grunt.log.ok(version_from);
} else {
let replaceText = "//--GRUNT-START--\n" +
" 'major': " + guiEasy.major + ",\n" +
" 'minor': " + guiEasy.minor + ",\n" +
" 'revision': " + guiEasy.revision + ",\n" +
" 'development': " + guiEasy.development + ",\n" +
" 'releaseCandidate': " + guiEasy.releaseCandidate + "\n" +
" //--GRUNT-END--"
;
settings = settings_from.replace(/\/\/--GRUNT-START--([\s\S]*?)\/\/--GRUNT-END--/, replaceText);
grunt.file.write( 'src/gui_easy_settings.js', settings);
grunt.log.ok(version_from + " --> " + version_to);
}
}
);
};