vuepress-plugin-typedoc
Version:
A VuePress plugin to build api documentation with TypeDoc.
74 lines (73 loc) • 2.79 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (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 path = __importStar(require("path"));
const typedoc_1 = require("typedoc");
const typedoc_plugin_markdown_1 = require("typedoc-plugin-markdown");
const render_1 = require("./render");
const options_1 = require("./options");
const sidebar_1 = require("./sidebar");
let app;
let project;
const typedocPlugin = (opts, ctx) => {
const options = (0, options_1.getOptions)(opts);
const outputDirectory = (ctx.sourceDir || ctx.dir.source()) + '/' + options.out;
(0, render_1.removeDir)(outputDirectory);
app = new typedoc_1.Application();
(0, typedoc_plugin_markdown_1.load)(app);
(0, options_1.addOptions)(app);
app.renderer.render = render_1.render;
app.bootstrap(options);
project = app.convert();
if (!project) {
return;
}
if (options.watch) {
app.convertAndWatch(async (project) => {
app.generateDocs(project, outputDirectory);
});
}
else {
app.generateDocs(project, outputDirectory);
}
return {
name: 'vuepress-plugin-typedoc',
async enhanceAppFiles() {
if (!options.sidebar) {
return;
}
const theme = app.renderer.theme;
const navigation = theme.getNavigation(project);
const sidebarJson = JSON.stringify({
[`/${path.relative(process.cwd(), options.out)}/`]: (0, sidebar_1.getSidebarJson)(navigation, options),
});
return {
name: 'typedoc-sidebar',
content: `export default ({ siteData, options }) => {
siteData.themeConfig.sidebarDepth = 0;
siteData.themeConfig.sidebar = Object.assign({},siteData.themeConfig.sidebar,${sidebarJson});
}`,
};
},
};
};
exports.typedocPlugin = typedocPlugin;