scripts/doc-generator/parse_doc_configs.js
/**
 * Parse root config file into a JS object and check that all properties are in
 * the right format.
 * Exit with a meaningful error if that's not the case.
 * @param {string} rootConfigFileName
 * @returns {Promise.<Object>}
 */
Parse root config file into a JS object and check that all properties are in
the right format.
Exit with a meaningful error if that's not the case.
@param {string} rootConfigFileName
@returns {Promise.}
Parse root config file into a JS object and check that all properties are in the right format . Exit with a meaningful error if that ' s not the case . @param { string } rootConfigFileName @returns { Promise . }
async function parseAndCheckRootConfigFile(rootConfigFileName) {
  let configStr;
  try {
    configStr = await promisify(fs.readFile)(rootConfigFileName, "utf8");
  } catch (err) {
    const srcMessage = (err ?? {}).message ?? "Unknown error";
    console.error(
      "Error: Impossible to read Root .docConfig.json file (\"" +
        rootConfigFileName +
        "\"): " +
      srcMessage
    );
    process.exit(1);
  }
  let config;
  try {
    config = JSON.parse(configStr);
  } catch (err) {
    const srcMessage = (err ?? {}).message ?? "Unknown error";
    exitWithInvalidRootConfig(srcMessage);
  }
  if (typeof config !== "object" || config === null) {
    exitWithInvalidRootConfig("Should be under an object form.");
  }
  if (config.logo !== undefined) {
    if (typeof config.logo !== "object" || config.logo === null) {
      exitWithInvalidRootConfig(
        `The "logo" property, if defined, should contain an object.`
      );
    }
    if (typeof config.logo.srcPath !== "string") {
      exitWithInvalidRootConfig(
        `The "logo" property, if defined, should contain a "srcPath" ` +
          "property set as a string."
      );
    }
    if (config.logo.link !== undefined && typeof config.logo.link !== "string") {
      exitWithInvalidRootConfig(
        `The "logo.link" property, if defined, should be set as a string.`
      );
    }
  }
  if (config.favicon !== undefined) {
    if (typeof config.favicon.srcPath !== "string") {
      exitWithInvalidRootConfig(
        `The "favicon" property, if defined, should contain a "srcPath" `+
         "property set as a string."
      );
    }
  }
  if (
    config.otherVersionsLink !== undefined &&
    typeof config.otherVersionsLink !== "string"
  ) {
    exitWithInvalidRootConfig(
      `The "otherVersionsLink" property, if defined, should be set as a string.`
    );
  }
  if (
    typeof config.linksLeft !== undefined &&
    !Array.isArray(config.linksLeft)
  ) {
    exitWithInvalidRootConfig(
      `The "linksLeft" property, if defined, should be set as an Array.`
    );
  }
  if (
    typeof config.linksRight !== undefined &&
    !Array.isArray(config.linksRight)
  ) {
    exitWithInvalidRootConfig(
      `The "linksRight" property, if defined, should be set as an Array.`
    );
  }
  return config;
  function exitWithInvalidRootConfig(reason) {
    console.error(
      `Error: Root .docConfig.json file ("${rootConfigFileName}") is invalid: ${reason}`
    );
    process.exit(1);
  }
}
async function parseAndCheckRootConfigFile ( rootConfigFileName ) { let configStr ; try { configStr = await promisify ( fs . readFile ) ( rootConfigFileName , "utf8" ) ; } catch ( err ) { const srcMessage = ( err ?? { } ) . message ?? "Unknown error" ; console . error ( "Error: Impossible to read Root .docConfig.json file (\"" + rootConfigFileName + "\"): " + srcMessage ) ; process . exit ( 1 ) ; } let config ; try { config = JSON . parse ( configStr ) ; } catch ( err ) { const srcMessage = ( err ?? { } ) . message ?? "Unknown error" ; exitWithInvalidRootConfig ( srcMessage ) ; } if ( typeof config !== "object" || config === null ) { exitWithInvalidRootConfig ( "Should be under an object form." ) ; } if ( config . logo !== undefined ) { if ( typeof config . logo !== "object" || config . logo === null ) { exitWithInvalidRootConfig ( ` ` ) ; } if ( typeof config . logo . srcPath !== "string" ) { exitWithInvalidRootConfig ( ` ` + "property set as a string." ) ; } if ( config . logo . link !== undefined && typeof config . logo . link !== "string" ) { exitWithInvalidRootConfig ( ` ` ) ; } } if ( config . favicon !== undefined ) { if ( typeof config . favicon . srcPath !== "string" ) { exitWithInvalidRootConfig ( ` ` + "property set as a string." ) ; } } if ( config . otherVersionsLink !== undefined && typeof config . otherVersionsLink !== "string" ) { exitWithInvalidRootConfig ( ` ` ) ; } if ( typeof config . linksLeft !== undefined && ! Array . isArray ( config . linksLeft ) ) { exitWithInvalidRootConfig ( ` ` ) ; } if ( typeof config . linksRight !== undefined && ! Array . isArray ( config . linksRight ) ) { exitWithInvalidRootConfig ( ` ` ) ; } return config ; function exitWithInvalidRootConfig ( reason ) { console . error ( ` ${ rootConfigFileName } ${ reason } ` ) ; process . exit ( 1 ) ; } }
Parse root config file into a JS object and check that all properties are in
 the right format.
Parse root config file into a JS object and check that all properties are in the right format .