-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgulpfile.js
89 lines (72 loc) · 2.77 KB
/
gulpfile.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
/*
ESP8266 file system builder
Copyright (C) 2016-2017 by Xose Pérez <xose dot perez at gmail dot com>;
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
5/21/18 : Jason Brown - adapted to operate on multiple html files
*/
// -----------------------------------------------------------------------------
// File system builder
// -----------------------------------------------------------------------------
const fs = require('fs');
const gulp = require('gulp');
const htmlmin = require('gulp-htmlmin');
const cleancss = require('gulp-clean-css');
const uglify = require('gulp-uglify');
const gzip = require('gulp-gzip');
const inline = require('gulp-inline');
const inlineImages = require('gulp-css-base64');
const debug = require('gulp-debug');
const tap = require('gulp-tap');
const log = require('fancy-log');
const dataFolder = 'data/';
const outputFolder = 'data/';
function hex (filename, data) {
var outputfile = outputFolder + filename + '.h';
log('output file: ' + outputfile);
var wstream = fs.createWriteStream(outputfile);
wstream.on('error', function (err) {
console.log(err);
});
var filevar = filename.replace(/\./g, '_');
wstream.write('#define ' + filevar + '_len ' + data.length + '\n');
wstream.write('const char ' + filevar +'[] PROGMEM = {');
for (i=0; i<data.length; i++) {
if (i % 1000 == 0) wstream.write("\n");
wstream.write('0x' + ('00' + data[i].toString(16)).slice(-2));
if (i<data.length-1) wstream.write(',');
}
wstream.write('\n};')
wstream.end();
return data;
}
gulp.task('default', function() {
return gulp.src(dataFolder + '*.html')
.pipe(debug({title: 'file:'}))
.pipe(inline({
base: dataFolder,
js: uglify,
css: [cleancss, inlineImages],
disabledTypes: ['svg', 'img']
}))
.pipe(htmlmin({
collapseWhitespace: true,
removeComments: true,
minifyCSS: true,
minifyJS: true
}))
.pipe(gzip())
.pipe(tap(function (file, t) {
file.contents = Buffer.from(hex(file.relative, file.contents))
}))
// uncomment to write intermediate gzipped temp file
//.pipe(gulp.dest(outputFolder));
});