MCPcopy Create free account
hub / github.com/BCsabaEngine/svelteesp32 / validateRcConfig

Function validateRcConfig

src/commandLine.ts:338–474  ·  view source on GitHub ↗
(config: unknown, rcPath: string)

Source from the content-addressed store, hash-verified

336}
337
338function validateRcConfig(config: unknown, rcPath: string): IRcFileConfig {
339 if (typeof config !== 'object' || config === null) throw new Error(`RC file ${rcPath} must contain a JSON object`);
340
341 // Type assertion after runtime check
342 const configObject = config as Record<string, unknown>;
343
344 const validKeys = new Set([
345 'engine',
346 'sourcepath',
347 'outputfile',
348 'espmethod',
349 'define',
350 'gzip',
351 'etag',
352 'cachetime',
353 'cachetimehtml',
354 'cachetimeassets',
355 'created',
356 'version',
357 'exclude',
358 'basepath',
359 'maxsize',
360 'maxgzipsize',
361 'noindexcheck',
362 'dryrun',
363 'analyze',
364 'spa',
365 'manifest'
366 ]);
367
368 // Warn about unknown keys
369 for (const key of Object.keys(configObject))
370 if (!validKeys.has(key)) console.warn(yellowLog(`Warning: Unknown property '${key}' in RC file ${rcPath}`));
371
372 // Validate individual properties
373 if (configObject['engine'] !== undefined) configObject['engine'] = validateEngine(configObject['engine'] as string);
374
375 if (configObject['etag'] !== undefined)
376 configObject['etag'] = validateTriState(configObject['etag'] as string, 'etag');
377
378 if (configObject['gzip'] !== undefined)
379 configObject['gzip'] = validateTriState(configObject['gzip'] as string, 'gzip');
380
381 if (configObject['espmethod'] !== undefined) validateCppIdentifier(configObject['espmethod'] as string, 'espmethod');
382
383 if (configObject['define'] !== undefined) validateCppIdentifier(configObject['define'] as string, 'define');
384
385 if (configObject['cachetime'] !== undefined) {
386 if (typeof configObject['cachetime'] !== 'number' || Number.isNaN(configObject['cachetime']))
387 throw new TypeError(`Invalid cachetime in RC file: ${configObject['cachetime']}`);
388 if (configObject['cachetime'] < 0)
389 throw new TypeError(`Invalid cachetime in RC file: ${configObject['cachetime']} (must be non-negative)`);
390 }
391
392 if (configObject['cachetimehtml'] !== undefined) {
393 if (typeof configObject['cachetimehtml'] !== 'number' || Number.isNaN(configObject['cachetimehtml']))
394 throw new TypeError(`Invalid cachetimehtml in RC file: ${configObject['cachetimehtml']}`);
395 if (configObject['cachetimehtml'] < 0)

Callers 1

loadRcFileFunction · 0.85

Calls 5

yellowLogFunction · 0.90
validateEngineFunction · 0.85
validateTriStateFunction · 0.85
validateCppIdentifierFunction · 0.85
validateSizeOptionFunction · 0.85

Tested by

no test coverage detected