Skip to content

Commit dd33a8a

Browse files
committed
fix: show config
1 parent 2708773 commit dd33a8a

File tree

4 files changed

+59
-20
lines changed

4 files changed

+59
-20
lines changed

src/commandLine.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,29 @@ function parseArguments(): ICopyFilesArguments {
418418
return result as ICopyFilesArguments;
419419
}
420420

421+
export function formatConfiguration(cmdLine: ICopyFilesArguments): string {
422+
const parts: string[] = [
423+
`engine=${cmdLine.engine}`,
424+
`sourcepath=${cmdLine.sourcepath}`,
425+
`outputfile=${cmdLine.outputfile}`,
426+
`etag=${cmdLine.etag}`,
427+
`gzip=${cmdLine.gzip}`,
428+
`cachetime=${cmdLine.cachetime}`
429+
];
430+
431+
if (cmdLine.created) parts.push(`created=${cmdLine.created}`);
432+
433+
if (cmdLine.version) parts.push(`version=${cmdLine.version}`);
434+
435+
if (cmdLine.espmethod) parts.push(`espmethod=${cmdLine.espmethod}`);
436+
437+
if (cmdLine.define) parts.push(`define=${cmdLine.define}`);
438+
439+
if (cmdLine.exclude.length > 0) parts.push(`exclude=[${cmdLine.exclude.join(', ')}]`);
440+
441+
return parts.join(' ');
442+
}
443+
421444
export const cmdLine = parseArguments();
422445

423446
if (!existsSync(cmdLine.sourcepath) || !statSync(cmdLine.sourcepath).isDirectory()) {

src/cppCode.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { compile as handlebarsCompile, HelperOptions } from 'handlebars';
22

3-
import { cmdLine } from './commandLine';
3+
import { cmdLine, formatConfiguration } from './commandLine';
44
import { espidfTemplate } from './cppCodeEspIdf';
55

66
export type CppCodeSource = {
@@ -126,7 +126,7 @@ const char * etag_{{this.dataname}} = "{{this.md5}}";
126126

127127
const psychicTemplate = `
128128
//engine: PsychicHttpServer
129-
//cmdline: {{{commandLine}}}
129+
//config: {{{config}}}
130130
//You should use server.config.max_uri_handlers = {{fileCount}}; or higher value to proper handles all files
131131
{{#if created }}
132132
//created: {{now}}
@@ -237,7 +237,7 @@ void {{methodName}}(PsychicHttpServer * server) {
237237

238238
const psychic2Template = `
239239
//engine: PsychicHttpServerV2
240-
//cmdline: {{{commandLine}}}
240+
//config: {{{config}}}
241241
{{#if created }}
242242
//created: {{now}}
243243
{{/if}}
@@ -344,7 +344,7 @@ void {{methodName}}(PsychicHttpServer * server) {
344344

345345
const asyncTemplate = `
346346
//engine: ESPAsyncWebServer
347-
//cmdline: {{{commandLine}}}
347+
//config: {{{config}}}
348348
{{#if created }}
349349
//created: {{now}}
350350
{{/if}}
@@ -573,7 +573,7 @@ const createHandlebarsHelpers = () => {
573573
export const getCppCode = (sources: CppCodeSources, filesByExtension: ExtensionGroups): string => {
574574
const template = handlebarsCompile(getTemplate(cmdLine.engine));
575575
const templateData = {
576-
commandLine: process.argv.slice(2).join(' '),
576+
config: formatConfiguration(cmdLine),
577577
now: `${new Date().toLocaleDateString()} ${new Date().toLocaleTimeString()}`,
578578
fileCount: sources.length.toString(),
579579
fileSize: sources.reduce((previous, current) => previous + current.content.length, 0).toString(),

src/cppCodeEspIdf.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export const espidfTemplate = `
22
//engine: espidf
3-
//cmdline: {{{commandLine}}}
3+
//config: {{{config}}}
44
{{#if created }}
55
//created: {{now}}
66
{{/if}}

test/unit/cppCode.test.ts

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,12 @@ vi.mock('../../src/commandLine', () => ({
1313
created: false,
1414
version: 'v1.0.0',
1515
espmethod: 'initSvelteStaticFiles',
16-
define: 'SVELTEESP32'
17-
}
16+
define: 'SVELTEESP32',
17+
exclude: []
18+
},
19+
formatConfiguration: vi.fn((cmdLine) => {
20+
return `engine=${cmdLine.engine} sourcepath=${cmdLine.sourcepath} outputfile=${cmdLine.outputfile} etag=${cmdLine.etag} gzip=${cmdLine.gzip} cachetime=${cmdLine.cachetime}`;
21+
})
1822
}));
1923

2024
const createMockSource = (filename: string, content: string): CppCodeSource => ({
@@ -208,8 +212,10 @@ describe('cppCode', () => {
208212
created: false,
209213
version: '',
210214
espmethod: 'initSvelteStaticFiles',
211-
define: 'SVELTEESP32'
212-
}
215+
define: 'SVELTEESP32',
216+
exclude: []
217+
},
218+
formatConfiguration: vi.fn((cmdLine) => `engine=${cmdLine.engine}`)
213219
}));
214220

215221
const { getCppCode } = await import('../../src/cppCode');
@@ -231,8 +237,10 @@ describe('cppCode', () => {
231237
created: false,
232238
version: '',
233239
espmethod: 'initSvelteStaticFiles',
234-
define: 'SVELTEESP32'
235-
}
240+
define: 'SVELTEESP32',
241+
exclude: []
242+
},
243+
formatConfiguration: vi.fn((cmdLine) => `engine=${cmdLine.engine}`)
236244
}));
237245

238246
const { getCppCode } = await import('../../src/cppCode');
@@ -254,8 +262,10 @@ describe('cppCode', () => {
254262
created: false,
255263
version: '',
256264
espmethod: 'initSvelteStaticFiles',
257-
define: 'SVELTEESP32'
258-
}
265+
define: 'SVELTEESP32',
266+
exclude: []
267+
},
268+
formatConfiguration: vi.fn((cmdLine) => `engine=${cmdLine.engine}`)
259269
}));
260270

261271
const { getCppCode } = await import('../../src/cppCode');
@@ -278,8 +288,10 @@ describe('cppCode', () => {
278288
created: false,
279289
version: '',
280290
espmethod: 'initSvelteStaticFiles',
281-
define: 'SVELTEESP32'
282-
}
291+
define: 'SVELTEESP32',
292+
exclude: []
293+
},
294+
formatConfiguration: vi.fn((cmdLine) => `engine=${cmdLine.engine}`)
283295
}));
284296

285297
const { getCppCode } = await import('../../src/cppCode');
@@ -303,8 +315,10 @@ describe('cppCode', () => {
303315
created: false,
304316
version: '',
305317
espmethod: 'initSvelteStaticFiles',
306-
define: 'SVELTEESP32'
307-
}
318+
define: 'SVELTEESP32',
319+
exclude: []
320+
},
321+
formatConfiguration: vi.fn((cmdLine) => `engine=${cmdLine.engine}`)
308322
}));
309323

310324
const { getCppCode } = await import('../../src/cppCode');
@@ -327,8 +341,10 @@ describe('cppCode', () => {
327341
created: false,
328342
version: '',
329343
espmethod: 'initSvelteStaticFiles',
330-
define: 'SVELTEESP32'
331-
}
344+
define: 'SVELTEESP32',
345+
exclude: []
346+
},
347+
formatConfiguration: vi.fn((cmdLine) => `engine=${cmdLine.engine}`)
332348
}));
333349

334350
const { getCppCode } = await import('../../src/cppCode');

0 commit comments

Comments
 (0)