summaryrefslogtreecommitdiffstats
path: root/html/gulpfile.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 02:54:31 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 02:54:31 +0000
commit3b4936b6f2b870f9f2444ebb6ce1ca2de3f49d9f (patch)
treec91ab0ac9447b25f91c05e901212c2142fb95953 /html/gulpfile.js
parentInitial commit. (diff)
downloadttyd-3b4936b6f2b870f9f2444ebb6ce1ca2de3f49d9f.tar.xz
ttyd-3b4936b6f2b870f9f2444ebb6ce1ca2de3f49d9f.zip
Adding upstream version 1.7.4.upstream/1.7.4
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'html/gulpfile.js')
-rw-r--r--html/gulpfile.js64
1 files changed, 64 insertions, 0 deletions
diff --git a/html/gulpfile.js b/html/gulpfile.js
new file mode 100644
index 0000000..b1a4aad
--- /dev/null
+++ b/html/gulpfile.js
@@ -0,0 +1,64 @@
+const { src, dest, task, series } = require('gulp');
+const clean = require('gulp-clean');
+const gzip = require('gulp-gzip');
+const inlineSource = require('gulp-inline-source');
+const rename = require('gulp-rename');
+const through2 = require('through2');
+
+const genHeader = (size, buf, len) => {
+ let idx = 0;
+ let data = 'unsigned char index_html[] = {\n ';
+
+ for (const value of buf) {
+ idx++;
+
+ const 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`;
+ data += `unsigned int index_html_size = ${size};\n`;
+ return data;
+};
+let fileSize = 0;
+
+task('clean', () => {
+ return src('dist', { read: false, allowEmpty: true }).pipe(clean());
+});
+
+task('inline', () => {
+ return src('dist/index.html').pipe(inlineSource()).pipe(rename('inline.html')).pipe(dest('dist/'));
+});
+
+task(
+ 'default',
+ series('inline', () => {
+ return src('dist/inline.html')
+ .pipe(
+ through2.obj((file, enc, cb) => {
+ fileSize = file.contents.length;
+ return cb(null, file);
+ })
+ )
+ .pipe(gzip())
+ .pipe(
+ through2.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/'));
+ })
+);