2021-01-19 20:41:04 -08:00
|
|
|
// @ts-check
|
|
|
|
|
2024-11-28 20:36:44 -08:00
|
|
|
import fs from "node:fs/promises";
|
|
|
|
import path from "node:path";
|
|
|
|
import yaml from "js-yaml";
|
|
|
|
import { __dirname, importWithTypeJson } from "../test/esm-helpers.mjs";
|
|
|
|
const configSchema = await importWithTypeJson(import.meta, "../schema/markdownlint-config-schema.json");
|
2021-01-19 20:41:04 -08:00
|
|
|
|
|
|
|
const configExample = {};
|
|
|
|
for (const rule in configSchema.properties) {
|
2022-12-19 21:51:18 -08:00
|
|
|
if (/^(?:MD\d{3}|default|extends)$/.test(rule)) {
|
2021-01-19 20:41:04 -08:00
|
|
|
const properties = configSchema.properties[rule];
|
|
|
|
configExample[rule + "-description"] = properties.description;
|
|
|
|
configExample[rule] = properties.default;
|
|
|
|
if (properties.properties) {
|
|
|
|
const ruleExample = {};
|
|
|
|
// eslint-disable-next-line guard-for-in
|
|
|
|
for (const property in properties.properties) {
|
|
|
|
const ruleProperties = properties.properties[property];
|
|
|
|
ruleExample[property + "-sub-description"] = ruleProperties.description;
|
|
|
|
ruleExample[property] = ruleProperties.default;
|
|
|
|
}
|
|
|
|
configExample[rule] = ruleExample;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-21 00:04:05 +01:00
|
|
|
const transformComments = (input, commentPrefix) => (
|
|
|
|
commentPrefix +
|
|
|
|
" Example markdownlint configuration with all properties set to their default value\n" +
|
|
|
|
input
|
|
|
|
.replace(/^(\s*)[^-\s]+-sub-description"?: "?([^"\n]+)"?,?$/gm, "$1" + commentPrefix + " $2")
|
|
|
|
.replace(/^(\s*)[^-\s]+-description"?: "?([^"\n]+)"?,?$/gm, "\n$1" + commentPrefix + " $2")
|
|
|
|
);
|
|
|
|
|
|
|
|
const configStringJson = JSON.stringify(configExample, null, 2);
|
2024-11-28 20:36:44 -08:00
|
|
|
await fs.writeFile(
|
|
|
|
path.join(__dirname(import.meta), ".markdownlint.jsonc"),
|
2023-02-21 00:04:05 +01:00
|
|
|
transformComments(configStringJson, "//"),
|
2021-01-21 19:50:57 -08:00
|
|
|
"utf8"
|
|
|
|
);
|
|
|
|
|
2024-02-17 15:33:27 -08:00
|
|
|
const configStringYaml = yaml.dump(
|
2023-02-21 00:04:05 +01:00
|
|
|
configExample,
|
|
|
|
{
|
2024-02-17 15:33:27 -08:00
|
|
|
"forceQuotes": true,
|
|
|
|
"lineWidth": -1,
|
|
|
|
"quotingType": "\""
|
2023-02-21 00:04:05 +01:00
|
|
|
}
|
|
|
|
);
|
2024-11-28 20:36:44 -08:00
|
|
|
await fs.writeFile(
|
|
|
|
path.join(__dirname(import.meta), ".markdownlint.yaml"),
|
2023-02-21 00:04:05 +01:00
|
|
|
transformComments(configStringYaml, "#"),
|
2021-01-19 20:41:04 -08:00
|
|
|
"utf8"
|
|
|
|
);
|