All files / cli ConfigPrinter.ts

100% Statements 22/22
100% Branches 18/18
100% Functions 2/2
100% Lines 22/22

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67                        4x                   35x                 12x 12x 12x 12x 12x 12x 12x 12x 12x     12x     12x 12x     12x 2x   12x       12x 2x   12x 12x 12x          
/**
 * ConfigPrinter
 * Displays effective configuration and provides version info
 */
 
import ICliConfig from "./types/ICliConfig";
import IFileConfig from "./types/IFileConfig";
import packageJson from "../../package.json" with { type: "json" };
 
/**
 * Version string from package.json
 */
const VERSION = packageJson.version;
 
/**
 * Print effective configuration and version info
 */
class ConfigPrinter {
  /**
   * Get the current version string
   */
  static getVersion(): string {
    return VERSION;
  }
 
  /**
   * Display effective configuration
   * @param config - Merged effective configuration
   * @param fileConfig - Configuration loaded from file (for displaying path)
   */
  static showConfig(config: ICliConfig, fileConfig: IFileConfig): void {
    console.log("Effective configuration:");
    console.log("");
    console.log("  Config file:    " + (fileConfig._path ?? "(none)"));
    console.log("  cppRequired:    " + config.cppRequired);
    console.log("  debugMode:      " + (config.debugMode ?? false));
    console.log("  target:         " + (config.target ?? "(none)"));
    console.log("  noCache:        " + config.noCache);
    console.log("  preprocess:     " + config.preprocess);
    console.log(
      "  output:         " + (config.outputPath || "(same dir as input)"),
    );
    console.log(
      "  headerOut:      " + (config.headerOutDir ?? "(same as output)"),
    );
    console.log("  basePath:       " + (config.basePath ?? "(none)"));
    console.log(
      "  include:        " + (config.includeDirs.length > 0 ? "" : "(none)"),
    );
    for (const dir of config.includeDirs) {
      console.log("    - " + dir);
    }
    console.log(
      "  defines:        " +
        (Object.keys(config.defines).length > 0 ? "" : "(none)"),
    );
    for (const [key, value] of Object.entries(config.defines)) {
      console.log("    - " + key + (value === true ? "" : "=" + value));
    }
    console.log("");
    console.log("Source:");
    console.log("  CLI flags take precedence over config file values");
  }
}
 
export default ConfigPrinter;