cc4-embedded-system 3.1.7 → 3.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/makefsdata.js +35 -22
- package/dist/public/index.html +16 -13
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
- This version based on [html-minifier-next](https://github.com/j9t/html-minifier-next) and rewrite [lwIP makefsdata](https://github.com/m-labs/lwip/tree/master/src/apps/httpd/makefsdata), run on localhost, default port: ```3000```.
|
|
3
3
|
- This tool is deployed on [npm package](https://www.npmjs.com/package/cc4-embedded-system).
|
|
4
4
|
|
|
5
|
-

|
|
6
6
|
|
|
7
7
|
## Structure
|
|
8
8
|
```text
|
|
@@ -14,7 +14,7 @@ CC4EmbeddedSystem/
|
|
|
14
14
|
├── public/
|
|
15
15
|
│ └── index.html // Web GUI dashboard
|
|
16
16
|
├── Sereenshot/
|
|
17
|
-
│ └── v3.1.
|
|
17
|
+
│ └── v3.1.9.png // Demo image
|
|
18
18
|
├── node_modules/ // Required submodules during development
|
|
19
19
|
├── dist/ // Compiled JavaScript output (Auto-generated)
|
|
20
20
|
├── package.json // Project configuration & dependencies
|
package/dist/makefsdata.js
CHANGED
|
@@ -75,6 +75,7 @@ const COMPRESS_OPTS_DEFAULT = {
|
|
|
75
75
|
processConditionalComments: true,
|
|
76
76
|
decodeEntities: true
|
|
77
77
|
};
|
|
78
|
+
const REDIRHOME_PATH = '/redirhome.html';
|
|
78
79
|
// ----------------------------------------------------------------------
|
|
79
80
|
// 3. lwIP Helpers
|
|
80
81
|
// ----------------------------------------------------------------------
|
|
@@ -245,6 +246,14 @@ export async function runMakeFsData(opts) {
|
|
|
245
246
|
}
|
|
246
247
|
fileEntries.push({ varName, pathName: relativePath, nameBuffer, headerParts: headerData.parts, headerTotalBuffer: headerData.totalBuffer, contentBuffer: content, chksums });
|
|
247
248
|
}
|
|
249
|
+
// find real redirhome.html
|
|
250
|
+
const redirhomeIndex = fileEntries.findIndex(file => file.pathName.toLowerCase() === REDIRHOME_PATH);
|
|
251
|
+
const hasRealRedirhome = redirhomeIndex >= 0;
|
|
252
|
+
const orderedFileEntries = hasRealRedirhome
|
|
253
|
+
? fileEntries.slice(redirhomeIndex).concat(fileEntries.slice(0, redirhomeIndex))
|
|
254
|
+
: fileEntries;
|
|
255
|
+
if (hasRealRedirhome)
|
|
256
|
+
console.log(`🔗 Bridge compatibility enabled: using ${REDIRHOME_PATH} as static chain head.`);
|
|
248
257
|
// ====================================================================
|
|
249
258
|
// C Code Generation
|
|
250
259
|
// ====================================================================
|
|
@@ -253,7 +262,7 @@ export async function runMakeFsData(opts) {
|
|
|
253
262
|
cOutput += `#define file_NULL (struct fsdata_file *) NULL\n\n\n`;
|
|
254
263
|
if (opts.precalcChksum) {
|
|
255
264
|
cOutput += `#if HTTPD_PRECALCULATED_CHECKSUM\n`;
|
|
256
|
-
for (const file of
|
|
265
|
+
for (const file of orderedFileEntries) {
|
|
257
266
|
cOutput += `const struct fsdata_chksum chksums_${file.varName}[] = {\n`;
|
|
258
267
|
for (const chk of file.chksums)
|
|
259
268
|
cOutput += `\t{${chk.offset}, 0x${chk.chksum.toString(16).padStart(4, '0')}, ${chk.len}},\n`;
|
|
@@ -262,7 +271,7 @@ export async function runMakeFsData(opts) {
|
|
|
262
271
|
cOutput += `#endif /* HTTPD_PRECALCULATED_CHECKSUM */\n\n\n`;
|
|
263
272
|
}
|
|
264
273
|
// generate data arrays
|
|
265
|
-
for (const file of
|
|
274
|
+
for (const file of orderedFileEntries) {
|
|
266
275
|
cOutput += `static const unsigned int dummy_align_${file.varName} = 0;\n`;
|
|
267
276
|
cOutput += `static const unsigned char data_${file.varName}[] = {\n`;
|
|
268
277
|
cOutput += `\t/* ${file.pathName} (${file.nameBuffer.length} chars) */\n`;
|
|
@@ -281,24 +290,26 @@ export async function runMakeFsData(opts) {
|
|
|
281
290
|
cOutput += bufferToHexCArray(file.contentBuffer);
|
|
282
291
|
cOutput += `};\n\n\n\n`;
|
|
283
292
|
}
|
|
284
|
-
// redirhome.html
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
293
|
+
// if no real redirhome.html, generate empty arrays
|
|
294
|
+
if (!hasRealRedirhome) {
|
|
295
|
+
cOutput += `/* --- Empty arrays --- */\n`;
|
|
296
|
+
cOutput += `static const unsigned char data__redirhome_html[] = {};\n`;
|
|
297
|
+
cOutput += `const struct fsdata_file file__redirhome_html[] = { {\n`;
|
|
298
|
+
cOutput += `\tfile_NULL,\n`;
|
|
299
|
+
cOutput += `\tdata__redirhome_html,\n`;
|
|
300
|
+
cOutput += `\tdata__redirhome_html + 16,\n`;
|
|
301
|
+
cOutput += `\tsizeof(data__redirhome_html) - 16,\n`;
|
|
302
|
+
cOutput += `\t1,\n`;
|
|
303
|
+
if (opts.precalcChksum)
|
|
304
|
+
cOutput += `#if HTTPD_PRECALCULATED_CHECKSUM\n\t0, NULL,\n#endif /* HTTPD_PRECALCULATED_CHECKSUM */\n`;
|
|
305
|
+
cOutput += `}};\n\n\n`;
|
|
306
|
+
}
|
|
297
307
|
// generate linked-list
|
|
298
|
-
for (let i =
|
|
299
|
-
const current =
|
|
300
|
-
|
|
301
|
-
|
|
308
|
+
for (let i = orderedFileEntries.length - 1; i >= 0; i--) {
|
|
309
|
+
const current = orderedFileEntries[i];
|
|
310
|
+
const nextVar = orderedFileEntries[i + 1]
|
|
311
|
+
? `file_${orderedFileEntries[i + 1].varName}`
|
|
312
|
+
: (hasRealRedirhome ? 'file_NULL' : 'file__redirhome_html');
|
|
302
313
|
const nameLen = current.nameBuffer.length;
|
|
303
314
|
// address: e.g. "/index.html\0" = '/' + 'i' + 'n' + 'd' + 'e' + 'x' + '.' + 'h' + 't' + 'm' + 'l' + '\0' = 12
|
|
304
315
|
cOutput += `const struct fsdata_file file_${current.varName}[] = { {\n`;
|
|
@@ -307,15 +318,17 @@ export async function runMakeFsData(opts) {
|
|
|
307
318
|
cOutput += `#if HTTPD_PRECALCULATED_CHECKSUM\n\t${current.chksums.length}, chksums_${current.varName},\n#endif /* HTTPD_PRECALCULATED_CHECKSUM */\n`;
|
|
308
319
|
cOutput += `}};\n\n`;
|
|
309
320
|
}
|
|
310
|
-
const rootNode =
|
|
321
|
+
const rootNode = orderedFileEntries[0];
|
|
311
322
|
if (rootNode) {
|
|
312
|
-
cOutput += `#define FS_ROOT file_${rootNode.varName}\n#define FS_NUMFILES ${
|
|
323
|
+
cOutput += `#define FS_ROOT file_${rootNode.varName}\n#define FS_NUMFILES ${orderedFileEntries.length + (hasRealRedirhome ? 0 : 1)}\n`;
|
|
313
324
|
fs.writeFileSync(opts.outputFile, cOutput);
|
|
325
|
+
const convertedSize = fs.statSync(opts.outputFile).size;
|
|
314
326
|
console.log(`\n✨ Success! Output written to: ${opts.outputFile}`);
|
|
315
327
|
return {
|
|
316
328
|
originalSize: totalOriginalSize,
|
|
317
329
|
compressedSize: totalCompressedSize,
|
|
318
|
-
|
|
330
|
+
convertedSize: convertedSize,
|
|
331
|
+
filesCount: orderedFileEntries.length
|
|
319
332
|
};
|
|
320
333
|
}
|
|
321
334
|
throw new Error("No files processed.");
|
package/dist/public/index.html
CHANGED
|
@@ -94,12 +94,13 @@
|
|
|
94
94
|
</div>
|
|
95
95
|
</details>
|
|
96
96
|
|
|
97
|
-
<div id="statsPanel" class="stats-panel">
|
|
98
|
-
<div class="stats-title">📊 Compression Analysis</div>
|
|
99
|
-
<div class="stats-info">
|
|
100
|
-
<span>Compressed: <span id="compSize" style="color: #9cdcfe;">0</span> KB</span>
|
|
101
|
-
<span>
|
|
102
|
-
|
|
97
|
+
<div id="statsPanel" class="stats-panel">
|
|
98
|
+
<div class="stats-title">📊 Compression Analysis</div>
|
|
99
|
+
<div class="stats-info">
|
|
100
|
+
<span>Compressed: <span id="compSize" style="color: #9cdcfe;">0</span> KB</span>
|
|
101
|
+
<span>Converted: <span id="convSize" style="color: #dcdcaa;">0</span> KB</span>
|
|
102
|
+
<span>Original: <span id="origSize" style="color: #ce9178;">0</span> KB</span>
|
|
103
|
+
</div>
|
|
103
104
|
<div class="bar-container">
|
|
104
105
|
<div id="barFill" class="bar-fill"></div>
|
|
105
106
|
<div id="barText" class="bar-text">0% Saved</div>
|
|
@@ -261,18 +262,20 @@
|
|
|
261
262
|
const panel = document.getElementById('statsPanel');
|
|
262
263
|
panel.style.display = 'block';
|
|
263
264
|
|
|
264
|
-
const { originalSize, compressedSize } = result.stats;
|
|
265
|
-
const origKB = (originalSize / 1024).toFixed(2);
|
|
266
|
-
const compKB = (compressedSize / 1024).toFixed(2);
|
|
265
|
+
const { originalSize, compressedSize, convertedSize } = result.stats;
|
|
266
|
+
const origKB = (originalSize / 1024).toFixed(2);
|
|
267
|
+
const compKB = (compressedSize / 1024).toFixed(2);
|
|
268
|
+
const convKB = (convertedSize / 1024).toFixed(2);
|
|
267
269
|
|
|
268
270
|
// ratio: the saved percentage
|
|
269
271
|
const ratio = originalSize > 0 ? (((originalSize - compressedSize) / originalSize) * 100).toFixed(1) : 0;
|
|
270
272
|
// compressedRatio: the remainings percentage
|
|
271
273
|
const compressedRatio = (100 - ratio).toFixed(1);
|
|
272
274
|
|
|
273
|
-
document.getElementById('origSize').innerText = origKB;
|
|
274
|
-
document.getElementById('compSize').innerText = compKB;
|
|
275
|
-
document.getElementById('
|
|
275
|
+
document.getElementById('origSize').innerText = origKB;
|
|
276
|
+
document.getElementById('compSize').innerText = compKB;
|
|
277
|
+
document.getElementById('convSize').innerText = convKB;
|
|
278
|
+
document.getElementById('barText').innerText = `${ratio}% Size Reduced`;
|
|
276
279
|
|
|
277
280
|
// actual used percentage
|
|
278
281
|
setTimeout(() => {
|
|
@@ -314,4 +317,4 @@
|
|
|
314
317
|
</div>
|
|
315
318
|
|
|
316
319
|
</body>
|
|
317
|
-
</html>
|
|
320
|
+
</html>
|