honkit 3.6.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +10 -0
- package/bin/honkit.js +8 -0
- package/lib/BuildGenerator.js +2 -0
- package/lib/__tests__/__fixtures__/honkit/book.js +9 -0
- package/lib/__tests__/githon.js +11 -0
- package/lib/__tests__/init.js +19 -0
- package/lib/__tests__/snapshot-honkit.js +45 -0
- package/lib/api/decodeConfig.js +17 -0
- package/lib/api/decodeGlobal.js +21 -0
- package/lib/api/decodePage.js +41 -0
- package/lib/api/deprecate.js +113 -0
- package/lib/api/encodeConfig.js +30 -0
- package/lib/api/encodeGlobal.js +226 -0
- package/lib/api/encodeNavigation.js +60 -0
- package/lib/api/encodePage.js +37 -0
- package/lib/api/encodeProgress.js +58 -0
- package/lib/api/encodeSummary.js +52 -0
- package/lib/api/index.js +15 -0
- package/lib/bin.js +46 -0
- package/lib/browser.js +41 -0
- package/lib/cli/build.js +36 -0
- package/lib/cli/buildEbook.js +63 -0
- package/lib/cli/getBook.js +24 -0
- package/lib/cli/getOutputFolder.js +19 -0
- package/lib/cli/index.js +11 -0
- package/lib/cli/init.js +17 -0
- package/lib/cli/options.js +38 -0
- package/lib/cli/parse.js +65 -0
- package/lib/cli/serve.js +184 -0
- package/lib/cli/server.js +116 -0
- package/lib/cli/watch.js +35 -0
- package/lib/constants/__tests__/configSchema.js +41 -0
- package/lib/constants/configDefault.js +9 -0
- package/lib/constants/configFiles.js +3 -0
- package/lib/constants/configSchema.js +235 -0
- package/lib/constants/defaultBlocks.js +48 -0
- package/lib/constants/defaultFilters.js +18 -0
- package/lib/constants/defaultPlugins.js +20 -0
- package/lib/constants/extsAsciidoc.js +3 -0
- package/lib/constants/extsMarkdown.js +3 -0
- package/lib/constants/ignoreFiles.js +3 -0
- package/lib/constants/pluginAssetsFolder.js +3 -0
- package/lib/constants/pluginHooks.js +3 -0
- package/lib/constants/pluginPrefix.js +3 -0
- package/lib/constants/pluginResources.js +7 -0
- package/lib/constants/templatesFolder.js +3 -0
- package/lib/constants/themePrefix.js +3 -0
- package/lib/fs/__tests__/mock.js +68 -0
- package/lib/fs/mock.js +88 -0
- package/lib/fs/node.js +44 -0
- package/lib/honkit.js +34 -0
- package/lib/index.js +17 -0
- package/lib/init.js +79 -0
- package/lib/json/encodeBook.js +41 -0
- package/lib/json/encodeBookWithPage.js +25 -0
- package/lib/json/encodeFile.js +20 -0
- package/lib/json/encodeGlossary.js +22 -0
- package/lib/json/encodeGlossaryEntry.js +16 -0
- package/lib/json/encodeLanguages.js +29 -0
- package/lib/json/encodeOutput.js +26 -0
- package/lib/json/encodeOutputWithPage.js +26 -0
- package/lib/json/encodePage.js +38 -0
- package/lib/json/encodeReadme.js +19 -0
- package/lib/json/encodeSummary.js +22 -0
- package/lib/json/encodeSummaryArticle.js +25 -0
- package/lib/json/encodeSummaryPart.js +19 -0
- package/lib/json/index.js +27 -0
- package/lib/models/__tests__/config.js +164 -0
- package/lib/models/__tests__/glossary.js +38 -0
- package/lib/models/__tests__/glossaryEntry.js +16 -0
- package/lib/models/__tests__/page.js +26 -0
- package/lib/models/__tests__/plugin.js +26 -0
- package/lib/models/__tests__/pluginDependency.js +71 -0
- package/lib/models/__tests__/summary.js +115 -0
- package/lib/models/__tests__/summaryArticle.js +62 -0
- package/lib/models/__tests__/summaryPart.js +24 -0
- package/lib/models/__tests__/templateBlock.js +172 -0
- package/lib/models/__tests__/templateEngine.js +49 -0
- package/lib/models/book.js +312 -0
- package/lib/models/config.js +152 -0
- package/lib/models/file.js +83 -0
- package/lib/models/fs.js +255 -0
- package/lib/models/glossary.js +90 -0
- package/lib/models/glossaryEntry.js +34 -0
- package/lib/models/hash.js +191 -0
- package/lib/models/ignore.js +40 -0
- package/lib/models/language.js +22 -0
- package/lib/models/languages.js +64 -0
- package/lib/models/output.js +109 -0
- package/lib/models/page.js +91 -0
- package/lib/models/parser.js +102 -0
- package/lib/models/plugin.js +139 -0
- package/lib/models/pluginDependency.js +192 -0
- package/lib/models/readme.js +38 -0
- package/lib/models/summary.js +199 -0
- package/lib/models/summaryArticle.js +169 -0
- package/lib/models/summaryPart.js +53 -0
- package/lib/models/templateBlock.js +230 -0
- package/lib/models/templateEngine.js +115 -0
- package/lib/models/templateOutput.js +36 -0
- package/lib/models/templateShortcut.js +65 -0
- package/lib/modifiers/config/__tests__/addPlugin.js +30 -0
- package/lib/modifiers/config/__tests__/removePlugin.js +29 -0
- package/lib/modifiers/config/__tests__/togglePlugin.js +28 -0
- package/lib/modifiers/config/addPlugin.js +27 -0
- package/lib/modifiers/config/editPlugin.js +13 -0
- package/lib/modifiers/config/getPluginConfig.js +22 -0
- package/lib/modifiers/config/hasPlugin.js +15 -0
- package/lib/modifiers/config/index.js +21 -0
- package/lib/modifiers/config/isDefaultPlugin.js +17 -0
- package/lib/modifiers/config/removePlugin.js +27 -0
- package/lib/modifiers/config/togglePlugin.js +32 -0
- package/lib/modifiers/index.js +11 -0
- package/lib/modifiers/summary/__tests__/editPartTitle.js +41 -0
- package/lib/modifiers/summary/__tests__/insertArticle.js +72 -0
- package/lib/modifiers/summary/__tests__/insertPart.js +56 -0
- package/lib/modifiers/summary/__tests__/mergeAtLevel.js +45 -0
- package/lib/modifiers/summary/__tests__/moveArticle.js +66 -0
- package/lib/modifiers/summary/__tests__/moveArticleAfter.js +75 -0
- package/lib/modifiers/summary/__tests__/removeArticle.js +54 -0
- package/lib/modifiers/summary/editArticleRef.js +20 -0
- package/lib/modifiers/summary/editArticleTitle.js +20 -0
- package/lib/modifiers/summary/editPartTitle.js +21 -0
- package/lib/modifiers/summary/index.js +27 -0
- package/lib/modifiers/summary/indexArticleLevels.js +21 -0
- package/lib/modifiers/summary/indexLevels.js +18 -0
- package/lib/modifiers/summary/indexPartLevels.js +25 -0
- package/lib/modifiers/summary/insertArticle.js +47 -0
- package/lib/modifiers/summary/insertPart.js +21 -0
- package/lib/modifiers/summary/mergeAtLevel.js +68 -0
- package/lib/modifiers/summary/moveArticle.js +27 -0
- package/lib/modifiers/summary/moveArticleAfter.js +59 -0
- package/lib/modifiers/summary/removeArticle.js +36 -0
- package/lib/modifiers/summary/removePart.js +18 -0
- package/lib/modifiers/summary/unshiftArticle.js +27 -0
- package/lib/output/__tests__/ebook.js +17 -0
- package/lib/output/__tests__/json.js +43 -0
- package/lib/output/__tests__/plugin-hooks.js +57 -0
- package/lib/output/__tests__/website.js +121 -0
- package/lib/output/callHook.js +51 -0
- package/lib/output/callPageHook.js +23 -0
- package/lib/output/createTemplateEngine.js +42 -0
- package/lib/output/ebook/getConvertOptions.js +69 -0
- package/lib/output/ebook/getCoverPath.js +30 -0
- package/lib/output/ebook/getPDFTemplate.js +40 -0
- package/lib/output/ebook/index.js +16 -0
- package/lib/output/ebook/onFinish.js +84 -0
- package/lib/output/ebook/onPage.js +23 -0
- package/lib/output/ebook/options.js +17 -0
- package/lib/output/generateAssets.js +26 -0
- package/lib/output/generateBook.js +167 -0
- package/lib/output/generatePage.js +90 -0
- package/lib/output/generatePages.js +52 -0
- package/lib/output/getModifiers.js +63 -0
- package/lib/output/helper/fileToOutput.js +30 -0
- package/lib/output/helper/fileToURL.js +30 -0
- package/lib/output/helper/index.js +3 -0
- package/lib/output/helper/resolveFileToURL.js +25 -0
- package/lib/output/helper/writeFile.js +26 -0
- package/lib/output/index.js +27 -0
- package/lib/output/json/index.js +14 -0
- package/lib/output/json/onFinish.js +39 -0
- package/lib/output/json/onPage.js +37 -0
- package/lib/output/json/options.js +11 -0
- package/lib/output/modifiers/__tests__/addHeadingId.js +23 -0
- package/lib/output/modifiers/__tests__/annotateText.js +39 -0
- package/lib/output/modifiers/__tests__/fetchRemoteImages.js +32 -0
- package/lib/output/modifiers/__tests__/highlightCode.js +48 -0
- package/lib/output/modifiers/__tests__/inlinePng.js +22 -0
- package/lib/output/modifiers/__tests__/inlineSvg.js +42 -0
- package/lib/output/modifiers/__tests__/resolveImages.js +39 -0
- package/lib/output/modifiers/__tests__/resolveLinks.js +81 -0
- package/lib/output/modifiers/__tests__/svgToImg.js +29 -0
- package/lib/output/modifiers/addHeadingId.js +26 -0
- package/lib/output/modifiers/annotateText.js +76 -0
- package/lib/output/modifiers/editHTMLElement.js +17 -0
- package/lib/output/modifiers/fetchRemoteImages.js +42 -0
- package/lib/output/modifiers/highlightCode.js +59 -0
- package/lib/output/modifiers/index.js +26 -0
- package/lib/output/modifiers/inlineAssets.js +29 -0
- package/lib/output/modifiers/inlinePng.js +43 -0
- package/lib/output/modifiers/inlineSvg.js +39 -0
- package/lib/output/modifiers/modifyHTML.js +27 -0
- package/lib/output/modifiers/resolveImages.js +30 -0
- package/lib/output/modifiers/resolveLinks.js +46 -0
- package/lib/output/modifiers/svgToImg.js +58 -0
- package/lib/output/page-cache.js +15 -0
- package/lib/output/prepareAssets.js +22 -0
- package/lib/output/preparePages.js +25 -0
- package/lib/output/preparePlugins.js +36 -0
- package/lib/output/testing/createMock.js +39 -0
- package/lib/output/testing/generateMock.js +55 -0
- package/lib/output/website/__tests__/i18n.js +40 -0
- package/lib/output/website/copyPluginAssets.js +92 -0
- package/lib/output/website/createTemplateEngine.js +136 -0
- package/lib/output/website/index.js +22 -0
- package/lib/output/website/listSearchPaths.js +20 -0
- package/lib/output/website/onAsset.js +29 -0
- package/lib/output/website/onFinish.js +35 -0
- package/lib/output/website/onInit.js +19 -0
- package/lib/output/website/onPage.js +73 -0
- package/lib/output/website/options.js +15 -0
- package/lib/output/website/prepareI18n.js +28 -0
- package/lib/output/website/prepareResources.js +49 -0
- package/lib/output/website/state.js +20 -0
- package/lib/parse/__tests__/listAssets.js +63 -0
- package/lib/parse/__tests__/parseBook.js +77 -0
- package/lib/parse/__tests__/parseGlossary.js +32 -0
- package/lib/parse/__tests__/parseIgnore.js +37 -0
- package/lib/parse/__tests__/parsePageFromString.js +34 -0
- package/lib/parse/__tests__/parseReadme.js +33 -0
- package/lib/parse/__tests__/parseSummary.js +30 -0
- package/lib/parse/findParsableFile.js +33 -0
- package/lib/parse/index.js +31 -0
- package/lib/parse/listAssets.js +36 -0
- package/lib/parse/lookupStructureFile.js +21 -0
- package/lib/parse/parseBook.js +68 -0
- package/lib/parse/parseConfig.js +52 -0
- package/lib/parse/parseGlossary.js +25 -0
- package/lib/parse/parseIgnore.js +43 -0
- package/lib/parse/parseLanguages.js +26 -0
- package/lib/parse/parsePage.js +21 -0
- package/lib/parse/parsePageFromString.js +25 -0
- package/lib/parse/parsePagesList.js +80 -0
- package/lib/parse/parseReadme.js +26 -0
- package/lib/parse/parseStructureFile.js +64 -0
- package/lib/parse/parseSummary.js +43 -0
- package/lib/parse/validateConfig.js +31 -0
- package/lib/parse/walkSummary.js +34 -0
- package/lib/parsers.js +60 -0
- package/lib/plugins/PluginResolver.js +84 -0
- package/lib/plugins/__tests__/findInstalled.js +25 -0
- package/lib/plugins/__tests__/listDependencies.js +28 -0
- package/lib/plugins/__tests__/sortDependencies.js +28 -0
- package/lib/plugins/__tests__/validatePlugin.js +99 -0
- package/lib/plugins/findInstalled.js +87 -0
- package/lib/plugins/index.js +17 -0
- package/lib/plugins/listBlocks.js +19 -0
- package/lib/plugins/listDependencies.js +33 -0
- package/lib/plugins/listDepsForBook.js +20 -0
- package/lib/plugins/listFilters.js +18 -0
- package/lib/plugins/listResources.js +44 -0
- package/lib/plugins/loadForBook.js +38 -0
- package/lib/plugins/loadPlugin.js +89 -0
- package/lib/plugins/package-name-util.js +48 -0
- package/lib/plugins/sortDependencies.js +30 -0
- package/lib/plugins/toNames.js +16 -0
- package/lib/plugins/validateConfig.js +60 -0
- package/lib/plugins/validatePlugin.js +36 -0
- package/lib/templating/__tests__/conrefsLoader.js +93 -0
- package/lib/templating/__tests__/postRender.js +52 -0
- package/lib/templating/__tests__/replaceShortcuts.js +27 -0
- package/lib/templating/conrefsLoader.js +88 -0
- package/lib/templating/index.js +19 -0
- package/lib/templating/listShortcuts.js +29 -0
- package/lib/templating/postRender.js +46 -0
- package/lib/templating/render.js +41 -0
- package/lib/templating/renderFile.js +39 -0
- package/lib/templating/replaceShortcuts.js +36 -0
- package/lib/templating/themesLoader.js +98 -0
- package/lib/utils/__tests__/git.js +47 -0
- package/lib/utils/__tests__/location.js +81 -0
- package/lib/utils/__tests__/path.js +19 -0
- package/lib/utils/command.js +104 -0
- package/lib/utils/error.js +88 -0
- package/lib/utils/fs.js +163 -0
- package/lib/utils/genKey.js +13 -0
- package/lib/utils/git.js +116 -0
- package/lib/utils/images.js +22 -0
- package/lib/utils/location.js +129 -0
- package/lib/utils/logger.js +158 -0
- package/lib/utils/mergeDefaults.js +18 -0
- package/lib/utils/path.js +62 -0
- package/lib/utils/promise.js +142 -0
- package/lib/utils/reducedObject.js +31 -0
- package/lib/utils/timing.js +90 -0
- package/package.json +112 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const parseStructureFile_1 = __importDefault(require("./parseStructureFile"));
|
|
7
|
+
const readme_1 = __importDefault(require("../models/readme"));
|
|
8
|
+
const error_1 = __importDefault(require("../utils/error"));
|
|
9
|
+
/**
|
|
10
|
+
Parse readme from book
|
|
11
|
+
|
|
12
|
+
@param {Book} book
|
|
13
|
+
@return {Promise<Book>}
|
|
14
|
+
*/
|
|
15
|
+
function parseReadme(book) {
|
|
16
|
+
const logger = book.getLogger();
|
|
17
|
+
return parseStructureFile_1.default(book, "readme").spread((file, result) => {
|
|
18
|
+
if (!file) {
|
|
19
|
+
throw new error_1.default.FileNotFoundError({ filename: "README" });
|
|
20
|
+
}
|
|
21
|
+
logger.debug.ln("readme found at", file.getPath());
|
|
22
|
+
const readme = readme_1.default.create(file, result);
|
|
23
|
+
return book.set("readme", readme);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
exports.default = parseReadme;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const promise_1 = __importDefault(require("../utils/promise"));
|
|
7
|
+
const error_1 = __importDefault(require("../utils/error"));
|
|
8
|
+
const lookupStructureFile_1 = __importDefault(require("./lookupStructureFile"));
|
|
9
|
+
/**
|
|
10
|
+
Parse a ParsableFile using a specific method
|
|
11
|
+
|
|
12
|
+
@param {FS} fs
|
|
13
|
+
@param {ParsableFile} file
|
|
14
|
+
@param {string} type
|
|
15
|
+
@return {Promise<Array<String, List|Map>>}
|
|
16
|
+
*/
|
|
17
|
+
function parseFile(fs, file, type) {
|
|
18
|
+
const filepath = file.getPath();
|
|
19
|
+
const parser = file.getParser();
|
|
20
|
+
if (!parser) {
|
|
21
|
+
return promise_1.default.reject(error_1.default.FileNotParsableError({
|
|
22
|
+
filename: filepath,
|
|
23
|
+
}));
|
|
24
|
+
}
|
|
25
|
+
return fs
|
|
26
|
+
.readAsString(filepath)
|
|
27
|
+
.then((content) => {
|
|
28
|
+
if (type === "readme") {
|
|
29
|
+
return parser.parseReadme(content);
|
|
30
|
+
}
|
|
31
|
+
else if (type === "glossary") {
|
|
32
|
+
return parser.parseGlossary(content);
|
|
33
|
+
}
|
|
34
|
+
else if (type === "summary") {
|
|
35
|
+
return parser.parseSummary(content);
|
|
36
|
+
}
|
|
37
|
+
else if (type === "langs") {
|
|
38
|
+
return parser.parseLanguages(content);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
throw new Error(`Parsing invalid type "${type}"`);
|
|
42
|
+
}
|
|
43
|
+
})
|
|
44
|
+
.then((result) => {
|
|
45
|
+
return [file, result];
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
Parse a structure file (ex: SUMMARY.md, GLOSSARY.md).
|
|
50
|
+
It uses the configuration to find the specified file.
|
|
51
|
+
|
|
52
|
+
@param {Book} book
|
|
53
|
+
@param {string} type: one of ["glossary", "readme", "summary"]
|
|
54
|
+
@return {Promise<List|Map>}
|
|
55
|
+
*/
|
|
56
|
+
function parseStructureFile(book, type) {
|
|
57
|
+
const fs = book.getContentFS();
|
|
58
|
+
return lookupStructureFile_1.default(book, type).then((file) => {
|
|
59
|
+
if (!file)
|
|
60
|
+
return [undefined, undefined];
|
|
61
|
+
return parseFile(fs, file, type);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
exports.default = parseStructureFile;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const parseStructureFile_1 = __importDefault(require("./parseStructureFile"));
|
|
7
|
+
const summary_1 = __importDefault(require("../models/summary"));
|
|
8
|
+
const modifiers_1 = __importDefault(require("../modifiers"));
|
|
9
|
+
const SummaryModifier = modifiers_1.default.Summary;
|
|
10
|
+
/**
|
|
11
|
+
Parse summary in a book, the summary can only be parsed
|
|
12
|
+
if the readme as be detected before.
|
|
13
|
+
|
|
14
|
+
@param {Book} book
|
|
15
|
+
@return {Promise<Book>}
|
|
16
|
+
*/
|
|
17
|
+
function parseSummary(book) {
|
|
18
|
+
const readme = book.getReadme();
|
|
19
|
+
const logger = book.getLogger();
|
|
20
|
+
const readmeFile = readme.getFile();
|
|
21
|
+
return parseStructureFile_1.default(book, "summary").spread((file, result) => {
|
|
22
|
+
let summary;
|
|
23
|
+
if (!file) {
|
|
24
|
+
logger.warn.ln("no summary file in this book");
|
|
25
|
+
summary = new summary_1.default();
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
logger.debug.ln("summary file found at", file.getPath());
|
|
29
|
+
summary = summary_1.default.createFromParts(file, result.parts);
|
|
30
|
+
}
|
|
31
|
+
// Insert readme as first entry if not in SUMMARY.md
|
|
32
|
+
const readmeArticle = summary.getByPath(readmeFile.getPath());
|
|
33
|
+
if (readmeFile.exists() && !readmeArticle) {
|
|
34
|
+
summary = SummaryModifier.unshiftArticle(summary, {
|
|
35
|
+
title: "Introduction",
|
|
36
|
+
ref: readmeFile.getPath(),
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
// Set new summary
|
|
40
|
+
return book.setSummary(summary);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
exports.default = parseSummary;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const jsonschema_1 = __importDefault(require("jsonschema"));
|
|
7
|
+
const json_schema_defaults_1 = __importDefault(require("json-schema-defaults"));
|
|
8
|
+
const configSchema_1 = __importDefault(require("../constants/configSchema"));
|
|
9
|
+
const error_1 = __importDefault(require("../utils/error"));
|
|
10
|
+
const mergeDefaults_1 = __importDefault(require("../utils/mergeDefaults"));
|
|
11
|
+
/**
|
|
12
|
+
Validate a book.json content
|
|
13
|
+
And return a mix with the default value
|
|
14
|
+
|
|
15
|
+
@param {Object} bookJson
|
|
16
|
+
@return {Object}
|
|
17
|
+
*/
|
|
18
|
+
function validateConfig(bookJson) {
|
|
19
|
+
const v = new jsonschema_1.default.Validator();
|
|
20
|
+
const result = v.validate(bookJson, configSchema_1.default, {
|
|
21
|
+
propertyName: "config",
|
|
22
|
+
});
|
|
23
|
+
// Throw error
|
|
24
|
+
if (result.errors.length > 0) {
|
|
25
|
+
throw new error_1.default.ConfigurationError(new Error(result.errors[0].stack));
|
|
26
|
+
}
|
|
27
|
+
// Insert default values
|
|
28
|
+
const defaults = json_schema_defaults_1.default(configSchema_1.default);
|
|
29
|
+
return mergeDefaults_1.default(bookJson, defaults);
|
|
30
|
+
}
|
|
31
|
+
exports.default = validateConfig;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const promise_1 = __importDefault(require("../utils/promise"));
|
|
7
|
+
/**
|
|
8
|
+
Walk over a list of articles
|
|
9
|
+
|
|
10
|
+
@param {List<Article>} articles
|
|
11
|
+
@param {Function(article)}
|
|
12
|
+
@return {Promise}
|
|
13
|
+
*/
|
|
14
|
+
function walkArticles(articles, fn) {
|
|
15
|
+
return promise_1.default.forEach(articles, (article) => {
|
|
16
|
+
return promise_1.default(fn(article)).then(() => {
|
|
17
|
+
return walkArticles(article.getArticles(), fn);
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
Walk over summary and execute "fn" on each article
|
|
23
|
+
|
|
24
|
+
@param {Summary} summary
|
|
25
|
+
@param {Function(article)}
|
|
26
|
+
@return {Promise}
|
|
27
|
+
*/
|
|
28
|
+
function walkSummary(summary, fn) {
|
|
29
|
+
const parts = summary.getParts();
|
|
30
|
+
return promise_1.default.forEach(parts, (part) => {
|
|
31
|
+
return walkArticles(part.getArticles(), fn);
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
exports.default = walkSummary;
|
package/lib/parsers.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const path_1 = __importDefault(require("path"));
|
|
7
|
+
const immutable_1 = __importDefault(require("immutable"));
|
|
8
|
+
const markdown_legacy_1 = __importDefault(require("@honkit/markdown-legacy"));
|
|
9
|
+
const asciidoc_1 = __importDefault(require("@honkit/asciidoc"));
|
|
10
|
+
const extsMarkdown_1 = __importDefault(require("./constants/extsMarkdown"));
|
|
11
|
+
const extsAsciidoc_1 = __importDefault(require("./constants/extsAsciidoc"));
|
|
12
|
+
const parser_1 = __importDefault(require("./models/parser"));
|
|
13
|
+
// This list is ordered by priority of parsers to use
|
|
14
|
+
const parsers = immutable_1.default.List([
|
|
15
|
+
parser_1.default.create("markdown", extsMarkdown_1.default, markdown_legacy_1.default),
|
|
16
|
+
parser_1.default.create("asciidoc", extsAsciidoc_1.default, asciidoc_1.default),
|
|
17
|
+
]);
|
|
18
|
+
/**
|
|
19
|
+
* Return a specific parser by its name
|
|
20
|
+
*
|
|
21
|
+
* @param {string} name
|
|
22
|
+
* @return {Parser|undefined}
|
|
23
|
+
*/
|
|
24
|
+
function getParser(name) {
|
|
25
|
+
return parsers.find((parser) => {
|
|
26
|
+
return parser.getName() === name;
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Return a specific parser according to an extension
|
|
31
|
+
*
|
|
32
|
+
* @param {string} ext
|
|
33
|
+
* @return {Parser|undefined}
|
|
34
|
+
*/
|
|
35
|
+
function getParserByExt(ext) {
|
|
36
|
+
return parsers.find((parser) => {
|
|
37
|
+
return parser.matchExtension(ext);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Return parser for a file
|
|
42
|
+
*
|
|
43
|
+
* @param {string} ext
|
|
44
|
+
* @return {Parser|undefined}
|
|
45
|
+
*/
|
|
46
|
+
function getParserForFile(filename) {
|
|
47
|
+
return getParserByExt(path_1.default.extname(filename));
|
|
48
|
+
}
|
|
49
|
+
// List all parsable extensions
|
|
50
|
+
const extensions = parsers
|
|
51
|
+
.map((parser) => {
|
|
52
|
+
return parser.getExtensions();
|
|
53
|
+
})
|
|
54
|
+
.flatten();
|
|
55
|
+
exports.default = {
|
|
56
|
+
extensions: extensions,
|
|
57
|
+
get: getParser,
|
|
58
|
+
getByExt: getParserByExt,
|
|
59
|
+
getForFile: getParserForFile,
|
|
60
|
+
};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// LICENSE : MIT
|
|
2
|
+
"use strict";
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
6
|
+
}) : (function(o, m, k, k2) {
|
|
7
|
+
if (k2 === undefined) k2 = k;
|
|
8
|
+
o[k2] = m[k];
|
|
9
|
+
}));
|
|
10
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
11
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
12
|
+
}) : function(o, v) {
|
|
13
|
+
o["default"] = v;
|
|
14
|
+
});
|
|
15
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
16
|
+
if (mod && mod.__esModule) return mod;
|
|
17
|
+
var result = {};
|
|
18
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
19
|
+
__setModuleDefault(result, mod);
|
|
20
|
+
return result;
|
|
21
|
+
};
|
|
22
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.PluginResolver = void 0;
|
|
27
|
+
const path_1 = __importDefault(require("path"));
|
|
28
|
+
const util = __importStar(require("./package-name-util"));
|
|
29
|
+
const try_resolve_1 = __importDefault(require("try-resolve"));
|
|
30
|
+
const SPECIAL_PACKAGE_NAME = [
|
|
31
|
+
"highlight",
|
|
32
|
+
"theme-default", // → @honkit/honkit-plugin-theme-default
|
|
33
|
+
];
|
|
34
|
+
/**
|
|
35
|
+
* This class aim to resolve honkit's package name and get the module path.
|
|
36
|
+
*
|
|
37
|
+
* Define
|
|
38
|
+
*
|
|
39
|
+
* - `package` is npm package
|
|
40
|
+
* - `module` is package's main module
|
|
41
|
+
*
|
|
42
|
+
* ## Support
|
|
43
|
+
*
|
|
44
|
+
* - honkit-plugin-*
|
|
45
|
+
* - gitbook-plugin-*
|
|
46
|
+
*/
|
|
47
|
+
class PluginResolver {
|
|
48
|
+
constructor(config = {}) {
|
|
49
|
+
/**
|
|
50
|
+
* @type {string} baseDirectory for resolving
|
|
51
|
+
*/
|
|
52
|
+
this.baseDirectory = config && config.baseDirectory ? config.baseDirectory : "";
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Take package name, and return path to module.
|
|
56
|
+
* @param {string} packageName
|
|
57
|
+
* @returns {string} return path to module
|
|
58
|
+
*/
|
|
59
|
+
resolvePluginPackageName(packageName) {
|
|
60
|
+
const baseDir = this.baseDirectory;
|
|
61
|
+
const honkitFullPackageName = util.createFullPackageName("honkit-plugin-", packageName);
|
|
62
|
+
// honkit > gitbook > normal
|
|
63
|
+
const gitbookFullPackageName = util.createFullPackageName("gitbook-plugin-", packageName);
|
|
64
|
+
// special case for backward-compatible
|
|
65
|
+
// e.g.) load theme-default as @honkit/honkit-plugins-theme-default
|
|
66
|
+
const honkitScopePackageName = `@honkit/${honkitFullPackageName}`;
|
|
67
|
+
// In sometimes, HonKit package has not main field - so search package.json
|
|
68
|
+
const pkgPath = try_resolve_1.default(path_1.default.join(baseDir, honkitFullPackageName, "/package.json")) ||
|
|
69
|
+
try_resolve_1.default(path_1.default.join(baseDir, gitbookFullPackageName, "/package.json")) ||
|
|
70
|
+
try_resolve_1.default(path_1.default.join(baseDir, packageName, "/package.json")) ||
|
|
71
|
+
(SPECIAL_PACKAGE_NAME.includes(packageName) &&
|
|
72
|
+
try_resolve_1.default(path_1.default.join(baseDir, honkitScopePackageName, "/package.json")));
|
|
73
|
+
if (!pkgPath) {
|
|
74
|
+
throw new ReferenceError(`Failed to load HonKit's plugin module: "${packageName}" is not found.
|
|
75
|
+
|
|
76
|
+
cwd: ${process.cwd()}
|
|
77
|
+
baseDir: ${baseDir}
|
|
78
|
+
|
|
79
|
+
`);
|
|
80
|
+
}
|
|
81
|
+
return pkgPath.substring(0, pkgPath.length - "/package.json".length);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
exports.PluginResolver = PluginResolver;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const path_1 = __importDefault(require("path"));
|
|
7
|
+
const immutable_1 = __importDefault(require("immutable"));
|
|
8
|
+
const findInstalled_1 = __importDefault(require("../findInstalled"));
|
|
9
|
+
describe("findInstalled", () => {
|
|
10
|
+
test.skip("must list default plugins for gitbook directory", () => {
|
|
11
|
+
// Read gitbook-plugins from package.json
|
|
12
|
+
const pkg = require(path_1.default.resolve(__dirname, "../../../package.json"));
|
|
13
|
+
const gitbookPlugins = immutable_1.default.Seq(pkg.dependencies)
|
|
14
|
+
.filter((v, k) => {
|
|
15
|
+
return k.indexOf("gitbook-plugin") === 0;
|
|
16
|
+
})
|
|
17
|
+
// @ts-expect-error
|
|
18
|
+
.cacheResult();
|
|
19
|
+
return findInstalled_1.default(path_1.default.resolve(__dirname, "../../../")).then((plugins) => {
|
|
20
|
+
expect(plugins.size >= gitbookPlugins.size).toBeTruthy();
|
|
21
|
+
expect(plugins.has("fontsettings")).toBe(true);
|
|
22
|
+
expect(plugins.has("search")).toBe(true);
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const pluginDependency_1 = __importDefault(require("../../models/pluginDependency"));
|
|
7
|
+
const listDependencies_1 = __importDefault(require("../listDependencies"));
|
|
8
|
+
const toNames_1 = __importDefault(require("../toNames"));
|
|
9
|
+
describe("listDependencies", () => {
|
|
10
|
+
test("must list default", () => {
|
|
11
|
+
const deps = pluginDependency_1.default.listFromString("ga,great");
|
|
12
|
+
const plugins = listDependencies_1.default(deps);
|
|
13
|
+
const names = toNames_1.default(plugins);
|
|
14
|
+
expect(names).toEqual(["ga", "great", "highlight", "search", "lunr", "fontsettings", "theme-default"]);
|
|
15
|
+
});
|
|
16
|
+
test("must list from array with -", () => {
|
|
17
|
+
const deps = pluginDependency_1.default.listFromString("ga,-great");
|
|
18
|
+
const plugins = listDependencies_1.default(deps);
|
|
19
|
+
const names = toNames_1.default(plugins);
|
|
20
|
+
expect(names).toEqual(["ga", "highlight", "search", "lunr", "fontsettings", "theme-default"]);
|
|
21
|
+
});
|
|
22
|
+
test("must remove default plugins using -", () => {
|
|
23
|
+
const deps = pluginDependency_1.default.listFromString("ga,-search");
|
|
24
|
+
const plugins = listDependencies_1.default(deps);
|
|
25
|
+
const names = toNames_1.default(plugins);
|
|
26
|
+
expect(names).toEqual(["ga", "highlight", "lunr", "fontsettings", "theme-default"]);
|
|
27
|
+
});
|
|
28
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const pluginDependency_1 = __importDefault(require("../../models/pluginDependency"));
|
|
7
|
+
const sortDependencies_1 = __importDefault(require("../sortDependencies"));
|
|
8
|
+
const toNames_1 = __importDefault(require("../toNames"));
|
|
9
|
+
describe("sortDependencies", () => {
|
|
10
|
+
test("must load themes after plugins", () => {
|
|
11
|
+
const allPlugins = pluginDependency_1.default.listFromArray(["hello", "theme-test", "world"]);
|
|
12
|
+
const sorted = sortDependencies_1.default(allPlugins);
|
|
13
|
+
const names = toNames_1.default(sorted);
|
|
14
|
+
expect(names).toEqual(["hello", "world", "theme-test"]);
|
|
15
|
+
});
|
|
16
|
+
test("must keep order of themes", () => {
|
|
17
|
+
const allPlugins = pluginDependency_1.default.listFromArray([
|
|
18
|
+
"theme-test",
|
|
19
|
+
"theme-test1",
|
|
20
|
+
"hello",
|
|
21
|
+
"theme-test2",
|
|
22
|
+
"world",
|
|
23
|
+
]);
|
|
24
|
+
const sorted = sortDependencies_1.default(allPlugins);
|
|
25
|
+
const names = toNames_1.default(sorted);
|
|
26
|
+
expect(names).toEqual(["hello", "world", "theme-test", "theme-test1", "theme-test2"]);
|
|
27
|
+
});
|
|
28
|
+
});
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const immutable_1 = __importDefault(require("immutable"));
|
|
7
|
+
const promise_1 = __importDefault(require("../../utils/promise"));
|
|
8
|
+
const plugin_1 = __importDefault(require("../../models/plugin"));
|
|
9
|
+
const validatePlugin_1 = __importDefault(require("../validatePlugin"));
|
|
10
|
+
describe("validatePlugin", () => {
|
|
11
|
+
test("must not validate a not loaded plugin", () => {
|
|
12
|
+
const plugin = plugin_1.default.createFromString("test");
|
|
13
|
+
return validatePlugin_1.default(plugin).then(() => {
|
|
14
|
+
throw new Error("Should not be validate");
|
|
15
|
+
}, (err) => {
|
|
16
|
+
return promise_1.default();
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
test("alpha plugin can loaded plugin", () => {
|
|
20
|
+
const testPkgRequireAlphaVersion = {
|
|
21
|
+
title: "Disqus",
|
|
22
|
+
name: "gitbook-plugin-disqus",
|
|
23
|
+
description: "Disqus comments thread in the footer of your pages",
|
|
24
|
+
icon: "./icon.png",
|
|
25
|
+
main: "index.js",
|
|
26
|
+
browser: "./_assets/plugin.js",
|
|
27
|
+
version: "1.0.1",
|
|
28
|
+
engines: {
|
|
29
|
+
gitbook: ">=4.0.0-alpha",
|
|
30
|
+
},
|
|
31
|
+
dependencies: {
|
|
32
|
+
react: "^15.3.2",
|
|
33
|
+
"react-disqus-thread": "^0.4.0",
|
|
34
|
+
},
|
|
35
|
+
devDependencies: {
|
|
36
|
+
"gitbook-plugin": "^4.0.0-alpha.0",
|
|
37
|
+
eslint: "3.7.1",
|
|
38
|
+
"eslint-config-gitbook": "1.4.0",
|
|
39
|
+
},
|
|
40
|
+
homepage: "https://github.com/GitbookIO/plugin-disqus",
|
|
41
|
+
repository: {
|
|
42
|
+
type: "git",
|
|
43
|
+
url: "https://github.com/GitbookIO/plugin-disqus.git",
|
|
44
|
+
},
|
|
45
|
+
license: "Apache-2.0",
|
|
46
|
+
bugs: {
|
|
47
|
+
url: "https://github.com/GitbookIO/plugin-disqus/issues",
|
|
48
|
+
},
|
|
49
|
+
keywords: ["gitbook:social"],
|
|
50
|
+
scripts: {
|
|
51
|
+
"build-js": "gitbook-plugin build ./src/index.js ./_assets/plugin.js",
|
|
52
|
+
prepublish: "npm run build-js",
|
|
53
|
+
},
|
|
54
|
+
gitbook: {
|
|
55
|
+
properties: {
|
|
56
|
+
shortName: {
|
|
57
|
+
type: "string",
|
|
58
|
+
title: "Website Shortname",
|
|
59
|
+
description: "Unique identifier for your website as registered on Disqus",
|
|
60
|
+
required: true,
|
|
61
|
+
},
|
|
62
|
+
useIdentifier: {
|
|
63
|
+
type: "boolean",
|
|
64
|
+
title: "Pass page identifier option to Disqus",
|
|
65
|
+
default: false,
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
page: {
|
|
69
|
+
title: "Disqus configuration for this page",
|
|
70
|
+
properties: {
|
|
71
|
+
disqus: {
|
|
72
|
+
type: "object",
|
|
73
|
+
properties: {
|
|
74
|
+
enabled: {
|
|
75
|
+
type: "boolean",
|
|
76
|
+
title: "Enable Disqus comments for this page.",
|
|
77
|
+
default: true,
|
|
78
|
+
},
|
|
79
|
+
identifier: {
|
|
80
|
+
type: "string",
|
|
81
|
+
title: "Identifier for this page.",
|
|
82
|
+
description: "Tells the Disqus service how to identify the current page",
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
const plugin = new plugin_1.default({
|
|
91
|
+
name: "test",
|
|
92
|
+
version: "4.0.0",
|
|
93
|
+
path: "/",
|
|
94
|
+
package: immutable_1.default.fromJS(testPkgRequireAlphaVersion),
|
|
95
|
+
content: immutable_1.default.fromJS({}),
|
|
96
|
+
});
|
|
97
|
+
return validatePlugin_1.default(plugin);
|
|
98
|
+
});
|
|
99
|
+
});
|