Skip to content

Commit 1dc263c

Browse files
committed
feat: psychic v2
1 parent 7df2b07 commit 1dc263c

File tree

9 files changed

+333
-32
lines changed

9 files changed

+333
-32
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Change log
22

3+
## 1.5
4+
5+
### 1.5.0
6+
7+
- New engine type (-e psychic2) for PsychicHttp v2
8+
9+
- Run tests with github repos instead of packages
10+
311
## 1.4
412

513
### 1.4.1

README.md

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ In order to be able to easily update OTA, it is important - from the users' poin
1212

1313
This npm package provides a solution for **inserting any JS client application into the ESP web server** (PsychicHttp and also ESPAsyncWebServer 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**.
1414

15+
> Starting with version v1.5.0, PsychicHttp v2 is also supported.
16+
1517
> Version v1.4.0 has a breaking change! --no-gzip changed to --gzip. Starting with this version c++ compiler directives are available to setup operation in project level.
1618
1719
> Starting with version v1.3.0, c++ defines can be used.
@@ -34,6 +36,9 @@ After a successful Svelte build (rollup/webpack/vite) **create an includeable c+
3436
// for PsychicHttpServer
3537
npx svelteesp32 -e psychic -s ../svelteapp/dist -o ../esp32project/svelteesp32.h --etag=true
3638

39+
// for PsychicHttpServer V2
40+
npx svelteesp32 -e psychic2 -s ../svelteapp/dist -o ../esp32project/svelteesp32.h --etag=true
41+
3742
// for ESPAsyncWebServer
3843
npx svelteesp32 -e async -s ../svelteapp/dist -o ../esp32project/svelteesp32.h --etag=true
3944
```
@@ -217,18 +222,18 @@ You can use the following c++ directives at the project level if you want to con
217222

218223
### Command line options
219224

220-
| Option | Description | default |
221-
| ------------- | ---------------------------------------------------------------- | ----------------------- |
222-
| `-s` | **Source dist folder contains compiled web files** | |
223-
| `-e` | The engine for which the include file is created (psychic/async) | psychic |
224-
| `-o` | Generated output file with path | `svelteesp32.h` |
225-
| `--etag` | Use ETag header for cache (true/false/compiler) | false |
226-
| `--gzip` | Compress content with gzip (true/false/compiler) | true |
227-
| `--created` | Include creation time | false |
228-
| `--version` | Include a version string, `--version=v$npm_package_version` | '' |
229-
| `--espmethod` | Name of generated method | `initSvelteStaticFiles` |
230-
| `--define` | Prefix of c++ defines | `SVELTEESP32` |
231-
| `-h` | Show help | |
225+
| Option | Description | default |
226+
| ------------- | ------------------------------------------------------------------------- | ----------------------- |
227+
| `-s` | **Source dist folder contains compiled web files** | |
228+
| `-e` | The engine for which the include file is created (psychic/psychic2/async) | psychic |
229+
| `-o` | Generated output file with path | `svelteesp32.h` |
230+
| `--etag` | Use ETag header for cache (true/false/compiler) | false |
231+
| `--gzip` | Compress content with gzip (true/false/compiler) | true |
232+
| `--created` | Include creation time | false |
233+
| `--version` | Include a version string, `--version=v$npm_package_version` | '' |
234+
| `--espmethod` | Name of generated method | `initSvelteStaticFiles` |
235+
| `--define` | Prefix of c++ defines | `SVELTEESP32` |
236+
| `-h` | Show help | |
232237

233238
### Q&A
234239

demo/esp32/platformio.ini

Lines changed: 71 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,58 +71,120 @@ lib_deps = https://github.com/me-no-dev/ESPAsyncWebServer
7171
build_flags =
7272
-D PSYCHIC
7373
-I include/_
74-
lib_deps = hoeken/PsychicHttp
74+
lib_deps = https://github.com/hoeken/PsychicHttp
7575

7676
[env:psychic_E]
7777
build_flags =
7878
-D PSYCHIC
7979
-I include/e
80-
lib_deps = hoeken/PsychicHttp
80+
lib_deps = https://github.com/hoeken/PsychicHttp
8181

8282
[env:psychic_EC]
8383
build_flags =
8484
-D PSYCHIC
8585
-I include/ec
8686
-D SVELTEESP32_ENABLE_ETAG
87-
lib_deps = hoeken/PsychicHttp
87+
lib_deps = https://github.com/hoeken/PsychicHttp
8888

8989
[env:psychic_ECG]
9090
build_flags =
9191
-D PSYCHIC
9292
-I include/ecg
9393
-D SVELTEESP32_ENABLE_ETAG
94-
lib_deps = hoeken/PsychicHttp
94+
lib_deps = https://github.com/hoeken/PsychicHttp
9595

9696
[env:psychic_ECGC]
9797
build_flags =
9898
-D PSYCHIC
9999
-I include/ecgc
100100
-D SVELTEESP32_ENABLE_ETAG
101101
-D SVELTEESP32_ENABLE_GZIP
102-
lib_deps = hoeken/PsychicHttp
102+
lib_deps = https://github.com/hoeken/PsychicHttp
103103

104104
[env:psychic_EG]
105105
build_flags =
106106
-D PSYCHIC
107107
-I include/eg
108-
lib_deps = hoeken/PsychicHttp
108+
lib_deps = https://github.com/hoeken/PsychicHttp
109109

110110
[env:psychic_EGC]
111111
build_flags =
112112
-D PSYCHIC
113113
-I include/egc
114114
-D SVELTEESP32_ENABLE_GZIP
115-
lib_deps = hoeken/PsychicHttp
115+
lib_deps = https://github.com/hoeken/PsychicHttp
116116

117117
[env:psychic_G]
118118
build_flags =
119119
-D PSYCHIC
120120
-I include/g
121-
lib_deps = hoeken/PsychicHttp
121+
lib_deps = https://github.com/hoeken/PsychicHttp
122122

123123
[env:psychic_GC]
124124
build_flags =
125125
-D PSYCHIC
126126
-I include/gc
127127
-D SVELTEESP32_ENABLE_GZIP
128-
lib_deps = hoeken/PsychicHttp
128+
lib_deps = https://github.com/hoeken/PsychicHttp
129+
130+
131+
132+
[env:psychic2]
133+
build_flags =
134+
-D PSYCHIC2
135+
-I include/_
136+
lib_deps = https://github.com/hoeken/PsychicHttp#v2-dev
137+
138+
[env:psychic2_E]
139+
build_flags =
140+
-D PSYCHIC2
141+
-I include/e
142+
lib_deps = https://github.com/hoeken/PsychicHttp#v2-dev
143+
144+
[env:psychic2_EC]
145+
build_flags =
146+
-D PSYCHIC2
147+
-I include/ec
148+
-D SVELTEESP32_ENABLE_ETAG
149+
lib_deps = https://github.com/hoeken/PsychicHttp#v2-dev
150+
151+
[env:psychic2_ECG]
152+
build_flags =
153+
-D PSYCHIC2
154+
-I include/ecg
155+
-D SVELTEESP32_ENABLE_ETAG
156+
lib_deps = https://github.com/hoeken/PsychicHttp#v2-dev
157+
158+
[env:psychic2_ECGC]
159+
build_flags =
160+
-D PSYCHIC2
161+
-I include/ecgc
162+
-D SVELTEESP32_ENABLE_ETAG
163+
-D SVELTEESP32_ENABLE_GZIP
164+
lib_deps = https://github.com/hoeken/PsychicHttp#v2-dev
165+
166+
[env:psychic2_EG]
167+
build_flags =
168+
-D PSYCHIC2
169+
-I include/eg
170+
lib_deps = https://github.com/hoeken/PsychicHttp#v2-dev
171+
172+
[env:psychic2_EGC]
173+
build_flags =
174+
-D PSYCHIC2
175+
-I include/egc
176+
-D SVELTEESP32_ENABLE_GZIP
177+
lib_deps = https://github.com/hoeken/PsychicHttp#v2-dev
178+
179+
[env:psychic2_G]
180+
build_flags =
181+
-D PSYCHIC2
182+
-I include/g
183+
lib_deps = https://github.com/hoeken/PsychicHttp#v2-dev
184+
185+
[env:psychic2_GC]
186+
build_flags =
187+
-D PSYCHIC2
188+
-I include/gc
189+
-D SVELTEESP32_ENABLE_GZIP
190+
lib_deps = https://github.com/hoeken/PsychicHttp#v2-dev

demo/esp32/src/main.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,40 @@ void setup()
6666
}
6767
void loop() {}
6868

69+
#elif PSYCHIC2
70+
/* PsychicHttp example */
71+
72+
#include "credentials.h"
73+
#include <WiFi.h>
74+
#include <PsychicHttp.h>
75+
#include "svelteesp32psychic2.h"
76+
77+
#if SVELTEESP32_COUNT != 11
78+
#error Invalid file count
79+
#endif
80+
81+
#ifndef SVELTEESP32_FILE_INDEX_HTML
82+
#error Missing index file
83+
#endif
84+
85+
#if SVELTEESP32_CSS_FILES > 1
86+
#error Too many CSS files
87+
#endif
88+
89+
PsychicHttpServer server(80);
90+
void setup()
91+
{
92+
WiFi.mode(WIFI_STA);
93+
WiFi.begin(ssid, pass);
94+
if (WiFi.waitForConnectResult() != WL_CONNECTED)
95+
while (true)
96+
;
97+
98+
server.begin();
99+
initSvelteStaticFiles(&server);
100+
}
101+
void loop() {}
102+
69103
#else
70104
#error Unknown platform
71105
#endif

package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "svelteesp32",
3-
"version": "1.4.2",
3+
"version": "1.5.0",
44
"description": "Convert Svelte (or any frontend) JS application to serve it from ESP32 webserver (PsychicHttp)",
55
"author": "BCsabaEngine",
66
"license": "ISC",
@@ -30,6 +30,7 @@
3030
"scripts": {
3131
"dev:async": "nodemon src/index.ts -- -e async -s ./demo/svelte/dist -o ./demo/esp32/include/svelteesp32.h --etag=true --gzip=true --version=v$npm_package_version",
3232
"dev:psychic": "nodemon src/index.ts -- -e psychic -s ./demo/svelte/dist -o ./demo/esp32/include/svelteesp32.h --etag=false --gzip=false --version=v$npm_package_version",
33+
"dev:psychic2": "nodemon src/index.ts -- -e psychic2 -s ./demo/svelte/dist -o ./demo/esp32/include/svelteesp32.h --etag=false --gzip=false --version=v$npm_package_version",
3334
"test:all": "./package.script && ~/.platformio/penv/bin/pio run -d ./demo/esp32",
3435
"clean": "tsc --build --clean",
3536
"build": "tsc --build --clean && tsc --build --force",
@@ -49,11 +50,12 @@
4950
"esp8266",
5051
"webserver",
5152
"psychichttpserver",
53+
"psychichttpserverV2",
5254
"espasyncwebserver"
5355
],
5456
"devDependencies": {
5557
"@types/mime-types": "^2.1.4",
56-
"@types/node": "^22.5.1",
58+
"@types/node": "^22.5.2",
5759
"@typescript-eslint/eslint-plugin": "^8.3.0",
5860
"@typescript-eslint/parser": "^8.3.0",
5961
"eslint": "^9.9.1",

package.script

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,13 @@ npx tsx src/index.ts -e psychic -s ./demo/svelte/dist -o ./demo/esp32/include/eg
1717
npx tsx src/index.ts -e psychic -s ./demo/svelte/dist -o ./demo/esp32/include/ec/svelteesp32psychic.h --etag=compiler --gzip=false
1818
npx tsx src/index.ts -e psychic -s ./demo/svelte/dist -o ./demo/esp32/include/ecg/svelteesp32psychic.h --etag=compiler --gzip=true
1919
npx tsx src/index.ts -e psychic -s ./demo/svelte/dist -o ./demo/esp32/include/ecgc/svelteesp32psychic.h --etag=compiler --gzip=compiler
20+
21+
npx tsx src/index.ts -e psychic2 -s ./demo/svelte/dist -o ./demo/esp32/include/_/svelteesp32psychic2.h --etag=false --gzip=false
22+
npx tsx src/index.ts -e psychic2 -s ./demo/svelte/dist -o ./demo/esp32/include/g/svelteesp32psychic2.h --etag=false --gzip=true
23+
npx tsx src/index.ts -e psychic2 -s ./demo/svelte/dist -o ./demo/esp32/include/gc/svelteesp32psychic2.h --etag=false --gzip=compiler
24+
npx tsx src/index.ts -e psychic2 -s ./demo/svelte/dist -o ./demo/esp32/include/e/svelteesp32psychic2.h --etag=true --gzip=false
25+
npx tsx src/index.ts -e psychic2 -s ./demo/svelte/dist -o ./demo/esp32/include/eg/svelteesp32psychic2.h --etag=true --gzip=true
26+
npx tsx src/index.ts -e psychic2 -s ./demo/svelte/dist -o ./demo/esp32/include/egc/svelteesp32psychic2.h --etag=true --gzip=compiler
27+
npx tsx src/index.ts -e psychic2 -s ./demo/svelte/dist -o ./demo/esp32/include/ec/svelteesp32psychic2.h --etag=compiler --gzip=false
28+
npx tsx src/index.ts -e psychic2 -s ./demo/svelte/dist -o ./demo/esp32/include/ecg/svelteesp32psychic2.h --etag=compiler --gzip=true
29+
npx tsx src/index.ts -e psychic2 -s ./demo/svelte/dist -o ./demo/esp32/include/ecgc/svelteesp32psychic2.h --etag=compiler --gzip=compiler

src/commandLine.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { existsSync, statSync } from 'node:fs';
33
import { parse } from 'ts-command-line-args';
44

55
interface ICopyFilesArguments {
6-
engine: 'psychic' | 'async';
6+
engine: 'psychic' | 'psychic2' | 'async';
77
sourcepath: string;
88
outputfile: string;
99
espmethod: string;
@@ -20,11 +20,12 @@ export const cmdLine = parse<ICopyFilesArguments>(
2020
engine: {
2121
type: (value) => {
2222
if (value === 'psychic') return 'psychic';
23+
if (value === 'psychic2') return 'psychic2';
2324
if (value === 'async') return 'async';
2425
throw new Error(`Invalid engine: ${value}`);
2526
},
2627
alias: 'e',
27-
description: 'The engine for which the include file is created (psychic|async)',
28+
description: 'The engine for which the include file is created (psychic|psychic2|async)',
2829
defaultValue: 'psychic'
2930
},
3031
sourcepath: {

0 commit comments

Comments
 (0)