1 | "use strict";
|
2 |
|
3 |
|
4 | var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
5 | if (k2 === undefined) k2 = k;
|
6 | var desc = Object.getOwnPropertyDescriptor(m, k);
|
7 | if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
8 | desc = { enumerable: true, get: function() { return m[k]; } };
|
9 | }
|
10 | Object.defineProperty(o, k2, desc);
|
11 | }) : (function(o, m, k, k2) {
|
12 | if (k2 === undefined) k2 = k;
|
13 | o[k2] = m[k];
|
14 | }));
|
15 | var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
16 | Object.defineProperty(o, "default", { enumerable: true, value: v });
|
17 | }) : function(o, v) {
|
18 | o["default"] = v;
|
19 | });
|
20 | var __importStar = (this && this.__importStar) || function (mod) {
|
21 | if (mod && mod.__esModule) return mod;
|
22 | var result = {};
|
23 | if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
24 | __setModuleDefault(result, mod);
|
25 | return result;
|
26 | };
|
27 | Object.defineProperty(exports, "__esModule", { value: true });
|
28 | exports.PluginLoader = void 0;
|
29 | const path = __importStar(require("path"));
|
30 | const resolve = __importStar(require("resolve"));
|
31 | const MarkdownDocumenterFeature_1 = require("./MarkdownDocumenterFeature");
|
32 | const PluginFeature_1 = require("./PluginFeature");
|
33 | class PluginLoader {
|
34 | load(documenterConfig, createContext) {
|
35 | const configFileFolder = path.dirname(documenterConfig.configFilePath);
|
36 | for (const configPlugin of documenterConfig.configFile.plugins || []) {
|
37 | try {
|
38 |
|
39 | const resolvedEntryPointPath = resolve.sync(configPlugin.packageName, {
|
40 | basedir: configFileFolder
|
41 | });
|
42 |
|
43 | const entryPoint = require(resolvedEntryPointPath);
|
44 | if (!entryPoint) {
|
45 | throw new Error('Invalid entry point');
|
46 | }
|
47 | if (!entryPoint.apiDocumenterPluginManifest) {
|
48 | throw new Error(`The package is not an API documenter plugin;` +
|
49 | ` the "apiDocumenterPluginManifest" export was not found`);
|
50 | }
|
51 | const manifest = entryPoint.apiDocumenterPluginManifest;
|
52 | if (manifest.manifestVersion !== 1000) {
|
53 | throw new Error(`The plugin is not compatible with this version of API Documenter;` +
|
54 | ` unsupported manifestVersion`);
|
55 | }
|
56 | const loadedPlugin = {
|
57 | packageName: configPlugin.packageName,
|
58 | manifest
|
59 | };
|
60 | const featureDefinitionsByName = new Map();
|
61 | for (const featureDefinition of manifest.features) {
|
62 | featureDefinitionsByName.set(featureDefinition.featureName, featureDefinition);
|
63 | }
|
64 | for (const featureName of configPlugin.enabledFeatureNames) {
|
65 | const featureDefinition = featureDefinitionsByName.get(featureName);
|
66 | if (!featureDefinition) {
|
67 | throw new Error(`The plugin ${loadedPlugin.packageName} does not have a feature with name "${featureName}"`);
|
68 | }
|
69 | if (featureDefinition.kind === 'MarkdownDocumenterFeature') {
|
70 | if (this.markdownDocumenterFeature) {
|
71 | throw new Error('A MarkdownDocumenterFeature is already loaded');
|
72 | }
|
73 | const initialization = new PluginFeature_1.PluginFeatureInitialization();
|
74 | initialization._context = createContext();
|
75 | let markdownDocumenterFeature = undefined;
|
76 | try {
|
77 | markdownDocumenterFeature = new featureDefinition.subclass(initialization);
|
78 | }
|
79 | catch (e) {
|
80 | throw new Error(`Failed to construct feature subclass:\n` + e.toString());
|
81 | }
|
82 | if (!(markdownDocumenterFeature instanceof MarkdownDocumenterFeature_1.MarkdownDocumenterFeature)) {
|
83 | throw new Error('The constructed subclass was not an instance of MarkdownDocumenterFeature');
|
84 | }
|
85 | try {
|
86 | markdownDocumenterFeature.onInitialized();
|
87 | }
|
88 | catch (e) {
|
89 | throw new Error('Error occurred during the onInitialized() event: ' + e.toString());
|
90 | }
|
91 | this.markdownDocumenterFeature = markdownDocumenterFeature;
|
92 | }
|
93 | else {
|
94 | throw new Error(`Unknown feature definition kind: "${featureDefinition.kind}"`);
|
95 | }
|
96 | }
|
97 | }
|
98 | catch (e) {
|
99 | throw new Error(`Error loading plugin ${configPlugin.packageName}: ` + e.message);
|
100 | }
|
101 | }
|
102 | }
|
103 | }
|
104 | exports.PluginLoader = PluginLoader;
|
105 |
|
\ | No newline at end of file |