svelteesp32 3.0.0 → 3.0.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 +11 -9
- package/dist/commandLine.d.ts +4 -3
- package/dist/commandLine.js +12 -12
- package/dist/consoleColor.d.ts +0 -1
- package/dist/cppCode.d.ts +2 -2
- package/dist/cppCode.js +16 -16
- package/dist/cppCodeEspIdf.d.ts +0 -1
- package/dist/errorMessages.d.ts +0 -1
- package/dist/file.d.ts +0 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +13 -1
- package/dist/initCommand.d.ts +0 -1
- package/dist/pipeline.d.ts +0 -1
- package/dist/pipeline.js +1 -1
- package/dist/vitePlugin.d.ts +7 -7
- package/dist/vitePlugin.js +31 -32
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -88,6 +88,7 @@ void setup() {
|
|
|
88
88
|
|
|
89
89
|
## What's New
|
|
90
90
|
|
|
91
|
+
- **v3.0.1** — Vite plugin now reads RC file automatically; `output` is optional when `outputfile` is in the RC file; option names aligned to lowercase to match RC file keys (`cachetimehtml`, `cachetimeassets`, `noindexcheck`, `maxsize`, `maxgzipsize`); new `config` option to point at a custom RC file
|
|
91
92
|
- **v3.0.0** — **Vite plugin** (`import { svelteESP32 } from 'svelteesp32/vite'`) generates the header automatically after every build; `npx svelteesp32 init` interactive RC file wizard; Node.js >= 22 required
|
|
92
93
|
- **v2.4.0** — `--analyze` for CI size budget checks (per-file table, exits 1 on over-budget); `--manifest` to write a companion JSON manifest alongside the header
|
|
93
94
|
- **v2.3.0** — `--cachetime-html` and `--cachetime-assets` for per-type cache control (e.g. `no-cache` for HTML, 1-year for content-hashed JS/CSS)
|
|
@@ -147,27 +148,27 @@ export default defineConfig({
|
|
|
147
148
|
engine: 'psychic',
|
|
148
149
|
etag: 'always',
|
|
149
150
|
gzip: 'always',
|
|
150
|
-
|
|
151
|
-
|
|
151
|
+
cachetimehtml: 0,
|
|
152
|
+
cachetimeassets: 31536000
|
|
152
153
|
})
|
|
153
154
|
]
|
|
154
155
|
});
|
|
155
156
|
```
|
|
156
157
|
|
|
157
|
-
|
|
158
|
+
`output` can be omitted when `outputfile` is set in an RC file. `sourcepath` defaults to Vite's `build.outDir`. All other options mirror CLI flags and fall back to the RC file before applying built-in defaults.
|
|
158
159
|
|
|
159
160
|
**Plugin options**
|
|
160
161
|
|
|
161
162
|
| Option | Type | Default | Description |
|
|
162
163
|
| ----------------- | ------------------------------------------- | ------------------------- | -------------------------------------------------- |
|
|
163
|
-
| `output` | `string` |
|
|
164
|
+
| `output` | `string` | RC `outputfile` | Output `.h` file path |
|
|
164
165
|
| `sourcepath` | `string` | Vite's `build.outDir` | Source directory (compiled web files) |
|
|
165
166
|
| `engine` | `'psychic'\|'async'\|'espidf'\|'webserver'` | `'psychic'` | Target web server engine |
|
|
166
167
|
| `etag` | `'always'\|'never'\|'compiler'` | `'never'` | ETag generation mode |
|
|
167
168
|
| `gzip` | `'always'\|'never'\|'compiler'` | `'always'` | Gzip compression mode |
|
|
168
169
|
| `cachetime` | `number` | `0` | `Cache-Control: max-age` in seconds (all files) |
|
|
169
|
-
| `
|
|
170
|
-
| `
|
|
170
|
+
| `cachetimehtml` | `number` | (unset) | max-age for HTML files (overrides `cachetime`) |
|
|
171
|
+
| `cachetimeassets` | `number` | (unset) | max-age for non-HTML files (overrides `cachetime`) |
|
|
171
172
|
| `exclude` | `string[]` | `[]` | Glob patterns to exclude |
|
|
172
173
|
| `basepath` | `string` | (none) | URL prefix for all routes |
|
|
173
174
|
| `espmethod` | `string` | `'initSvelteStaticFiles'` | Generated init function name |
|
|
@@ -176,9 +177,10 @@ The `output` path is required; all other options mirror the CLI flags and have t
|
|
|
176
177
|
| `created` | `boolean` | `false` | Include creation timestamp |
|
|
177
178
|
| `spa` | `boolean` | `false` | Serve `index.html` for unmatched routes |
|
|
178
179
|
| `manifest` | `boolean` | `false` | Write companion `.manifest.json` |
|
|
179
|
-
| `
|
|
180
|
-
| `
|
|
181
|
-
| `
|
|
180
|
+
| `noindexcheck` | `boolean` | `false` | Skip `index.html` validation |
|
|
181
|
+
| `maxsize` | `number` | (none) | Max total uncompressed size in bytes |
|
|
182
|
+
| `maxgzipsize` | `number` | (none) | Max total gzip size in bytes |
|
|
183
|
+
| `config` | `string` | auto-discover | Path to a custom RC file |
|
|
182
184
|
|
|
183
185
|
### Generate Header File (CLI)
|
|
184
186
|
|
package/dist/commandLine.d.ts
CHANGED
|
@@ -22,7 +22,7 @@ export interface ICopyFilesArguments {
|
|
|
22
22
|
manifest?: boolean;
|
|
23
23
|
help?: boolean;
|
|
24
24
|
}
|
|
25
|
-
interface IRcFileConfig {
|
|
25
|
+
export interface IRcFileConfig {
|
|
26
26
|
engine?: 'psychic' | 'async' | 'espidf' | 'webserver';
|
|
27
27
|
sourcepath?: string;
|
|
28
28
|
outputfile?: string;
|
|
@@ -46,11 +46,12 @@ interface IRcFileConfig {
|
|
|
46
46
|
manifest?: boolean | 'true' | 'false';
|
|
47
47
|
}
|
|
48
48
|
declare function validateCppIdentifier(value: string, name: string): string;
|
|
49
|
+
export declare function validateBasePath(value: string): string;
|
|
49
50
|
declare function parseSize(value: string, name: string): number;
|
|
50
51
|
declare function getNpmPackageVariable(packageJson: Record<string, unknown>, variableName: string): string | undefined;
|
|
51
52
|
declare function hasNpmVariables(config: IRcFileConfig): boolean;
|
|
52
53
|
declare function interpolateNpmVariables(config: IRcFileConfig, rcFilePath: string): IRcFileConfig;
|
|
54
|
+
export declare function loadRcFileConfig(configPath?: string): Partial<IRcFileConfig>;
|
|
55
|
+
export declare function parseArguments(): ICopyFilesArguments;
|
|
53
56
|
export { getNpmPackageVariable, hasNpmVariables, interpolateNpmVariables, parseSize, validateCppIdentifier };
|
|
54
57
|
export declare function formatConfiguration(cmdLine: ICopyFilesArguments): string;
|
|
55
|
-
export declare const cmdLine: ICopyFilesArguments;
|
|
56
|
-
//# sourceMappingURL=commandLine.d.ts.map
|
package/dist/commandLine.js
CHANGED
|
@@ -3,7 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.validateBasePath = validateBasePath;
|
|
7
|
+
exports.loadRcFileConfig = loadRcFileConfig;
|
|
8
|
+
exports.parseArguments = parseArguments;
|
|
7
9
|
exports.getNpmPackageVariable = getNpmPackageVariable;
|
|
8
10
|
exports.hasNpmVariables = hasNpmVariables;
|
|
9
11
|
exports.interpolateNpmVariables = interpolateNpmVariables;
|
|
@@ -255,6 +257,12 @@ function loadRcFile(rcPath) {
|
|
|
255
257
|
throw error;
|
|
256
258
|
}
|
|
257
259
|
}
|
|
260
|
+
function loadRcFileConfig(configPath) {
|
|
261
|
+
const rcPath = findRcFile(configPath);
|
|
262
|
+
if (!rcPath)
|
|
263
|
+
return {};
|
|
264
|
+
return loadRcFile(rcPath);
|
|
265
|
+
}
|
|
258
266
|
function validateSizeOption(configObject, key) {
|
|
259
267
|
const value = configObject[key];
|
|
260
268
|
if (value === undefined)
|
|
@@ -525,8 +533,10 @@ function parseArguments() {
|
|
|
525
533
|
const argument = arguments_[index];
|
|
526
534
|
if (!argument)
|
|
527
535
|
continue;
|
|
528
|
-
if (argument === '--help' || argument === '-h')
|
|
536
|
+
if (argument === '--help' || argument === '-h') {
|
|
529
537
|
showHelp();
|
|
538
|
+
return result;
|
|
539
|
+
}
|
|
530
540
|
if (argument.startsWith('--') && argument.includes('=')) {
|
|
531
541
|
const parts = argument.split('=');
|
|
532
542
|
const flag = parts[0];
|
|
@@ -639,13 +649,3 @@ function formatConfiguration(cmdLine) {
|
|
|
639
649
|
parts.push(`exclude=[${cmdLine.exclude.join(', ')}]`);
|
|
640
650
|
return parts.join(' ').replace(/[\n\r]/g, ' ');
|
|
641
651
|
}
|
|
642
|
-
exports.cmdLine = parseArguments();
|
|
643
|
-
if (!(0, node_fs_1.existsSync)(exports.cmdLine.sourcepath)) {
|
|
644
|
-
console.error((0, errorMessages_1.getSourcepathNotFoundError)(exports.cmdLine.sourcepath, 'not_found'));
|
|
645
|
-
process.exit(1);
|
|
646
|
-
}
|
|
647
|
-
if (!(0, node_fs_1.statSync)(exports.cmdLine.sourcepath).isDirectory()) {
|
|
648
|
-
console.error((0, errorMessages_1.getSourcepathNotFoundError)(exports.cmdLine.sourcepath, 'not_directory'));
|
|
649
|
-
process.exit(1);
|
|
650
|
-
}
|
|
651
|
-
console.log(`[SvelteESP32] Generate code for ${exports.cmdLine.engine} engine`);
|
package/dist/consoleColor.d.ts
CHANGED
package/dist/cppCode.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ICopyFilesArguments } from './commandLine';
|
|
1
2
|
export type CppCodeSource = {
|
|
2
3
|
filename: string;
|
|
3
4
|
dataname: string;
|
|
@@ -14,5 +15,4 @@ export type ExtensionGroup = {
|
|
|
14
15
|
count: number;
|
|
15
16
|
};
|
|
16
17
|
export type ExtensionGroups = ExtensionGroup[];
|
|
17
|
-
export declare const getCppCode: (sources: CppCodeSources, filesByExtension: ExtensionGroups) => string;
|
|
18
|
-
//# sourceMappingURL=cppCode.d.ts.map
|
|
18
|
+
export declare const getCppCode: (sources: CppCodeSources, filesByExtension: ExtensionGroups, options: ICopyFilesArguments) => string;
|
package/dist/cppCode.js
CHANGED
|
@@ -1010,17 +1010,17 @@ const createHandlebarsHelpers = () => {
|
|
|
1010
1010
|
}
|
|
1011
1011
|
};
|
|
1012
1012
|
};
|
|
1013
|
-
const getCppCode = (sources, filesByExtension) => {
|
|
1014
|
-
const template = (0, handlebars_1.compile)(getTemplate(
|
|
1013
|
+
const getCppCode = (sources, filesByExtension, options) => {
|
|
1014
|
+
const template = (0, handlebars_1.compile)(getTemplate(options.engine));
|
|
1015
1015
|
const transformedSources = sources.map((s) => {
|
|
1016
1016
|
const effectiveCacheTime = s.mime === 'text/html'
|
|
1017
|
-
? (
|
|
1018
|
-
: (
|
|
1019
|
-
return transformSourceToTemplateData(s,
|
|
1017
|
+
? (options.cachetimeHtml ?? options.cachetime)
|
|
1018
|
+
: (options.cachetimeAssets ?? options.cachetime);
|
|
1019
|
+
return transformSourceToTemplateData(s, options.etag, effectiveCacheTime);
|
|
1020
1020
|
});
|
|
1021
|
-
const spaSource =
|
|
1021
|
+
const spaSource = options.spa ? transformedSources.find((s) => s.isDefault) : undefined;
|
|
1022
1022
|
const templateData = {
|
|
1023
|
-
config: (0, commandLine_1.formatConfiguration)(
|
|
1023
|
+
config: (0, commandLine_1.formatConfiguration)(options),
|
|
1024
1024
|
now: (() => {
|
|
1025
1025
|
const d = new Date();
|
|
1026
1026
|
return `${d.toLocaleDateString()} ${d.toLocaleTimeString()}`;
|
|
@@ -1030,16 +1030,16 @@ const getCppCode = (sources, filesByExtension) => {
|
|
|
1030
1030
|
fileGzipSize: sources.reduce((previous, current) => previous + current.contentGzip.length, 0).toString(),
|
|
1031
1031
|
sources: transformedSources,
|
|
1032
1032
|
filesByExtension,
|
|
1033
|
-
etag:
|
|
1034
|
-
gzip:
|
|
1035
|
-
created:
|
|
1036
|
-
version:
|
|
1037
|
-
methodName:
|
|
1038
|
-
definePrefix:
|
|
1039
|
-
basePath:
|
|
1040
|
-
spa: !!
|
|
1033
|
+
etag: options.etag,
|
|
1034
|
+
gzip: options.gzip,
|
|
1035
|
+
created: options.created,
|
|
1036
|
+
version: options.version,
|
|
1037
|
+
methodName: options.espmethod,
|
|
1038
|
+
definePrefix: options.define,
|
|
1039
|
+
basePath: options.basePath,
|
|
1040
|
+
spa: !!options.spa,
|
|
1041
1041
|
spaSource,
|
|
1042
|
-
isPsychic:
|
|
1042
|
+
isPsychic: options.engine === 'psychic',
|
|
1043
1043
|
maxUriHandlers: (sources.length + 5).toString()
|
|
1044
1044
|
};
|
|
1045
1045
|
const rawCode = template(templateData, { helpers: createHandlebarsHelpers() });
|
package/dist/cppCodeEspIdf.d.ts
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
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 \"always\"}}\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 \"never\"}}\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 \"always\"}}\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 \"never\"}}\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 \"always\"}}\n {{#each sources}}\nstatic const unsigned char datagzip_{{this.dataname}}[{{this.lengthGzip}}] = { {{this.bytesGzip}} };\n {{/each}}\n{{/case}}\n{{#case \"never\"}}\n {{#each sources}}\nstatic const unsigned char data_{{this.dataname}}[{{this.length}}] = { {{this.bytes}} };\n {{/each}}\n{{/case}}\n{{#case \"compiler\"}}\n#ifdef {{definePrefix}}_ENABLE_GZIP\n {{#each sources}}\nstatic const unsigned char datagzip_{{this.dataname}}[{{this.lengthGzip}}] = { {{this.bytesGzip}} };\n {{/each}}\n#else\n {{#each sources}}\nstatic const unsigned char data_{{this.dataname}}[{{this.length}}] = { {{this.bytes}} };\n {{/each}}\n#endif \n{{/case}}\n{{/switch}}\n\n//\n{{#switch etag}}\n{{#case \"always\"}}\n {{#each sources}}\nstatic const char etag_{{this.dataname}}[] = \"{{this.sha256}}\";\n {{/each}}\n{{/case}}\n{{#case \"never\"}}\n{{/case}}\n{{#case \"compiler\"}}\n#ifdef {{definePrefix}}_ENABLE_ETAG\n {{#each sources}}\nstatic const char etag_{{this.dataname}}[] = \"{{this.sha256}}\";\n {{/each}}\n#endif\n{{/case}}\n{{/switch}}\n\n// File manifest struct (C-compatible typedef)\ntypedef struct {\n const char* path;\n uint32_t size;\n uint32_t gzipSize;\n const char* etag;\n const char* contentType;\n} {{definePrefix}}_FileInfo;\n\n// File manifest array\nstatic const {{definePrefix}}_FileInfo {{definePrefix}}_FILES[] = {\n{{#each sources}}\n { \"{{../basePath}}/{{this.filename}}\", {{this.length}}, {{this.gzipSizeForManifest}}, {{this.etagForManifest}}, \"{{this.mime}}\" },\n{{/each}}\n};\nstatic const size_t {{definePrefix}}_FILE_COUNT = sizeof({{definePrefix}}_FILES) / sizeof({{definePrefix}}_FILES[0]);\n\n// File served hook - override with your own implementation\n__attribute__((weak)) void {{definePrefix}}_onFileServed(const char* path, int statusCode) {}\n\n{{#each sources}}\n\nstatic esp_err_t file_handler_{{this.datanameUpperCase}} (httpd_req_t *req)\n{\n{{#switch ../etag}}\n{{#case \"always\"}}\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 (hdr_value == NULL) { httpd_resp_send_500(req); return ESP_FAIL; }\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 {{../definePrefix}}_onFileServed(\"{{../basePath}}/{{this.filename}}\", 304);\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 (hdr_value == NULL) { httpd_resp_send_500(req); return ESP_FAIL; }\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 {{../definePrefix}}_onFileServed(\"{{../basePath}}/{{this.filename}}\", 304);\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 \"always\"}}\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 \"always\"}}\n{{#this.cacheTime}}\n httpd_resp_set_hdr(req, \"Cache-Control\", \"max-age={{value}}\");\n{{/this.cacheTime}}\n{{^this.cacheTime}}\n httpd_resp_set_hdr(req, \"Cache-Control\", \"no-cache\");\n{{/this.cacheTime}}\n httpd_resp_set_hdr(req, \"ETag\", etag_{{this.dataname}});\n{{/case}}\n{{#case \"compiler\"}}\n #ifdef {{../definePrefix}}_ENABLE_ETAG\n{{#this.cacheTime}}\n httpd_resp_set_hdr(req, \"Cache-Control\", \"max-age={{value}}\");\n{{/this.cacheTime}}\n{{^this.cacheTime}}\n httpd_resp_set_hdr(req, \"Cache-Control\", \"no-cache\");\n{{/this.cacheTime}}\n httpd_resp_set_hdr(req, \"ETag\", etag_{{this.dataname}});\n #endif \n{{/case}}\n{{/switch}}\n\n{{#switch ../gzip}}\n{{#case \"always\"}}\n {{../definePrefix}}_onFileServed(\"{{../basePath}}/{{this.filename}}\", 200);\n httpd_resp_send(req, (const char *)datagzip_{{this.dataname}}, {{this.lengthGzip}});\n{{/case}}\n{{#case \"never\"}}\n {{../definePrefix}}_onFileServed(\"{{../basePath}}/{{this.filename}}\", 200);\n httpd_resp_send(req, (const char *)data_{{this.dataname}}, {{this.length}});\n{{/case}}\n{{#case \"compiler\"}}\n {{../definePrefix}}_onFileServed(\"{{../basePath}}/{{this.filename}}\", 200);\n #ifdef {{../definePrefix}}_ENABLE_GZIP\n httpd_resp_send(req, (const char *)datagzip_{{this.dataname}}, {{this.lengthGzip}});\n #else\n httpd_resp_send(req, (const char *)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 = \"{{#if ../basePath}}{{../basePath}}{{else}}/{{/if}}\",\n .method = HTTP_GET,\n .handler = file_handler_{{this.datanameUpperCase}},\n};\n{{/if}}\n\nstatic const httpd_uri_t route_{{this.datanameUpperCase}} = {\n .uri = \"{{../basePath}}/{{this.filename}}\",\n .method = HTTP_GET,\n .handler = file_handler_{{this.datanameUpperCase}},\n};\n\n{{/each}}\n\n{{#if spa}}\n{{#with spaSource}}\nstatic esp_err_t spa_handler_{{this.datanameUpperCase}}(httpd_req_t *req, httpd_err_code_t err) {\n{{#if ../basePath}}\n const char* prefix = \"{{../basePath}}/\";\n if (strncmp(req->uri, prefix, strlen(prefix)) != 0 && strcmp(req->uri, \"{{../basePath}}\") != 0) {\n httpd_resp_send_err(req, HTTPD_404_NOT_FOUND, \"Not found\");\n return ESP_FAIL;\n }\n{{/if}}\n return file_handler_{{this.datanameUpperCase}}(req);\n}\n{{/with}}\n{{/if}}\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{{#if spa}}\n{{#with spaSource}}\n httpd_register_err_handler(server, HTTPD_404_NOT_FOUND, spa_handler_{{this.datanameUpperCase}});\n{{/with}}\n{{/if}}\n\n}";
|
|
2
|
-
//# sourceMappingURL=cppCodeEspIdf.d.ts.map
|
package/dist/errorMessages.d.ts
CHANGED
|
@@ -3,4 +3,3 @@ export declare function getInvalidEngineError(attempted: string): string;
|
|
|
3
3
|
export declare function getSourcepathNotFoundError(sourcepath: string, reason: 'not_found' | 'not_directory'): string;
|
|
4
4
|
export declare function getSizeBudgetExceededError(type: 'size' | 'gzipSize', limit: number, actual: number): string;
|
|
5
5
|
export declare function getMaxUriHandlersHint(engine: string, routeCount: number, espmethod?: string): string;
|
|
6
|
-
//# sourceMappingURL=errorMessages.d.ts.map
|
package/dist/file.d.ts
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
1
|
export declare function main(): void;
|
|
2
2
|
export { calculateCompressionRatio, createSourceEntry, formatAnalyzeTable, formatChangeSummary, formatCompressionLog, formatDryRunRoutes, formatSize, formatSizePrecise, type PreviousManifestFile, shouldUseGzip, updateExtensionGroup } from './pipeline';
|
|
3
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -2,11 +2,23 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.updateExtensionGroup = exports.shouldUseGzip = exports.formatSizePrecise = exports.formatSize = exports.formatDryRunRoutes = exports.formatCompressionLog = exports.formatChangeSummary = exports.formatAnalyzeTable = exports.createSourceEntry = exports.calculateCompressionRatio = void 0;
|
|
4
4
|
exports.main = main;
|
|
5
|
+
const node_fs_1 = require("node:fs");
|
|
5
6
|
const commandLine_1 = require("./commandLine");
|
|
7
|
+
const errorMessages_1 = require("./errorMessages");
|
|
6
8
|
const pipeline_1 = require("./pipeline");
|
|
7
9
|
function main() {
|
|
10
|
+
const cmdLine = (0, commandLine_1.parseArguments)();
|
|
11
|
+
if (!(0, node_fs_1.existsSync)(cmdLine.sourcepath)) {
|
|
12
|
+
console.error((0, errorMessages_1.getSourcepathNotFoundError)(cmdLine.sourcepath, 'not_found'));
|
|
13
|
+
process.exit(1);
|
|
14
|
+
}
|
|
15
|
+
if (!(0, node_fs_1.statSync)(cmdLine.sourcepath).isDirectory()) {
|
|
16
|
+
console.error((0, errorMessages_1.getSourcepathNotFoundError)(cmdLine.sourcepath, 'not_directory'));
|
|
17
|
+
process.exit(1);
|
|
18
|
+
}
|
|
19
|
+
console.log(`[SvelteESP32] Generate code for ${cmdLine.engine} engine`);
|
|
8
20
|
try {
|
|
9
|
-
(0, pipeline_1.runPipeline)(
|
|
21
|
+
(0, pipeline_1.runPipeline)(cmdLine);
|
|
10
22
|
}
|
|
11
23
|
catch (error) {
|
|
12
24
|
if (!(error instanceof pipeline_1.OverBudgetError)) {
|
package/dist/initCommand.d.ts
CHANGED
package/dist/pipeline.d.ts
CHANGED
|
@@ -26,4 +26,3 @@ export declare class OverBudgetError extends Error {
|
|
|
26
26
|
declare const formatChangeSummary: (sources: CppCodeSources, previousFiles: PreviousManifestFile[]) => string;
|
|
27
27
|
export declare function runPipeline(options: ICopyFilesArguments): void;
|
|
28
28
|
export { calculateCompressionRatio, createSourceEntry, formatAnalyzeTable, formatChangeSummary, formatCompressionLog, formatDryRunRoutes, formatSize, formatSizePrecise, shouldUseGzip, updateExtensionGroup };
|
|
29
|
-
//# sourceMappingURL=pipeline.d.ts.map
|
package/dist/pipeline.js
CHANGED
|
@@ -237,7 +237,7 @@ function runPipeline(options) {
|
|
|
237
237
|
console.log(formatDryRunRoutes(sources, options.engine, options.basePath, options.spa ?? false));
|
|
238
238
|
return;
|
|
239
239
|
}
|
|
240
|
-
const cppFile = (0, cppCode_1.getCppCode)(sources, filesByExtension);
|
|
240
|
+
const cppFile = (0, cppCode_1.getCppCode)(sources, filesByExtension, options);
|
|
241
241
|
(0, node_fs_1.mkdirSync)(node_path_1.default.normalize(node_path_1.default.dirname(options.outputfile)), { recursive: true });
|
|
242
242
|
(0, node_fs_1.writeFileSync)(options.outputfile, cppFile, { flush: true, encoding: 'utf8' });
|
|
243
243
|
console.log(`${summary.filecount} files, ${formatSize(summary.size)} original size, ${formatSize(summary.gzipsize)} gzip size`);
|
package/dist/vitePlugin.d.ts
CHANGED
|
@@ -9,14 +9,14 @@ interface VitePlugin {
|
|
|
9
9
|
closeBundle: () => void;
|
|
10
10
|
}
|
|
11
11
|
export interface SvelteESP32PluginOptions {
|
|
12
|
-
output
|
|
12
|
+
output?: string;
|
|
13
13
|
sourcepath?: string;
|
|
14
14
|
engine?: 'psychic' | 'async' | 'espidf' | 'webserver';
|
|
15
15
|
etag?: 'always' | 'never' | 'compiler';
|
|
16
16
|
gzip?: 'always' | 'never' | 'compiler';
|
|
17
17
|
cachetime?: number;
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
cachetimehtml?: number;
|
|
19
|
+
cachetimeassets?: number;
|
|
20
20
|
exclude?: string[];
|
|
21
21
|
basepath?: string;
|
|
22
22
|
espmethod?: string;
|
|
@@ -25,10 +25,10 @@ export interface SvelteESP32PluginOptions {
|
|
|
25
25
|
created?: boolean;
|
|
26
26
|
spa?: boolean;
|
|
27
27
|
manifest?: boolean;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
noindexcheck?: boolean;
|
|
29
|
+
maxsize?: number;
|
|
30
|
+
maxgzipsize?: number;
|
|
31
|
+
config?: string;
|
|
31
32
|
}
|
|
32
33
|
export declare function svelteESP32(options: SvelteESP32PluginOptions): VitePlugin;
|
|
33
34
|
export {};
|
|
34
|
-
//# sourceMappingURL=vitePlugin.d.ts.map
|
package/dist/vitePlugin.js
CHANGED
|
@@ -5,7 +5,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.svelteESP32 = svelteESP32;
|
|
7
7
|
const node_path_1 = __importDefault(require("node:path"));
|
|
8
|
+
const commandLine_1 = require("./commandLine");
|
|
8
9
|
const pipeline_1 = require("./pipeline");
|
|
10
|
+
function coerceBool(value) {
|
|
11
|
+
if (value === undefined)
|
|
12
|
+
return undefined;
|
|
13
|
+
return value === true || value === 'true';
|
|
14
|
+
}
|
|
9
15
|
function svelteESP32(options) {
|
|
10
16
|
let outDirectory = 'dist';
|
|
11
17
|
return {
|
|
@@ -14,41 +20,34 @@ function svelteESP32(options) {
|
|
|
14
20
|
outDirectory = config.build.outDir;
|
|
15
21
|
},
|
|
16
22
|
closeBundle() {
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
if (
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
if (bp.includes('//'))
|
|
26
|
-
throw new Error(`basePath must not contain //: ${bp}`);
|
|
27
|
-
if (bp.includes('"'))
|
|
28
|
-
throw new Error(`basePath must not contain double quotes: ${bp}`);
|
|
29
|
-
if (bp.includes('\\'))
|
|
30
|
-
throw new Error(`basePath must not contain backslashes: ${bp}`);
|
|
31
|
-
}
|
|
23
|
+
const rcConfig = (0, commandLine_1.loadRcFileConfig)(options.config);
|
|
24
|
+
const rawOutput = options.output ?? rcConfig.outputfile;
|
|
25
|
+
if (!rawOutput)
|
|
26
|
+
throw new Error('output is required — specify it as a plugin option or in the RC file (outputfile)');
|
|
27
|
+
const outputfile = node_path_1.default.resolve(rawOutput);
|
|
28
|
+
const sourcepath = options.sourcepath ?? rcConfig.sourcepath ?? outDirectory;
|
|
29
|
+
const rawBasepath = options.basepath ?? rcConfig.basepath ?? '';
|
|
30
|
+
const basePath = (0, commandLine_1.validateBasePath)(rawBasepath);
|
|
32
31
|
const options_ = {
|
|
33
|
-
engine: options.engine ?? 'psychic',
|
|
32
|
+
engine: options.engine ?? rcConfig.engine ?? 'psychic',
|
|
34
33
|
sourcepath,
|
|
35
34
|
outputfile,
|
|
36
|
-
etag: options.etag ?? 'never',
|
|
37
|
-
gzip: options.gzip ?? 'always',
|
|
38
|
-
cachetime: options.cachetime ?? 0,
|
|
39
|
-
cachetimeHtml: options.
|
|
40
|
-
cachetimeAssets: options.
|
|
41
|
-
created: options.created ?? false,
|
|
42
|
-
version: options.version ?? '',
|
|
43
|
-
espmethod: options.espmethod ?? 'initSvelteStaticFiles',
|
|
44
|
-
define: options.define ?? 'SVELTEESP32',
|
|
45
|
-
exclude: options.exclude ?? [],
|
|
46
|
-
basePath
|
|
47
|
-
noIndexCheck: options.
|
|
48
|
-
spa: options.spa,
|
|
49
|
-
manifest: options.manifest,
|
|
50
|
-
maxSize: options.
|
|
51
|
-
maxGzipSize: options.
|
|
35
|
+
etag: options.etag ?? rcConfig.etag ?? 'never',
|
|
36
|
+
gzip: options.gzip ?? rcConfig.gzip ?? 'always',
|
|
37
|
+
cachetime: options.cachetime ?? rcConfig.cachetime ?? 0,
|
|
38
|
+
cachetimeHtml: options.cachetimehtml ?? rcConfig.cachetimehtml,
|
|
39
|
+
cachetimeAssets: options.cachetimeassets ?? rcConfig.cachetimeassets,
|
|
40
|
+
created: options.created ?? coerceBool(rcConfig.created) ?? false,
|
|
41
|
+
version: options.version ?? rcConfig.version ?? '',
|
|
42
|
+
espmethod: options.espmethod ?? rcConfig.espmethod ?? 'initSvelteStaticFiles',
|
|
43
|
+
define: options.define ?? rcConfig.define ?? 'SVELTEESP32',
|
|
44
|
+
exclude: options.exclude ?? rcConfig.exclude ?? [],
|
|
45
|
+
basePath,
|
|
46
|
+
noIndexCheck: options.noindexcheck ?? coerceBool(rcConfig.noindexcheck),
|
|
47
|
+
spa: options.spa ?? coerceBool(rcConfig.spa),
|
|
48
|
+
manifest: options.manifest ?? coerceBool(rcConfig.manifest),
|
|
49
|
+
maxSize: options.maxsize ?? rcConfig.maxsize,
|
|
50
|
+
maxGzipSize: options.maxgzipsize ?? rcConfig.maxgzipsize
|
|
52
51
|
};
|
|
53
52
|
(0, pipeline_1.runPipeline)(options_);
|
|
54
53
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "svelteesp32",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.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",
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
},
|
|
12
12
|
"./vite": {
|
|
13
13
|
"types": "./dist/vitePlugin.d.ts",
|
|
14
|
+
"require": "./dist/vitePlugin.js",
|
|
14
15
|
"default": "./dist/vitePlugin.js"
|
|
15
16
|
}
|
|
16
17
|
},
|