37 lines
1.6 KiB
JavaScript
37 lines
1.6 KiB
JavaScript
"use strict";
|
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const honkit_1 = __importDefault(require("../honkit"));
|
|
const promise_1 = __importDefault(require("../utils/promise"));
|
|
/**
|
|
Validate a plugin
|
|
|
|
@param {Plugin} plugin
|
|
@return {Promise<Plugin>}
|
|
*/
|
|
function validatePlugin(plugin) {
|
|
const packageInfos = plugin.getPackage();
|
|
const isValid = plugin.isLoaded() &&
|
|
packageInfos &&
|
|
packageInfos.get("name") &&
|
|
packageInfos.get("engines") &&
|
|
(packageInfos.get("engines").get("gitbook") || packageInfos.get("engines").get("honkit"));
|
|
const pluginName = packageInfos.get("name") || "unknown plugin";
|
|
if (!isValid) {
|
|
return promise_1.default.reject(new Error(`Error loading plugin "${pluginName}" at "${plugin.getPath()}"`));
|
|
}
|
|
const gitbookVersion = packageInfos.get("engines").get("gitbook");
|
|
const honkitVersion = packageInfos.get("engines").get("honkit");
|
|
// support "gitbook" and "honkit"
|
|
if (gitbookVersion && !honkit_1.default.satisfies(gitbookVersion)) {
|
|
return promise_1.default.reject(new Error(`HonKit doesn't satisfy the requirements of this plugin: ${pluginName} require ${gitbookVersion}`));
|
|
}
|
|
if (honkitVersion && !honkit_1.default.satisfies(honkitVersion)) {
|
|
return promise_1.default.reject(new Error(`HonKit doesn't satisfy the requirements of this plugin: ${pluginName} require ${honkitVersion}`));
|
|
}
|
|
return (0, promise_1.default)(plugin);
|
|
}
|
|
exports.default = validatePlugin;
|