svelteesp32 1.3.0 → 1.3.1

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 CHANGED
@@ -107,7 +107,8 @@ The content of **generated file** (do not edit, just use)
107
107
  ```c
108
108
  #define SVELTEESP32_COUNT 5
109
109
  #define SVELTEESP32_SIZE 145633
110
- #define SVELTEESP32_FILE_index_html
110
+ #define SVELTEESP32_FILE_INDEX_HTML
111
+ #define SVELTEESP32_HTML_FILES 1
111
112
  ...
112
113
 
113
114
  const uint8_t data0[12547] = {0x1f, 0x8b, 0x8, 0x0, ...
@@ -189,30 +190,42 @@ You can use the COUNT and SIZE constants:
189
190
  ...
190
191
  ```
191
192
 
192
- You can include a warning if a named file accidentally missing from the build:
193
+ You can include a blocker error if a named file accidentally missing from the build:
193
194
 
194
195
  ```c
195
196
  ...
196
197
  #include "svelteesp32.h"
197
198
 
198
- #ifndef SVELTEESP32_FILE_index_html
199
+ #ifndef SVELTEESP32_FILE_INDEX_HTML
199
200
  #error Missing index file
200
201
  #endif
201
202
  ...
202
203
  ```
203
204
 
205
+ ...or if there are too many of a file type:
206
+
207
+ ```c
208
+ ...
209
+ #include "svelteesp32.h"
210
+
211
+ #if SVELTEESP32_CSS_FILES > 1
212
+ #error Too many CSS files
213
+ #endif
214
+ ...
215
+ ```
216
+
204
217
  ### Command line options
205
218
 
206
- | Option | Required | Description | default |
207
- | ------------- | :------: | ---------------------------------------------------------------- | ----------------------- |
208
- | `-e` | x | The engine for which the include file is created (psychic/async) | psychic |
209
- | `-s` | x | Source dist folder contains compiled web files | |
210
- | `-o` | x | Generated output file with path | `svelteesp32.h` |
211
- | `--etag` | | Use ETag header for cache | false |
212
- | `--no-gzip` | | Do not compress content with gzip | false -> gzip used |
213
- | `--espmethod` | x | Name of generated method | `initSvelteStaticFiles` |
214
- | `--define` | x | Prefix of c++ defines | `SVELTEESP32` |
215
- | `-h` | | Show help | |
219
+ | Option | Description | default |
220
+ | ------------- | --------------------------------------------------------- | ----------------------- | ------- |
221
+ | `-s` | **Source dist folder contains compiled web files** | |
222
+ | `-e` | The engine for which the include file is created [psychic | async] | psychic |
223
+ | `-o` | Generated output file with path | `svelteesp32.h` |
224
+ | `--etag` | Use ETag header for cache | false |
225
+ | `--no-gzip` | Do not compress content with gzip | false -> gzip used |
226
+ | `--espmethod` | Name of generated method | `initSvelteStaticFiles` |
227
+ | `--define` | Prefix of c++ defines | `SVELTEESP32` |
228
+ | `-h` | Show help | |
216
229
 
217
230
  ### Q&A
218
231
 
package/dist/cppCode.d.ts CHANGED
@@ -1,9 +1,16 @@
1
- export type cppCodeSource = {
1
+ export type CppCodeSource = {
2
2
  filename: string;
3
3
  dataname: string;
4
+ datanameUpperCase: string;
4
5
  mime: string;
5
6
  content: Buffer;
6
7
  isGzip: boolean;
7
8
  md5: string;
8
9
  };
9
- export declare const getCppCode: (sources: cppCodeSource[]) => string;
10
+ export type CppCodeSources = CppCodeSource[];
11
+ export type ExtensionGroup = {
12
+ extension: string;
13
+ count: number;
14
+ };
15
+ export type ExtensionGroups = ExtensionGroup[];
16
+ export declare const getCppCode: (sources: CppCodeSources, filesByExtension: ExtensionGroups) => string;
package/dist/cppCode.js CHANGED
@@ -16,8 +16,13 @@ const psychicTemplate = `
16
16
 
17
17
  #define {{definePrefix}}_COUNT {{fileCount}}
18
18
  #define {{definePrefix}}_SIZE {{fileSize}}
19
+
19
20
  {{#each sources}}
20
- #define {{../definePrefix}}_FILE_{{this.dataname}}
21
+ #define {{../definePrefix}}_FILE_{{this.datanameUpperCase}}
22
+ {{/each}}
23
+
24
+ {{#each filesByExtension}}
25
+ #define {{../definePrefix}}_{{this.extension}}_FILES {{this.count}}
21
26
  {{/each}}
22
27
 
23
28
  {{#each sources}}
@@ -63,8 +68,13 @@ const asyncTemplate = `
63
68
 
64
69
  #define {{definePrefix}}_COUNT {{fileCount}}
65
70
  #define {{definePrefix}}_SIZE {{fileSize}}
71
+
66
72
  {{#each sources}}
67
- #define {{../definePrefix}}_FILE_{{this.dataname}}
73
+ #define {{../definePrefix}}_FILE_{{this.datanameUpperCase}}
74
+ {{/each}}
75
+
76
+ {{#each filesByExtension}}
77
+ #define {{../definePrefix}}_{{this.extension}}_FILES {{this.count}}
68
78
  {{/each}}
69
79
 
70
80
  {{#each sources}}
@@ -99,7 +109,7 @@ void {{methodName}}(AsyncWebServer * server) {
99
109
 
100
110
  {{/each}}
101
111
  }`;
102
- const getCppCode = (sources) => (0, handlebars_1.compile)(commandLine_1.cmdLine.engine === 'psychic' ? psychicTemplate : asyncTemplate)({
112
+ const getCppCode = (sources, filesByExtension) => (0, handlebars_1.compile)(commandLine_1.cmdLine.engine === 'psychic' ? psychicTemplate : asyncTemplate)({
103
113
  commandLine: process.argv.slice(2).join(' '),
104
114
  now: `${new Date().toLocaleDateString()} ${new Date().toLocaleTimeString()}`,
105
115
  fileCount: sources.length.toString(),
@@ -110,6 +120,7 @@ const getCppCode = (sources) => (0, handlebars_1.compile)(commandLine_1.cmdLine.
110
120
  bytes: [...s.content].map((v) => `0x${v.toString(16)}`).join(', '),
111
121
  isDefault: s.filename.startsWith('index.htm')
112
122
  })),
123
+ filesByExtension,
113
124
  isEtag: commandLine_1.cmdLine.etag,
114
125
  methodName: commandLine_1.cmdLine.espmethod,
115
126
  definePrefix: commandLine_1.cmdLine.define
package/dist/index.js CHANGED
@@ -17,6 +17,7 @@ const summary = {
17
17
  gzipsize: 0
18
18
  };
19
19
  const sources = [];
20
+ const filesByExtension = [];
20
21
  const files = (0, file_1.getFiles)();
21
22
  if (files.length === 0) {
22
23
  console.error(`Directory ${commandLine_1.cmdLine.sourcepath} is empty`);
@@ -28,6 +29,14 @@ for (const file of files) {
28
29
  console.log(`[${file}]`);
29
30
  const filename = file.replace(/\\/g, '/');
30
31
  const dataname = filename.replace(/[./-]/g, '_');
32
+ let extension = node_path_1.default.extname(filename).toUpperCase();
33
+ if (extension.startsWith('.'))
34
+ extension = extension.slice(1);
35
+ const group = filesByExtension.find((fe) => fe.extension === extension);
36
+ if (group)
37
+ group.count += 1;
38
+ else
39
+ filesByExtension.push({ extension, count: 1 });
31
40
  const rawContent = (0, node_fs_1.readFileSync)(node_path_1.default.join(commandLine_1.cmdLine.sourcepath, file), { flag: 'r' });
32
41
  const md5 = (0, node_crypto_1.createHash)('md5').update(rawContent).digest('hex');
33
42
  summary.size += rawContent.length;
@@ -35,6 +44,7 @@ for (const file of files) {
35
44
  sources.push({
36
45
  filename: filename,
37
46
  dataname,
47
+ datanameUpperCase: dataname.toUpperCase(),
38
48
  content: rawContent,
39
49
  isGzip: false,
40
50
  mime,
@@ -49,6 +59,7 @@ for (const file of files) {
49
59
  sources.push({
50
60
  filename: filename,
51
61
  dataname,
62
+ datanameUpperCase: dataname.toUpperCase(),
52
63
  content: zipContent,
53
64
  isGzip: true,
54
65
  mime,
@@ -60,6 +71,7 @@ for (const file of files) {
60
71
  sources.push({
61
72
  filename: filename,
62
73
  dataname,
74
+ datanameUpperCase: dataname.toUpperCase(),
63
75
  content: rawContent,
64
76
  isGzip: false,
65
77
  mime,
@@ -70,7 +82,8 @@ for (const file of files) {
70
82
  }
71
83
  console.log('');
72
84
  }
73
- const cppFile = (0, cppCode_1.getCppCode)(sources);
85
+ filesByExtension.sort((left, right) => left.extension.localeCompare(right.extension));
86
+ const cppFile = (0, cppCode_1.getCppCode)(sources, filesByExtension);
74
87
  (0, node_fs_1.writeFileSync)(commandLine_1.cmdLine.outputfile, cppFile);
75
88
  if (commandLine_1.cmdLine['no-gzip']) {
76
89
  console.log(`${summary.filecount} files, ${Math.round(summary.size / 1024)}kB original size`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelteesp32",
3
- "version": "1.3.0",
3
+ "version": "1.3.1",
4
4
  "description": "Convert Svelte (or any frontend) JS application to serve it from ESP32 webserver (PsychicHttp)",
5
5
  "author": "BCsabaEngine",
6
6
  "license": "ISC",
@@ -56,7 +56,7 @@
56
56
  ],
57
57
  "devDependencies": {
58
58
  "@types/mime-types": "^2.1.4",
59
- "@types/node": "^22.2.0",
59
+ "@types/node": "^22.3.0",
60
60
  "@typescript-eslint/eslint-plugin": "^8.1.0",
61
61
  "@typescript-eslint/parser": "^8.1.0",
62
62
  "eslint": "^9.9.0",