-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgulpfile.js
71 lines (56 loc) · 1.59 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
const gulp = require('gulp');
const del = require('del');
const uglify = require('gulp-uglify');
const inline = require('gulp-inline');
const cleancss = require('gulp-clean-css');
const htmlmin = require('gulp-htmlmin');
const gzip = require('gulp-gzip');
const fs = require('fs');
gulp.task('copiar', function () {
return gulp.src([
"pagina/*.html"
])
.pipe(
gulp.dest("server/")
);
});
gulp.task('inline', function () {
return gulp.src('pagina/*.html').pipe(
inline({
base: 'pagina/',
js: uglify,
css: cleancss
}
)
).pipe(htmlmin({
collapseWhitespace: true,
removeComments: true,
minifyCSS: true,
minifyJS: true
})).pipe(gzip()
).pipe(
gulp.dest("build/")
)
});
gulp.task('generarh', ['inline'], function () {
let source = "build/index.html.gz";
let destino = "server/index.html.gz.h";
let wstream = fs.createWriteStream(destino);
wstream.on('error', (err) => {
console.log(err);
});
let data = fs.readFileSync(source);
wstream.write("#define index_html_gz_len " + data.length + "\n");
wstream.write("const char index_html_gz[] = {\n");
for (let i = 0; i < data.length; i++) {
if (i % 30 == 0)
wstream.write('\n');
let d = ('00' + data[i].toString(16)).slice(-2);
wstream.write("0x" + d);
if (i < data.length - 1)
wstream.write(', ');
}
wstream.write('\n};');
wstream.end();
});
gulp.task('default', ['generarh']);