svelteesp32 3.0.2 → 3.1.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 +38 -37
- package/dist/commandLine.js +9 -9
- package/dist/cppCode.d.ts +49 -0
- package/dist/cppCode.js +107 -985
- package/dist/cppCodeAsync.d.ts +2 -0
- package/dist/cppCodeAsync.js +101 -0
- package/dist/cppCodeEspIdf.d.ts +2 -1
- package/dist/cppCodeEspIdf.js +172 -266
- package/dist/cppCodePsychic.d.ts +2 -0
- package/dist/cppCodePsychic.js +105 -0
- package/dist/cppCodeWebserver.d.ts +2 -0
- package/dist/cppCodeWebserver.js +118 -0
- package/dist/index.js +2 -0
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -79,7 +79,7 @@ void setup() {
|
|
|
79
79
|
>
|
|
80
80
|
> ```bash
|
|
81
81
|
> npx svelteesp32 -e psychic -s ./dist -o ./esp32/svelteesp32.h \
|
|
82
|
-
> --etag=always --gzip=always --
|
|
82
|
+
> --etag=always --gzip=always --cachetimehtml=0 --cachetimeassets=31536000
|
|
83
83
|
> ```
|
|
84
84
|
>
|
|
85
85
|
> ETags for instant 304s, gzip for smaller transfers, `no-cache` for HTML so updates are always picked up, and 1-year caching for content-hashed JS/CSS assets.
|
|
@@ -88,9 +88,10 @@ void setup() {
|
|
|
88
88
|
|
|
89
89
|
## What's New
|
|
90
90
|
|
|
91
|
+
- **v3.1.0** — Removed `handlebars` dependency; C++ generation is now pure TypeScript. `--cachetime-html` → `--cachetimehtml`, `--cachetime-assets` → `--cachetimeassets` (CLI now matches RC file keys); `--dry-run` alias removed — use `--dryrun`
|
|
91
92
|
- **v3.0.0** — **Vite plugin** (`import { svelteESP32 } from 'svelteesp32/vite'`) generates the header automatically after every build — call with no argument for RC file mode or pass an options object for plugin-options mode; `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
|
-
- **v2.3.0** — `--
|
|
94
|
+
- **v2.3.0** — `--cachetimehtml` and `--cachetimeassets` for per-type cache control (e.g. `no-cache` for HTML, 1-year for content-hashed JS/CSS)
|
|
94
95
|
- **v2.2.0** — SPA routing catch-all (`--spa`) for client-side routers on all four engines
|
|
95
96
|
- **v2.1.0** — New Arduino WebServer engine (`-e webserver`), dependency updates
|
|
96
97
|
- **v2.0.0** — **BREAKING**: PsychicHttpServer V2 is now the default `psychic` engine. The `psychic2` engine has been removed. Dry run mode, C++ identifier validation, improved MIME type warnings
|
|
@@ -409,22 +410,22 @@ Fine-tune how browsers cache your content:
|
|
|
409
410
|
|
|
410
411
|
- **Default:** `no-cache` — browsers always validate with server (ETag check)
|
|
411
412
|
- **Long-term caching:** `--cachetime=86400` — cache for 24 hours without any server requests
|
|
412
|
-
- **Per-type caching:** Use `--
|
|
413
|
+
- **Per-type caching:** Use `--cachetimehtml` and `--cachetimeassets` independently
|
|
413
414
|
|
|
414
415
|
Vite and webpack produce content-hashed filenames for JS/CSS (e.g., `app.a1b2c3.js`). Those can be cached for up to a year because the hash changes with every build, but `index.html` must stay `no-cache` since it's the entry point that references them:
|
|
415
416
|
|
|
416
417
|
```bash
|
|
417
418
|
npx svelteesp32 -e psychic -s ./dist -o ./output.h \
|
|
418
|
-
--etag=always --
|
|
419
|
+
--etag=always --cachetimehtml=0 --cachetimeassets=31536000
|
|
419
420
|
```
|
|
420
421
|
|
|
421
422
|
This emits `Cache-Control: no-cache` for every `text/html` file and `Cache-Control: max-age=31536000` for all other assets in the same header, with no per-file configuration needed.
|
|
422
423
|
|
|
423
|
-
| Option
|
|
424
|
-
|
|
|
425
|
-
| `--
|
|
426
|
-
| `--
|
|
427
|
-
| `--cachetime`
|
|
424
|
+
| Option | Applies to | Falls back to |
|
|
425
|
+
| ------------------- | -------------------------------- | -------------- |
|
|
426
|
+
| `--cachetimehtml` | `text/html` only | `--cachetime` |
|
|
427
|
+
| `--cachetimeassets` | everything else | `--cachetime` |
|
|
428
|
+
| `--cachetime` | all files (when no override set) | `0` (no-cache) |
|
|
428
429
|
|
|
429
430
|
### Automatic Index Handling
|
|
430
431
|
|
|
@@ -608,31 +609,31 @@ Called for every response (200 = content served, 304 = cache hit).
|
|
|
608
609
|
|
|
609
610
|
## CLI Reference
|
|
610
611
|
|
|
611
|
-
| Option
|
|
612
|
-
|
|
|
613
|
-
| `-s`
|
|
614
|
-
| `-e`
|
|
615
|
-
| `-o`
|
|
616
|
-
| `--etag`
|
|
617
|
-
| `--gzip`
|
|
618
|
-
| `--created`
|
|
619
|
-
| `--exclude`
|
|
620
|
-
| `--basepath`
|
|
621
|
-
| `--maxsize`
|
|
622
|
-
| `--maxgzipsize`
|
|
623
|
-
| `--cachetime`
|
|
624
|
-
| `--
|
|
625
|
-
| `--
|
|
626
|
-
| `--version`
|
|
627
|
-
| `--define`
|
|
628
|
-
| `--espmethod`
|
|
629
|
-
| `--config`
|
|
630
|
-
| `--dryrun`
|
|
631
|
-
| `--analyze`
|
|
632
|
-
| `--manifest`
|
|
633
|
-
| `--spa`
|
|
634
|
-
| `--noindexcheck`
|
|
635
|
-
| `-h`
|
|
612
|
+
| Option | Description | Default |
|
|
613
|
+
| ------------------- | -------------------------------------------------------------------------------------- | ----------------------- |
|
|
614
|
+
| `-s` | Source folder with compiled web files | (required) |
|
|
615
|
+
| `-e` | Web server engine (psychic/async/espidf/webserver) | `psychic` |
|
|
616
|
+
| `-o` | Output header file path | `svelteesp32.h` |
|
|
617
|
+
| `--etag` | ETag caching (always/never/compiler) | `never` |
|
|
618
|
+
| `--gzip` | Gzip compression (always/never/compiler) | `always` |
|
|
619
|
+
| `--created` | Include creation timestamp in header | `false` |
|
|
620
|
+
| `--exclude` | Exclude files by glob pattern | (none) |
|
|
621
|
+
| `--basepath` | URL prefix for all routes | (none) |
|
|
622
|
+
| `--maxsize` | Max total uncompressed size (e.g., `400k`, `1m`) | (none) |
|
|
623
|
+
| `--maxgzipsize` | Max total gzip size (e.g., `150k`, `500k`) | (none) |
|
|
624
|
+
| `--cachetime` | Cache-Control max-age in seconds (all files) | `0` |
|
|
625
|
+
| `--cachetimehtml` | max-age for HTML files (overrides `--cachetime`) | (unset) |
|
|
626
|
+
| `--cachetimeassets` | max-age for non-HTML files (overrides `--cachetime`) | (unset) |
|
|
627
|
+
| `--version` | Version string in header | (none) |
|
|
628
|
+
| `--define` | C++ define prefix | `SVELTEESP32` |
|
|
629
|
+
| `--espmethod` | Init function name | `initSvelteStaticFiles` |
|
|
630
|
+
| `--config` | Custom RC file path | `.svelteesp32rc.json` |
|
|
631
|
+
| `--dryrun` | Show route table + summary without writing output | `false` |
|
|
632
|
+
| `--analyze` | Print per-file size table and budget status, no output written; exits 1 if over budget | `false` |
|
|
633
|
+
| `--manifest` | Write companion `.manifest.json` alongside the header | `false` |
|
|
634
|
+
| `--spa` | Serve index.html for unmatched routes (SPA routing) | `false` |
|
|
635
|
+
| `--noindexcheck` | Skip index.html validation | `false` |
|
|
636
|
+
| `-h` | Show help | |
|
|
636
637
|
|
|
637
638
|
---
|
|
638
639
|
|
|
@@ -763,7 +764,7 @@ def build_frontend(source, target, env):
|
|
|
763
764
|
"-s", "frontend/dist",
|
|
764
765
|
"-o", "src/svelteesp32.h",
|
|
765
766
|
"--etag=always", "--gzip=always",
|
|
766
|
-
"--
|
|
767
|
+
"--cachetimehtml=0", "--cachetimeassets=31536000"
|
|
767
768
|
], check=True)
|
|
768
769
|
|
|
769
770
|
env.AddPreAction("buildprog", build_frontend)
|
|
@@ -788,7 +789,7 @@ add_custom_command(
|
|
|
788
789
|
-s ${CMAKE_CURRENT_SOURCE_DIR}/frontend/dist
|
|
789
790
|
-o ${CMAKE_CURRENT_SOURCE_DIR}/main/svelteesp32.h
|
|
790
791
|
--etag=always --gzip=always
|
|
791
|
-
--
|
|
792
|
+
--cachetimehtml=0 --cachetimeassets=31536000
|
|
792
793
|
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
|
793
794
|
COMMENT "Generating svelteesp32.h from frontend build"
|
|
794
795
|
VERBATIM
|
|
@@ -817,7 +818,7 @@ void app_main(void) {
|
|
|
817
818
|
}
|
|
818
819
|
```
|
|
819
820
|
|
|
820
|
-
The `--
|
|
821
|
+
The `--cachetimehtml=0 --cachetimeassets=31536000` combination gives you `no-cache` for `index.html` (so browser always checks for updates) and a 1-year `max-age` for content-hashed JS/CSS bundles.
|
|
821
822
|
|
|
822
823
|
---
|
|
823
824
|
|
package/dist/commandLine.js
CHANGED
|
@@ -39,8 +39,8 @@ Options:
|
|
|
39
39
|
--espmethod <name> Name of generated method (default: "initSvelteStaticFiles")
|
|
40
40
|
--define <prefix> Prefix of c++ defines (default: "SVELTEESP32")
|
|
41
41
|
--cachetime <seconds> max-age cache time in seconds (default: 0)
|
|
42
|
-
--
|
|
43
|
-
--
|
|
42
|
+
--cachetimehtml <sec> Cache-Control max-age for HTML files (overrides --cachetime)
|
|
43
|
+
--cachetimeassets <sec> Cache-Control max-age for non-HTML assets (overrides --cachetime)
|
|
44
44
|
--exclude <pattern> Exclude files matching glob pattern (repeatable or comma-separated)
|
|
45
45
|
Examples: --exclude="*.map" --exclude="test/**/*.ts"
|
|
46
46
|
--basepath <path> URL prefix for all routes (e.g., "/ui") (default: "")
|
|
@@ -493,20 +493,20 @@ function parseArguments() {
|
|
|
493
493
|
if (result.cachetime < 0)
|
|
494
494
|
throw new TypeError(`Invalid cachetime: ${value} (must be non-negative)`);
|
|
495
495
|
break;
|
|
496
|
-
case '
|
|
496
|
+
case 'cachetimehtml': {
|
|
497
497
|
result.cachetimeHtml = Number.parseInt(value, 10);
|
|
498
498
|
if (Number.isNaN(result.cachetimeHtml))
|
|
499
|
-
throw new TypeError(`Invalid
|
|
499
|
+
throw new TypeError(`Invalid cachetimehtml: ${value}`);
|
|
500
500
|
if (result.cachetimeHtml < 0)
|
|
501
|
-
throw new TypeError(`Invalid
|
|
501
|
+
throw new TypeError(`Invalid cachetimehtml: ${value} (must be non-negative)`);
|
|
502
502
|
break;
|
|
503
503
|
}
|
|
504
|
-
case '
|
|
504
|
+
case 'cachetimeassets': {
|
|
505
505
|
result.cachetimeAssets = Number.parseInt(value, 10);
|
|
506
506
|
if (Number.isNaN(result.cachetimeAssets))
|
|
507
|
-
throw new TypeError(`Invalid
|
|
507
|
+
throw new TypeError(`Invalid cachetimeassets: ${value}`);
|
|
508
508
|
if (result.cachetimeAssets < 0)
|
|
509
|
-
throw new TypeError(`Invalid
|
|
509
|
+
throw new TypeError(`Invalid cachetimeassets: ${value} (must be non-negative)`);
|
|
510
510
|
break;
|
|
511
511
|
}
|
|
512
512
|
case 'exclude': {
|
|
@@ -555,7 +555,7 @@ function parseArguments() {
|
|
|
555
555
|
result.noIndexCheck = true;
|
|
556
556
|
continue;
|
|
557
557
|
}
|
|
558
|
-
if (argument === '--dryrun'
|
|
558
|
+
if (argument === '--dryrun') {
|
|
559
559
|
result.dryRun = true;
|
|
560
560
|
continue;
|
|
561
561
|
}
|
package/dist/cppCode.d.ts
CHANGED
|
@@ -15,4 +15,53 @@ export type ExtensionGroup = {
|
|
|
15
15
|
count: number;
|
|
16
16
|
};
|
|
17
17
|
export type ExtensionGroups = ExtensionGroup[];
|
|
18
|
+
export declare const sw: (value: string, cases: Partial<Record<"always" | "never" | "compiler", string>>) => string;
|
|
19
|
+
declare const transformSourceToTemplateData: (s: CppCodeSource, etag: string, effectiveCacheTime: number) => {
|
|
20
|
+
length: number;
|
|
21
|
+
bytes: string;
|
|
22
|
+
lengthGzip: number;
|
|
23
|
+
bytesGzip: string;
|
|
24
|
+
isDefault: boolean;
|
|
25
|
+
gzipSizeForManifest: number;
|
|
26
|
+
etagForManifest: string;
|
|
27
|
+
cacheTime: {
|
|
28
|
+
value: number;
|
|
29
|
+
} | undefined;
|
|
30
|
+
filename: string;
|
|
31
|
+
dataname: string;
|
|
32
|
+
datanameUpperCase: string;
|
|
33
|
+
mime: string;
|
|
34
|
+
content: Buffer;
|
|
35
|
+
contentGzip: Buffer;
|
|
36
|
+
isGzip: boolean;
|
|
37
|
+
sha256: string;
|
|
38
|
+
};
|
|
39
|
+
export type TransformedSource = ReturnType<typeof transformSourceToTemplateData>;
|
|
40
|
+
export type TemplateData = {
|
|
41
|
+
config: string;
|
|
42
|
+
now: string;
|
|
43
|
+
fileCount: string;
|
|
44
|
+
fileSize: string;
|
|
45
|
+
fileGzipSize: string;
|
|
46
|
+
sources: TransformedSource[];
|
|
47
|
+
filesByExtension: ExtensionGroups;
|
|
48
|
+
etag: string;
|
|
49
|
+
gzip: string;
|
|
50
|
+
created: boolean | undefined;
|
|
51
|
+
version: string | undefined;
|
|
52
|
+
methodName: string;
|
|
53
|
+
definePrefix: string;
|
|
54
|
+
basePath: string;
|
|
55
|
+
spa: boolean;
|
|
56
|
+
spaSource: TransformedSource | undefined;
|
|
57
|
+
isPsychic: boolean;
|
|
58
|
+
maxUriHandlers: string;
|
|
59
|
+
};
|
|
60
|
+
export declare const cacheCtrl: (source: TransformedSource) => string;
|
|
61
|
+
export declare const genCommonHeader: (d: TemplateData) => string;
|
|
62
|
+
export declare const genDataArrays: (d: TemplateData, progmem: boolean) => string;
|
|
63
|
+
export declare const genEtagArrays: (d: TemplateData) => string;
|
|
64
|
+
export declare const genManifest: (d: TemplateData) => string;
|
|
65
|
+
export declare const genHook: (d: TemplateData) => string;
|
|
18
66
|
export declare const getCppCode: (sources: CppCodeSources, filesByExtension: ExtensionGroups, options: ICopyFilesArguments) => string;
|
|
67
|
+
export {};
|