Skip to content

Commit d05af49

Browse files
committed
Add the web page files and tools for building the header file
1 parent a33b495 commit d05af49

24 files changed

+3763
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
*.DS_Store
22
*.hex
33
releases*
4+
node_modules

build-web.js

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#! /usr/bin/env node
2+
3+
var fs = require("fs");
4+
var mime = require( "mime-types" );
5+
var inline = require( "web-resource-inliner" );
6+
var minify = require('html-minifier').minify;
7+
8+
var files = [
9+
{name: "index.html", process: true},
10+
{name: "favicon.ico", process: false}
11+
]
12+
var fileCount = files.length;
13+
14+
var baseDir = './web/';
15+
var outFile = './src/lib/web.h';
16+
17+
var minifySettings = {minifyJS: true, minifyCSS: true}
18+
19+
outFiles = [];
20+
21+
function convert(f){
22+
var data = new Buffer(f[1]);
23+
byteData = []
24+
for(var i=0; i<data.length; i++){
25+
byteData.push("0x" + data[i].toString(16));
26+
}
27+
var dataname = f[0].replace('.', '_');
28+
return ["const char " + dataname + "[] PROGMEM = { " + byteData + " };" , f[0], dataname, data.length, mime.lookup(f[0])]
29+
}
30+
31+
function makeHeaderFile(){
32+
if(fileCount) return;
33+
var data = outFiles.map(convert);
34+
output = data.map(function(d){
35+
return d[0];
36+
}).join("\n");
37+
output += "\nstruct t_websitefiles {\n const char* filename;\n const char* mime;\n const unsigned int len;\n const char* content;\n} files[] = {\n";
38+
output += data.map(function(d){
39+
return ' {.filename = "/' + d[1] + '", .mime = "' + d[4] + '", .len = ' + d[3] + ', .content = &' + d[2] + '[0]}'
40+
}).join(',\n');
41+
output += '};\nuint8_t fileCount = ' + files.length + ';\n';
42+
fs.writeFileSync(outFile, output);
43+
}
44+
45+
files.map(function (f){
46+
if(f.process){
47+
// Process the file:
48+
// - bring all resources inline
49+
// - minify the css and js
50+
// - inline the images
51+
inline.html({
52+
fileContent: fs.readFileSync( baseDir + f.name, "utf8" ),
53+
strict: true,
54+
uglify: false,
55+
cssmin: false,
56+
scripts: true,
57+
relativeTo: baseDir
58+
},
59+
function( err, result ){
60+
if(err) return console.log(err);
61+
outFiles.push([f.name, minify(result, minifySettings)]);
62+
fileCount--;
63+
makeHeaderFile();
64+
}
65+
);
66+
}else{
67+
// Just copy the file across
68+
outFiles.push([f.name, fs.readFileSync( baseDir + f.name )]);
69+
fileCount--;
70+
makeHeaderFile();
71+
}
72+
})

package.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "CompressUI",
3+
"description": "Compress the Mirobot UI",
4+
"version": "1.0.0",
5+
"dependencies": {
6+
"html-minifier": "1.2.0",
7+
"web-resource-inliner": "1.2.1",
8+
"mime-types": "2.1.10"
9+
}
10+
}

web/FileSaver.min.js

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)