From dd33a8aade0cbd6f905085784744ab8591309a81 Mon Sep 17 00:00:00 2001 From: BCsabaEngine Date: Thu, 4 Dec 2025 08:02:46 +0100 Subject: [PATCH 1/2] fix: show config --- src/commandLine.ts | 23 ++++++++++++++++++++ src/cppCode.ts | 10 ++++----- src/cppCodeEspIdf.ts | 2 +- test/unit/cppCode.test.ts | 44 ++++++++++++++++++++++++++------------- 4 files changed, 59 insertions(+), 20 deletions(-) diff --git a/src/commandLine.ts b/src/commandLine.ts index 2dd5e95..c5212db 100644 --- a/src/commandLine.ts +++ b/src/commandLine.ts @@ -418,6 +418,29 @@ function parseArguments(): ICopyFilesArguments { return result as ICopyFilesArguments; } +export function formatConfiguration(cmdLine: ICopyFilesArguments): string { + const parts: string[] = [ + `engine=${cmdLine.engine}`, + `sourcepath=${cmdLine.sourcepath}`, + `outputfile=${cmdLine.outputfile}`, + `etag=${cmdLine.etag}`, + `gzip=${cmdLine.gzip}`, + `cachetime=${cmdLine.cachetime}` + ]; + + if (cmdLine.created) parts.push(`created=${cmdLine.created}`); + + if (cmdLine.version) parts.push(`version=${cmdLine.version}`); + + if (cmdLine.espmethod) parts.push(`espmethod=${cmdLine.espmethod}`); + + if (cmdLine.define) parts.push(`define=${cmdLine.define}`); + + if (cmdLine.exclude.length > 0) parts.push(`exclude=[${cmdLine.exclude.join(', ')}]`); + + return parts.join(' '); +} + export const cmdLine = parseArguments(); if (!existsSync(cmdLine.sourcepath) || !statSync(cmdLine.sourcepath).isDirectory()) { diff --git a/src/cppCode.ts b/src/cppCode.ts index 8b4ded8..74bb868 100644 --- a/src/cppCode.ts +++ b/src/cppCode.ts @@ -1,6 +1,6 @@ import { compile as handlebarsCompile, HelperOptions } from 'handlebars'; -import { cmdLine } from './commandLine'; +import { cmdLine, formatConfiguration } from './commandLine'; import { espidfTemplate } from './cppCodeEspIdf'; export type CppCodeSource = { @@ -126,7 +126,7 @@ const char * etag_{{this.dataname}} = "{{this.md5}}"; const psychicTemplate = ` //engine: PsychicHttpServer -//cmdline: {{{commandLine}}} +//config: {{{config}}} //You should use server.config.max_uri_handlers = {{fileCount}}; or higher value to proper handles all files {{#if created }} //created: {{now}} @@ -237,7 +237,7 @@ void {{methodName}}(PsychicHttpServer * server) { const psychic2Template = ` //engine: PsychicHttpServerV2 -//cmdline: {{{commandLine}}} +//config: {{{config}}} {{#if created }} //created: {{now}} {{/if}} @@ -344,7 +344,7 @@ void {{methodName}}(PsychicHttpServer * server) { const asyncTemplate = ` //engine: ESPAsyncWebServer -//cmdline: {{{commandLine}}} +//config: {{{config}}} {{#if created }} //created: {{now}} {{/if}} @@ -573,7 +573,7 @@ const createHandlebarsHelpers = () => { export const getCppCode = (sources: CppCodeSources, filesByExtension: ExtensionGroups): string => { const template = handlebarsCompile(getTemplate(cmdLine.engine)); const templateData = { - commandLine: process.argv.slice(2).join(' '), + config: formatConfiguration(cmdLine), now: `${new Date().toLocaleDateString()} ${new Date().toLocaleTimeString()}`, fileCount: sources.length.toString(), fileSize: sources.reduce((previous, current) => previous + current.content.length, 0).toString(), diff --git a/src/cppCodeEspIdf.ts b/src/cppCodeEspIdf.ts index 66997d5..1c58c51 100644 --- a/src/cppCodeEspIdf.ts +++ b/src/cppCodeEspIdf.ts @@ -1,6 +1,6 @@ export const espidfTemplate = ` //engine: espidf -//cmdline: {{{commandLine}}} +//config: {{{config}}} {{#if created }} //created: {{now}} {{/if}} diff --git a/test/unit/cppCode.test.ts b/test/unit/cppCode.test.ts index 8c15b14..02f4685 100644 --- a/test/unit/cppCode.test.ts +++ b/test/unit/cppCode.test.ts @@ -13,8 +13,12 @@ vi.mock('../../src/commandLine', () => ({ created: false, version: 'v1.0.0', espmethod: 'initSvelteStaticFiles', - define: 'SVELTEESP32' - } + define: 'SVELTEESP32', + exclude: [] + }, + formatConfiguration: vi.fn((cmdLine) => { + return `engine=${cmdLine.engine} sourcepath=${cmdLine.sourcepath} outputfile=${cmdLine.outputfile} etag=${cmdLine.etag} gzip=${cmdLine.gzip} cachetime=${cmdLine.cachetime}`; + }) })); const createMockSource = (filename: string, content: string): CppCodeSource => ({ @@ -208,8 +212,10 @@ describe('cppCode', () => { created: false, version: '', espmethod: 'initSvelteStaticFiles', - define: 'SVELTEESP32' - } + define: 'SVELTEESP32', + exclude: [] + }, + formatConfiguration: vi.fn((cmdLine) => `engine=${cmdLine.engine}`) })); const { getCppCode } = await import('../../src/cppCode'); @@ -231,8 +237,10 @@ describe('cppCode', () => { created: false, version: '', espmethod: 'initSvelteStaticFiles', - define: 'SVELTEESP32' - } + define: 'SVELTEESP32', + exclude: [] + }, + formatConfiguration: vi.fn((cmdLine) => `engine=${cmdLine.engine}`) })); const { getCppCode } = await import('../../src/cppCode'); @@ -254,8 +262,10 @@ describe('cppCode', () => { created: false, version: '', espmethod: 'initSvelteStaticFiles', - define: 'SVELTEESP32' - } + define: 'SVELTEESP32', + exclude: [] + }, + formatConfiguration: vi.fn((cmdLine) => `engine=${cmdLine.engine}`) })); const { getCppCode } = await import('../../src/cppCode'); @@ -278,8 +288,10 @@ describe('cppCode', () => { created: false, version: '', espmethod: 'initSvelteStaticFiles', - define: 'SVELTEESP32' - } + define: 'SVELTEESP32', + exclude: [] + }, + formatConfiguration: vi.fn((cmdLine) => `engine=${cmdLine.engine}`) })); const { getCppCode } = await import('../../src/cppCode'); @@ -303,8 +315,10 @@ describe('cppCode', () => { created: false, version: '', espmethod: 'initSvelteStaticFiles', - define: 'SVELTEESP32' - } + define: 'SVELTEESP32', + exclude: [] + }, + formatConfiguration: vi.fn((cmdLine) => `engine=${cmdLine.engine}`) })); const { getCppCode } = await import('../../src/cppCode'); @@ -327,8 +341,10 @@ describe('cppCode', () => { created: false, version: '', espmethod: 'initSvelteStaticFiles', - define: 'SVELTEESP32' - } + define: 'SVELTEESP32', + exclude: [] + }, + formatConfiguration: vi.fn((cmdLine) => `engine=${cmdLine.engine}`) })); const { getCppCode } = await import('../../src/cppCode'); From 3d159cbadc2d431fda17b752d88c8f26cd60c899 Mon Sep 17 00:00:00 2001 From: BCsabaEngine Date: Thu, 4 Dec 2025 08:06:19 +0100 Subject: [PATCH 2/2] release: 1.12.1 --- CHANGELOG.md | 15 +++++++++++++++ CLAUDE.md | 16 ++++++++++++++++ README.md | 2 +- package-lock.json | 4 ++-- package.json | 2 +- 5 files changed, 35 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 32b9a20..1ba038a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [1.12.1] - 2025-12-04 + +### Changed + +- **Configuration Display in Generated Headers**: Renamed `//cmdline:` to `//config:` in all generated header files + - Now displays effective configuration values regardless of source (RC file, CLI arguments, or both) + - Shows all active configuration parameters: `engine`, `sourcepath`, `outputfile`, `etag`, `gzip`, `cachetime`, `espmethod`, `define`, and `exclude` patterns + - Provides complete traceability of configuration used for code generation + - Format: `//config: engine=psychic sourcepath=./dist outputfile=./output.h etag=true gzip=true ...` + +### Fixed + +- Configuration comment in generated headers now displays values when using RC file (previously showed empty when using RC file without CLI arguments) + ## [1.12.0] - 2025-12-04 ### Added @@ -306,6 +320,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.1]: https://github.com/BCsabaEngine/svelteesp32/compare/v1.12.0...v1.12.1 [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 diff --git a/CLAUDE.md b/CLAUDE.md index 1734f10..ec05268 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -294,3 +294,19 @@ The generated header file includes C++ defines for build-time validation: - `{PREFIX}_{EXT}_FILES`: Count of files by extension (e.g., `SVELTEESP32_CSS_FILES`) These allow C++ code to verify expected files are present using `#ifndef` and `#error` directives. + +## Generated Header Configuration Comment + +The generated header file includes a `//config:` comment at the top that displays the effective configuration used during code generation: + +```cpp +//engine: PsychicHttpServer +//config: engine=psychic sourcepath=./dist outputfile=./output.h etag=true gzip=true cachetime=0 espmethod=initSvelteStaticFiles define=SVELTEESP32 exclude=[*.map, *.md] +``` + +**Implementation** (`src/commandLine.ts`, `src/cppCode.ts`): + +- `formatConfiguration()` function creates a formatted string from the `ICopyFilesArguments` object +- Shows all configuration parameters: `engine`, `sourcepath`, `outputfile`, `etag`, `gzip`, `cachetime`, `espmethod`, `define`, and `exclude` patterns +- Works consistently whether configuration comes from RC file, CLI arguments, or both +- Provides complete traceability of the configuration used for code generation diff --git a/README.md b/README.md index 0e2633f..d0798c7 100644 --- a/README.md +++ b/README.md @@ -202,7 +202,7 @@ The content of **generated file** (do not edit, just use): ```c //engine: PsychicHttpServer -//cmdline: -e psychic -s ./dist -o ./output.h --etag=true --gzip=true +//config: engine=psychic sourcepath=./dist outputfile=./output.h etag=true gzip=true cachetime=0 espmethod=initSvelteStaticFiles define=SVELTEESP32 // #define SVELTEESP32_COUNT 5 #define SVELTEESP32_SIZE 468822 diff --git a/package-lock.json b/package-lock.json index 34ea2ad..8b5356c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "svelteesp32", - "version": "1.12.0", + "version": "1.12.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "svelteesp32", - "version": "1.12.0", + "version": "1.12.1", "license": "ISC", "dependencies": { "handlebars": "^4.7.8", diff --git a/package.json b/package.json index cdae9a0..0a31ba0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "svelteesp32", - "version": "1.12.0", + "version": "1.12.1", "description": "Convert Svelte (or any frontend) JS application to serve it from ESP32 webserver (PsychicHttp)", "author": "BCsabaEngine", "license": "ISC",