| 1 |
import fs from "node:fs"; |
| 2 |
import path from "node:path"; |
| 3 |
import { URL } from "node:url"; |
| 4 |
import prettier from "prettier"; |
| 5 |
import pc from "picocolors"; |
| 6 |
// eslint-disable-next-line import/no-relative-packages |
| 7 |
import { analyze, generate } from "../docs-generator/dist"; |
| 8 |
|
| 9 |
const dirname = new URL(".", import.meta.url).pathname; |
| 10 |
const docsPath = path.resolve(dirname, "..", "index.d.ts"); |
| 11 |
|
| 12 |
const currentDocs = fs.readFileSync("docs.json", { encoding: "utf-8" }); |
| 13 |
const expectedDocs = await prettier.format(JSON.stringify(generate(analyze(docsPath))), { |
| 14 |
parser: "json", |
| 15 |
}); |
| 16 |
|
| 17 |
if (currentDocs !== expectedDocs) { |
| 18 |
console.error( |
| 19 |
pc.red( |
| 20 |
"Current docs from @withfig/autocomplete-types are different from the expected ones, please run 'yarn workspace @withfig/autocomplete-types generate-docs' to regenerate them." |
| 21 |
) |
| 22 |
); |
| 23 |
process.exit(1); |
| 24 |
} else { |
| 25 |
console.log(pc.green("@withfig/autocomplete-docs are updated")); |
| 26 |
} |