mirror of
https://github.com/tsl0922/ttyd.git
synced 2026-02-06 10:04:23 +01:00
html: embed gziped version
This commit is contained in:
@@ -1,39 +1,36 @@
|
||||
const { src, dest, task } = require("gulp");
|
||||
const clean = require('gulp-clean');
|
||||
const gzip = require('gulp-gzip');
|
||||
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 ";
|
||||
const genHeader = (size, buf, len) => {
|
||||
let idx = 0;
|
||||
let data = "unsigned char index_html[] = {\n ";
|
||||
|
||||
for (const value of buf) {
|
||||
idx++;
|
||||
for (const value of buf) {
|
||||
idx++;
|
||||
|
||||
let current = value < 0 ? value + 256 : value;
|
||||
let current = value < 0 ? value + 256 : value;
|
||||
|
||||
data += "0x";
|
||||
data += (current >>> 4).toString(16);
|
||||
data += (current & 0xF).toString(16);
|
||||
data += "0x";
|
||||
data += (current >>> 4).toString(16);
|
||||
data += (current & 0xF).toString(16);
|
||||
|
||||
if (idx === len) {
|
||||
data += "\n";
|
||||
} else {
|
||||
data += idx % 12 === 0 ? ",\n " : ", ";
|
||||
}
|
||||
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);
|
||||
});
|
||||
data += "};\n";
|
||||
data += `unsigned int index_html_len = ${len};\n`;
|
||||
data += `unsigned int index_html_size = ${size};\n`;
|
||||
return data;
|
||||
};
|
||||
let fileSize = 0;
|
||||
|
||||
task('clean', () => {
|
||||
return src('dist', {read: false, allowEmpty: true})
|
||||
@@ -43,7 +40,16 @@ task('clean', () => {
|
||||
task('default', () => {
|
||||
return src('dist/index.html')
|
||||
.pipe(inlineSource())
|
||||
.pipe(toCHeader())
|
||||
.pipe(through.obj((file, enc, cb) => {
|
||||
fileSize = file.contents.length;
|
||||
return cb(null, file);
|
||||
}))
|
||||
.pipe(gzip())
|
||||
.pipe(through.obj((file, enc, cb) => {
|
||||
const buf = file.contents;
|
||||
file.contents = Buffer.from(genHeader(fileSize, buf, buf.length));
|
||||
return cb(null, file);
|
||||
}))
|
||||
.pipe(rename("html.h"))
|
||||
.pipe(dest('../src/'));
|
||||
});
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
"gts": "^1.1.2",
|
||||
"gulp": "^4.0.2",
|
||||
"gulp-clean": "^0.4.0",
|
||||
"gulp-gzip": "^1.4.2",
|
||||
"gulp-inline-source": "^4.0.0",
|
||||
"gulp-rename": "^2.0.0",
|
||||
"html-webpack-plugin": "^3.2.0",
|
||||
|
||||
@@ -415,6 +415,11 @@ any-observable@^0.3.0:
|
||||
resolved "https://registry.yarnpkg.com/any-observable/-/any-observable-0.3.0.tgz#af933475e5806a67d0d7df090dd5e8bef65d119b"
|
||||
integrity sha512-/FQM1EDkTsf63Ub2C6O7GuYFDsSXUwsaZDurV0np41ocwq0jthUAYCmhBX9f+KwlaCgIuWyr/4WlUQUBfKfZog==
|
||||
|
||||
any-promise@^1.1.0:
|
||||
version "1.3.0"
|
||||
resolved "https://registry.yarnpkg.com/any-promise/-/any-promise-1.3.0.tgz#abc6afeedcea52e809cdc0376aed3ce39635d17f"
|
||||
integrity sha1-q8av7tzqUugJzcA3au0845Y10X8=
|
||||
|
||||
anymatch@^2.0.0:
|
||||
version "2.0.0"
|
||||
resolved "https://registry.yarnpkg.com/anymatch/-/anymatch-2.0.0.tgz#bcb24b4f37934d9aa7ac17b4adaf89e7c76ef2eb"
|
||||
@@ -950,7 +955,7 @@ bytes@3.0.0:
|
||||
resolved "https://registry.yarnpkg.com/bytes/-/bytes-3.0.0.tgz#d32815404d689699f85a4ea4fa8755dd13a96048"
|
||||
integrity sha1-0ygVQE1olpn4Wk6k+odV3ROpYEg=
|
||||
|
||||
bytes@3.1.0:
|
||||
bytes@3.1.0, bytes@^3.0.0:
|
||||
version "3.1.0"
|
||||
resolved "https://registry.yarnpkg.com/bytes/-/bytes-3.1.0.tgz#f6cf7933a360e0588fa9fde85651cdc7f805d1f6"
|
||||
integrity sha512-zauLjrfCG+xvoyaqLoV8bLVXXNGC4JqlxFCutSDWA6fJrTo2ZuvLYTqZ7aHBLZSMOopbzwv8f+wZcVzfVTI2Dg==
|
||||
@@ -3282,6 +3287,18 @@ gulp-cli@^2.2.0:
|
||||
v8flags "^3.0.1"
|
||||
yargs "^7.1.0"
|
||||
|
||||
gulp-gzip@^1.4.2:
|
||||
version "1.4.2"
|
||||
resolved "https://registry.yarnpkg.com/gulp-gzip/-/gulp-gzip-1.4.2.tgz#0422a94014248655b5b1a9eea1c2abee1d4f4337"
|
||||
integrity sha512-ZIxfkUwk2XmZPTT9pPHrHUQlZMyp9nPhg2sfoeN27mBGpi7OaHnOD+WCN41NXjfJQ69lV1nQ9LLm1hYxx4h3UQ==
|
||||
dependencies:
|
||||
ansi-colors "^1.0.1"
|
||||
bytes "^3.0.0"
|
||||
fancy-log "^1.3.2"
|
||||
plugin-error "^1.0.0"
|
||||
stream-to-array "^2.3.0"
|
||||
through2 "^2.0.3"
|
||||
|
||||
gulp-inline-source@^4.0.0:
|
||||
version "4.0.0"
|
||||
resolved "https://registry.yarnpkg.com/gulp-inline-source/-/gulp-inline-source-4.0.0.tgz#e0958b631719fc6a91bee29905415fa825164c69"
|
||||
@@ -5881,7 +5898,7 @@ plugin-error@^0.1.2:
|
||||
arr-union "^2.0.1"
|
||||
extend-shallow "^1.1.2"
|
||||
|
||||
plugin-error@~1.0.1:
|
||||
plugin-error@^1.0.0, plugin-error@~1.0.1:
|
||||
version "1.0.1"
|
||||
resolved "https://registry.yarnpkg.com/plugin-error/-/plugin-error-1.0.1.tgz#77016bd8919d0ac377fdcdd0322328953ca5781c"
|
||||
integrity sha512-L1zP0dk7vGweZME2i+EeakvUNqSrdiI3F91TwEoYiGrAfUXmVv6fJIq4g82PAXxNsWOp0J7ZqQy/3Szz0ajTxA==
|
||||
@@ -7384,6 +7401,13 @@ stream-shift@^1.0.0:
|
||||
resolved "https://registry.yarnpkg.com/stream-shift/-/stream-shift-1.0.0.tgz#d5c752825e5367e786f78e18e445ea223a155952"
|
||||
integrity sha1-1cdSgl5TZ+eG944Y5EXqIjoVWVI=
|
||||
|
||||
stream-to-array@^2.3.0:
|
||||
version "2.3.0"
|
||||
resolved "https://registry.yarnpkg.com/stream-to-array/-/stream-to-array-2.3.0.tgz#bbf6b39f5f43ec30bc71babcb37557acecf34353"
|
||||
integrity sha1-u/azn19D7DC8cbq8s3VXrOzzQ1M=
|
||||
dependencies:
|
||||
any-promise "^1.1.0"
|
||||
|
||||
strict-uri-encode@^1.0.0:
|
||||
version "1.1.0"
|
||||
resolved "https://registry.yarnpkg.com/strict-uri-encode/-/strict-uri-encode-1.1.0.tgz#279b225df1d582b1f54e65addd4352e18faa0713"
|
||||
|
||||
Reference in New Issue
Block a user