Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .svelteesp32rc.example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"engine": "psychic",
"sourcepath": "./demo/svelte/dist",
"outputfile": "./output.h",
"etag": "true",
"gzip": "true",
"cachetime": 0,
"created": false,
"version": "",
"espmethod": "initSvelteStaticFiles",
"define": "SVELTEESP32",
"exclude": ["*.map", "*.md", "test/**/*"]
}
41 changes: 41 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,46 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.12.0] - 2025-12-04

### Added

- **Configuration File Support**: New RC file feature (`.svelteesp32rc.json`) for storing frequently-used options
- Automatic search in current directory and user home directory
- `--config` flag for specifying custom RC file path
- All CLI options can be configured in RC file using long-form property names
- CLI arguments always override RC file values (3-stage merge: defaults → RC → CLI)
- **Replace mode** for exclude patterns: RC or CLI exclude completely replaces defaults
- Cyan-colored console output showing which RC file was loaded
- Comprehensive validation with unknown property warnings to catch typos
- Example RC file (`.svelteesp32rc.example.json`) included in repository
- 16 new unit tests for RC file functionality:
- RC file discovery (current directory, home directory, custom path)
- RC file parsing and validation (invalid JSON, invalid values, unknown properties)
- CLI override behavior
- Exclude pattern replace mode
- Backward compatibility
- Updated test coverage to 84.32% for `commandLine.ts` (up from 84.56%)
- TypeScript type safety improvements: replaced `any` with `unknown` in `validateRcConfig()`

### Changed

- Enhanced `commandLine.ts` with RC file loading, validation, and merging logic
- Updated help text with RC file documentation and examples
- Enhanced README.md with comprehensive "Configuration File" section:
- Quick start guide with example RC file
- Configuration reference table mapping RC properties to CLI flags
- CLI override examples
- Multiple environment setup guide (dev/prod configs)
- Exclude pattern behavior documentation
- Updated command line options table with `--config` flag
- Error message for missing `--sourcepath` now mentions RC file option
- All 92 tests passing with new RC file test suite

### Fixed

- ESLint error: replaced `any` type with `unknown` in configuration validation

## [1.11.0] - 2025-12-03

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

[1.12.0]: https://github.com/BCsabaEngine/svelteesp32/compare/v1.11.0...v1.12.0
[1.11.0]: https://github.com/BCsabaEngine/svelteesp32/compare/v1.10.0...v1.11.0
[1.10.0]: https://github.com/BCsabaEngine/svelteesp32/compare/v1.9.4...v1.10.0
[1.9.4]: https://github.com/BCsabaEngine/svelteesp32/compare/v1.9.3...v1.9.4
Expand Down
117 changes: 115 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ 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 (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**.

> Starting with version v1.12.0, you can use RC file for configuration

> Starting with version v1.11.0, you can exclude files by pattern

> Starting with version v1.10.0, we reduced npm dependencies

> Starting with version v1.9.0, code generator for esp-idf is available
Expand Down Expand Up @@ -84,13 +88,13 @@ npm run fix

### Usage

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

```bash
npm install -D svelteesp32
```

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

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

### Configuration File

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.

#### Quick Start

Create `.svelteesp32rc.json` in your project directory:

```json
{
"engine": "psychic",
"sourcepath": "./dist",
"outputfile": "./esp32/include/svelteesp32.h",
"etag": "true",
"gzip": "true",
"cachetime": 86400,
"exclude": ["*.map", "*.md"]
}
```

Then simply run:

```bash
npx svelteesp32
```

No command line arguments needed!

#### Search Locations

The tool automatically searches for `.svelteesp32rc.json` in:

1. Current working directory
2. User home directory

Or specify a custom location:

```bash
npx svelteesp32 --config=.svelteesp32rc.prod.json
```

#### Configuration Reference

All CLI options can be specified in the RC file using long-form property names:

| RC Property | CLI Flag | Type | Example |
| ------------ | ------------- | ------- | ------------------------------------------------ |
| `engine` | `-e` | string | `"psychic"`, `"psychic2"`, `"async"`, `"espidf"` |
| `sourcepath` | `-s` | string | `"./dist"` |
| `outputfile` | `-o` | string | `"./output.h"` |
| `etag` | `--etag` | string | `"true"`, `"false"`, `"compiler"` |
| `gzip` | `--gzip` | string | `"true"`, `"false"`, `"compiler"` |
| `cachetime` | `--cachetime` | number | `86400` |
| `created` | `--created` | boolean | `true`, `false` |
| `version` | `--version` | string | `"v1.0.0"` |
| `espmethod` | `--espmethod` | string | `"initSvelteStaticFiles"` |
| `define` | `--define` | string | `"SVELTEESP32"` |
| `exclude` | `--exclude` | array | `["*.map", "*.md"]` |

#### CLI Override

Command line arguments always take precedence over RC file values:

```bash
# Use RC settings but override etag
npx svelteesp32 --etag=false

# Use RC settings but add different exclude pattern
npx svelteesp32 --exclude="*.txt"
```

#### Multiple Environments

Create different config files for different environments:

```bash
# Development build
npx svelteesp32 --config=.svelteesp32rc.dev.json

# Production build
npx svelteesp32 --config=.svelteesp32rc.prod.json
```

#### Exclude Pattern Behavior

**Replace mode**: When you specify `exclude` patterns in RC file or CLI, they completely replace the defaults.

- **No exclude specified**: Uses default system exclusions (`.DS_Store`, `Thumbs.db`, `.git`, etc.)
- **RC file has exclude**: Replaces defaults with RC patterns
- **CLI has --exclude**: Replaces RC patterns (or defaults if no RC)

Example:

```json
// .svelteesp32rc.json
{ "exclude": ["*.map"] }
```

Result: Only `*.map` is excluded (default patterns are replaced)

To keep defaults, explicitly list them in your RC file:

```json
{
"exclude": [".DS_Store", "Thumbs.db", ".git", "*.map", "*.md"]
}
```

### Q&A

- **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.
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "svelteesp32",
"version": "1.11.0",
"version": "1.12.0",
"description": "Convert Svelte (or any frontend) JS application to serve it from ESP32 webserver (PsychicHttp)",
"author": "BCsabaEngine",
"license": "ISC",
Expand Down
Loading