| 1 | import { program } from "commander"; |
| 2 | import path from "path"; |
| 3 | import fs from "fs/promises"; |
| 4 | import prettier from "prettier"; |
| 5 | import { analyze } from "./src/analyzer"; |
| 6 | import { generate } from "./src/generate"; |
| 7 | |
| 8 | const DECLARATIONS_PATH = path.resolve(__dirname, "..", "index.d.ts"); |
| 9 | |
| 10 | program.name("autocomplete-types-docs-generator"); |
| 11 | program.argument("<outfile>"); |
| 12 | program.action(async (outfile) => { |
| 13 | const absoluteOutfile = path.resolve(outfile); |
| 14 | console.info(`Using ${DECLARATIONS_PATH} as input file.`); |
| 15 | fs.writeFile( |
| 16 | absoluteOutfile, |
| 17 | await prettier.format(JSON.stringify(generate(analyze(DECLARATIONS_PATH))), { parser: "json" }) |
| 18 | ); |
| 19 | }); |
| 20 | program.parse(); |