vuepress-plugin-typedoc
Version:
A VuePress plugin to build API documentation with TypeDoc.
86 lines (85 loc) • 3.69 kB
JavaScript
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.typedocPlugin = void 0;
const fs = __importStar(require("fs"));
const path = __importStar(require("path"));
const typedoc_1 = require("typedoc");
const typedoc_plugin_markdown_1 = require("typedoc-plugin-markdown");
const options_1 = require("../shared/options");
const render_1 = require("../shared/render");
const theme_1 = require("../shared/theme");
const sidebar_1 = require("./sidebar");
let app;
let project;
const typedocPlugin = (opts) => {
return (ctx) => {
const typedocOptions = (0, options_1.getTypedocOptions)(opts);
const outputDirectory = ctx.dir.source() + '/' + typedocOptions.out;
return {
name: 'vuepress-plugin-typedoc',
onInitialized: async () => {
if (typedocOptions.cleanOutputDir) {
(0, render_1.removeDir)(outputDirectory);
}
app = await typedoc_1.Application.bootstrapWithPlugins();
(0, typedoc_plugin_markdown_1.load)(app);
(0, options_1.addOptions)(app);
app.renderer.render = render_1.render;
setOptions(app, typedocOptions);
app.renderer.defineTheme('vuepress', theme_1.VuepressTheme);
project = await app.convert();
if (!project) {
return;
}
if (typedocOptions.watch) {
app.convertAndWatch(async (project) => {
await app.generateDocs(project, outputDirectory);
});
}
else {
await app.generateDocs(project, outputDirectory);
}
const sidebarOptions = (0, options_1.getSidebarOptions)(opts);
if (!sidebarOptions.autoConfiguration) {
return;
}
if (sidebarOptions.autoConfiguration) {
const theme = app.renderer.theme;
const navigation = theme.getNavigation(project);
const sidebarPath = path.resolve(outputDirectory, 'typedoc-sidebar.json');
const sidebarJson = (0, sidebar_1.getSidebarJson)(navigation, sidebarOptions, typedocOptions.out);
fs.writeFileSync(sidebarPath, JSON.stringify(sidebarJson));
}
},
};
};
};
exports.typedocPlugin = typedocPlugin;
function setOptions(app, options, reportErrors = true) {
for (const [key, val] of Object.entries(options)) {
app.options.setValue(key, val);
}
}
;