Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3.0 refactoring #76

Open
wants to merge 13 commits into
base: 3.0
Choose a base branch
from
  •  
  •  
  •  
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ for them go [here](https://github.com/luc-github/ESP3D)

[All releases](https://github.com/luc-github/ESP3DLib/releases)

> [!WARNING]
>### Disclaimer
> The software is provided 'as is,' without any warranty of any kind, expressed or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose, and non-infringement. In no event shall the authors or copyright holders be liable for any claim, damages, or other liability, whether in an action of contract, tort, or otherwise, arising from, out of, or in connection with the software or the use or other dealings in the software.
>It is essential that you carefully read and understand this disclaimer before using this software and its components. If you do not agree with any part of this disclaimer, please refrain from using the software.


## Sponsors
[<img width="200px" src="https://raw.githubusercontent.com/luc-github/ESP3DLib/master/images/sponsors-supporters/MKS/mksmakerbase.jpg" title="MKS Makerbase">](https://github.com/makerbase-mks)&nbsp;&nbsp;
Expand Down
27 changes: 27 additions & 0 deletions embedded/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"printWidth": 80,
"tabWidth": 4,
"useTabs": false,
"semi": true,
"singleQuote": false,
"trailingComma": "es5",
"bracketSpacing": true,
"bracketSameLine": false,
"arrowParens": "always",
"requirePragma": false,
"insertPragma": false,
"proseWrap": "preserve",
"overrides": [
{
"files": "*.js",
"options": {
"parser": "babel"
}
},
{"files": "*.scss",
"options": {
"parser": "css"
}
}
]
}
143 changes: 71 additions & 72 deletions embedded/config/buildassets.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,89 +7,88 @@ const chalk = require("chalk");
let distPath = path.normalize(__dirname + "/../dist/");
let srcPath = path.normalize(__dirname + "/../assets/");
let headerPath = path.normalize(
__dirname + "/../../src/modules/http/favicon.h"
__dirname + "/../../src/modules/http/favicon.h"
);



const convertToC = (filepath) => {
console.log(chalk.yellow("Converting bin to text file"));
//Cleaning files
if (fs.existsSync(distPath + "out.tmp")) fs.rmSync(distPath + "out.tmp");
if (fs.existsSync(distPath + "favicon.h")) fs.rmSync(distPath + "favicon.h");
console.log(chalk.yellow("Converting bin to text file"));
//Cleaning files
if (fs.existsSync(distPath + "out.tmp")) fs.rmSync(distPath + "out.tmp");
if (fs.existsSync(distPath + "favicon.h"))
fs.rmSync(distPath + "favicon.h");

const data = new Uint8Array(
fs.readFileSync(filepath, { flag: "r" })
);
console.log("data size is ", data.length);
let out = "#define favicon_size " + data.length + "\n";
out += "const unsigned char favicon[" + data.length + "] PROGMEM = {\n ";
let nb = 0;
data.forEach((byte, index) => {
out += " 0x" + (byte.toString(16).length == 1 ? "0" : "") + byte.toString(16);
if (index < data.length - 1) out += ",";
if (nb == 15) {
out += "\n ";
nb = 0;
} else {
nb++;
}
});
const data = new Uint8Array(fs.readFileSync(filepath, { flag: "r" }));
console.log("data size is ", data.length);
let out = "#define favicon_size " + data.length + "\n";
out += "const unsigned char favicon[" + data.length + "] PROGMEM = {\n ";
let nb = 0;
data.forEach((byte, index) => {
out +=
" 0x" +
(byte.toString(16).length == 1 ? "0" : "") +
byte.toString(16);
if (index < data.length - 1) out += ",";
if (nb == 15) {
out += "\n ";
nb = 0;
} else {
nb++;
}
});

out += "\n};\n";
fs.writeFileSync(distPath + "out.tmp", out);
out += "\n};\n";
fs.writeFileSync(distPath + "out.tmp", out);

//Check conversion
if (fs.existsSync(distPath + "out.tmp")) {
console.log(chalk.green("[ok]"));
} else {
console.log(chalk.red("[error]Conversion failed"));
return;
}

//Format header file
console.log(chalk.yellow("Building header"));
fs.writeFileSync(
distPath + "favicon.h",
fs.readFileSync(srcPath + "header.txt")
);
let bin2cfile = fs.readFileSync(distPath + "out.tmp").toString();
fs.appendFileSync(distPath + "favicon.h", bin2cfile);
fs.appendFileSync(
distPath + "favicon.h",
fs.readFileSync(srcPath + "footer.txt")
);
//Check conversion
if (fs.existsSync(distPath + "out.tmp")) {
console.log(chalk.green("[ok]"));
} else {
console.log(chalk.red("[error]Conversion failed"));
return;
}

//Check format result
if (fs.existsSync(distPath + "favicon.h")) {
console.log(chalk.green("[ok]"));
} else {
console.log(chalk.red("[error]Conversion failed"));
return;
}
//Format header file
console.log(chalk.yellow("Building header"));
fs.writeFileSync(
distPath + "favicon.h",
fs.readFileSync(srcPath + "header.txt")
);
let bin2cfile = fs.readFileSync(distPath + "out.tmp").toString();
fs.appendFileSync(distPath + "favicon.h", bin2cfile);
fs.appendFileSync(
distPath + "favicon.h",
fs.readFileSync(srcPath + "footer.txt")
);

//Move file to src
console.log(chalk.yellow("Overwriting header in sources"));
fs.writeFileSync(headerPath, fs.readFileSync(distPath + "favicon.h"));
if (fs.existsSync(headerPath)) {
console.log(chalk.green("[ok]"));
} else {
console.log(chalk.red("[error]Overwriting failed"));
return;
}
//Check format result
if (fs.existsSync(distPath + "favicon.h")) {
console.log(chalk.green("[ok]"));
} else {
console.log(chalk.red("[error]Conversion failed"));
return;
}

}
//Move file to src
console.log(chalk.yellow("Overwriting header in sources"));
fs.writeFileSync(headerPath, fs.readFileSync(distPath + "favicon.h"));
if (fs.existsSync(headerPath)) {
console.log(chalk.green("[ok]"));
} else {
console.log(chalk.red("[error]Overwriting failed"));
return;
}
};


// Create a gzip function for reusable purpose
const compressFile = (filePath, targetPath) => {
const stream = createReadStream(filePath);
stream
.pipe(createGzip(targetPath))
.pipe(createWriteStream(targetPath))
.on("finish", () =>{console.log(`Successfully compressed at ${targetPath}`);
convertToC (targetPath)}
);
const stream = createReadStream(filePath);
stream
.pipe(createGzip(targetPath))
.pipe(createWriteStream(targetPath))
.on("finish", () => {
console.log(`Successfully compressed at ${targetPath}`);
convertToC(targetPath);
});
};

compressFile(srcPath + "favicon.ico", distPath + "favicon.ico.gz");
compressFile(srcPath + "favicon.ico", distPath + "favicon.ico.gz");
47 changes: 24 additions & 23 deletions embedded/config/buildheader.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const chalk = require("chalk");
let distPath = path.normalize(__dirname + "/../dist/");
let srcPath = path.normalize(__dirname + "/../src/");
let headerPath = path.normalize(
__dirname + "/../../src/modules/http/embedded.h"
__dirname + "/../../src/modules/http/embedded.h"
);

console.log(chalk.yellow("Converting bin to text file"));
Expand All @@ -15,61 +15,62 @@ if (fs.existsSync(distPath + "out.tmp")) fs.rmSync(distPath + "out.tmp");
if (fs.existsSync(distPath + "embedded.h")) fs.rmSync(distPath + "embedded.h");

const data = new Uint8Array(
fs.readFileSync(distPath + "index.html.gz", { flag: "r" })
fs.readFileSync(distPath + "index.html.gz", { flag: "r" })
);
console.log("data size is ", data.length);
let out = "#define tool_html_gz_size " + data.length + "\n";
out += "const unsigned char tool_html_gz[" + data.length + "] PROGMEM = {\n ";
let nb = 0;
data.forEach((byte, index) => {
out += " 0x" + (byte.toString(16).length == 1 ? "0" : "") + byte.toString(16);
if (index < data.length - 1) out += ",";
if (nb == 15) {
out += "\n ";
nb = 0;
} else {
nb++;
}
out +=
" 0x" + (byte.toString(16).length == 1 ? "0" : "") + byte.toString(16);
if (index < data.length - 1) out += ",";
if (nb == 15) {
out += "\n ";
nb = 0;
} else {
nb++;
}
});

out += "\n};\n";
fs.writeFileSync(distPath + "out.tmp", out);

//Check conversion
if (fs.existsSync(distPath + "out.tmp")) {
console.log(chalk.green("[ok]"));
console.log(chalk.green("[ok]"));
} else {
console.log(chalk.red("[error]Conversion failed"));
return;
console.log(chalk.red("[error]Conversion failed"));
return;
}

//Format header file
console.log(chalk.yellow("Building header"));
fs.writeFileSync(
distPath + "embedded.h",
fs.readFileSync(srcPath + "header.txt")
distPath + "embedded.h",
fs.readFileSync(srcPath + "header.txt")
);
let bin2cfile = fs.readFileSync(distPath + "out.tmp").toString();
fs.appendFileSync(distPath + "embedded.h", bin2cfile);
fs.appendFileSync(
distPath + "embedded.h",
fs.readFileSync(srcPath + "footer.txt")
distPath + "embedded.h",
fs.readFileSync(srcPath + "footer.txt")
);

//Check format result
if (fs.existsSync(distPath + "embedded.h")) {
console.log(chalk.green("[ok]"));
console.log(chalk.green("[ok]"));
} else {
console.log(chalk.red("[error]Conversion failed"));
return;
console.log(chalk.red("[error]Conversion failed"));
return;
}

//Move file to src
console.log(chalk.yellow("Overwriting header in sources"));
fs.writeFileSync(headerPath, fs.readFileSync(distPath + "embedded.h"));
if (fs.existsSync(headerPath)) {
console.log(chalk.green("[ok]"));
console.log(chalk.green("[ok]"));
} else {
console.log(chalk.red("[error]Overwriting failed"));
return;
console.log(chalk.red("[error]Overwriting failed"));
return;
}
17 changes: 9 additions & 8 deletions embedded/config/pack_favicon.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ const path = require("path");
const { createReadStream, createWriteStream } = require("fs");
const { createGzip } = require("zlib");
const faviconPath = path.normalize(__dirname + "/../assets/favicon.ico");

// Create a gzip function for reusable purpose
const compressFile = (filePath) => {
const stream = createReadStream(filePath);
stream
.pipe(createGzip())
.pipe(createWriteStream(`${filePath}.gz`))
.on("finish", () =>console.log(`Successfully compressed the file at ${filePath}`)
);
const stream = createReadStream(filePath);
stream
.pipe(createGzip())
.pipe(createWriteStream(`${filePath}.gz`))
.on("finish", () =>
console.log(`Successfully compressed the file at ${filePath}`)
);
};
compressFile(faviconPath);
compressFile(faviconPath);
Loading
Loading