schlechtenburg/packages/docgen/parse.mjs

48 lines
1.4 KiB
JavaScript
Raw Normal View History

2022-03-15 19:58:11 +00:00
#!/usr/bin/env node
2022-03-13 22:12:18 +00:00
import { parse } from 'vue-docgen-api'
import { join } from 'path'
import glob from 'glob-promise'
2022-03-15 19:58:11 +00:00
import TypeDoc from 'typedoc'
import { writeFile } from 'fs/promises'
2022-03-13 22:12:18 +00:00
2022-03-15 19:58:11 +00:00
const DOCS_PATH = join(process.cwd(), process.argv[2] || './docs');
const LIB_PATH = join(process.cwd(), process.argv[3] || './lib');
const getTSDocs = (outputFile) => {
const app = new TypeDoc.Application();
app.options.addReader(new TypeDoc.TSConfigReader());
app.bootstrap();
const project = app.convert();
return app.generateJson(project, outputFile);
};
const getVueComponentDocs = async (dir) => {
const found = await glob(join(dir, '/**/*'));
const files = found
.filter(found_path => found_path.match(/\.(tsx|jsx|vue)$/));
2022-03-13 22:12:18 +00:00
const vueParsed = await Promise.all(files
.map(file => parse(file)
.catch((error) => {
// For now, ignore any errors
// console.log(error, file);
return null;
})
)
);
const vueFiltered = vueParsed.filter(p => p);
2022-03-15 19:58:11 +00:00
return vueFiltered;
};
(async () => {
const tsDocsOutput = join(DOCS_PATH, 'lib.json');
await getTSDocs(tsDocsOutput);
const vueComponents = await getVueComponentDocs(LIB_PATH);
const componentJsonPath = join(DOCS_PATH, 'components.json');
console.log(`Info: JSON written to ${componentJsonPath}`);
await writeFile(componentJsonPath, JSON.stringify(vueComponents, null, 2));
2022-03-13 22:12:18 +00:00
})();