mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-22 05:40:48 +02:00
56 lines
1.4 KiB
JavaScript
56 lines
1.4 KiB
JavaScript
import { readFile } from "node:fs/promises";
|
|
import { parse } from "../helpers/micromark.cjs";
|
|
import library from "../lib/markdownlint.js";
|
|
const markdownlint = library.promises.markdownlint;
|
|
|
|
/* eslint-disable no-await-in-loop, no-console */
|
|
|
|
/**
|
|
* Log the structure of a Micromark token list.
|
|
*
|
|
* @param {Object[]} tokens Micromark tokens.
|
|
* @param {number} depth Tree depth.
|
|
* @returns {void}
|
|
*/
|
|
function consoleLogTokens(tokens, depth = 0) {
|
|
for (const token of tokens) {
|
|
const { children, text, type } = token;
|
|
console.log(
|
|
`${" ".repeat(depth * 2)}${type} ${text.replace(/\n/g, "\\n")}`
|
|
);
|
|
if (children.length > 0) {
|
|
consoleLogTokens(children, depth + 1);
|
|
}
|
|
}
|
|
}
|
|
|
|
let profile = false;
|
|
let count = 1;
|
|
const files = process.argv.slice(2).filter((arg) => {
|
|
if (arg === "--profile") {
|
|
profile = true;
|
|
count = 1000;
|
|
return false;
|
|
}
|
|
return true;
|
|
});
|
|
|
|
for (const file of files) {
|
|
if (!profile) {
|
|
const content = await readFile(file, "utf8");
|
|
consoleLogTokens(parse(content));
|
|
}
|
|
let results = null;
|
|
performance.mark("profile-start");
|
|
for (let i = 0; i < count; i++) {
|
|
results = await markdownlint({
|
|
"files": [ file ]
|
|
});
|
|
}
|
|
const measure = performance.measure("profile", "profile-start");
|
|
if (profile) {
|
|
console.log(Math.round(measure.duration));
|
|
} else {
|
|
console.dir(results, { "depth": null });
|
|
}
|
|
}
|