Skip to content

Commit 2708773

Browse files
authored
feat: RC file support (#52)
* fix: excluded file list * fix: readme * feat: rc file * fix: lint * release: 1.12.0 * fix: typo
1 parent dcb2735 commit 2708773

File tree

8 files changed

+647
-17
lines changed

8 files changed

+647
-17
lines changed

.svelteesp32rc.example.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"engine": "psychic",
3+
"sourcepath": "./demo/svelte/dist",
4+
"outputfile": "./output.h",
5+
"etag": "true",
6+
"gzip": "true",
7+
"cachetime": 0,
8+
"created": false,
9+
"version": "",
10+
"espmethod": "initSvelteStaticFiles",
11+
"define": "SVELTEESP32",
12+
"exclude": ["*.map", "*.md", "test/**/*"]
13+
}

CHANGELOG.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,46 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [1.12.0] - 2025-12-04
11+
12+
### Added
13+
14+
- **Configuration File Support**: New RC file feature (`.svelteesp32rc.json`) for storing frequently-used options
15+
- Automatic search in current directory and user home directory
16+
- `--config` flag for specifying custom RC file path
17+
- All CLI options can be configured in RC file using long-form property names
18+
- CLI arguments always override RC file values (3-stage merge: defaults → RC → CLI)
19+
- **Replace mode** for exclude patterns: RC or CLI exclude completely replaces defaults
20+
- Cyan-colored console output showing which RC file was loaded
21+
- Comprehensive validation with unknown property warnings to catch typos
22+
- Example RC file (`.svelteesp32rc.example.json`) included in repository
23+
- 16 new unit tests for RC file functionality:
24+
- RC file discovery (current directory, home directory, custom path)
25+
- RC file parsing and validation (invalid JSON, invalid values, unknown properties)
26+
- CLI override behavior
27+
- Exclude pattern replace mode
28+
- Backward compatibility
29+
- Updated test coverage to 84.32% for `commandLine.ts` (up from 84.56%)
30+
- TypeScript type safety improvements: replaced `any` with `unknown` in `validateRcConfig()`
31+
32+
### Changed
33+
34+
- Enhanced `commandLine.ts` with RC file loading, validation, and merging logic
35+
- Updated help text with RC file documentation and examples
36+
- Enhanced README.md with comprehensive "Configuration File" section:
37+
- Quick start guide with example RC file
38+
- Configuration reference table mapping RC properties to CLI flags
39+
- CLI override examples
40+
- Multiple environment setup guide (dev/prod configs)
41+
- Exclude pattern behavior documentation
42+
- Updated command line options table with `--config` flag
43+
- Error message for missing `--sourcepath` now mentions RC file option
44+
- All 92 tests passing with new RC file test suite
45+
46+
### Fixed
47+
48+
- ESLint error: replaced `any` type with `unknown` in configuration validation
49+
1050
## [1.11.0] - 2025-12-03
1151

1252
### Added
@@ -266,6 +306,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
266306
- CLI interface with `-s`, `-e`, `-o` options
267307
- `index.html` automatic default route handling
268308

309+
[1.12.0]: https://github.com/BCsabaEngine/svelteesp32/compare/v1.11.0...v1.12.0
269310
[1.11.0]: https://github.com/BCsabaEngine/svelteesp32/compare/v1.10.0...v1.11.0
270311
[1.10.0]: https://github.com/BCsabaEngine/svelteesp32/compare/v1.9.4...v1.10.0
271312
[1.9.4]: https://github.com/BCsabaEngine/svelteesp32/compare/v1.9.3...v1.9.4

README.md

Lines changed: 115 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ 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 (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**.
1414

15+
> Starting with version v1.12.0, you can use RC file for configuration
16+
17+
> Starting with version v1.11.0, you can exclude files by pattern
18+
1519
> Starting with version v1.10.0, we reduced npm dependencies
1620
1721
> Starting with version v1.9.0, code generator for esp-idf is available
@@ -84,13 +88,13 @@ npm run fix
8488

8589
### Usage
8690

87-
**Install package** as devDependency (it is practical if the package is part of the project so that you always receive updates)
91+
**Install package** as dev dependency (it is practical if the package is part of the project so that you always receive updates)
8892

8993
```bash
9094
npm install -D svelteesp32
9195
```
9296

93-
After a successful Svelte build (rollup/webpack/vite) **create an includeable c++ header** file
97+
After a successful Svelte build (rollup/webpack/vite) **create an includable c++ header** file
9498

9599
```bash
96100
// for PsychicHttpServer
@@ -425,8 +429,117 @@ You can use the following c++ directives at the project level if you want to con
425429
| `--version` | Include a version string in generated header, e.g. `--version=v$npm_package_version` | '' |
426430
| `--espmethod` | Name of generated initialization method | `initSvelteStaticFiles` |
427431
| `--define` | Prefix of c++ defines (e.g., SVELTEESP32_COUNT) | `SVELTEESP32` |
432+
| `--config` | Use custom RC file path | `.svelteesp32rc.json` |
428433
| `-h` | Show help | |
429434

435+
### Configuration File
436+
437+
You can store frequently-used options in a configuration file to avoid repeating command line arguments. This is especially useful for CI/CD pipelines and team collaboration.
438+
439+
#### Quick Start
440+
441+
Create `.svelteesp32rc.json` in your project directory:
442+
443+
```json
444+
{
445+
"engine": "psychic",
446+
"sourcepath": "./dist",
447+
"outputfile": "./esp32/include/svelteesp32.h",
448+
"etag": "true",
449+
"gzip": "true",
450+
"cachetime": 86400,
451+
"exclude": ["*.map", "*.md"]
452+
}
453+
```
454+
455+
Then simply run:
456+
457+
```bash
458+
npx svelteesp32
459+
```
460+
461+
No command line arguments needed!
462+
463+
#### Search Locations
464+
465+
The tool automatically searches for `.svelteesp32rc.json` in:
466+
467+
1. Current working directory
468+
2. User home directory
469+
470+
Or specify a custom location:
471+
472+
```bash
473+
npx svelteesp32 --config=.svelteesp32rc.prod.json
474+
```
475+
476+
#### Configuration Reference
477+
478+
All CLI options can be specified in the RC file using long-form property names:
479+
480+
| RC Property | CLI Flag | Type | Example |
481+
| ------------ | ------------- | ------- | ------------------------------------------------ |
482+
| `engine` | `-e` | string | `"psychic"`, `"psychic2"`, `"async"`, `"espidf"` |
483+
| `sourcepath` | `-s` | string | `"./dist"` |
484+
| `outputfile` | `-o` | string | `"./output.h"` |
485+
| `etag` | `--etag` | string | `"true"`, `"false"`, `"compiler"` |
486+
| `gzip` | `--gzip` | string | `"true"`, `"false"`, `"compiler"` |
487+
| `cachetime` | `--cachetime` | number | `86400` |
488+
| `created` | `--created` | boolean | `true`, `false` |
489+
| `version` | `--version` | string | `"v1.0.0"` |
490+
| `espmethod` | `--espmethod` | string | `"initSvelteStaticFiles"` |
491+
| `define` | `--define` | string | `"SVELTEESP32"` |
492+
| `exclude` | `--exclude` | array | `["*.map", "*.md"]` |
493+
494+
#### CLI Override
495+
496+
Command line arguments always take precedence over RC file values:
497+
498+
```bash
499+
# Use RC settings but override etag
500+
npx svelteesp32 --etag=false
501+
502+
# Use RC settings but add different exclude pattern
503+
npx svelteesp32 --exclude="*.txt"
504+
```
505+
506+
#### Multiple Environments
507+
508+
Create different config files for different environments:
509+
510+
```bash
511+
# Development build
512+
npx svelteesp32 --config=.svelteesp32rc.dev.json
513+
514+
# Production build
515+
npx svelteesp32 --config=.svelteesp32rc.prod.json
516+
```
517+
518+
#### Exclude Pattern Behavior
519+
520+
**Replace mode**: When you specify `exclude` patterns in RC file or CLI, they completely replace the defaults.
521+
522+
- **No exclude specified**: Uses default system exclusions (`.DS_Store`, `Thumbs.db`, `.git`, etc.)
523+
- **RC file has exclude**: Replaces defaults with RC patterns
524+
- **CLI has --exclude**: Replaces RC patterns (or defaults if no RC)
525+
526+
Example:
527+
528+
```json
529+
// .svelteesp32rc.json
530+
{ "exclude": ["*.map"] }
531+
```
532+
533+
Result: Only `*.map` is excluded (default patterns are replaced)
534+
535+
To keep defaults, explicitly list them in your RC file:
536+
537+
```json
538+
{
539+
"exclude": [".DS_Store", "Thumbs.db", ".git", "*.map", "*.md"]
540+
}
541+
```
542+
430543
### Q&A
431544

432545
- **How big a frontend application can be placed?** If you compress the content with gzip, even a 3-4Mb assets directory can be placed. This is a serious enough amount to serve a complete application.

package-lock.json

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "svelteesp32",
3-
"version": "1.11.0",
3+
"version": "1.12.0",
44
"description": "Convert Svelte (or any frontend) JS application to serve it from ESP32 webserver (PsychicHttp)",
55
"author": "BCsabaEngine",
66
"license": "ISC",

0 commit comments

Comments
 (0)