Skip to content
This repository has been archived by the owner on Jun 7, 2024. It is now read-only.

Commit

Permalink
BREAKING CHANGE: remove respecDocWriter fetchAndWrite() (speced#3822)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoscaceres authored Oct 13, 2021
1 parent 1bd0786 commit 4d1f2e3
Showing 1 changed file with 0 additions and 56 deletions.
56 changes: 0 additions & 56 deletions tools/respecDocWriter.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,61 +166,6 @@ function isRespecScript(req) {
}
}

/**
* Fetches a ReSpec "src" URL, and writes the processed static HTML to an "out" path.
* @deprecated Please use `toHTML` instead.
* @param {string} src A URL or filepath that is the ReSpec source.
* @param {string | null | ""} out A path to write to. If null, goes to stdout. If "", then don't write, just return value.
* @param {object} [whenToHalt] Allowing execution to stop without writing.
* @param {boolean} [whenToHalt.haltOnError] Do not write if a ReSpec processing has an error.
* @param {boolean} [whenToHalt.haltOnWarn] Do not write if a ReSpec processing has a warning.
* @param {object} [options]
* @param {number} [options.timeout] Milliseconds before processing should timeout.
* @param {boolean} [options.disableSandbox] See https://peter.sh/experiments/chromium-command-line-switches/#no-sandbox
* @param {boolean} [options.debug] Show the Chromium window with devtools open for debugging.
* @param {boolean} [options.verbose] Log processing status to stdout.
* @param {(error: RsError) => void} [options.onError] What to do if a ReSpec processing has an error. Logs to stderr by default.
* @param {(warning: RsError) => void} [options.onWarning] What to do if a ReSpec processing has a warning. Logs to stderr by default.
* @return {Promise<string>} Resolves with HTML when done writing. Rejects on errors.
*/
async function fetchAndWrite(src, out, whenToHalt = {}, options = {}) {
const colors = require("colors");
colors.setTheme({ debug: "cyan", error: "red", warn: "yellow" });

const showError = error => console.error(colors.error(error));
const showWarning = warning => console.warn(colors.warn(warning));

showWarning(
"DEPRECATION WARNING: `fetchAndWrite` is deprecated and will be removed in a future version. Please use `toHTML` instead."
);

const opts = {
onError(error) {
showError(`💥 ReSpec error: ${colors.debug(error.message)}`);
},
onWarning(warning) {
showWarning(`⚠️ ReSpec warning: ${colors.debug(warning.message)}`);
},
...options,
devtools: options.debug,
};
const { html, errors, warnings } = await toHTML(src, opts);

const abortOnWarning = whenToHalt.haltOnWarn && warnings.length;
const abortOnError = whenToHalt.haltOnError && errors.length;
if (abortOnError || abortOnWarning) {
throw new Error(
`${abortOnError ? "Errors" : "Warnings"} found during processing.`
);
}

if (out === "") out = null;
else if (out === null) out = "stdout";

await write(out, html);
return html;
}

/**
* @param {import("puppeteer").Page} page
* @typedef {[major: number, minor: number, patch: number]} ReSpecVersion
Expand Down Expand Up @@ -425,5 +370,4 @@ async function write(destination, html) {
}

exports.toHTML = toHTML;
exports.fetchAndWrite = fetchAndWrite;
exports.write = write;

0 comments on commit 4d1f2e3

Please sign in to comment.