svelteesp32 1.9.3 → 1.10.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 CHANGED
@@ -12,6 +12,8 @@ In order to be able to easily update OTA, it is important - from the users' poin
12
12
 
13
13
  This npm package provides a solution for **inserting any JS client application into the ESP web server** (PsychicHttp and also ESPAsyncWebServer (https://github.com/ESP32Async/ESPAsyncWebServer) and ESP-IDF 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**.
14
14
 
15
+ > Starting with version v1.10.0, we reduced npm dependencies
16
+
15
17
  > Starting with version v1.9.0, code generator for esp-idf is available
16
18
 
17
19
  > Starting with version v1.8.0, use the new and maintained ESPAsyncWebserver available at https://github.com/ESP32Async/ESPAsyncWebServer
@@ -2,91 +2,184 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.cmdLine = void 0;
4
4
  const node_fs_1 = require("node:fs");
5
- const ts_command_line_args_1 = require("ts-command-line-args");
6
- exports.cmdLine = (0, ts_command_line_args_1.parse)({
7
- engine: {
8
- type: (value) => {
9
- if (value === 'psychic')
10
- return 'psychic';
11
- if (value === 'psychic2')
12
- return 'psychic2';
13
- if (value === 'async')
14
- return 'async';
15
- if (value === 'espidf')
16
- return 'espidf';
17
- throw new Error(`Invalid engine: ${value}`);
18
- },
19
- alias: 'e',
20
- description: 'The engine for which the include file is created (psychic|psychic2|async)',
21
- defaultValue: 'psychic'
22
- },
23
- sourcepath: {
24
- type: String,
25
- alias: 's',
26
- description: 'Source dist folder contains compiled web files'
27
- },
28
- outputfile: {
29
- type: String,
30
- alias: 'o',
31
- description: 'Generated output file with path',
32
- defaultValue: 'svelteesp32.h'
33
- },
34
- etag: {
35
- type: (value) => {
36
- if (value === 'true')
37
- return 'true';
38
- if (value === 'false')
39
- return 'false';
40
- if (value === 'compiler')
41
- return 'compiler';
42
- throw new Error(`Invalid etag: ${value}`);
43
- },
44
- description: 'Use ETAG header for cache',
45
- defaultValue: 'false'
46
- },
47
- gzip: {
48
- type: (value) => {
49
- if (value === 'true')
50
- return 'true';
51
- if (value === 'false')
52
- return 'false';
53
- if (value === 'compiler')
54
- return 'compiler';
55
- throw new Error(`Invalid etag: ${value}`);
56
- },
57
- description: 'Compress content with gzip',
58
- defaultValue: 'true'
59
- },
60
- created: {
61
- type: Boolean,
62
- description: 'Include creation time in the output file',
63
- defaultValue: false
64
- },
65
- version: {
66
- type: String,
67
- description: 'Include version info in the output file',
68
- defaultValue: ''
69
- },
70
- espmethod: {
71
- type: String,
72
- description: 'Name of generated method',
73
- defaultValue: 'initSvelteStaticFiles'
74
- },
75
- define: {
76
- type: String,
77
- description: 'Prefix of c++ defines',
78
- defaultValue: 'SVELTEESP32'
79
- },
80
- cachetime: {
81
- type: Number,
82
- description: 'max-age cache time in seconds',
83
- defaultValue: 0
84
- },
85
- help: { type: Boolean, optional: true, alias: 'h', description: 'Shows this help' }
86
- }, {
87
- helpArg: 'help',
88
- headerContentSections: [{ header: 'svelteesp32', content: 'Svelte JS to ESP32 converter' }]
89
- });
5
+ function showHelp() {
6
+ console.log(`
7
+ svelteesp32 - Svelte JS to ESP32 converter
8
+
9
+ Options:
10
+ -e, --engine <value> The engine for which the include file is created
11
+ (psychic|psychic2|async|espidf) (default: "psychic")
12
+ -s, --sourcepath <path> Source dist folder contains compiled web files (required)
13
+ -o, --outputfile <path> Generated output file with path (default: "svelteesp32.h")
14
+ --etag <value> Use ETAG header for cache (true|false|compiler) (default: "false")
15
+ --gzip <value> Compress content with gzip (true|false|compiler) (default: "true")
16
+ --created Include creation time in the output file (default: false)
17
+ --version <value> Include version info in the output file (default: "")
18
+ --espmethod <name> Name of generated method (default: "initSvelteStaticFiles")
19
+ --define <prefix> Prefix of c++ defines (default: "SVELTEESP32")
20
+ --cachetime <seconds> max-age cache time in seconds (default: 0)
21
+ -h, --help Shows this help
22
+ `);
23
+ process.exit(0);
24
+ }
25
+ function validateEngine(value) {
26
+ if (value === 'psychic' || value === 'psychic2' || value === 'async' || value === 'espidf')
27
+ return value;
28
+ throw new Error(`Invalid engine: ${value}`);
29
+ }
30
+ function validateTriState(value, name) {
31
+ if (value === 'true' || value === 'false' || value === 'compiler')
32
+ return value;
33
+ throw new Error(`Invalid ${name}: ${value}`);
34
+ }
35
+ function parseArguments() {
36
+ const arguments_ = process.argv.slice(2);
37
+ const result = {
38
+ engine: 'psychic',
39
+ outputfile: 'svelteesp32.h',
40
+ etag: 'false',
41
+ gzip: 'true',
42
+ created: false,
43
+ version: '',
44
+ espmethod: 'initSvelteStaticFiles',
45
+ define: 'SVELTEESP32',
46
+ cachetime: 0
47
+ };
48
+ for (let index = 0; index < arguments_.length; index++) {
49
+ const argument = arguments_[index];
50
+ if (!argument)
51
+ continue;
52
+ if (argument === '--help' || argument === '-h')
53
+ showHelp();
54
+ if (argument.startsWith('--') && argument.includes('=')) {
55
+ const parts = argument.split('=');
56
+ const flag = parts[0];
57
+ const value = parts.slice(1).join('=');
58
+ if (!flag || !value)
59
+ throw new Error(`Invalid argument format: ${argument}`);
60
+ const flagName = flag.slice(2);
61
+ switch (flagName) {
62
+ case 'engine':
63
+ result.engine = validateEngine(value);
64
+ break;
65
+ case 'sourcepath':
66
+ result.sourcepath = value;
67
+ break;
68
+ case 'outputfile':
69
+ result.outputfile = value;
70
+ break;
71
+ case 'etag':
72
+ result.etag = validateTriState(value, 'etag');
73
+ break;
74
+ case 'gzip':
75
+ result.gzip = validateTriState(value, 'gzip');
76
+ break;
77
+ case 'version':
78
+ result.version = value;
79
+ break;
80
+ case 'espmethod':
81
+ result.espmethod = value;
82
+ break;
83
+ case 'define':
84
+ result.define = value;
85
+ break;
86
+ case 'cachetime':
87
+ result.cachetime = Number.parseInt(value, 10);
88
+ if (Number.isNaN(result.cachetime)) {
89
+ throw new TypeError(`Invalid cachetime: ${value}`);
90
+ }
91
+ break;
92
+ default:
93
+ throw new Error(`Unknown flag: ${flag}`);
94
+ }
95
+ continue;
96
+ }
97
+ if (argument === '--created') {
98
+ result.created = true;
99
+ continue;
100
+ }
101
+ if (argument.startsWith('-') && !argument.startsWith('--')) {
102
+ const flag = argument.slice(1);
103
+ const nextArgument = arguments_[index + 1];
104
+ if (!nextArgument || nextArgument.startsWith('-'))
105
+ throw new Error(`Missing value for flag: ${argument}`);
106
+ switch (flag) {
107
+ case 'e':
108
+ result.engine = validateEngine(nextArgument);
109
+ index++;
110
+ break;
111
+ case 's':
112
+ result.sourcepath = nextArgument;
113
+ index++;
114
+ break;
115
+ case 'o':
116
+ result.outputfile = nextArgument;
117
+ index++;
118
+ break;
119
+ default:
120
+ throw new Error(`Unknown flag: ${argument}`);
121
+ }
122
+ continue;
123
+ }
124
+ if (argument.startsWith('--')) {
125
+ const flag = argument.slice(2);
126
+ const nextArgument = arguments_[index + 1];
127
+ if (!nextArgument || nextArgument.startsWith('-'))
128
+ throw new Error(`Missing value for flag: ${argument}`);
129
+ switch (flag) {
130
+ case 'engine':
131
+ result.engine = validateEngine(nextArgument);
132
+ index++;
133
+ break;
134
+ case 'sourcepath':
135
+ result.sourcepath = nextArgument;
136
+ index++;
137
+ break;
138
+ case 'outputfile':
139
+ result.outputfile = nextArgument;
140
+ index++;
141
+ break;
142
+ case 'etag':
143
+ result.etag = validateTriState(nextArgument, 'etag');
144
+ index++;
145
+ break;
146
+ case 'gzip':
147
+ result.gzip = validateTriState(nextArgument, 'gzip');
148
+ index++;
149
+ break;
150
+ case 'version':
151
+ result.version = nextArgument;
152
+ index++;
153
+ break;
154
+ case 'espmethod':
155
+ result.espmethod = nextArgument;
156
+ index++;
157
+ break;
158
+ case 'define':
159
+ result.define = nextArgument;
160
+ index++;
161
+ break;
162
+ case 'cachetime':
163
+ result.cachetime = Number.parseInt(nextArgument, 10);
164
+ if (Number.isNaN(result.cachetime)) {
165
+ throw new TypeError(`Invalid cachetime: ${nextArgument}`);
166
+ }
167
+ index++;
168
+ break;
169
+ default:
170
+ throw new Error(`Unknown flag: --${flag}`);
171
+ }
172
+ continue;
173
+ }
174
+ throw new Error(`Unknown argument: ${argument}`);
175
+ }
176
+ if (!result.sourcepath) {
177
+ console.error('Error: --sourcepath is required');
178
+ showHelp();
179
+ }
180
+ return result;
181
+ }
182
+ exports.cmdLine = parseArguments();
90
183
  if (!(0, node_fs_1.existsSync)(exports.cmdLine.sourcepath) || !(0, node_fs_1.statSync)(exports.cmdLine.sourcepath).isDirectory()) {
91
184
  console.error(`Directory ${exports.cmdLine.sourcepath} not exists or not a directory`);
92
185
  process.exit(1);
package/dist/file.js CHANGED
@@ -7,7 +7,7 @@ exports.getFiles = void 0;
7
7
  const node_crypto_1 = require("node:crypto");
8
8
  const node_fs_1 = require("node:fs");
9
9
  const node_path_1 = __importDefault(require("node:path"));
10
- const glob_1 = require("glob");
10
+ const tinyglobby_1 = require("tinyglobby");
11
11
  const commandLine_1 = require("./commandLine");
12
12
  const consoleColor_1 = require("./consoleColor");
13
13
  const findSimilarFiles = (files) => {
@@ -43,7 +43,7 @@ const shouldSkipFile = (filename, allFilenames) => {
43
43
  return false;
44
44
  };
45
45
  const getFiles = () => {
46
- const allFilenames = (0, glob_1.globSync)('**/*', { cwd: commandLine_1.cmdLine.sourcepath, nodir: true });
46
+ const allFilenames = (0, tinyglobby_1.globSync)('**/*', { cwd: commandLine_1.cmdLine.sourcepath, onlyFiles: true, dot: false });
47
47
  const filenames = allFilenames.filter((filename) => !shouldSkipFile(filename, allFilenames));
48
48
  const result = new Map();
49
49
  for (const filename of filenames) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelteesp32",
3
- "version": "1.9.3",
3
+ "version": "1.10.0",
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",
@@ -58,23 +58,23 @@
58
58
  ],
59
59
  "devDependencies": {
60
60
  "@types/mime-types": "^3.0.1",
61
- "@types/node": "^24.9.2",
62
- "@typescript-eslint/eslint-plugin": "^8.46.2",
63
- "@typescript-eslint/parser": "^8.46.2",
64
- "eslint": "^9.39.0",
61
+ "@types/node": "^24.10.1",
62
+ "@types/picomatch": "^4.0.2",
63
+ "@typescript-eslint/eslint-plugin": "^8.47.0",
64
+ "@typescript-eslint/parser": "^8.47.0",
65
+ "eslint": "^9.39.1",
65
66
  "eslint-config-prettier": "^10.1.8",
66
67
  "eslint-plugin-simple-import-sort": "^12.1.1",
67
68
  "eslint-plugin-unicorn": "^62.0.0",
68
- "nodemon": "^3.1.10",
69
+ "nodemon": "^3.1.11",
69
70
  "prettier": "^3.6.2",
70
71
  "ts-node": "^10.9.2",
71
72
  "tsx": "^4.20.6",
72
73
  "typescript": "^5.9.3"
73
74
  },
74
75
  "dependencies": {
75
- "glob": "^11.0.3",
76
76
  "handlebars": "^4.7.8",
77
- "mime-types": "^3.0.1",
78
- "ts-command-line-args": "^2.5.1"
77
+ "mime-types": "^3.0.2",
78
+ "tinyglobby": "^0.2.15"
79
79
  }
80
80
  }