Skip to content

Commit 07f7e85

Browse files
authored
Feat: named documents (#17)
* chore: deps * chore: vscode * feat: named document instead of index * chore: deps * feat: cpp defines * fix: fix
1 parent 2404192 commit 07f7e85

File tree

10 files changed

+263
-178
lines changed

10 files changed

+263
-178
lines changed

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"typescript.tsserver.experimental.enableProjectDiagnostics": true
3+
}

README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ This npm package provides a solution for **inserting any JS client application i
1414
1515
> Starting with version v1.2.0, ESP8266/ESP8285 is also supported.
1616
17+
> Starting with version v1.3.0, c++ defines can be used.
18+
1719
### Usage
1820

1921
**Install package** as devDependency (it is practical if the package is part of the project so that you always receive updates)
@@ -103,6 +105,11 @@ You can find a minimal buildable example platformio project in [demo/esp32](demo
103105
The content of **generated file** (do not edit, just use)
104106
105107
```c
108+
#define SVELTEESP32_COUNT 5
109+
#define SVELTEESP32_SIZE 145633
110+
#define SVELTEESP32_FILE_index_html
111+
...
112+
106113
const uint8_t data0[12547] = {0x1f, 0x8b, 0x8, 0x0, ...
107114
const uint8_t data1[5368] = {0x1f, 0x8b, 0x8, 0x0, 0x0, ...
108115
const char * etag0 = "387b88e345cc56ef9091...";
@@ -166,6 +173,34 @@ The use of ETag is **not enabled by default**, this can be achieved with the `--
166173

167174
Typically, the entry point for web applications is the **index.htm or index.html** file. This does not need to be listed in the browser's address bar because web servers know that this file should be served by default. Svelteesp32 also does this: if there is an index.htm or index.html file, it sets it as the main file to be served. So using `http://esp_xxx.local` or just entering the `http://x.y.w.z/` IP address will serve this main file.
168175

176+
### C++ defines
177+
178+
To make it easy to integrate into a larger c++ project, we have made a couple of variables available as c++ defines.
179+
180+
You can use the COUNT and SIZE constants:
181+
182+
```c
183+
...
184+
#include "svelteesp32.h"
185+
186+
#if SVELTEESP32_COUNT != 5
187+
#error Invalid file count
188+
#endif
189+
...
190+
```
191+
192+
You can include a warning if a named file accidentally missing from the build:
193+
194+
```c
195+
...
196+
#include "svelteesp32.h"
197+
198+
#ifndef SVELTEESP32_FILE_index_html
199+
#error Missing index file
200+
#endif
201+
...
202+
```
203+
169204
### Command line options
170205

171206
| Option | Required | Description | default |
@@ -176,6 +211,7 @@ Typically, the entry point for web applications is the **index.htm or index.html
176211
| `--etag` | | Use ETag header for cache | false |
177212
| `--no-gzip` | | Do not compress content with gzip | false -> gzip used |
178213
| `--espmethod` | x | Name of generated method | `initSvelteStaticFiles` |
214+
| `--define` | x | Prefix of c++ defines | `SVELTEESP32` |
179215
| `-h` | | Show help | |
180216

181217
### Q&A

demo/esp32/include/svelteesp32async.h

Lines changed: 45 additions & 37 deletions
Large diffs are not rendered by default.

demo/esp32/include/svelteesp32psychic.h

Lines changed: 34 additions & 26 deletions
Large diffs are not rendered by default.

demo/esp32/src/main.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@
44
#include <ESPAsyncWebServer.h>
55
#include "svelteesp32async.h"
66

7+
#if SVELTEESP32_COUNT != 5
8+
#error Invalid file count
9+
#endif
10+
11+
#ifndef SVELTEESP32_FILE_index_html
12+
#error Missing index file
13+
#endif
14+
715
AsyncWebServer server(80);
816
void setup()
917
{
@@ -18,6 +26,14 @@ void loop() {}
1826
#include <PsychicHttp.h>
1927
#include "svelteesp32psychic.h"
2028

29+
#if SVELTEESP32_COUNT != 5
30+
#error Invalid file count
31+
#endif
32+
33+
#ifndef SVELTEESP32_FILE_index_html
34+
#error Missing index file
35+
#endif
36+
2137
PsychicHttpServer server;
2238
void setup()
2339
{

0 commit comments

Comments
 (0)