Skip to content

Commit

Permalink
feat: psychic v2
Browse files Browse the repository at this point in the history
  • Loading branch information
BCsabaEngine committed Sep 1, 2024
1 parent 7df2b07 commit 1dc263c
Show file tree
Hide file tree
Showing 9 changed files with 333 additions and 32 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Change log

## 1.5

### 1.5.0

- New engine type (-e psychic2) for PsychicHttp v2

- Run tests with github repos instead of packages

## 1.4

### 1.4.1
Expand Down
29 changes: 17 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ In order to be able to easily update OTA, it is important - from the users' poin

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**.

> Starting with version v1.5.0, PsychicHttp v2 is also supported.
> 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.
> Starting with version v1.3.0, c++ defines can be used.
Expand All @@ -34,6 +36,9 @@ After a successful Svelte build (rollup/webpack/vite) **create an includeable c+
// for PsychicHttpServer
npx svelteesp32 -e psychic -s ../svelteapp/dist -o ../esp32project/svelteesp32.h --etag=true

// for PsychicHttpServer V2
npx svelteesp32 -e psychic2 -s ../svelteapp/dist -o ../esp32project/svelteesp32.h --etag=true

// for ESPAsyncWebServer
npx svelteesp32 -e async -s ../svelteapp/dist -o ../esp32project/svelteesp32.h --etag=true
```
Expand Down Expand Up @@ -217,18 +222,18 @@ You can use the following c++ directives at the project level if you want to con

### Command line options

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

### Q&A

Expand Down
80 changes: 71 additions & 9 deletions demo/esp32/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -71,58 +71,120 @@ lib_deps = https://github.com/me-no-dev/ESPAsyncWebServer
build_flags =
-D PSYCHIC
-I include/_
lib_deps = hoeken/PsychicHttp
lib_deps = https://github.com/hoeken/PsychicHttp

[env:psychic_E]
build_flags =
-D PSYCHIC
-I include/e
lib_deps = hoeken/PsychicHttp
lib_deps = https://github.com/hoeken/PsychicHttp

[env:psychic_EC]
build_flags =
-D PSYCHIC
-I include/ec
-D SVELTEESP32_ENABLE_ETAG
lib_deps = hoeken/PsychicHttp
lib_deps = https://github.com/hoeken/PsychicHttp

[env:psychic_ECG]
build_flags =
-D PSYCHIC
-I include/ecg
-D SVELTEESP32_ENABLE_ETAG
lib_deps = hoeken/PsychicHttp
lib_deps = https://github.com/hoeken/PsychicHttp

[env:psychic_ECGC]
build_flags =
-D PSYCHIC
-I include/ecgc
-D SVELTEESP32_ENABLE_ETAG
-D SVELTEESP32_ENABLE_GZIP
lib_deps = hoeken/PsychicHttp
lib_deps = https://github.com/hoeken/PsychicHttp

[env:psychic_EG]
build_flags =
-D PSYCHIC
-I include/eg
lib_deps = hoeken/PsychicHttp
lib_deps = https://github.com/hoeken/PsychicHttp

[env:psychic_EGC]
build_flags =
-D PSYCHIC
-I include/egc
-D SVELTEESP32_ENABLE_GZIP
lib_deps = hoeken/PsychicHttp
lib_deps = https://github.com/hoeken/PsychicHttp

[env:psychic_G]
build_flags =
-D PSYCHIC
-I include/g
lib_deps = hoeken/PsychicHttp
lib_deps = https://github.com/hoeken/PsychicHttp

[env:psychic_GC]
build_flags =
-D PSYCHIC
-I include/gc
-D SVELTEESP32_ENABLE_GZIP
lib_deps = hoeken/PsychicHttp
lib_deps = https://github.com/hoeken/PsychicHttp



[env:psychic2]
build_flags =
-D PSYCHIC2
-I include/_
lib_deps = https://github.com/hoeken/PsychicHttp#v2-dev

[env:psychic2_E]
build_flags =
-D PSYCHIC2
-I include/e
lib_deps = https://github.com/hoeken/PsychicHttp#v2-dev

[env:psychic2_EC]
build_flags =
-D PSYCHIC2
-I include/ec
-D SVELTEESP32_ENABLE_ETAG
lib_deps = https://github.com/hoeken/PsychicHttp#v2-dev

[env:psychic2_ECG]
build_flags =
-D PSYCHIC2
-I include/ecg
-D SVELTEESP32_ENABLE_ETAG
lib_deps = https://github.com/hoeken/PsychicHttp#v2-dev

[env:psychic2_ECGC]
build_flags =
-D PSYCHIC2
-I include/ecgc
-D SVELTEESP32_ENABLE_ETAG
-D SVELTEESP32_ENABLE_GZIP
lib_deps = https://github.com/hoeken/PsychicHttp#v2-dev

[env:psychic2_EG]
build_flags =
-D PSYCHIC2
-I include/eg
lib_deps = https://github.com/hoeken/PsychicHttp#v2-dev

[env:psychic2_EGC]
build_flags =
-D PSYCHIC2
-I include/egc
-D SVELTEESP32_ENABLE_GZIP
lib_deps = https://github.com/hoeken/PsychicHttp#v2-dev

[env:psychic2_G]
build_flags =
-D PSYCHIC2
-I include/g
lib_deps = https://github.com/hoeken/PsychicHttp#v2-dev

[env:psychic2_GC]
build_flags =
-D PSYCHIC2
-I include/gc
-D SVELTEESP32_ENABLE_GZIP
lib_deps = https://github.com/hoeken/PsychicHttp#v2-dev
34 changes: 34 additions & 0 deletions demo/esp32/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,40 @@ void setup()
}
void loop() {}

#elif PSYCHIC2
/* PsychicHttp example */

#include "credentials.h"
#include <WiFi.h>
#include <PsychicHttp.h>
#include "svelteesp32psychic2.h"

#if SVELTEESP32_COUNT != 11
#error Invalid file count
#endif

#ifndef SVELTEESP32_FILE_INDEX_HTML
#error Missing index file
#endif

#if SVELTEESP32_CSS_FILES > 1
#error Too many CSS files
#endif

PsychicHttpServer server(80);
void setup()
{
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, pass);
if (WiFi.waitForConnectResult() != WL_CONNECTED)
while (true)
;

server.begin();
initSvelteStaticFiles(&server);
}
void loop() {}

#else
#error Unknown platform
#endif
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "svelteesp32",
"version": "1.4.2",
"version": "1.5.0",
"description": "Convert Svelte (or any frontend) JS application to serve it from ESP32 webserver (PsychicHttp)",
"author": "BCsabaEngine",
"license": "ISC",
Expand Down Expand Up @@ -30,6 +30,7 @@
"scripts": {
"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",
"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",
"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",
"test:all": "./package.script && ~/.platformio/penv/bin/pio run -d ./demo/esp32",
"clean": "tsc --build --clean",
"build": "tsc --build --clean && tsc --build --force",
Expand All @@ -49,11 +50,12 @@
"esp8266",
"webserver",
"psychichttpserver",
"psychichttpserverV2",
"espasyncwebserver"
],
"devDependencies": {
"@types/mime-types": "^2.1.4",
"@types/node": "^22.5.1",
"@types/node": "^22.5.2",
"@typescript-eslint/eslint-plugin": "^8.3.0",
"@typescript-eslint/parser": "^8.3.0",
"eslint": "^9.9.1",
Expand Down
10 changes: 10 additions & 0 deletions package.script
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,13 @@ npx tsx src/index.ts -e psychic -s ./demo/svelte/dist -o ./demo/esp32/include/eg
npx tsx src/index.ts -e psychic -s ./demo/svelte/dist -o ./demo/esp32/include/ec/svelteesp32psychic.h --etag=compiler --gzip=false
npx tsx src/index.ts -e psychic -s ./demo/svelte/dist -o ./demo/esp32/include/ecg/svelteesp32psychic.h --etag=compiler --gzip=true
npx tsx src/index.ts -e psychic -s ./demo/svelte/dist -o ./demo/esp32/include/ecgc/svelteesp32psychic.h --etag=compiler --gzip=compiler

npx tsx src/index.ts -e psychic2 -s ./demo/svelte/dist -o ./demo/esp32/include/_/svelteesp32psychic2.h --etag=false --gzip=false
npx tsx src/index.ts -e psychic2 -s ./demo/svelte/dist -o ./demo/esp32/include/g/svelteesp32psychic2.h --etag=false --gzip=true
npx tsx src/index.ts -e psychic2 -s ./demo/svelte/dist -o ./demo/esp32/include/gc/svelteesp32psychic2.h --etag=false --gzip=compiler
npx tsx src/index.ts -e psychic2 -s ./demo/svelte/dist -o ./demo/esp32/include/e/svelteesp32psychic2.h --etag=true --gzip=false
npx tsx src/index.ts -e psychic2 -s ./demo/svelte/dist -o ./demo/esp32/include/eg/svelteesp32psychic2.h --etag=true --gzip=true
npx tsx src/index.ts -e psychic2 -s ./demo/svelte/dist -o ./demo/esp32/include/egc/svelteesp32psychic2.h --etag=true --gzip=compiler
npx tsx src/index.ts -e psychic2 -s ./demo/svelte/dist -o ./demo/esp32/include/ec/svelteesp32psychic2.h --etag=compiler --gzip=false
npx tsx src/index.ts -e psychic2 -s ./demo/svelte/dist -o ./demo/esp32/include/ecg/svelteesp32psychic2.h --etag=compiler --gzip=true
npx tsx src/index.ts -e psychic2 -s ./demo/svelte/dist -o ./demo/esp32/include/ecgc/svelteesp32psychic2.h --etag=compiler --gzip=compiler
5 changes: 3 additions & 2 deletions src/commandLine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { existsSync, statSync } from 'node:fs';
import { parse } from 'ts-command-line-args';

interface ICopyFilesArguments {
engine: 'psychic' | 'async';
engine: 'psychic' | 'psychic2' | 'async';
sourcepath: string;
outputfile: string;
espmethod: string;
Expand All @@ -20,11 +20,12 @@ export const cmdLine = parse<ICopyFilesArguments>(
engine: {
type: (value) => {
if (value === 'psychic') return 'psychic';
if (value === 'psychic2') return 'psychic2';
if (value === 'async') return 'async';
throw new Error(`Invalid engine: ${value}`);
},
alias: 'e',
description: 'The engine for which the include file is created (psychic|async)',
description: 'The engine for which the include file is created (psychic|psychic2|async)',
defaultValue: 'psychic'
},
sourcepath: {
Expand Down
Loading

0 comments on commit 1dc263c

Please sign in to comment.