cc4-embedded-system 3.1.7 ā 3.1.8
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/dist/makefsdata.js +33 -22
- package/package.json +1 -1
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,15 @@ 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);
|
|
314
325
|
console.log(`\n⨠Success! Output written to: ${opts.outputFile}`);
|
|
315
326
|
return {
|
|
316
327
|
originalSize: totalOriginalSize,
|
|
317
328
|
compressedSize: totalCompressedSize,
|
|
318
|
-
filesCount:
|
|
329
|
+
filesCount: orderedFileEntries.length
|
|
319
330
|
};
|
|
320
331
|
}
|
|
321
332
|
throw new Error("No files processed.");
|