svelteesp32 1.12.0 → 1.13.0
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 +86 -1
- package/dist/commandLine.d.ts +18 -1
- package/dist/commandLine.js +115 -1
- package/dist/cppCode.js +4 -4
- package/dist/cppCodeEspIdf.d.ts +1 -1
- package/dist/cppCodeEspIdf.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -12,6 +12,8 @@ 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.13.0, RC files support npm package variable interpolation
|
|
16
|
+
|
|
15
17
|
> Starting with version v1.12.0, you can use RC file for configuration
|
|
16
18
|
|
|
17
19
|
> Starting with version v1.11.0, you can exclude files by pattern
|
|
@@ -202,7 +204,7 @@ The content of **generated file** (do not edit, just use):
|
|
|
202
204
|
|
|
203
205
|
```c
|
|
204
206
|
//engine: PsychicHttpServer
|
|
205
|
-
//
|
|
207
|
+
//config: engine=psychic sourcepath=./dist outputfile=./output.h etag=true gzip=true cachetime=0 espmethod=initSvelteStaticFiles define=SVELTEESP32
|
|
206
208
|
//
|
|
207
209
|
#define SVELTEESP32_COUNT 5
|
|
208
210
|
#define SVELTEESP32_SIZE 468822
|
|
@@ -540,6 +542,89 @@ To keep defaults, explicitly list them in your RC file:
|
|
|
540
542
|
}
|
|
541
543
|
```
|
|
542
544
|
|
|
545
|
+
#### NPM Package Variable Interpolation
|
|
546
|
+
|
|
547
|
+
RC files support automatic variable interpolation from your `package.json`. This allows you to reference package.json fields in your RC configuration using npm-style variable syntax.
|
|
548
|
+
|
|
549
|
+
**Syntax:** `$npm_package_<field_name>`
|
|
550
|
+
|
|
551
|
+
**Supported in:** All string fields (`version`, `define`, `sourcepath`, `outputfile`, `espmethod`, `exclude` patterns)
|
|
552
|
+
|
|
553
|
+
**Example:**
|
|
554
|
+
|
|
555
|
+
```json
|
|
556
|
+
// .svelteesp32rc.json
|
|
557
|
+
{
|
|
558
|
+
"engine": "psychic",
|
|
559
|
+
"version": "v$npm_package_version",
|
|
560
|
+
"define": "$npm_package_name",
|
|
561
|
+
"sourcepath": "./dist",
|
|
562
|
+
"outputfile": "./output.h"
|
|
563
|
+
}
|
|
564
|
+
```
|
|
565
|
+
|
|
566
|
+
With `package.json` containing:
|
|
567
|
+
|
|
568
|
+
```json
|
|
569
|
+
{
|
|
570
|
+
"name": "my-esp32-app",
|
|
571
|
+
"version": "2.1.0"
|
|
572
|
+
}
|
|
573
|
+
```
|
|
574
|
+
|
|
575
|
+
The variables are automatically interpolated to:
|
|
576
|
+
|
|
577
|
+
```json
|
|
578
|
+
{
|
|
579
|
+
"version": "v2.1.0",
|
|
580
|
+
"define": "my_esp32_app"
|
|
581
|
+
}
|
|
582
|
+
```
|
|
583
|
+
|
|
584
|
+
**Nested Fields:**
|
|
585
|
+
|
|
586
|
+
You can access nested package.json fields using underscores:
|
|
587
|
+
|
|
588
|
+
```json
|
|
589
|
+
// package.json
|
|
590
|
+
{
|
|
591
|
+
"name": "myapp",
|
|
592
|
+
"repository": {
|
|
593
|
+
"type": "git",
|
|
594
|
+
"url": "https://github.com/user/repo.git"
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
// .svelteesp32rc.json
|
|
599
|
+
{
|
|
600
|
+
"version": "$npm_package_repository_type"
|
|
601
|
+
}
|
|
602
|
+
// Results in: "version": "git"
|
|
603
|
+
```
|
|
604
|
+
|
|
605
|
+
**Multiple Variables:**
|
|
606
|
+
|
|
607
|
+
Combine multiple variables in a single field:
|
|
608
|
+
|
|
609
|
+
```json
|
|
610
|
+
{
|
|
611
|
+
"version": "$npm_package_name-v$npm_package_version-release"
|
|
612
|
+
}
|
|
613
|
+
// Results in: "my-esp32-app-v2.1.0-release"
|
|
614
|
+
```
|
|
615
|
+
|
|
616
|
+
**Requirements:**
|
|
617
|
+
|
|
618
|
+
- `package.json` must exist in the same directory as the RC file
|
|
619
|
+
- If variables are used but `package.json` is not found, an error is thrown with details about which fields contain variables
|
|
620
|
+
- Unknown variables are left unchanged (e.g., `$npm_package_nonexistent` stays as-is)
|
|
621
|
+
|
|
622
|
+
**Use Cases:**
|
|
623
|
+
|
|
624
|
+
- **Version Synchronization:** Keep header version in sync with npm package version
|
|
625
|
+
- **Dynamic Naming:** Use package name for C++ defines automatically
|
|
626
|
+
- **CI/CD Integration:** Reusable RC files across projects with different package names
|
|
627
|
+
|
|
543
628
|
### Q&A
|
|
544
629
|
|
|
545
630
|
- **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
|
@@ -12,5 +12,22 @@ interface ICopyFilesArguments {
|
|
|
12
12
|
exclude: string[];
|
|
13
13
|
help?: boolean;
|
|
14
14
|
}
|
|
15
|
+
interface IRcFileConfig {
|
|
16
|
+
engine?: 'psychic' | 'psychic2' | 'async' | 'espidf';
|
|
17
|
+
sourcepath?: string;
|
|
18
|
+
outputfile?: string;
|
|
19
|
+
espmethod?: string;
|
|
20
|
+
define?: string;
|
|
21
|
+
gzip?: 'true' | 'false' | 'compiler';
|
|
22
|
+
etag?: 'true' | 'false' | 'compiler';
|
|
23
|
+
cachetime?: number;
|
|
24
|
+
created?: boolean;
|
|
25
|
+
version?: string;
|
|
26
|
+
exclude?: string[];
|
|
27
|
+
}
|
|
28
|
+
declare function getNpmPackageVariable(packageJson: Record<string, unknown>, variableName: string): string | undefined;
|
|
29
|
+
declare function hasNpmVariables(config: IRcFileConfig): boolean;
|
|
30
|
+
declare function interpolateNpmVariables(config: IRcFileConfig, rcFilePath: string): IRcFileConfig;
|
|
31
|
+
export { getNpmPackageVariable, hasNpmVariables, interpolateNpmVariables };
|
|
32
|
+
export declare function formatConfiguration(cmdLine: ICopyFilesArguments): string;
|
|
15
33
|
export declare const cmdLine: ICopyFilesArguments;
|
|
16
|
-
export {};
|
package/dist/commandLine.js
CHANGED
|
@@ -4,6 +4,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.cmdLine = void 0;
|
|
7
|
+
exports.getNpmPackageVariable = getNpmPackageVariable;
|
|
8
|
+
exports.hasNpmVariables = hasNpmVariables;
|
|
9
|
+
exports.interpolateNpmVariables = interpolateNpmVariables;
|
|
10
|
+
exports.formatConfiguration = formatConfiguration;
|
|
7
11
|
const node_fs_1 = require("node:fs");
|
|
8
12
|
const node_os_1 = require("node:os");
|
|
9
13
|
const node_path_1 = __importDefault(require("node:path"));
|
|
@@ -89,11 +93,100 @@ function findRcFile(customConfigPath) {
|
|
|
89
93
|
}
|
|
90
94
|
return undefined;
|
|
91
95
|
}
|
|
96
|
+
function findPackageJson(rcFilePath) {
|
|
97
|
+
const rcDirectory = node_path_1.default.dirname(rcFilePath);
|
|
98
|
+
const packageJsonPath = node_path_1.default.join(rcDirectory, 'package.json');
|
|
99
|
+
return (0, node_fs_1.existsSync)(packageJsonPath) ? packageJsonPath : undefined;
|
|
100
|
+
}
|
|
101
|
+
function parsePackageJson(packageJsonPath) {
|
|
102
|
+
try {
|
|
103
|
+
const content = (0, node_fs_1.readFileSync)(packageJsonPath, 'utf8');
|
|
104
|
+
return JSON.parse(content);
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
throw new Error(`Failed to parse package.json at ${packageJsonPath}: ${error.message}`);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
function getNpmPackageVariable(packageJson, variableName) {
|
|
111
|
+
const prefix = '$npm_package_';
|
|
112
|
+
if (!variableName.startsWith(prefix))
|
|
113
|
+
return undefined;
|
|
114
|
+
const pathString = variableName.slice(prefix.length);
|
|
115
|
+
const pathSegments = pathString.split('_');
|
|
116
|
+
let current = packageJson;
|
|
117
|
+
for (const segment of pathSegments) {
|
|
118
|
+
if (current === null || current === undefined)
|
|
119
|
+
return undefined;
|
|
120
|
+
if (typeof current !== 'object')
|
|
121
|
+
return undefined;
|
|
122
|
+
current = current[segment];
|
|
123
|
+
}
|
|
124
|
+
if (current === null || current === undefined)
|
|
125
|
+
return undefined;
|
|
126
|
+
return String(current);
|
|
127
|
+
}
|
|
128
|
+
function checkStringForNpmVariable(value) {
|
|
129
|
+
return value?.includes('$npm_package_') ?? false;
|
|
130
|
+
}
|
|
131
|
+
function hasNpmVariables(config) {
|
|
132
|
+
return (checkStringForNpmVariable(config.sourcepath) ||
|
|
133
|
+
checkStringForNpmVariable(config.outputfile) ||
|
|
134
|
+
checkStringForNpmVariable(config.espmethod) ||
|
|
135
|
+
checkStringForNpmVariable(config.define) ||
|
|
136
|
+
checkStringForNpmVariable(config.version) ||
|
|
137
|
+
(Array.isArray(config.exclude) && config.exclude.some((pattern) => checkStringForNpmVariable(pattern))) ||
|
|
138
|
+
false);
|
|
139
|
+
}
|
|
140
|
+
function interpolateNpmVariables(config, rcFilePath) {
|
|
141
|
+
if (!hasNpmVariables(config))
|
|
142
|
+
return config;
|
|
143
|
+
const packageJsonPath = findPackageJson(rcFilePath);
|
|
144
|
+
if (!packageJsonPath) {
|
|
145
|
+
const affectedFields = [];
|
|
146
|
+
if (config.sourcepath?.includes('$npm_package_'))
|
|
147
|
+
affectedFields.push('sourcepath');
|
|
148
|
+
if (config.outputfile?.includes('$npm_package_'))
|
|
149
|
+
affectedFields.push('outputfile');
|
|
150
|
+
if (config.version?.includes('$npm_package_'))
|
|
151
|
+
affectedFields.push('version');
|
|
152
|
+
if (config.espmethod?.includes('$npm_package_'))
|
|
153
|
+
affectedFields.push('espmethod');
|
|
154
|
+
if (config.define?.includes('$npm_package_'))
|
|
155
|
+
affectedFields.push('define');
|
|
156
|
+
if (config.exclude)
|
|
157
|
+
for (const [index, pattern] of config.exclude.entries())
|
|
158
|
+
if (pattern.includes('$npm_package_'))
|
|
159
|
+
affectedFields.push(`exclude[${index}]`);
|
|
160
|
+
throw new Error(`RC file uses npm package variables but package.json not found in ${node_path_1.default.dirname(rcFilePath)}\n` +
|
|
161
|
+
`Variables found in fields: ${affectedFields.join(', ')}\n` +
|
|
162
|
+
`Please ensure package.json exists in the same directory as your RC file.`);
|
|
163
|
+
}
|
|
164
|
+
const packageJson = parsePackageJson(packageJsonPath);
|
|
165
|
+
const interpolateString = (value) => {
|
|
166
|
+
const regex = /\$npm_package_[\dA-Za-z]+(?:_[a-z][\dA-Za-z]*)*/g;
|
|
167
|
+
return value.replace(regex, (match) => getNpmPackageVariable(packageJson, match) ?? match);
|
|
168
|
+
};
|
|
169
|
+
const result = { ...config };
|
|
170
|
+
if (result.sourcepath)
|
|
171
|
+
result.sourcepath = interpolateString(result.sourcepath);
|
|
172
|
+
if (result.outputfile)
|
|
173
|
+
result.outputfile = interpolateString(result.outputfile);
|
|
174
|
+
if (result.espmethod)
|
|
175
|
+
result.espmethod = interpolateString(result.espmethod);
|
|
176
|
+
if (result.define)
|
|
177
|
+
result.define = interpolateString(result.define);
|
|
178
|
+
if (result.version)
|
|
179
|
+
result.version = interpolateString(result.version);
|
|
180
|
+
if (result.exclude)
|
|
181
|
+
result.exclude = result.exclude.map((pattern) => interpolateString(pattern));
|
|
182
|
+
return result;
|
|
183
|
+
}
|
|
92
184
|
function loadRcFile(rcPath) {
|
|
93
185
|
try {
|
|
94
186
|
const content = (0, node_fs_1.readFileSync)(rcPath, 'utf8');
|
|
95
187
|
const config = JSON.parse(content);
|
|
96
|
-
|
|
188
|
+
const interpolatedConfig = interpolateNpmVariables(config, rcPath);
|
|
189
|
+
return validateRcConfig(interpolatedConfig, rcPath);
|
|
97
190
|
}
|
|
98
191
|
catch (error) {
|
|
99
192
|
if (error instanceof SyntaxError)
|
|
@@ -350,6 +443,27 @@ function parseArguments() {
|
|
|
350
443
|
}
|
|
351
444
|
return result;
|
|
352
445
|
}
|
|
446
|
+
function formatConfiguration(cmdLine) {
|
|
447
|
+
const parts = [
|
|
448
|
+
`engine=${cmdLine.engine}`,
|
|
449
|
+
`sourcepath=${cmdLine.sourcepath}`,
|
|
450
|
+
`outputfile=${cmdLine.outputfile}`,
|
|
451
|
+
`etag=${cmdLine.etag}`,
|
|
452
|
+
`gzip=${cmdLine.gzip}`,
|
|
453
|
+
`cachetime=${cmdLine.cachetime}`
|
|
454
|
+
];
|
|
455
|
+
if (cmdLine.created)
|
|
456
|
+
parts.push(`created=${cmdLine.created}`);
|
|
457
|
+
if (cmdLine.version)
|
|
458
|
+
parts.push(`version=${cmdLine.version}`);
|
|
459
|
+
if (cmdLine.espmethod)
|
|
460
|
+
parts.push(`espmethod=${cmdLine.espmethod}`);
|
|
461
|
+
if (cmdLine.define)
|
|
462
|
+
parts.push(`define=${cmdLine.define}`);
|
|
463
|
+
if (cmdLine.exclude.length > 0)
|
|
464
|
+
parts.push(`exclude=[${cmdLine.exclude.join(', ')}]`);
|
|
465
|
+
return parts.join(' ');
|
|
466
|
+
}
|
|
353
467
|
exports.cmdLine = parseArguments();
|
|
354
468
|
if (!(0, node_fs_1.existsSync)(exports.cmdLine.sourcepath) || !(0, node_fs_1.statSync)(exports.cmdLine.sourcepath).isDirectory()) {
|
|
355
469
|
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