mirror of
https://github.com/tsl0922/ttyd.git
synced 2025-12-23 20:24:20 +01:00
50 lines
1.3 KiB
JavaScript
50 lines
1.3 KiB
JavaScript
const { src, dest, task } = require("gulp");
|
|
const clean = require('gulp-clean');
|
|
const inlineSource = require('gulp-inline-source');
|
|
const rename = require("gulp-rename");
|
|
const through = require('through2');
|
|
|
|
const toCHeader = () => {
|
|
return through.obj((file, enc, cb) => {
|
|
const buf = file.contents;
|
|
const len = buf.length;
|
|
let idx = 0;
|
|
let data = "unsigned char index_html[] = {\n ";
|
|
|
|
for (const value of buf) {
|
|
idx++;
|
|
|
|
let current = value < 0 ? value + 256 : value;
|
|
|
|
data += "0x";
|
|
data += (current >>> 4).toString(16);
|
|
data += (current & 0xF).toString(16);
|
|
|
|
if (idx === len) {
|
|
data += "\n";
|
|
} else {
|
|
data += idx % 12 === 0 ? ",\n " : ", ";
|
|
}
|
|
}
|
|
|
|
data += "};\n";
|
|
data += `unsigned int index_html_len = ${len};\n`;
|
|
file.contents = Buffer.from(data);
|
|
|
|
return cb(null, file);
|
|
});
|
|
};
|
|
|
|
task('clean', () => {
|
|
return src('dist', {read: false, allowEmpty: true})
|
|
.pipe(clean());
|
|
});
|
|
|
|
task('default', () => {
|
|
return src('dist/index.html')
|
|
.pipe(inlineSource())
|
|
.pipe(toCHeader())
|
|
.pipe(rename("html.h"))
|
|
.pipe(dest('../src/'));
|
|
});
|