cmake: remove xxd dependency

This commit is contained in:
Shuanglei Tao
2020-02-02 14:32:17 +08:00
parent 9f8e94d4a6
commit 0e728e61ce
8 changed files with 34061 additions and 12 deletions

View File

@@ -1,6 +1,39 @@
const { src, dest, task } = require("gulp");
const clean = require('gulp-clean');
const inlinesource = require('gulp-inline-source');
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})
@@ -9,6 +42,8 @@ task('clean', () => {
task('default', () => {
return src('dist/index.html')
.pipe(inlinesource())
.pipe(inlineSource())
.pipe(toCHeader())
.pipe(rename("html.h"))
.pipe(dest('../src/'));
});