svelteesp32 1.0.1 → 1.0.3
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 +31 -1
- package/bin/index.js +2 -0
- package/dist/cppCode.d.ts +2 -2
- package/dist/cppCode.js +45 -23
- package/dist/index.js +23 -7
- package/package.json +6 -2
package/README.md
CHANGED
|
@@ -12,7 +12,7 @@ This npm package provides a solution for **inserting any JS client application i
|
|
|
12
12
|
|
|
13
13
|
Install package as devDependency (it is practical if the package is part of the project so that you always receive updates)
|
|
14
14
|
|
|
15
|
-
```
|
|
15
|
+
```bash
|
|
16
16
|
npm install -D svelteesp32
|
|
17
17
|
```
|
|
18
18
|
|
|
@@ -46,3 +46,33 @@ void setup()
|
|
|
46
46
|
initSvelteStaticFiles(&server);
|
|
47
47
|
}
|
|
48
48
|
```
|
|
49
|
+
|
|
50
|
+
The content of generated file (do not edit, just use)
|
|
51
|
+
|
|
52
|
+
```c
|
|
53
|
+
void initSvelteStaticFiles(PsychicHttpServer * server) {
|
|
54
|
+
server->on("assets/index-KwubEIf-.js", HTTP_GET, [](PsychicRequest * request)
|
|
55
|
+
{
|
|
56
|
+
const uint8_t data[] = {0x1f, 0x8b, 0x8, 0x0, 0x0, ...}
|
|
57
|
+
|
|
58
|
+
PsychicStreamResponse response(request, "application/javascript");
|
|
59
|
+
response.addHeader("Content-Encoding", "gzip");
|
|
60
|
+
response.beginSend();
|
|
61
|
+
for (int i = 0; i < sizeof(data); i++) response.write(data[i]);
|
|
62
|
+
return response.endSend();
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
server->on("assets/index-Soe6cpLA.css", HTTP_GET, [](PsychicRequest * request)
|
|
66
|
+
{
|
|
67
|
+
const uint8_t data[] = {0x1f, 0x8b, 0x8, 0x0, 0x0, ...}
|
|
68
|
+
|
|
69
|
+
PsychicStreamResponse response(request, "text/css");
|
|
70
|
+
response.addHeader("Content-Encoding", "gzip");
|
|
71
|
+
response.beginSend();
|
|
72
|
+
for (int i = 0; i < sizeof(data); i++) response.write(data[i]);
|
|
73
|
+
return response.endSend();
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
...
|
|
77
|
+
}
|
|
78
|
+
```
|
package/bin/index.js
ADDED
package/dist/cppCode.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
export type cppCodeSource = {
|
|
3
|
+
index: number;
|
|
3
4
|
filename: string;
|
|
4
5
|
mime: string;
|
|
5
6
|
content: Buffer;
|
|
6
7
|
isGzip: boolean;
|
|
7
8
|
};
|
|
8
|
-
export declare const getCppCode: (
|
|
9
|
-
export declare const adoptMethodName: (content: string) => string;
|
|
9
|
+
export declare const getCppCode: (sources: cppCodeSource[]) => string;
|
package/dist/cppCode.js
CHANGED
|
@@ -1,28 +1,50 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.getCppCode = void 0;
|
|
4
4
|
const commandLine_1 = require("./commandLine");
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
});
|
|
5
|
+
const replaceAll = (s, from, to) => {
|
|
6
|
+
while (s.includes(from))
|
|
7
|
+
s = s.replace(from, to);
|
|
8
|
+
return s;
|
|
9
|
+
};
|
|
10
|
+
const blockTemplate = `
|
|
11
|
+
$default$server->on("/$filename$", HTTP_GET, [](PsychicRequest * request)
|
|
12
|
+
{
|
|
13
|
+
PsychicResponse response(request);
|
|
14
|
+
response.setContentType("$mime$");
|
|
15
|
+
response.addHeader("Content-Encoding", "$encoding$");
|
|
16
|
+
response.setContent(data$index$, sizeof(data$index$));
|
|
17
|
+
return response.send();
|
|
18
|
+
});
|
|
20
19
|
`;
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
20
|
+
const getCppBlock = (source) => {
|
|
21
|
+
let result = blockTemplate;
|
|
22
|
+
result = replaceAll(result, '$default$', source.filename.startsWith('index.htm') ? 'server->defaultEndpoint = ' : '');
|
|
23
|
+
result = replaceAll(result, '$index$', source.index.toString());
|
|
24
|
+
result = replaceAll(result, '$filename$', source.filename);
|
|
25
|
+
result = replaceAll(result, '$size$', source.content.length.toString());
|
|
26
|
+
result = replaceAll(result, '$mime$', source.mime);
|
|
27
|
+
result = replaceAll(result, '$encoding$', source.isGzip ? 'gzip' : 'identity');
|
|
28
|
+
return result;
|
|
29
|
+
};
|
|
30
|
+
const fileTemplate = `
|
|
31
|
+
$arrays$
|
|
32
|
+
|
|
33
|
+
void $method$(PsychicHttpServer * server) {
|
|
34
|
+
$code$
|
|
35
|
+
}`;
|
|
36
|
+
const getCppCode = (sources) => {
|
|
37
|
+
const arrays = [];
|
|
38
|
+
const blocks = [];
|
|
39
|
+
for (const source of sources) {
|
|
40
|
+
const bytesString = [...source.content].map((v) => `0x${v.toString(16)}`).join(', ');
|
|
41
|
+
arrays.push(`const uint8_t data${source.index}[${source.content.length}] = {${bytesString}};`);
|
|
42
|
+
blocks.push(getCppBlock(source));
|
|
43
|
+
}
|
|
44
|
+
let result = fileTemplate;
|
|
45
|
+
result = replaceAll(result, '$arrays$', arrays.join('\n'));
|
|
46
|
+
result = replaceAll(result, '$method$', commandLine_1.cmdLine.espMethodName);
|
|
47
|
+
result = replaceAll(result, '$code$', blocks.join(''));
|
|
48
|
+
return result;
|
|
49
|
+
};
|
|
26
50
|
exports.getCppCode = getCppCode;
|
|
27
|
-
const adoptMethodName = (content) => containerTemplate.replace('$method', commandLine_1.cmdLine.espMethodName).replace('$code', content);
|
|
28
|
-
exports.adoptMethodName = adoptMethodName;
|
package/dist/index.js
CHANGED
|
@@ -13,6 +13,7 @@ const summary = {
|
|
|
13
13
|
gzipsize: 0
|
|
14
14
|
};
|
|
15
15
|
const sources = [];
|
|
16
|
+
let sourceIndex = 0;
|
|
16
17
|
for (const file of (0, file_1.getFiles)()) {
|
|
17
18
|
const mime = (0, mime_types_1.lookup)(file) || 'text/plain';
|
|
18
19
|
summary.filecount++;
|
|
@@ -23,24 +24,39 @@ for (const file of (0, file_1.getFiles)()) {
|
|
|
23
24
|
const zipContent = (0, node_zlib_1.gzipSync)(rawContent, { level: 9 });
|
|
24
25
|
summary.gzipsize += zipContent.length;
|
|
25
26
|
if (rawContent.length > 100 && zipContent.length < rawContent.length * 0.85) {
|
|
26
|
-
sources.push({
|
|
27
|
+
sources.push({
|
|
28
|
+
index: sourceIndex++,
|
|
29
|
+
filename: file,
|
|
30
|
+
content: zipContent,
|
|
31
|
+
isGzip: true,
|
|
32
|
+
mime
|
|
33
|
+
});
|
|
27
34
|
console.log(`✓ gzip used (${rawContent.length} -> ${zipContent.length})`);
|
|
28
35
|
}
|
|
29
36
|
else {
|
|
30
|
-
sources.push({
|
|
37
|
+
sources.push({
|
|
38
|
+
index: sourceIndex++,
|
|
39
|
+
filename: file,
|
|
40
|
+
content: rawContent,
|
|
41
|
+
isGzip: false,
|
|
42
|
+
mime
|
|
43
|
+
});
|
|
31
44
|
console.log(`x gzip unused (${rawContent.length} -> ${zipContent.length})`);
|
|
32
45
|
}
|
|
33
46
|
}
|
|
34
47
|
else {
|
|
35
|
-
sources.push({
|
|
48
|
+
sources.push({
|
|
49
|
+
index: sourceIndex++,
|
|
50
|
+
filename: file,
|
|
51
|
+
content: rawContent,
|
|
52
|
+
isGzip: false,
|
|
53
|
+
mime
|
|
54
|
+
});
|
|
36
55
|
console.log(`- gzip skipped (${rawContent.length})`);
|
|
37
56
|
}
|
|
38
57
|
console.log('');
|
|
39
58
|
}
|
|
40
|
-
|
|
41
|
-
for (const source of sources)
|
|
42
|
-
cppFile += (0, cppCode_1.getCppCode)(source);
|
|
43
|
-
cppFile = (0, cppCode_1.adoptMethodName)(cppFile);
|
|
59
|
+
const cppFile = (0, cppCode_1.getCppCode)(sources);
|
|
44
60
|
(0, node_fs_1.writeFileSync)(commandLine_1.cmdLine.outputFile, cppFile);
|
|
45
61
|
if (commandLine_1.cmdLine.gzip)
|
|
46
62
|
console.log(`${summary.filecount} files, ${Math.round(summary.size / 1024)}kB original size, ${Math.round(summary.gzipsize / 1024)}kB gzip size`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "svelteesp32",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
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",
|
|
@@ -12,9 +12,13 @@
|
|
|
12
12
|
"npm": ">=9"
|
|
13
13
|
},
|
|
14
14
|
"files": [
|
|
15
|
+
"bin/*.js",
|
|
15
16
|
"dist/**/*.js",
|
|
16
17
|
"dist/**/*.d.ts"
|
|
17
18
|
],
|
|
19
|
+
"bin": {
|
|
20
|
+
"svelteesp32": "bin/index.js"
|
|
21
|
+
},
|
|
18
22
|
"repository": {
|
|
19
23
|
"type": "git",
|
|
20
24
|
"url": "git+https://github.com/BCsabaEngine/svelteesp32.git"
|
|
@@ -24,7 +28,7 @@
|
|
|
24
28
|
},
|
|
25
29
|
"homepage": "https://github.com/BCsabaEngine/svelteesp32",
|
|
26
30
|
"scripts": {
|
|
27
|
-
"dev": "nodemon src/index.ts -- -s ./svelte/dist -o
|
|
31
|
+
"dev": "nodemon src/index.ts -- -s ./svelte/dist -o ../../../Arduino/EspSvelte/svelteesp32.h -g",
|
|
28
32
|
"clean": "tsc --build --clean",
|
|
29
33
|
"build": "tsc --build --clean && tsc --build --force",
|
|
30
34
|
"format:check": "prettier --check .",
|