mirror of
https://github.com/openshwprojects/OpenBK7231T_App.git
synced 2026-02-19 16:22:07 +01:00
Added gulp script
This commit is contained in:
116
gulpfile.js
Normal file
116
gulpfile.js
Normal file
@@ -0,0 +1,116 @@
|
||||
const gulp = require("gulp");
|
||||
const uglify = require("gulp-uglify");
|
||||
const cssnano = require("gulp-cssnano");
|
||||
const through = require("through2");
|
||||
const path = require("path");
|
||||
const fs = require("fs");
|
||||
const readline = require("readline");
|
||||
|
||||
const destination = "new_http.c";
|
||||
|
||||
function dumpFileSize() {
|
||||
return through.obj(function (file, enc, cb) {
|
||||
console.log(
|
||||
`Processing ${file.basename}, original length ${file.stat.size}`
|
||||
);
|
||||
cb(null, file);
|
||||
});
|
||||
}
|
||||
|
||||
/** This function injects C for a const field in new_http.c */
|
||||
function generateCode(field_name, is_script) {
|
||||
return through.obj(function (file, enc, cb) {
|
||||
if (file.isBuffer()) {
|
||||
const contents = file.contents;
|
||||
|
||||
let output = String(contents);
|
||||
output = output.replace(/\"/g, '\\"');
|
||||
console.log(
|
||||
`Processing ${file.basename}, reduced length ${contents.length}`
|
||||
);
|
||||
|
||||
const prefix = is_script ? "<script type='text/javascript'>" : "<style>";
|
||||
const suffix = is_script ? "</script>" : "</style>";
|
||||
output = `const char ${field_name}[]="${prefix}${output}${suffix}";`;
|
||||
|
||||
const target_path = path.join(path.dirname(file.path), destination);
|
||||
//console.log(`Updated ${target_path}`);
|
||||
|
||||
const rl = readline.createInterface({
|
||||
input: fs.createReadStream(target_path),
|
||||
crlfDelay: Infinity,
|
||||
});
|
||||
|
||||
const merged_contents = [];
|
||||
const marker_start = `//region_start ${field_name}`;
|
||||
const marker_end = `//region_end ${field_name}`;
|
||||
let region_state = 0;
|
||||
|
||||
rl.on("line", (line) => {
|
||||
if (line.trim() === marker_start) {
|
||||
region_state = 1;
|
||||
merged_contents.push(marker_start);
|
||||
merged_contents.push(output);
|
||||
merged_contents.push(marker_end);
|
||||
} else {
|
||||
//Skip all existing content lines till region ends
|
||||
if (region_state === 1) {
|
||||
if (line.trim() === marker_end) {
|
||||
region_state = 2;
|
||||
}
|
||||
} else {
|
||||
merged_contents.push(line);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
rl.on("close", () => {
|
||||
if (region_state === 0) {
|
||||
//Starting marker was not found, append
|
||||
|
||||
merged_contents.push("");
|
||||
merged_contents.push(marker_start);
|
||||
merged_contents.push(output);
|
||||
merged_contents.push(marker_end);
|
||||
}
|
||||
|
||||
if (region_state === 1) {
|
||||
cb(`Ending marker "${marker_end}" was not found.`, file);
|
||||
} else {
|
||||
fs.writeFile(
|
||||
target_path,
|
||||
merged_contents.join("\r\n"),
|
||||
"utf8",
|
||||
(err) => {
|
||||
cb(err, file);
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
cb(null, file);
|
||||
});
|
||||
}
|
||||
|
||||
function minifyJs() {
|
||||
return (
|
||||
gulp
|
||||
.src("./src/httpserver/script.js")
|
||||
.pipe(dumpFileSize())
|
||||
.pipe(uglify())
|
||||
.pipe(generateCode("pageScript", true))
|
||||
);
|
||||
}
|
||||
|
||||
function minifyCss() {
|
||||
return gulp
|
||||
.src("./src/httpserver/style.css")
|
||||
.pipe(dumpFileSize())
|
||||
.pipe(cssnano())
|
||||
.pipe(generateCode("htmlHeadStyle", false));
|
||||
}
|
||||
|
||||
exports.default = gulp.series(minifyJs, minifyCss);
|
||||
9615
package-lock.json
generated
Normal file
9615
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
28
package.json
Normal file
28
package.json
Normal file
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"name": "obk-builder",
|
||||
"version": "1.0.0",
|
||||
"description": "Gulp based script content builder",
|
||||
"main": "gulpfile.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/iprak/OpenBK7231T_App.git"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"bugs": {
|
||||
"url": "https://github.com/iprak/OpenBK7231T_App/issues"
|
||||
},
|
||||
"homepage": "https://github.com/iprak/OpenBK7231T_App#readme",
|
||||
"devDependencies": {
|
||||
"gulp": "^4.0.2",
|
||||
"gulp-cssnano": "^2.1.3",
|
||||
"gulp-gzip": "^1.4.2",
|
||||
"gulp-rename": "^2.0.0",
|
||||
"gulp-uglify": "^3.0.2",
|
||||
"through2": "^4.0.2"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user