-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.mjs
More file actions
132 lines (105 loc) · 3.89 KB
/
gulpfile.mjs
File metadata and controls
132 lines (105 loc) · 3.89 KB
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
/*
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/>.
*/
// -----------------------------------------------------------------------------
// File system builder
// -----------------------------------------------------------------------------
// const { series, src, dest } = require('gulp');
// const htmlmin = require('gulp-htmlmin');
// const cleancss = require('gulp-clean-css');
// const uglify = require('gulp-uglify-es').default;
// const gzip = require('gulp-gzip');
// const del = require('del');
// const inline = require('gulp-inline');
// const inlineImages = require('gulp-css-base64');
// const favicon = require('gulp-base64-favicon');
// const fs = require('fs');
import gulp from 'gulp';
const { series, src, dest } = gulp;
import htmlmin from 'gulp-htmlmin';
import cleancss from 'gulp-clean-css';
import uglify from 'gulp-uglify-es';
import gzip from 'gulp-gzip';
import { deleteAsync } from 'del';
import inline from 'gulp-inline';
import inlineImages from 'gulp-css-base64';
import favicon from 'gulp-base64-favicon';
import fs from 'fs';
import crypto from 'crypto';
function clean(cb) {
deleteAsync(["dist/*"]);
cb();
}
function build(cb) {
cb();
}
function buildfs_inline(cb) {
return src('html/*.html')
.pipe(favicon({ src: "html" }))
.pipe(inline({
base: 'html/',
// js: uglify,
css: [cleancss, inlineImages],
// disabledTypes: ['svg', 'img']
}))
.pipe(htmlmin({
// collapseWhitespace: true,
removecomments: true,
minifyCSS: true,
minifyJS: true
}))
.pipe(gzip())
.pipe(dest("dist"));
}
function buildfs_embeded(cb) {
var source = 'dist/index.html.gz';
var destination = 'include/index.html.gz.h';
write_header_file(source, destination, "index_html_gz");
cb();
}
function buildfs_logo_gz(cb) {
return src('html/favicon.ico')
.pipe(gzip())
.pipe(dest("dist"));
}
function buildfs_logo_embedded(cb) {
var source = 'dist/favicon.ico.gz';
var destination = 'include/favicon.ico.gz.h';
write_header_file(source, destination, "favicon_gz");
cb();
}
function write_header_file(source, destination, name) {
const wstream = fs.createWriteStream(destination);
wstream.on('error', function (err) {
console.log(err);
});
const data = fs.readFileSync(source);
const hashSum = crypto.createHash('sha256');
hashSum.update(data);
const hex = hashSum.digest('hex');
wstream.write(`#define ${name}_len ${data.length}\n`);
wstream.write(`const char ${name}_sha[] = "${hex}";\n`);
wstream.write(`const uint8_t ${name}[] = {`);
for (var 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();
deleteAsync([source]);
}
const all = series(clean, buildfs_inline, buildfs_embeded, buildfs_logo_gz, buildfs_logo_embedded);
export default all;
//export build;