function extract()

in util/extract.js [50:96]


function extract(filePath) {
  const fileName = basename(filePath, ext);
  const tmpdir = require("os").tmpdir();
  const markdownSpecFile = resolve(tmpdir, `${fileName}${ext}`);
  const xmlRfcFile = resolve(tmpdir, `${fileName}.xml`);
  const complianceSpec = join(pathToComplianceRoot, dirname(filePath), `${fileName}.txt`);
  const complianceDir = join(pathToComplianceRoot, dirname(filePath), fileName);

  /*
    1. Get the file name without extension
    2. Add the RFC crap to a new tmp file
    3. kramdown
    4. xml2rfc
    5. cargo-compliance extract
  */

  // Write the spec file with the header and footer
  writeFileSync(
    markdownSpecFile,
    [header(fileName), readFileSync(filePath, { encoding: "utf8" }), footer()].join("\n"),
    { encoding: "utf8" }
  );

  // Convert the markdown file from RFC XML
  execSync(["kramdown-rfc2629", markdownSpecFile, ">", xmlRfcFile].join(" "), {stdio: 'inherit'});

  // Convert the RFC XML to a ietf rfc
  execSync(["xml2rfc", "-P", xmlRfcFile, "-o", complianceSpec].join(" "), {stdio: 'inherit'});

  // An existing spec may exists, clean up first
  try {
    // This will throw if the directory does not exist
    statSync(complianceDir).isDirectory();
    // If the directory exists, remove it. Nothing could go wrong... :(
    execSync(["rm", "-rf", complianceDir].join(" "));
  } catch (ex) {
    // If the directory does not exist, that is OK
    needs(ex.errno === -2, "Unknown error");
  }

  // make sure the compliance directory exists
  mkdirSync(complianceDir, { recursive: true });

  const args = ["duvet", "extract", `${complianceSpec}`, "-o", "compliance"];
  // extract the specification
  execSync(args.join(" "), { encoding: 'utf8', stdio: 'inherit'});
}