This commit is contained in:
2025-05-12 05:38:44 +09:00
parent dced21c3f8
commit 6d78bfa46e
8120 changed files with 1161564 additions and 0 deletions

View File

@ -0,0 +1,26 @@
/**
* This class aim to resolve honkit's package name and get the module path.
*
* Define
*
* - `package` is npm package
* - `module` is package's main module
*
* ## Support
*
* - honkit-plugin-*
* - gitbook-plugin-*
*/
export declare class PluginResolver {
baseDirectory: string;
constructor(config?: {
baseDirectory?: string;
});
/**
* Take package name, and return path to module.
* @param {string} packageName
* @returns {string} return path to module
*/
resolvePluginPackageName(packageName: any): any;
}
//# sourceMappingURL=PluginResolver.d.ts.map

View File

@ -0,0 +1 @@
{"version":3,"file":"PluginResolver.d.ts","sourceRoot":"","sources":["../../src/plugins/PluginResolver.ts"],"names":[],"mappings":"AAaA;;;;;;;;;;;;GAYG;AAEH,qBAAa,cAAc;IACvB,aAAa,EAAE,MAAM,CAAC;gBAEV,MAAM,GAAE;QAAE,aAAa,CAAC,EAAE,MAAM,CAAA;KAAO;IAOnD;;;;OAIG;IACH,wBAAwB,CAAC,WAAW,KAAA;CAyBvC"}

90
book/node_modules/honkit/lib/plugins/PluginResolver.js generated vendored Normal file
View File

@ -0,0 +1,90 @@
// LICENSE : MIT
"use strict";
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;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.PluginResolver = void 0;
const path_1 = __importDefault(require("path"));
const util = __importStar(require("./package-name-util"));
const try_resolve_1 = __importDefault(require("try-resolve"));
const SPECIAL_PACKAGE_NAME = [
"fontsettings", // → @honkit/honkit-plugin-fontsettings
"highlight", // → @honkit/honkit-plugin-highlight
"theme-default" // → @honkit/honkit-plugin-theme-default
];
/**
* This class aim to resolve honkit's package name and get the module path.
*
* Define
*
* - `package` is npm package
* - `module` is package's main module
*
* ## Support
*
* - honkit-plugin-*
* - gitbook-plugin-*
*/
class PluginResolver {
baseDirectory;
constructor(config = {}) {
/**
* @type {string} baseDirectory for resolving
*/
this.baseDirectory = config && config.baseDirectory ? config.baseDirectory : "";
}
/**
* Take package name, and return path to module.
* @param {string} packageName
* @returns {string} return path to module
*/
resolvePluginPackageName(packageName) {
const baseDir = this.baseDirectory;
const honkitFullPackageName = util.createFullPackageName("honkit-plugin-", packageName);
// honkit > gitbook > normal
const gitbookFullPackageName = util.createFullPackageName("gitbook-plugin-", packageName);
// special case for backward-compatible
// e.g.) load theme-default as @honkit/honkit-plugins-theme-default
const honkitScopePackageName = `@honkit/${honkitFullPackageName}`;
// In sometimes, HonKit package has not main field - so search package.json
const pkgPath = (0, try_resolve_1.default)(path_1.default.join(baseDir, honkitFullPackageName, "/package.json")) ||
(0, try_resolve_1.default)(path_1.default.join(baseDir, gitbookFullPackageName, "/package.json")) ||
(0, try_resolve_1.default)(path_1.default.join(baseDir, packageName, "/package.json")) ||
(SPECIAL_PACKAGE_NAME.includes(packageName) &&
(0, try_resolve_1.default)(path_1.default.join(baseDir, honkitScopePackageName, "/package.json")));
if (!pkgPath) {
throw new ReferenceError(`Failed to load HonKit's plugin module: "${packageName}" is not found.
cwd: ${process.cwd()}
baseDir: ${baseDir}
`);
}
return pkgPath.substring(0, pkgPath.length - "/package.json".length);
}
}
exports.PluginResolver = PluginResolver;

14
book/node_modules/honkit/lib/plugins/index.d.ts generated vendored Normal file
View File

@ -0,0 +1,14 @@
import loadForBook0 from "./loadForBook";
import validateConfig0 from "./validateConfig";
import listResources0 from "./listResources";
import listBlocks0 from "./listBlocks";
import listFilters0 from "./listFilters";
declare const _default: {
loadForBook: typeof loadForBook0;
validateConfig: typeof validateConfig0;
listResources: typeof listResources0;
listBlocks: typeof listBlocks0;
listFilters: typeof listFilters0;
};
export default _default;
//# sourceMappingURL=index.d.ts.map

1
book/node_modules/honkit/lib/plugins/index.d.ts.map generated vendored Normal file
View File

@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/plugins/index.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,eAAe,CAAC;AACzC,OAAO,eAAe,MAAM,kBAAkB,CAAC;AAC/C,OAAO,cAAc,MAAM,iBAAiB,CAAC;AAC7C,OAAO,WAAW,MAAM,cAAc,CAAC;AACvC,OAAO,YAAY,MAAM,eAAe,CAAC;;;;;;;;AACzC,wBAME"}

17
book/node_modules/honkit/lib/plugins/index.js generated vendored Normal file
View File

@ -0,0 +1,17 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const loadForBook_1 = __importDefault(require("./loadForBook"));
const validateConfig_1 = __importDefault(require("./validateConfig"));
const listResources_1 = __importDefault(require("./listResources"));
const listBlocks_1 = __importDefault(require("./listBlocks"));
const listFilters_1 = __importDefault(require("./listFilters"));
exports.default = {
loadForBook: loadForBook_1.default,
validateConfig: validateConfig_1.default,
listResources: listResources_1.default,
listBlocks: listBlocks_1.default,
listFilters: listFilters_1.default
};

9
book/node_modules/honkit/lib/plugins/listBlocks.d.ts generated vendored Normal file
View File

@ -0,0 +1,9 @@
/**
List blocks from a list of plugins
@param {OrderedMap<String:Plugin>}
@return {Map<String:TemplateBlock>}
*/
declare function listBlocks(plugins: any): any;
export default listBlocks;
//# sourceMappingURL=listBlocks.d.ts.map

View File

@ -0,0 +1 @@
{"version":3,"file":"listBlocks.d.ts","sourceRoot":"","sources":["../../src/plugins/listBlocks.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,iBAAS,UAAU,CAAC,OAAO,KAAA,OAK1B;AAED,eAAe,UAAU,CAAC"}

19
book/node_modules/honkit/lib/plugins/listBlocks.js generated vendored Normal file
View File

@ -0,0 +1,19 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const immutable_1 = __importDefault(require("immutable"));
/**
List blocks from a list of plugins
@param {OrderedMap<String:Plugin>}
@return {Map<String:TemplateBlock>}
*/
function listBlocks(plugins) {
return plugins.reverse().reduce((result, plugin) => {
const blocks = plugin.getBlocks();
return result.merge(blocks);
}, immutable_1.default.Map());
}
exports.default = listBlocks;

View File

@ -0,0 +1,10 @@
/**
* List all dependencies for a book, including default plugins.
* It returns a concat with default plugins and remove disabled ones.
*
* @param {List<PluginDependency>} deps
* @return {List<PluginDependency>}
*/
declare function listDependencies(deps: any): any;
export default listDependencies;
//# sourceMappingURL=listDependencies.d.ts.map

View File

@ -0,0 +1 @@
{"version":3,"file":"listDependencies.d.ts","sourceRoot":"","sources":["../../src/plugins/listDependencies.ts"],"names":[],"mappings":"AAGA;;;;;;GAMG;AAEH,iBAAS,gBAAgB,CAAC,IAAI,KAAA,OAoB7B;AAED,eAAe,gBAAgB,CAAC"}

View File

@ -0,0 +1,33 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const defaultPlugins_1 = __importDefault(require("../constants/defaultPlugins"));
const sortDependencies_1 = __importDefault(require("./sortDependencies"));
/**
* List all dependencies for a book, including default plugins.
* It returns a concat with default plugins and remove disabled ones.
*
* @param {List<PluginDependency>} deps
* @return {List<PluginDependency>}
*/
function listDependencies(deps) {
// Extract list of plugins to disable (starting with -)
const toRemove = deps
.filter((plugin) => {
return !plugin.isEnabled();
})
.map((plugin) => {
return plugin.getName();
});
// Concat with default plugins
deps = deps.concat(defaultPlugins_1.default);
// Remove plugins
deps = deps.filterNot((plugin) => {
return toRemove.includes(plugin.getName());
});
// Sort
return (0, sortDependencies_1.default)(deps);
}
exports.default = listDependencies;

View File

@ -0,0 +1,11 @@
/**
* List all plugin requirements for a book.
* It can be different from the final list of plugins,
* since plugins can have their own dependencies
*
* @param {Book}
* @return {List<PluginDependency>}
*/
declare function listDepsForBook(book: any): any;
export default listDepsForBook;
//# sourceMappingURL=listDepsForBook.d.ts.map

View File

@ -0,0 +1 @@
{"version":3,"file":"listDepsForBook.d.ts","sourceRoot":"","sources":["../../src/plugins/listDepsForBook.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AAEH,iBAAS,eAAe,CAAC,IAAI,KAAA,OAK5B;AAED,eAAe,eAAe,CAAC"}

View File

@ -0,0 +1,20 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const listDependencies_1 = __importDefault(require("./listDependencies"));
/**
* List all plugin requirements for a book.
* It can be different from the final list of plugins,
* since plugins can have their own dependencies
*
* @param {Book}
* @return {List<PluginDependency>}
*/
function listDepsForBook(book) {
const config = book.getConfig();
const plugins = config.getPluginDependencies();
return (0, listDependencies_1.default)(plugins);
}
exports.default = listDepsForBook;

View File

@ -0,0 +1,9 @@
/**
List filters from a list of plugins
@param {OrderedMap<String:Plugin>}
@return {Map<String:Function>}
*/
declare function listFilters(plugins: any): any;
export default listFilters;
//# sourceMappingURL=listFilters.d.ts.map

View File

@ -0,0 +1 @@
{"version":3,"file":"listFilters.d.ts","sourceRoot":"","sources":["../../src/plugins/listFilters.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,iBAAS,WAAW,CAAC,OAAO,KAAA,OAI3B;AAED,eAAe,WAAW,CAAC"}

18
book/node_modules/honkit/lib/plugins/listFilters.js generated vendored Normal file
View File

@ -0,0 +1,18 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const immutable_1 = __importDefault(require("immutable"));
/**
List filters from a list of plugins
@param {OrderedMap<String:Plugin>}
@return {Map<String:Function>}
*/
function listFilters(plugins) {
return plugins.reverse().reduce((result, plugin) => {
return result.merge(plugin.getFilters());
}, immutable_1.default.Map());
}
exports.default = listFilters;

View File

@ -0,0 +1,9 @@
import Immutable from "immutable";
import Plugin from "../models/plugin";
/**
List all resources from a list of plugins
@return {Map<String:List<{url, path}>}
*/
declare function listResources(plugins: Plugin[], resources: any): Immutable.Map<string, any>;
export default listResources;
//# sourceMappingURL=listResources.d.ts.map

View File

@ -0,0 +1 @@
{"version":3,"file":"listResources.d.ts","sourceRoot":"","sources":["../../src/plugins/listResources.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,WAAW,CAAC;AAIlC,OAAO,MAAM,MAAM,kBAAkB,CAAC;AAEtC;;;GAGG;AACH,iBAAS,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,SAAS,KAAA,8BA6BlD;AAED,eAAe,aAAa,CAAC"}

41
book/node_modules/honkit/lib/plugins/listResources.js generated vendored Normal file
View File

@ -0,0 +1,41 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const immutable_1 = __importDefault(require("immutable"));
const path_1 = __importDefault(require("path"));
const location_1 = __importDefault(require("../utils/location"));
const pluginResources_1 = __importDefault(require("../constants/pluginResources"));
/**
List all resources from a list of plugins
@return {Map<String:List<{url, path}>}
*/
function listResources(plugins, resources) {
return plugins.reduce((result, plugin) => {
const npmId = plugin.getNpmID();
const pluginResources = resources.get(plugin.getName());
pluginResources_1.default.forEach((resourceType) => {
let assets = pluginResources.get(resourceType);
if (!assets)
return;
let list = result.get(resourceType) || immutable_1.default.List();
assets = assets.map((assetFile) => {
if (location_1.default.isExternal(assetFile)) {
return {
url: assetFile
};
}
else {
return {
path: location_1.default.normalize(path_1.default.join(npmId, assetFile))
};
}
});
list = list.concat(assets);
result = result.set(resourceType, list);
});
return result;
}, immutable_1.default.Map());
}
exports.default = listResources;

View File

@ -0,0 +1,9 @@
/**
* Load all plugins in a book
*
* @param {Book}
* @return {Promise<Map<String:Plugin>}
*/
declare function loadForBook(book: any): Promise<any[]>;
export default loadForBook;
//# sourceMappingURL=loadForBook.d.ts.map

View File

@ -0,0 +1 @@
{"version":3,"file":"loadForBook.d.ts","sourceRoot":"","sources":["../../src/plugins/loadForBook.ts"],"names":[],"mappings":"AAKA;;;;;GAKG;AACH,iBAAS,WAAW,CAAC,IAAI,KAAA,kBA4BxB;AAED,eAAe,WAAW,CAAC"}

38
book/node_modules/honkit/lib/plugins/loadForBook.js generated vendored Normal file
View File

@ -0,0 +1,38 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const listDepsForBook_1 = __importDefault(require("./listDepsForBook"));
const loadPlugin_1 = require("./loadPlugin");
const PluginResolver_1 = require("./PluginResolver");
/**
* Load all plugins in a book
*
* @param {Book}
* @return {Promise<Map<String:Plugin>}
*/
function loadForBook(book) {
const logger = book.getLogger();
// List the dependencies are defined in book.js
/**
* @type {List<PluginDependency>}
*/
const requirements = (0, listDepsForBook_1.default)(book);
const pluginResolver = new PluginResolver_1.PluginResolver();
const installedPlugins = requirements.map((dep) => {
const name = dep.getName();
return dep.merge({
path: pluginResolver.resolvePluginPackageName(name)
});
});
// Log state
logger.info.ln(`${installedPlugins.size} plugins are installed`);
if (requirements.size !== installedPlugins.length) {
logger.info.ln(`${requirements.size} explicitly listed`);
}
return Promise.all(installedPlugins.map((plugin) => {
return (0, loadPlugin_1.loadPlugin)(book, plugin);
}));
}
exports.default = loadForBook;

11
book/node_modules/honkit/lib/plugins/loadPlugin.d.ts generated vendored Normal file
View File

@ -0,0 +1,11 @@
/**
Load a plugin in a book
@param {Book} book
@param {PluginDependency[]} plugin
@param {string} pkgPath (optional)
@return {Promise<Plugin>}
*/
declare function loadPlugin(book: any, plugin: any): any;
export { loadPlugin };
//# sourceMappingURL=loadPlugin.d.ts.map

View File

@ -0,0 +1 @@
{"version":3,"file":"loadPlugin.d.ts","sourceRoot":"","sources":["../../src/plugins/loadPlugin.ts"],"names":[],"mappings":"AAeA;;;;;;;GAOG;AACH,iBAAS,UAAU,CAAC,IAAI,KAAA,EAAE,MAAM,KAAA,OAkE/B;AAED,OAAO,EAAE,UAAU,EAAE,CAAC"}

88
book/node_modules/honkit/lib/plugins/loadPlugin.js generated vendored Normal file
View File

@ -0,0 +1,88 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.loadPlugin = loadPlugin;
const path_1 = __importDefault(require("path"));
const resolve_1 = __importDefault(require("resolve"));
const immutable_1 = __importDefault(require("immutable"));
const promise_1 = __importDefault(require("../utils/promise"));
const error_1 = __importDefault(require("../utils/error"));
const timing_1 = __importDefault(require("../utils/timing"));
const validatePlugin_1 = __importDefault(require("./validatePlugin"));
const plugin_1 = __importDefault(require("../models/plugin"));
// Return true if an error is a "module not found"
// Wait on https://github.com/substack/node-resolve/pull/81 to be merged
function isModuleNotFound(err) {
return err.code == "MODULE_NOT_FOUND" || err.message.indexOf("Cannot find module") >= 0;
}
/**
Load a plugin in a book
@param {Book} book
@param {PluginDependency[]} plugin
@param {string} pkgPath (optional)
@return {Promise<Plugin>}
*/
function loadPlugin(book, plugin) {
const logger = book.getLogger();
const name = plugin.getName();
let pkgPath = plugin.getPath();
// Try loading plugins from different location
let p = (0, promise_1.default)()
.then(() => {
let packageContent;
let packageMain;
let content;
// Locate plugin and load package.json
try {
const res = resolve_1.default.sync("./package.json", { basedir: pkgPath });
pkgPath = path_1.default.dirname(res);
packageContent = require(res);
}
catch (err) {
if (!isModuleNotFound(err))
throw err;
packageContent = undefined;
content = undefined;
return;
}
// Locate the main package
try {
const indexJs = path_1.default.normalize(packageContent.main || "index.js");
packageMain = resolve_1.default.sync(`./${indexJs}`, { basedir: pkgPath });
}
catch (err) {
if (!isModuleNotFound(err))
throw err;
packageMain = undefined;
}
// Load plugin JS content
if (packageMain) {
try {
content = require(packageMain);
}
catch (err) {
throw new error_1.default.PluginError(err, {
plugin: name
});
}
}
// Update plugin
return new plugin_1.default({
name: name,
version: packageContent.version || "*",
path: pkgPath,
package: immutable_1.default.fromJS(packageContent),
content: immutable_1.default.fromJS(content || {})
});
})
.then((plugin) => (0, validatePlugin_1.default)(plugin))
.then((plugin) => {
logger.info(`plugin "${plugin.get("name")}" is loaded\n`);
return plugin;
});
p = timing_1.default.measure("plugin.load", p);
return p;
}

View File

@ -0,0 +1,13 @@
/**
* Remove `prefix` from `text`.
*/
declare const removePrefixFromPackageName: (prefixList: any, packageName: any) => any;
/**
* Create full package name and return
* @param {string} prefix
* @param {string} name
* @returns {string}
*/
declare const createFullPackageName: (prefix: any, name: any) => any;
export { createFullPackageName, removePrefixFromPackageName };
//# sourceMappingURL=package-name-util.d.ts.map

View File

@ -0,0 +1 @@
{"version":3,"file":"package-name-util.d.ts","sourceRoot":"","sources":["../../src/plugins/package-name-util.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,QAAA,MAAM,2BAA2B,4CAmBhC,CAAC;AACF;;;;;GAKG;AACH,QAAA,MAAM,qBAAqB,iCAa1B,CAAC;AAEF,OAAO,EAAE,qBAAqB,EAAE,2BAA2B,EAAE,CAAC"}

View File

@ -0,0 +1,48 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.removePrefixFromPackageName = exports.createFullPackageName = void 0;
/**
* Remove `prefix` from `text`.
*/
const removePrefixFromPackageName = (prefixList, packageName) => {
for (let i = 0; i < prefixList.length; i++) {
const prefix = prefixList[i];
// @scope/name -> @scope/name
// @scope/textlint-rule-name -> @scope/name
if (packageName.charAt(0) === "@") {
const [namespace, name] = packageName.split("/");
if (name.startsWith(prefix)) {
return `${namespace}/${name.slice(prefix.length)}`;
}
}
// name -> name
// textlint-rule-name -> name
else if (packageName.startsWith(prefix)) {
return packageName.slice(prefix.length);
}
}
// No match
return packageName;
};
exports.removePrefixFromPackageName = removePrefixFromPackageName;
/**
* Create full package name and return
* @param {string} prefix
* @param {string} name
* @returns {string}
*/
const createFullPackageName = (prefix, name) => {
if (name.charAt(0) === "@") {
const scopedPackageNameRegex = new RegExp(`^${prefix}(-|$)`);
// if @scope/<name> -> @scope/<prefix><name>
if (!scopedPackageNameRegex.test(name.split("/")[1])) {
/*
* for scoped packages, insert the textlint-rule after the first / unless
* the path is already @scope/<name> or @scope/textlint-rule-<name>
*/
return name.replace(/^@([^/]+)\/(.*)$/, `@$1/${prefix}$2`);
}
}
return `${prefix}${name}`;
};
exports.createFullPackageName = createFullPackageName;

View File

@ -0,0 +1,10 @@
/**
* Sort the list of dependencies to match list in book.json
* The themes should always be loaded after the plugins
*
* @param {List<PluginDependency>} deps
* @return {List<PluginDependency>}
*/
declare function sortDependencies(plugins: any): any;
export default sortDependencies;
//# sourceMappingURL=sortDependencies.d.ts.map

View File

@ -0,0 +1 @@
{"version":3,"file":"sortDependencies.d.ts","sourceRoot":"","sources":["../../src/plugins/sortDependencies.ts"],"names":[],"mappings":"AAgBA;;;;;;GAMG;AAEH,iBAAS,gBAAgB,CAAC,OAAO,KAAA,OAIhC;AAED,eAAe,gBAAgB,CAAC"}

View File

@ -0,0 +1,30 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const immutable_1 = __importDefault(require("immutable"));
const themePrefix_1 = __importDefault(require("../constants/themePrefix"));
const TYPE_PLUGIN = "plugin";
const TYPE_THEME = "theme";
/**
* Returns the type of a plugin given its name
* @param {Plugin} plugin
* @return {string}
*/
function pluginType(plugin) {
const name = plugin.getName();
return name && name.indexOf(themePrefix_1.default) === 0 ? TYPE_THEME : TYPE_PLUGIN;
}
/**
* Sort the list of dependencies to match list in book.json
* The themes should always be loaded after the plugins
*
* @param {List<PluginDependency>} deps
* @return {List<PluginDependency>}
*/
function sortDependencies(plugins) {
const byTypes = plugins.groupBy(pluginType);
return byTypes.get(TYPE_PLUGIN, immutable_1.default.List()).concat(byTypes.get(TYPE_THEME, immutable_1.default.List()));
}
exports.default = sortDependencies;

9
book/node_modules/honkit/lib/plugins/toNames.d.ts generated vendored Normal file
View File

@ -0,0 +1,9 @@
/**
* Return list of plugin names. This method is nly used in unit tests.
*
* @param {OrderedMap<String:Plugin} plugins
* @return {Array<String>}
*/
declare function toNames(plugins: any): any;
export default toNames;
//# sourceMappingURL=toNames.d.ts.map

View File

@ -0,0 +1 @@
{"version":3,"file":"toNames.d.ts","sourceRoot":"","sources":["../../src/plugins/toNames.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,iBAAS,OAAO,CAAC,OAAO,KAAA,OAMvB;AAED,eAAe,OAAO,CAAC"}

16
book/node_modules/honkit/lib/plugins/toNames.js generated vendored Normal file
View File

@ -0,0 +1,16 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Return list of plugin names. This method is nly used in unit tests.
*
* @param {OrderedMap<String:Plugin} plugins
* @return {Array<String>}
*/
function toNames(plugins) {
return plugins
.map((plugin) => {
return plugin.getName();
})
.toArray();
}
exports.default = toNames;

View File

@ -0,0 +1,11 @@
/**
Validate a book configuration for plugins and
returns an update configuration with default values.
@param {Book}
@param {OrderedMap<String:Plugin>}
@return {Promise<Book>}
*/
declare function validateConfig(book: any, plugins: any): any;
export default validateConfig;
//# sourceMappingURL=validateConfig.d.ts.map

View File

@ -0,0 +1 @@
{"version":3,"file":"validateConfig.d.ts","sourceRoot":"","sources":["../../src/plugins/validateConfig.ts"],"names":[],"mappings":"AAmDA;;;;;;;GAOG;AAEH,iBAAS,cAAc,CAAC,IAAI,KAAA,EAAE,OAAO,KAAA,OAQpC;AAED,eAAe,cAAc,CAAC"}

60
book/node_modules/honkit/lib/plugins/validateConfig.js generated vendored Normal file
View File

@ -0,0 +1,60 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const immutable_1 = __importDefault(require("immutable"));
const jsonschema_1 = __importDefault(require("jsonschema"));
const json_schema_defaults_1 = __importDefault(require("json-schema-defaults"));
const promise_1 = __importDefault(require("../utils/promise"));
const error_1 = __importDefault(require("../utils/error"));
const mergeDefaults_1 = __importDefault(require("../utils/mergeDefaults"));
/**
Validate one plugin for a book and update book's confiration
@param {Book}
@param {Plugin}
@return {Book}
*/
function validatePluginConfig(book, plugin) {
let config = book.getConfig();
const packageInfos = plugin.getPackage();
const configKey = ["pluginsConfig", plugin.getName()].join(".");
let pluginConfig = config.getValue(configKey, {}).toJS();
const schema = (packageInfos.get("gitbook") || immutable_1.default.Map()).toJS();
if (!schema)
return book;
// Normalize schema
schema.id = `/${configKey}`;
schema.type = "object";
// Validate and throw if invalid
const v = new jsonschema_1.default.Validator();
const result = v.validate(pluginConfig, schema, {
propertyName: configKey
});
// Throw error
if (result.errors.length > 0) {
throw new error_1.default.ConfigurationError(new Error(result.errors[0].stack));
}
// Insert default values
const defaults = (0, json_schema_defaults_1.default)(schema);
pluginConfig = (0, mergeDefaults_1.default)(pluginConfig, defaults);
// Update configuration
config = config.setValue(configKey, pluginConfig);
// Return new book
return book.set("config", config);
}
/**
Validate a book configuration for plugins and
returns an update configuration with default values.
@param {Book}
@param {OrderedMap<String:Plugin>}
@return {Promise<Book>}
*/
function validateConfig(book, plugins) {
return promise_1.default.reduce(plugins, (newBook, plugin) => {
return validatePluginConfig(newBook, plugin);
}, book);
}
exports.default = validateConfig;

View File

@ -0,0 +1,9 @@
/**
Validate a plugin
@param {Plugin} plugin
@return {Promise<Plugin>}
*/
declare function validatePlugin(plugin: any): any;
export default validatePlugin;
//# sourceMappingURL=validatePlugin.d.ts.map

View File

@ -0,0 +1 @@
{"version":3,"file":"validatePlugin.d.ts","sourceRoot":"","sources":["../../src/plugins/validatePlugin.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AAEH,iBAAS,cAAc,CAAC,MAAM,KAAA,OA4B7B;AAED,eAAe,cAAc,CAAC"}

36
book/node_modules/honkit/lib/plugins/validatePlugin.js generated vendored Normal file
View File

@ -0,0 +1,36 @@
"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;