svelteesp32 1.11.0 → 1.12.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 +116 -3
- package/dist/commandLine.d.ts +1 -0
- package/dist/commandLine.js +168 -5
- package/dist/cppCode.js +4 -4
- package/dist/cppCodeEspIdf.d.ts +1 -1
- package/dist/cppCodeEspIdf.js +1 -1
- package/dist/file.js +3 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -12,6 +12,10 @@ In order to be able to easily update OTA, it is important - from the users' poin
|
|
|
12
12
|
|
|
13
13
|
This npm package provides a solution for **inserting any JS client application into the ESP web server** (PsychicHttp and also ESPAsyncWebServer (https://github.com/ESP32Async/ESPAsyncWebServer) and ESP-IDF available, PsychicHttp is the default). For this, JS, html, css, font, assets, etc. files must be converted to binary byte array. Npm mode is easy to use and easy to **integrate into your CI/CD pipeline**.
|
|
14
14
|
|
|
15
|
+
> Starting with version v1.12.0, you can use RC file for configuration
|
|
16
|
+
|
|
17
|
+
> Starting with version v1.11.0, you can exclude files by pattern
|
|
18
|
+
|
|
15
19
|
> Starting with version v1.10.0, we reduced npm dependencies
|
|
16
20
|
|
|
17
21
|
> Starting with version v1.9.0, code generator for esp-idf is available
|
|
@@ -84,13 +88,13 @@ npm run fix
|
|
|
84
88
|
|
|
85
89
|
### Usage
|
|
86
90
|
|
|
87
|
-
**Install package** as
|
|
91
|
+
**Install package** as dev dependency (it is practical if the package is part of the project so that you always receive updates)
|
|
88
92
|
|
|
89
93
|
```bash
|
|
90
94
|
npm install -D svelteesp32
|
|
91
95
|
```
|
|
92
96
|
|
|
93
|
-
After a successful Svelte build (rollup/webpack/vite) **create an
|
|
97
|
+
After a successful Svelte build (rollup/webpack/vite) **create an includable c++ header** file
|
|
94
98
|
|
|
95
99
|
```bash
|
|
96
100
|
// for PsychicHttpServer
|
|
@@ -198,7 +202,7 @@ The content of **generated file** (do not edit, just use):
|
|
|
198
202
|
|
|
199
203
|
```c
|
|
200
204
|
//engine: PsychicHttpServer
|
|
201
|
-
//
|
|
205
|
+
//config: engine=psychic sourcepath=./dist outputfile=./output.h etag=true gzip=true cachetime=0 espmethod=initSvelteStaticFiles define=SVELTEESP32
|
|
202
206
|
//
|
|
203
207
|
#define SVELTEESP32_COUNT 5
|
|
204
208
|
#define SVELTEESP32_SIZE 468822
|
|
@@ -425,8 +429,117 @@ You can use the following c++ directives at the project level if you want to con
|
|
|
425
429
|
| `--version` | Include a version string in generated header, e.g. `--version=v$npm_package_version` | '' |
|
|
426
430
|
| `--espmethod` | Name of generated initialization method | `initSvelteStaticFiles` |
|
|
427
431
|
| `--define` | Prefix of c++ defines (e.g., SVELTEESP32_COUNT) | `SVELTEESP32` |
|
|
432
|
+
| `--config` | Use custom RC file path | `.svelteesp32rc.json` |
|
|
428
433
|
| `-h` | Show help | |
|
|
429
434
|
|
|
435
|
+
### Configuration File
|
|
436
|
+
|
|
437
|
+
You can store frequently-used options in a configuration file to avoid repeating command line arguments. This is especially useful for CI/CD pipelines and team collaboration.
|
|
438
|
+
|
|
439
|
+
#### Quick Start
|
|
440
|
+
|
|
441
|
+
Create `.svelteesp32rc.json` in your project directory:
|
|
442
|
+
|
|
443
|
+
```json
|
|
444
|
+
{
|
|
445
|
+
"engine": "psychic",
|
|
446
|
+
"sourcepath": "./dist",
|
|
447
|
+
"outputfile": "./esp32/include/svelteesp32.h",
|
|
448
|
+
"etag": "true",
|
|
449
|
+
"gzip": "true",
|
|
450
|
+
"cachetime": 86400,
|
|
451
|
+
"exclude": ["*.map", "*.md"]
|
|
452
|
+
}
|
|
453
|
+
```
|
|
454
|
+
|
|
455
|
+
Then simply run:
|
|
456
|
+
|
|
457
|
+
```bash
|
|
458
|
+
npx svelteesp32
|
|
459
|
+
```
|
|
460
|
+
|
|
461
|
+
No command line arguments needed!
|
|
462
|
+
|
|
463
|
+
#### Search Locations
|
|
464
|
+
|
|
465
|
+
The tool automatically searches for `.svelteesp32rc.json` in:
|
|
466
|
+
|
|
467
|
+
1. Current working directory
|
|
468
|
+
2. User home directory
|
|
469
|
+
|
|
470
|
+
Or specify a custom location:
|
|
471
|
+
|
|
472
|
+
```bash
|
|
473
|
+
npx svelteesp32 --config=.svelteesp32rc.prod.json
|
|
474
|
+
```
|
|
475
|
+
|
|
476
|
+
#### Configuration Reference
|
|
477
|
+
|
|
478
|
+
All CLI options can be specified in the RC file using long-form property names:
|
|
479
|
+
|
|
480
|
+
| RC Property | CLI Flag | Type | Example |
|
|
481
|
+
| ------------ | ------------- | ------- | ------------------------------------------------ |
|
|
482
|
+
| `engine` | `-e` | string | `"psychic"`, `"psychic2"`, `"async"`, `"espidf"` |
|
|
483
|
+
| `sourcepath` | `-s` | string | `"./dist"` |
|
|
484
|
+
| `outputfile` | `-o` | string | `"./output.h"` |
|
|
485
|
+
| `etag` | `--etag` | string | `"true"`, `"false"`, `"compiler"` |
|
|
486
|
+
| `gzip` | `--gzip` | string | `"true"`, `"false"`, `"compiler"` |
|
|
487
|
+
| `cachetime` | `--cachetime` | number | `86400` |
|
|
488
|
+
| `created` | `--created` | boolean | `true`, `false` |
|
|
489
|
+
| `version` | `--version` | string | `"v1.0.0"` |
|
|
490
|
+
| `espmethod` | `--espmethod` | string | `"initSvelteStaticFiles"` |
|
|
491
|
+
| `define` | `--define` | string | `"SVELTEESP32"` |
|
|
492
|
+
| `exclude` | `--exclude` | array | `["*.map", "*.md"]` |
|
|
493
|
+
|
|
494
|
+
#### CLI Override
|
|
495
|
+
|
|
496
|
+
Command line arguments always take precedence over RC file values:
|
|
497
|
+
|
|
498
|
+
```bash
|
|
499
|
+
# Use RC settings but override etag
|
|
500
|
+
npx svelteesp32 --etag=false
|
|
501
|
+
|
|
502
|
+
# Use RC settings but add different exclude pattern
|
|
503
|
+
npx svelteesp32 --exclude="*.txt"
|
|
504
|
+
```
|
|
505
|
+
|
|
506
|
+
#### Multiple Environments
|
|
507
|
+
|
|
508
|
+
Create different config files for different environments:
|
|
509
|
+
|
|
510
|
+
```bash
|
|
511
|
+
# Development build
|
|
512
|
+
npx svelteesp32 --config=.svelteesp32rc.dev.json
|
|
513
|
+
|
|
514
|
+
# Production build
|
|
515
|
+
npx svelteesp32 --config=.svelteesp32rc.prod.json
|
|
516
|
+
```
|
|
517
|
+
|
|
518
|
+
#### Exclude Pattern Behavior
|
|
519
|
+
|
|
520
|
+
**Replace mode**: When you specify `exclude` patterns in RC file or CLI, they completely replace the defaults.
|
|
521
|
+
|
|
522
|
+
- **No exclude specified**: Uses default system exclusions (`.DS_Store`, `Thumbs.db`, `.git`, etc.)
|
|
523
|
+
- **RC file has exclude**: Replaces defaults with RC patterns
|
|
524
|
+
- **CLI has --exclude**: Replaces RC patterns (or defaults if no RC)
|
|
525
|
+
|
|
526
|
+
Example:
|
|
527
|
+
|
|
528
|
+
```json
|
|
529
|
+
// .svelteesp32rc.json
|
|
530
|
+
{ "exclude": ["*.map"] }
|
|
531
|
+
```
|
|
532
|
+
|
|
533
|
+
Result: Only `*.map` is excluded (default patterns are replaced)
|
|
534
|
+
|
|
535
|
+
To keep defaults, explicitly list them in your RC file:
|
|
536
|
+
|
|
537
|
+
```json
|
|
538
|
+
{
|
|
539
|
+
"exclude": [".DS_Store", "Thumbs.db", ".git", "*.map", "*.md"]
|
|
540
|
+
}
|
|
541
|
+
```
|
|
542
|
+
|
|
430
543
|
### Q&A
|
|
431
544
|
|
|
432
545
|
- **How big a frontend application can be placed?** If you compress the content with gzip, even a 3-4Mb assets directory can be placed. This is a serious enough amount to serve a complete application.
|
package/dist/commandLine.d.ts
CHANGED
package/dist/commandLine.js
CHANGED
|
@@ -1,11 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.cmdLine = void 0;
|
|
7
|
+
exports.formatConfiguration = formatConfiguration;
|
|
4
8
|
const node_fs_1 = require("node:fs");
|
|
9
|
+
const node_os_1 = require("node:os");
|
|
10
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
11
|
+
const consoleColor_1 = require("./consoleColor");
|
|
5
12
|
function showHelp() {
|
|
6
13
|
console.log(`
|
|
7
14
|
svelteesp32 - Svelte JS to ESP32 converter
|
|
8
15
|
|
|
16
|
+
Configuration:
|
|
17
|
+
--config <path> Use custom RC file (default: search for .svelteesp32rc.json)
|
|
18
|
+
|
|
9
19
|
Options:
|
|
10
20
|
-e, --engine <value> The engine for which the include file is created
|
|
11
21
|
(psychic|psychic2|async|espidf) (default: "psychic")
|
|
@@ -21,6 +31,23 @@ Options:
|
|
|
21
31
|
--exclude <pattern> Exclude files matching glob pattern (repeatable or comma-separated)
|
|
22
32
|
Examples: --exclude="*.map" --exclude="test/**/*.ts"
|
|
23
33
|
-h, --help Shows this help
|
|
34
|
+
|
|
35
|
+
RC File:
|
|
36
|
+
The tool searches for .svelteesp32rc.json in:
|
|
37
|
+
1. Current directory (./.svelteesp32rc.json)
|
|
38
|
+
2. User home directory (~/.svelteesp32rc.json)
|
|
39
|
+
|
|
40
|
+
Example RC file (all fields optional):
|
|
41
|
+
{
|
|
42
|
+
"engine": "psychic",
|
|
43
|
+
"sourcepath": "./dist",
|
|
44
|
+
"outputfile": "./output.h",
|
|
45
|
+
"etag": "true",
|
|
46
|
+
"gzip": "true",
|
|
47
|
+
"exclude": ["*.map", "*.md"]
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
CLI arguments override RC file values.
|
|
24
51
|
`);
|
|
25
52
|
process.exit(0);
|
|
26
53
|
}
|
|
@@ -44,8 +71,95 @@ const DEFAULT_EXCLUDE_PATTERNS = [
|
|
|
44
71
|
'.gitignore',
|
|
45
72
|
'.gitattributes'
|
|
46
73
|
];
|
|
74
|
+
function findRcFile(customConfigPath) {
|
|
75
|
+
if (customConfigPath) {
|
|
76
|
+
if ((0, node_fs_1.existsSync)(customConfigPath))
|
|
77
|
+
return customConfigPath;
|
|
78
|
+
throw new Error(`Config file not found: ${customConfigPath}`);
|
|
79
|
+
}
|
|
80
|
+
for (const filename of ['.svelteesp32rc.json', '.svelteesp32rc']) {
|
|
81
|
+
const cwdPath = node_path_1.default.join(process.cwd(), filename);
|
|
82
|
+
if ((0, node_fs_1.existsSync)(cwdPath))
|
|
83
|
+
return cwdPath;
|
|
84
|
+
}
|
|
85
|
+
const homeDirectory = (0, node_os_1.homedir)();
|
|
86
|
+
for (const filename of ['.svelteesp32rc.json', '.svelteesp32rc']) {
|
|
87
|
+
const homePath = node_path_1.default.join(homeDirectory, filename);
|
|
88
|
+
if ((0, node_fs_1.existsSync)(homePath))
|
|
89
|
+
return homePath;
|
|
90
|
+
}
|
|
91
|
+
return undefined;
|
|
92
|
+
}
|
|
93
|
+
function loadRcFile(rcPath) {
|
|
94
|
+
try {
|
|
95
|
+
const content = (0, node_fs_1.readFileSync)(rcPath, 'utf8');
|
|
96
|
+
const config = JSON.parse(content);
|
|
97
|
+
return validateRcConfig(config, rcPath);
|
|
98
|
+
}
|
|
99
|
+
catch (error) {
|
|
100
|
+
if (error instanceof SyntaxError)
|
|
101
|
+
throw new Error(`Invalid JSON in RC file ${rcPath}: ${error.message}`);
|
|
102
|
+
throw error;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
function validateRcConfig(config, rcPath) {
|
|
106
|
+
if (typeof config !== 'object' || config === null)
|
|
107
|
+
throw new Error(`RC file ${rcPath} must contain a JSON object`);
|
|
108
|
+
const configObject = config;
|
|
109
|
+
const validKeys = new Set([
|
|
110
|
+
'engine',
|
|
111
|
+
'sourcepath',
|
|
112
|
+
'outputfile',
|
|
113
|
+
'espmethod',
|
|
114
|
+
'define',
|
|
115
|
+
'gzip',
|
|
116
|
+
'etag',
|
|
117
|
+
'cachetime',
|
|
118
|
+
'created',
|
|
119
|
+
'version',
|
|
120
|
+
'exclude'
|
|
121
|
+
]);
|
|
122
|
+
for (const key of Object.keys(configObject))
|
|
123
|
+
if (!validKeys.has(key))
|
|
124
|
+
console.warn((0, consoleColor_1.yellowLog)(`Warning: Unknown property '${key}' in RC file ${rcPath}`));
|
|
125
|
+
if (configObject['engine'] !== undefined)
|
|
126
|
+
configObject['engine'] = validateEngine(configObject['engine']);
|
|
127
|
+
if (configObject['etag'] !== undefined)
|
|
128
|
+
configObject['etag'] = validateTriState(configObject['etag'], 'etag');
|
|
129
|
+
if (configObject['gzip'] !== undefined)
|
|
130
|
+
configObject['gzip'] = validateTriState(configObject['gzip'], 'gzip');
|
|
131
|
+
if (configObject['cachetime'] !== undefined &&
|
|
132
|
+
(typeof configObject['cachetime'] !== 'number' || Number.isNaN(configObject['cachetime'])))
|
|
133
|
+
throw new TypeError(`Invalid cachetime in RC file: ${configObject['cachetime']}`);
|
|
134
|
+
if (configObject['exclude'] !== undefined) {
|
|
135
|
+
if (!Array.isArray(configObject['exclude']))
|
|
136
|
+
throw new TypeError("'exclude' in RC file must be an array");
|
|
137
|
+
for (const pattern of configObject['exclude'])
|
|
138
|
+
if (typeof pattern !== 'string')
|
|
139
|
+
throw new TypeError('All exclude patterns must be strings');
|
|
140
|
+
}
|
|
141
|
+
return configObject;
|
|
142
|
+
}
|
|
47
143
|
function parseArguments() {
|
|
48
144
|
const arguments_ = process.argv.slice(2);
|
|
145
|
+
let customConfigPath;
|
|
146
|
+
for (let index = 0; index < arguments_.length; index++) {
|
|
147
|
+
const argument = arguments_[index];
|
|
148
|
+
if (!argument)
|
|
149
|
+
continue;
|
|
150
|
+
if (argument === '--config' && arguments_[index + 1]) {
|
|
151
|
+
customConfigPath = arguments_[index + 1];
|
|
152
|
+
break;
|
|
153
|
+
}
|
|
154
|
+
if (argument.startsWith('--config=')) {
|
|
155
|
+
customConfigPath = argument.slice('--config='.length);
|
|
156
|
+
break;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
const rcPath = findRcFile(customConfigPath);
|
|
160
|
+
const rcConfig = rcPath ? loadRcFile(rcPath) : {};
|
|
161
|
+
if (rcPath)
|
|
162
|
+
console.log((0, consoleColor_1.cyanLog)(`[SvelteESP32] Using config from: ${rcPath}`));
|
|
49
163
|
const result = {
|
|
50
164
|
engine: 'psychic',
|
|
51
165
|
outputfile: 'svelteesp32.h',
|
|
@@ -58,6 +172,29 @@ function parseArguments() {
|
|
|
58
172
|
cachetime: 0,
|
|
59
173
|
exclude: [...DEFAULT_EXCLUDE_PATTERNS]
|
|
60
174
|
};
|
|
175
|
+
if (rcConfig.engine)
|
|
176
|
+
result.engine = rcConfig.engine;
|
|
177
|
+
if (rcConfig.sourcepath)
|
|
178
|
+
result.sourcepath = rcConfig.sourcepath;
|
|
179
|
+
if (rcConfig.outputfile)
|
|
180
|
+
result.outputfile = rcConfig.outputfile;
|
|
181
|
+
if (rcConfig.etag)
|
|
182
|
+
result.etag = rcConfig.etag;
|
|
183
|
+
if (rcConfig.gzip)
|
|
184
|
+
result.gzip = rcConfig.gzip;
|
|
185
|
+
if (rcConfig.cachetime !== undefined)
|
|
186
|
+
result.cachetime = rcConfig.cachetime;
|
|
187
|
+
if (rcConfig.created !== undefined)
|
|
188
|
+
result.created = rcConfig.created;
|
|
189
|
+
if (rcConfig.version)
|
|
190
|
+
result.version = rcConfig.version;
|
|
191
|
+
if (rcConfig.espmethod)
|
|
192
|
+
result.espmethod = rcConfig.espmethod;
|
|
193
|
+
if (rcConfig.define)
|
|
194
|
+
result.define = rcConfig.define;
|
|
195
|
+
if (rcConfig.exclude && rcConfig.exclude.length > 0)
|
|
196
|
+
result.exclude = [...rcConfig.exclude];
|
|
197
|
+
const cliExclude = [];
|
|
61
198
|
for (let index = 0; index < arguments_.length; index++) {
|
|
62
199
|
const argument = arguments_[index];
|
|
63
200
|
if (!argument)
|
|
@@ -72,6 +209,8 @@ function parseArguments() {
|
|
|
72
209
|
throw new Error(`Invalid argument format: ${argument}`);
|
|
73
210
|
const flagName = flag.slice(2);
|
|
74
211
|
switch (flagName) {
|
|
212
|
+
case 'config':
|
|
213
|
+
break;
|
|
75
214
|
case 'engine':
|
|
76
215
|
result.engine = validateEngine(value);
|
|
77
216
|
break;
|
|
@@ -106,8 +245,7 @@ function parseArguments() {
|
|
|
106
245
|
.split(',')
|
|
107
246
|
.map((p) => p.trim())
|
|
108
247
|
.filter(Boolean);
|
|
109
|
-
|
|
110
|
-
result.exclude.push(...patterns);
|
|
248
|
+
cliExclude.push(...patterns);
|
|
111
249
|
break;
|
|
112
250
|
}
|
|
113
251
|
default:
|
|
@@ -148,6 +286,9 @@ function parseArguments() {
|
|
|
148
286
|
if (!nextArgument || nextArgument.startsWith('-'))
|
|
149
287
|
throw new Error(`Missing value for flag: ${argument}`);
|
|
150
288
|
switch (flag) {
|
|
289
|
+
case 'config':
|
|
290
|
+
index++;
|
|
291
|
+
break;
|
|
151
292
|
case 'engine':
|
|
152
293
|
result.engine = validateEngine(nextArgument);
|
|
153
294
|
index++;
|
|
@@ -191,8 +332,7 @@ function parseArguments() {
|
|
|
191
332
|
.split(',')
|
|
192
333
|
.map((p) => p.trim())
|
|
193
334
|
.filter(Boolean);
|
|
194
|
-
|
|
195
|
-
result.exclude.push(...patterns);
|
|
335
|
+
cliExclude.push(...patterns);
|
|
196
336
|
index++;
|
|
197
337
|
break;
|
|
198
338
|
}
|
|
@@ -203,12 +343,35 @@ function parseArguments() {
|
|
|
203
343
|
}
|
|
204
344
|
throw new Error(`Unknown argument: ${argument}`);
|
|
205
345
|
}
|
|
346
|
+
if (cliExclude.length > 0)
|
|
347
|
+
result.exclude = [...cliExclude];
|
|
206
348
|
if (!result.sourcepath) {
|
|
207
|
-
console.error('Error: --sourcepath is required');
|
|
349
|
+
console.error('Error: --sourcepath is required (can be specified in RC file or CLI)');
|
|
208
350
|
showHelp();
|
|
209
351
|
}
|
|
210
352
|
return result;
|
|
211
353
|
}
|
|
354
|
+
function formatConfiguration(cmdLine) {
|
|
355
|
+
const parts = [
|
|
356
|
+
`engine=${cmdLine.engine}`,
|
|
357
|
+
`sourcepath=${cmdLine.sourcepath}`,
|
|
358
|
+
`outputfile=${cmdLine.outputfile}`,
|
|
359
|
+
`etag=${cmdLine.etag}`,
|
|
360
|
+
`gzip=${cmdLine.gzip}`,
|
|
361
|
+
`cachetime=${cmdLine.cachetime}`
|
|
362
|
+
];
|
|
363
|
+
if (cmdLine.created)
|
|
364
|
+
parts.push(`created=${cmdLine.created}`);
|
|
365
|
+
if (cmdLine.version)
|
|
366
|
+
parts.push(`version=${cmdLine.version}`);
|
|
367
|
+
if (cmdLine.espmethod)
|
|
368
|
+
parts.push(`espmethod=${cmdLine.espmethod}`);
|
|
369
|
+
if (cmdLine.define)
|
|
370
|
+
parts.push(`define=${cmdLine.define}`);
|
|
371
|
+
if (cmdLine.exclude.length > 0)
|
|
372
|
+
parts.push(`exclude=[${cmdLine.exclude.join(', ')}]`);
|
|
373
|
+
return parts.join(' ');
|
|
374
|
+
}
|
|
212
375
|
exports.cmdLine = parseArguments();
|
|
213
376
|
if (!(0, node_fs_1.existsSync)(exports.cmdLine.sourcepath) || !(0, node_fs_1.statSync)(exports.cmdLine.sourcepath).isDirectory()) {
|
|
214
377
|
console.error(`Directory ${exports.cmdLine.sourcepath} not exists or not a directory`);
|
package/dist/cppCode.js
CHANGED
|
@@ -97,7 +97,7 @@ const char * etag_{{this.dataname}} = "{{this.md5}}";
|
|
|
97
97
|
`;
|
|
98
98
|
const psychicTemplate = `
|
|
99
99
|
//engine: PsychicHttpServer
|
|
100
|
-
//
|
|
100
|
+
//config: {{{config}}}
|
|
101
101
|
//You should use server.config.max_uri_handlers = {{fileCount}}; or higher value to proper handles all files
|
|
102
102
|
{{#if created }}
|
|
103
103
|
//created: {{now}}
|
|
@@ -207,7 +207,7 @@ void {{methodName}}(PsychicHttpServer * server) {
|
|
|
207
207
|
}`;
|
|
208
208
|
const psychic2Template = `
|
|
209
209
|
//engine: PsychicHttpServerV2
|
|
210
|
-
//
|
|
210
|
+
//config: {{{config}}}
|
|
211
211
|
{{#if created }}
|
|
212
212
|
//created: {{now}}
|
|
213
213
|
{{/if}}
|
|
@@ -313,7 +313,7 @@ void {{methodName}}(PsychicHttpServer * server) {
|
|
|
313
313
|
}`;
|
|
314
314
|
const asyncTemplate = `
|
|
315
315
|
//engine: ESPAsyncWebServer
|
|
316
|
-
//
|
|
316
|
+
//config: {{{config}}}
|
|
317
317
|
{{#if created }}
|
|
318
318
|
//created: {{now}}
|
|
319
319
|
{{/if}}
|
|
@@ -526,7 +526,7 @@ const createHandlebarsHelpers = () => {
|
|
|
526
526
|
const getCppCode = (sources, filesByExtension) => {
|
|
527
527
|
const template = (0, handlebars_1.compile)(getTemplate(commandLine_1.cmdLine.engine));
|
|
528
528
|
const templateData = {
|
|
529
|
-
|
|
529
|
+
config: (0, commandLine_1.formatConfiguration)(commandLine_1.cmdLine),
|
|
530
530
|
now: `${new Date().toLocaleDateString()} ${new Date().toLocaleTimeString()}`,
|
|
531
531
|
fileCount: sources.length.toString(),
|
|
532
532
|
fileSize: sources.reduce((previous, current) => previous + current.content.length, 0).toString(),
|
package/dist/cppCodeEspIdf.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const espidfTemplate = "\n//engine: espidf\n//
|
|
1
|
+
export declare const espidfTemplate = "\n//engine: espidf\n//config: {{{config}}}\n{{#if created }}\n//created: {{now}}\n{{/if}}\n//\n\n{{#switch etag}}\n{{#case \"true\"}}\n#ifdef {{definePrefix}}_ENABLE_ETAG\n#warning {{definePrefix}}_ENABLE_ETAG has no effect because it is permanently switched ON\n#endif\n{{/case}}\n{{#case \"false\"}}\n#ifdef {{definePrefix}}_ENABLE_ETAG\n#warning {{definePrefix}}_ENABLE_ETAG has no effect because it is permanently switched OFF\n#endif\n{{/case}}\n{{/switch}}\n\n{{#switch gzip}}\n{{#case \"true\"}}\n#ifdef {{definePrefix}}_ENABLE_GZIP\n#warning {{definePrefix}}_ENABLE_GZIP has no effect because it is permanently switched ON\n#endif\n{{/case}}\n{{#case \"false\"}}\n#ifdef {{definePrefix}}_ENABLE_GZIP\n#warning {{definePrefix}}_ENABLE_GZIP has no effect because it is permanently switched OFF\n#endif\n{{/case}}\n{{/switch}}\n\n//\n{{#if version }}\n#define {{definePrefix}}_VERSION \"{{version}}\"\n{{/if}}\n#define {{definePrefix}}_COUNT {{fileCount}}\n#define {{definePrefix}}_SIZE {{fileSize}}\n#define {{definePrefix}}_SIZE_GZIP {{fileGzipSize}}\n\n//\n{{#each sources}}\n#define {{../definePrefix}}_FILE_{{this.datanameUpperCase}}\n{{/each}}\n\n//\n{{#each filesByExtension}}\n#define {{../definePrefix}}_{{this.extension}}_FILES {{this.count}}\n{{/each}}\n\n#include <stdint.h>\n#include <string.h>\n#include <stdlib.h>\n#include <esp_err.h>\n#include <esp_http_server.h>\n\n//\n{{#switch gzip}}\n{{#case \"true\"}}\n {{#each sources}}\nconst char datagzip_{{this.dataname}}[{{this.lengthGzip}}] = { {{this.bytesGzip}} };\n {{/each}}\n{{/case}}\n{{#case \"false\"}}\n {{#each sources}}\nconst char data_{{this.dataname}}[{{this.length}}] = { {{this.bytes}} };\n {{/each}}\n{{/case}}\n{{#case \"compiler\"}}\n#ifdef {{definePrefix}}_ENABLE_GZIP\n {{#each sources}}\nconst char datagzip_{{this.dataname}}[{{this.lengthGzip}}] = { {{this.bytesGzip}} };\n {{/each}}\n#else\n {{#each sources}}\nconst char data_{{this.dataname}}[{{this.length}}] = { {{this.bytes}} };\n {{/each}}\n#endif \n{{/case}}\n{{/switch}}\n\n//\n{{#switch etag}}\n{{#case \"true\"}}\n {{#each sources}}\nconst char * etag_{{this.dataname}} = \"{{this.md5}}\";\n {{/each}}\n{{/case}}\n{{#case \"false\"}}\n{{/case}}\n{{#case \"compiler\"}}\n#ifdef {{definePrefix}}_ENABLE_ETAG\n {{#each sources}}\nconst char * etag_{{this.dataname}} = \"{{this.md5}}\";\n {{/each}}\n#endif \n{{/case}}\n{{/switch}}\n\n{{#each sources}}\n\nstatic esp_err_t file_handler_{{this.datanameUpperCase}} (httpd_req_t *req)\n{\n{{#switch ../etag}}\n{{#case \"true\"}}\n size_t hdr_len = httpd_req_get_hdr_value_len(req, \"If-None-Match\");\n if (hdr_len > 0) {\n char* hdr_value = malloc(hdr_len + 1);\n if (httpd_req_get_hdr_value_str(req, \"If-None-Match\", hdr_value, hdr_len + 1) == ESP_OK) {\n if (strcmp(hdr_value, etag_{{this.dataname}}) == 0) {\n free(hdr_value);\n httpd_resp_set_status(req, \"304 Not Modified\");\n httpd_resp_send(req, NULL, 0);\n return ESP_OK;\n }\n }\n free(hdr_value);\n }\n{{/case}}\n{{#case \"compiler\"}}\n #ifdef {{../definePrefix}}_ENABLE_ETAG\n size_t hdr_len = httpd_req_get_hdr_value_len(req, \"If-None-Match\");\n if (hdr_len > 0) {\n char* hdr_value = malloc(hdr_len + 1);\n if (httpd_req_get_hdr_value_str(req, \"If-None-Match\", hdr_value, hdr_len + 1) == ESP_OK) {\n if (strcmp(hdr_value, etag_{{this.dataname}}) == 0) {\n free(hdr_value);\n httpd_resp_set_status(req, \"304 Not Modified\");\n httpd_resp_send(req, NULL, 0);\n return ESP_OK;\n }\n }\n free(hdr_value);\n }\n #endif\n{{/case}}\n{{/switch}}\n httpd_resp_set_type(req, \"{{this.mime}}\");\n{{#switch ../gzip}}\n{{#case \"true\"}}\n{{#if this.isGzip}}\n httpd_resp_set_hdr(req, \"Content-Encoding\", \"gzip\");\n{{/if}}\n{{/case}}\n{{#case \"compiler\"}}\n {{#if this.isGzip}}\n #ifdef {{../definePrefix}}_ENABLE_GZIP\n httpd_resp_set_hdr(req, \"Content-Encoding\", \"gzip\");\n #endif \n {{/if}}\n{{/case}}\n{{/switch}}\n\n{{#switch ../etag}}\n{{#case \"true\"}}\n{{#../cacheTime}}\n httpd_resp_set_hdr(req, \"Cache-Control\", \"max-age={{value}}\");\n{{/../cacheTime}}\n{{^../cacheTime}}\n httpd_resp_set_hdr(req, \"Cache-Control\", \"no-cache\");\n{{/../cacheTime}}\n httpd_resp_set_hdr(req, \"ETag\", etag_{{this.dataname}});\n{{/case}}\n{{#case \"compiler\"}}\n #ifdef {{../definePrefix}}_ENABLE_ETAG\n{{#../cacheTime}}\n httpd_resp_set_hdr(req, \"Cache-Control\", \"max-age={{value}}\");\n{{/../cacheTime}}\n{{^../cacheTime}}\n httpd_resp_set_hdr(req, \"Cache-Control\", \"no-cache\");\n{{/../cacheTime}}\n httpd_resp_set_hdr(req, \"ETag\", etag_{{this.dataname}});\n #endif \n{{/case}}\n{{/switch}}\n\n{{#switch ../gzip}}\n{{#case \"true\"}}\n httpd_resp_send(req, datagzip_{{this.dataname}}, {{this.lengthGzip}});\n{{/case}}\n{{#case \"false\"}}\n httpd_resp_send(req, data_{{this.dataname}}, {{this.length}});\n{{/case}}\n{{#case \"compiler\"}}\n #ifdef {{../definePrefix}}_ENABLE_GZIP\n httpd_resp_send(req, datagzip_{{this.dataname}}, {{this.lengthGzip}});\n #else\n httpd_resp_send(req, data_{{this.dataname}}, {{this.length}});\n #endif \n{{/case}}\n{{/switch}}\n return ESP_OK;\n}\n\n{{#if this.isDefault}}\nstatic const httpd_uri_t route_def_{{this.datanameUpperCase}} = {\n .uri = \"/\",\n .method = HTTP_GET,\n .handler = file_handler_{{this.datanameUpperCase}},\n};\n{{/if}}\n\nstatic const httpd_uri_t route_{{this.datanameUpperCase}} = {\n .uri = \"/{{this.filename}}\",\n .method = HTTP_GET,\n .handler = file_handler_{{this.datanameUpperCase}},\n};\n\n{{/each}}\n\n\n\nstatic inline void {{methodName}}(httpd_handle_t server) {\n{{#each sources}}\n{{#if this.isDefault}}\n httpd_register_uri_handler(server, &route_def_{{this.datanameUpperCase}});\n{{/if}}\n httpd_register_uri_handler(server, &route_{{this.datanameUpperCase}});\n{{/each}}\n\n}";
|
package/dist/cppCodeEspIdf.js
CHANGED
package/dist/file.js
CHANGED
|
@@ -63,12 +63,12 @@ const getFiles = () => {
|
|
|
63
63
|
return true;
|
|
64
64
|
});
|
|
65
65
|
if (excludedFiles.length > 0) {
|
|
66
|
-
console.log(
|
|
66
|
+
console.log(`\nExcluded ${excludedFiles.length} file(s):`);
|
|
67
67
|
const displayLimit = 10;
|
|
68
68
|
for (const file of excludedFiles.slice(0, displayLimit))
|
|
69
|
-
console.log((0, consoleColor_1.cyanLog)(
|
|
69
|
+
console.log((0, consoleColor_1.cyanLog)(`- ${file}`));
|
|
70
70
|
if (excludedFiles.length > displayLimit)
|
|
71
|
-
console.log((0, consoleColor_1.cyanLog)(
|
|
71
|
+
console.log((0, consoleColor_1.cyanLog)(`... and ${excludedFiles.length - displayLimit} more`));
|
|
72
72
|
console.log();
|
|
73
73
|
}
|
|
74
74
|
const result = new Map();
|