Skip to content

Commit 98a7078

Browse files
committed
Sync with latest ESP3D Code
Add scripts to format c/cpp/h/js/css/scss files
1 parent 83a767a commit 98a7078

File tree

91 files changed

+4859
-4329
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+4859
-4329
lines changed

embedded/.prettierrc

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"printWidth": 80,
3+
"tabWidth": 4,
4+
"useTabs": false,
5+
"semi": true,
6+
"singleQuote": false,
7+
"trailingComma": "es5",
8+
"bracketSpacing": true,
9+
"bracketSameLine": false,
10+
"arrowParens": "always",
11+
"requirePragma": false,
12+
"insertPragma": false,
13+
"proseWrap": "preserve",
14+
"overrides": [
15+
{
16+
"files": "*.js",
17+
"options": {
18+
"parser": "babel"
19+
}
20+
},
21+
{"files": "*.scss",
22+
"options": {
23+
"parser": "css"
24+
}
25+
}
26+
]
27+
}

embedded/config/buildassets.js

Lines changed: 71 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -7,89 +7,88 @@ const chalk = require("chalk");
77
let distPath = path.normalize(__dirname + "/../dist/");
88
let srcPath = path.normalize(__dirname + "/../assets/");
99
let headerPath = path.normalize(
10-
__dirname + "/../../src/modules/http/favicon.h"
10+
__dirname + "/../../src/modules/http/favicon.h"
1111
);
1212

13-
14-
1513
const convertToC = (filepath) => {
16-
console.log(chalk.yellow("Converting bin to text file"));
17-
//Cleaning files
18-
if (fs.existsSync(distPath + "out.tmp")) fs.rmSync(distPath + "out.tmp");
19-
if (fs.existsSync(distPath + "favicon.h")) fs.rmSync(distPath + "favicon.h");
14+
console.log(chalk.yellow("Converting bin to text file"));
15+
//Cleaning files
16+
if (fs.existsSync(distPath + "out.tmp")) fs.rmSync(distPath + "out.tmp");
17+
if (fs.existsSync(distPath + "favicon.h"))
18+
fs.rmSync(distPath + "favicon.h");
2019

21-
const data = new Uint8Array(
22-
fs.readFileSync(filepath, { flag: "r" })
23-
);
24-
console.log("data size is ", data.length);
25-
let out = "#define favicon_size " + data.length + "\n";
26-
out += "const unsigned char favicon[" + data.length + "] PROGMEM = {\n ";
27-
let nb = 0;
28-
data.forEach((byte, index) => {
29-
out += " 0x" + (byte.toString(16).length == 1 ? "0" : "") + byte.toString(16);
30-
if (index < data.length - 1) out += ",";
31-
if (nb == 15) {
32-
out += "\n ";
33-
nb = 0;
34-
} else {
35-
nb++;
36-
}
37-
});
20+
const data = new Uint8Array(fs.readFileSync(filepath, { flag: "r" }));
21+
console.log("data size is ", data.length);
22+
let out = "#define favicon_size " + data.length + "\n";
23+
out += "const unsigned char favicon[" + data.length + "] PROGMEM = {\n ";
24+
let nb = 0;
25+
data.forEach((byte, index) => {
26+
out +=
27+
" 0x" +
28+
(byte.toString(16).length == 1 ? "0" : "") +
29+
byte.toString(16);
30+
if (index < data.length - 1) out += ",";
31+
if (nb == 15) {
32+
out += "\n ";
33+
nb = 0;
34+
} else {
35+
nb++;
36+
}
37+
});
3838

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

42-
//Check conversion
43-
if (fs.existsSync(distPath + "out.tmp")) {
44-
console.log(chalk.green("[ok]"));
45-
} else {
46-
console.log(chalk.red("[error]Conversion failed"));
47-
return;
48-
}
49-
50-
//Format header file
51-
console.log(chalk.yellow("Building header"));
52-
fs.writeFileSync(
53-
distPath + "favicon.h",
54-
fs.readFileSync(srcPath + "header.txt")
55-
);
56-
let bin2cfile = fs.readFileSync(distPath + "out.tmp").toString();
57-
fs.appendFileSync(distPath + "favicon.h", bin2cfile);
58-
fs.appendFileSync(
59-
distPath + "favicon.h",
60-
fs.readFileSync(srcPath + "footer.txt")
61-
);
42+
//Check conversion
43+
if (fs.existsSync(distPath + "out.tmp")) {
44+
console.log(chalk.green("[ok]"));
45+
} else {
46+
console.log(chalk.red("[error]Conversion failed"));
47+
return;
48+
}
6249

63-
//Check format result
64-
if (fs.existsSync(distPath + "favicon.h")) {
65-
console.log(chalk.green("[ok]"));
66-
} else {
67-
console.log(chalk.red("[error]Conversion failed"));
68-
return;
69-
}
50+
//Format header file
51+
console.log(chalk.yellow("Building header"));
52+
fs.writeFileSync(
53+
distPath + "favicon.h",
54+
fs.readFileSync(srcPath + "header.txt")
55+
);
56+
let bin2cfile = fs.readFileSync(distPath + "out.tmp").toString();
57+
fs.appendFileSync(distPath + "favicon.h", bin2cfile);
58+
fs.appendFileSync(
59+
distPath + "favicon.h",
60+
fs.readFileSync(srcPath + "footer.txt")
61+
);
7062

71-
//Move file to src
72-
console.log(chalk.yellow("Overwriting header in sources"));
73-
fs.writeFileSync(headerPath, fs.readFileSync(distPath + "favicon.h"));
74-
if (fs.existsSync(headerPath)) {
75-
console.log(chalk.green("[ok]"));
76-
} else {
77-
console.log(chalk.red("[error]Overwriting failed"));
78-
return;
79-
}
63+
//Check format result
64+
if (fs.existsSync(distPath + "favicon.h")) {
65+
console.log(chalk.green("[ok]"));
66+
} else {
67+
console.log(chalk.red("[error]Conversion failed"));
68+
return;
69+
}
8070

81-
}
71+
//Move file to src
72+
console.log(chalk.yellow("Overwriting header in sources"));
73+
fs.writeFileSync(headerPath, fs.readFileSync(distPath + "favicon.h"));
74+
if (fs.existsSync(headerPath)) {
75+
console.log(chalk.green("[ok]"));
76+
} else {
77+
console.log(chalk.red("[error]Overwriting failed"));
78+
return;
79+
}
80+
};
8281

83-
8482
// Create a gzip function for reusable purpose
8583
const compressFile = (filePath, targetPath) => {
86-
const stream = createReadStream(filePath);
87-
stream
88-
.pipe(createGzip(targetPath))
89-
.pipe(createWriteStream(targetPath))
90-
.on("finish", () =>{console.log(`Successfully compressed at ${targetPath}`);
91-
convertToC (targetPath)}
92-
);
84+
const stream = createReadStream(filePath);
85+
stream
86+
.pipe(createGzip(targetPath))
87+
.pipe(createWriteStream(targetPath))
88+
.on("finish", () => {
89+
console.log(`Successfully compressed at ${targetPath}`);
90+
convertToC(targetPath);
91+
});
9392
};
9493

95-
compressFile(srcPath + "favicon.ico", distPath + "favicon.ico.gz");
94+
compressFile(srcPath + "favicon.ico", distPath + "favicon.ico.gz");

embedded/config/buildheader.js

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const chalk = require("chalk");
66
let distPath = path.normalize(__dirname + "/../dist/");
77
let srcPath = path.normalize(__dirname + "/../src/");
88
let headerPath = path.normalize(
9-
__dirname + "/../../src/modules/http/embedded.h"
9+
__dirname + "/../../src/modules/http/embedded.h"
1010
);
1111

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

1717
const data = new Uint8Array(
18-
fs.readFileSync(distPath + "index.html.gz", { flag: "r" })
18+
fs.readFileSync(distPath + "index.html.gz", { flag: "r" })
1919
);
2020
console.log("data size is ", data.length);
2121
let out = "#define tool_html_gz_size " + data.length + "\n";
2222
out += "const unsigned char tool_html_gz[" + data.length + "] PROGMEM = {\n ";
2323
let nb = 0;
2424
data.forEach((byte, index) => {
25-
out += " 0x" + (byte.toString(16).length == 1 ? "0" : "") + byte.toString(16);
26-
if (index < data.length - 1) out += ",";
27-
if (nb == 15) {
28-
out += "\n ";
29-
nb = 0;
30-
} else {
31-
nb++;
32-
}
25+
out +=
26+
" 0x" + (byte.toString(16).length == 1 ? "0" : "") + byte.toString(16);
27+
if (index < data.length - 1) out += ",";
28+
if (nb == 15) {
29+
out += "\n ";
30+
nb = 0;
31+
} else {
32+
nb++;
33+
}
3334
});
3435

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

3839
//Check conversion
3940
if (fs.existsSync(distPath + "out.tmp")) {
40-
console.log(chalk.green("[ok]"));
41+
console.log(chalk.green("[ok]"));
4142
} else {
42-
console.log(chalk.red("[error]Conversion failed"));
43-
return;
43+
console.log(chalk.red("[error]Conversion failed"));
44+
return;
4445
}
4546

4647
//Format header file
4748
console.log(chalk.yellow("Building header"));
4849
fs.writeFileSync(
49-
distPath + "embedded.h",
50-
fs.readFileSync(srcPath + "header.txt")
50+
distPath + "embedded.h",
51+
fs.readFileSync(srcPath + "header.txt")
5152
);
5253
let bin2cfile = fs.readFileSync(distPath + "out.tmp").toString();
5354
fs.appendFileSync(distPath + "embedded.h", bin2cfile);
5455
fs.appendFileSync(
55-
distPath + "embedded.h",
56-
fs.readFileSync(srcPath + "footer.txt")
56+
distPath + "embedded.h",
57+
fs.readFileSync(srcPath + "footer.txt")
5758
);
5859

5960
//Check format result
6061
if (fs.existsSync(distPath + "embedded.h")) {
61-
console.log(chalk.green("[ok]"));
62+
console.log(chalk.green("[ok]"));
6263
} else {
63-
console.log(chalk.red("[error]Conversion failed"));
64-
return;
64+
console.log(chalk.red("[error]Conversion failed"));
65+
return;
6566
}
6667

6768
//Move file to src
6869
console.log(chalk.yellow("Overwriting header in sources"));
6970
fs.writeFileSync(headerPath, fs.readFileSync(distPath + "embedded.h"));
7071
if (fs.existsSync(headerPath)) {
71-
console.log(chalk.green("[ok]"));
72+
console.log(chalk.green("[ok]"));
7273
} else {
73-
console.log(chalk.red("[error]Overwriting failed"));
74-
return;
74+
console.log(chalk.red("[error]Overwriting failed"));
75+
return;
7576
}

embedded/config/pack_favicon.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ const path = require("path");
22
const { createReadStream, createWriteStream } = require("fs");
33
const { createGzip } = require("zlib");
44
const faviconPath = path.normalize(__dirname + "/../assets/favicon.ico");
5-
5+
66
// Create a gzip function for reusable purpose
77
const compressFile = (filePath) => {
8-
const stream = createReadStream(filePath);
9-
stream
10-
.pipe(createGzip())
11-
.pipe(createWriteStream(`${filePath}.gz`))
12-
.on("finish", () =>console.log(`Successfully compressed the file at ${filePath}`)
13-
);
8+
const stream = createReadStream(filePath);
9+
stream
10+
.pipe(createGzip())
11+
.pipe(createWriteStream(`${filePath}.gz`))
12+
.on("finish", () =>
13+
console.log(`Successfully compressed the file at ${filePath}`)
14+
);
1415
};
15-
compressFile(faviconPath);
16+
compressFile(faviconPath);

0 commit comments

Comments
 (0)