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,18 @@
|
|
|
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 moment_1 = __importDefault(require("moment"));
|
|
8
|
+
exports.default = immutable_1.default.Map({
|
|
9
|
+
// Format a date
|
|
10
|
+
// ex: 'MMMM Do YYYY, h:mm:ss a
|
|
11
|
+
date: function (time, format) {
|
|
12
|
+
return moment_1.default(time).format(format);
|
|
13
|
+
},
|
|
14
|
+
// Relative Time
|
|
15
|
+
dateFromNow: function (time) {
|
|
16
|
+
return moment_1.default(time).fromNow();
|
|
17
|
+
},
|
|
18
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
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 pluginDependency_1 = __importDefault(require("../models/pluginDependency"));
|
|
8
|
+
const pkg = require("../../package.json");
|
|
9
|
+
/**
|
|
10
|
+
* Create a PluginDependency from a dependency of gitbook
|
|
11
|
+
* @param {string} pluginName
|
|
12
|
+
* @return {PluginDependency}
|
|
13
|
+
*/
|
|
14
|
+
function createFromDependency(pluginName) {
|
|
15
|
+
const npmID = pluginDependency_1.default.nameToNpmID(pluginName);
|
|
16
|
+
const version = pkg.dependencies[npmID];
|
|
17
|
+
// @ts-expect-error ts-migrate(2339) FIXME: Property 'create' does not exist on type 'Class'.
|
|
18
|
+
return pluginDependency_1.default.create(pluginName, version);
|
|
19
|
+
}
|
|
20
|
+
exports.default = immutable_1.default.List(["highlight", "search", "lunr", "fontsettings", "theme-default"]).map(createFromDependency);
|
|
@@ -0,0 +1,7 @@
|
|
|
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
|
+
exports.default = immutable_1.default.List(["js", "css"]);
|
|
@@ -0,0 +1,68 @@
|
|
|
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 mock_1 = __importDefault(require("../mock"));
|
|
7
|
+
describe("MockFS", () => {
|
|
8
|
+
const fs = mock_1.default({
|
|
9
|
+
"README.md": "Hello World",
|
|
10
|
+
"SUMMARY.md": "# Summary",
|
|
11
|
+
folder: {
|
|
12
|
+
"test.md": "Cool",
|
|
13
|
+
folder2: {
|
|
14
|
+
"hello.md": "Hello",
|
|
15
|
+
"world.md": "World"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
describe("exists", () => {
|
|
20
|
+
test("must return true for a file", () => {
|
|
21
|
+
return fs.exists("README.md").then((result) => {
|
|
22
|
+
expect(result).toBeTruthy();
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
test("must return false for a non existing file", () => {
|
|
26
|
+
return fs.exists("README_NOTEXISTS.md").then((result) => {
|
|
27
|
+
expect(result).toBeFalsy();
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
test("must return true for a directory", () => {
|
|
31
|
+
return fs.exists("folder").then((result) => {
|
|
32
|
+
expect(result).toBeTruthy();
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
test("must return true for a deep file", () => {
|
|
36
|
+
return fs.exists("folder/test.md").then((result) => {
|
|
37
|
+
expect(result).toBeTruthy();
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
test("must return true for a deep file (2)", () => {
|
|
41
|
+
return fs.exists("folder/folder2/hello.md").then((result) => {
|
|
42
|
+
expect(result).toBeTruthy();
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
describe("readAsString", () => {
|
|
47
|
+
test("must return content for a file", () => {
|
|
48
|
+
return fs.readAsString("README.md").then((result) => {
|
|
49
|
+
expect(result).toBe("Hello World");
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
test("must return content for a deep file", () => {
|
|
53
|
+
return fs.readAsString("folder/test.md").then((result) => {
|
|
54
|
+
expect(result).toBe("Cool");
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
describe("readDir", () => {
|
|
59
|
+
test("must return content for a directory", () => {
|
|
60
|
+
return fs.readDir("./").then((files) => {
|
|
61
|
+
expect(files.size).toBe(3);
|
|
62
|
+
expect(files.includes("README.md")).toBeTruthy();
|
|
63
|
+
expect(files.includes("SUMMARY.md")).toBeTruthy();
|
|
64
|
+
expect(files.includes("folder/")).toBeTruthy();
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
});
|
package/lib/fs/mock.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
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 is_1 = __importDefault(require("is"));
|
|
8
|
+
const buffer_1 = require("buffer");
|
|
9
|
+
const immutable_1 = __importDefault(require("immutable"));
|
|
10
|
+
const fs_1 = __importDefault(require("../models/fs"));
|
|
11
|
+
const error_1 = __importDefault(require("../utils/error"));
|
|
12
|
+
/**
|
|
13
|
+
Create a fake filesystem for unit testing HonKit.
|
|
14
|
+
|
|
15
|
+
@param {Map<String:String|Map>}
|
|
16
|
+
*/
|
|
17
|
+
function createMockFS(files) {
|
|
18
|
+
files = immutable_1.default.fromJS(files);
|
|
19
|
+
const mtime = new Date();
|
|
20
|
+
function getFile(filePath) {
|
|
21
|
+
const parts = path_1.default.normalize(filePath).split(path_1.default.sep);
|
|
22
|
+
return parts.reduce((list, part, i) => {
|
|
23
|
+
if (!list)
|
|
24
|
+
return null;
|
|
25
|
+
let file;
|
|
26
|
+
if (!part || part === ".")
|
|
27
|
+
file = list;
|
|
28
|
+
else
|
|
29
|
+
file = list.get(part);
|
|
30
|
+
if (!file)
|
|
31
|
+
return null;
|
|
32
|
+
if (is_1.default.string(file)) {
|
|
33
|
+
if (i === parts.length - 1)
|
|
34
|
+
return file;
|
|
35
|
+
else
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
return file;
|
|
39
|
+
}, files);
|
|
40
|
+
}
|
|
41
|
+
function fsExists(filePath) {
|
|
42
|
+
return Boolean(getFile(filePath) !== null);
|
|
43
|
+
}
|
|
44
|
+
function fsReadFile(filePath) {
|
|
45
|
+
const file = getFile(filePath);
|
|
46
|
+
if (!is_1.default.string(file)) {
|
|
47
|
+
throw error_1.default.FileNotFoundError({
|
|
48
|
+
filename: filePath,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
return buffer_1.Buffer.from(file, "utf8");
|
|
52
|
+
}
|
|
53
|
+
function fsStatFile(filePath) {
|
|
54
|
+
const file = getFile(filePath);
|
|
55
|
+
if (!file) {
|
|
56
|
+
throw error_1.default.FileNotFoundError({
|
|
57
|
+
filename: filePath,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
return {
|
|
61
|
+
mtime: mtime,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
function fsReadDir(filePath) {
|
|
65
|
+
const dir = getFile(filePath);
|
|
66
|
+
if (!dir || is_1.default.string(dir)) {
|
|
67
|
+
throw error_1.default.FileNotFoundError({
|
|
68
|
+
filename: filePath,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
return dir
|
|
72
|
+
.map((content, name) => {
|
|
73
|
+
if (!is_1.default.string(content)) {
|
|
74
|
+
name = `${name}/`;
|
|
75
|
+
}
|
|
76
|
+
return name;
|
|
77
|
+
})
|
|
78
|
+
.valueSeq();
|
|
79
|
+
}
|
|
80
|
+
return fs_1.default.create({
|
|
81
|
+
root: "",
|
|
82
|
+
fsExists: fsExists,
|
|
83
|
+
fsReadFile: fsReadFile,
|
|
84
|
+
fsStatFile: fsStatFile,
|
|
85
|
+
fsReadDir: fsReadDir,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
exports.default = createMockFS;
|
package/lib/fs/node.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
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 fs_1 = __importDefault(require("../utils/fs"));
|
|
9
|
+
const fs_2 = __importDefault(require("../models/fs"));
|
|
10
|
+
function fsReadDir(folder) {
|
|
11
|
+
return fs_1.default.readdir(folder).then((files) => {
|
|
12
|
+
files = immutable_1.default.List(files);
|
|
13
|
+
return files
|
|
14
|
+
.map((file) => {
|
|
15
|
+
if (file === "." || file === "..")
|
|
16
|
+
return;
|
|
17
|
+
const stat = fs_1.default.statSync(path_1.default.join(folder, file));
|
|
18
|
+
if (stat.isSymbolicLink()) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
if (stat.isDirectory())
|
|
22
|
+
file = file + path_1.default.sep;
|
|
23
|
+
return file;
|
|
24
|
+
})
|
|
25
|
+
.filter((file) => {
|
|
26
|
+
return Boolean(file);
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
function fsLoadObject(filename) {
|
|
31
|
+
return require(filename);
|
|
32
|
+
}
|
|
33
|
+
function createNodeFS(root) {
|
|
34
|
+
return fs_2.default.create({
|
|
35
|
+
root: root,
|
|
36
|
+
fsExists: fs_1.default.exists,
|
|
37
|
+
fsReadFile: fs_1.default.readFile,
|
|
38
|
+
fsStatFile: fs_1.default.stat,
|
|
39
|
+
fsReadDir: fsReadDir,
|
|
40
|
+
fsLoadObject: fsLoadObject,
|
|
41
|
+
fsReadAsStream: fs_1.default.readStream,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
exports.default = createNodeFS;
|
package/lib/honkit.js
ADDED
|
@@ -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 semver_1 = __importDefault(require("semver"));
|
|
7
|
+
const pkg = require("../package.json");
|
|
8
|
+
const VERSION = pkg.version;
|
|
9
|
+
const VERSION_STABLE = VERSION.replace(/-(\S+)/g, "");
|
|
10
|
+
const START_TIME = new Date();
|
|
11
|
+
/**
|
|
12
|
+
Verify that this gitbook version satisfies a requirement
|
|
13
|
+
We can't directly use samver.satisfies since it will break all plugins when gitbook version is a prerelease (beta, alpha)
|
|
14
|
+
|
|
15
|
+
@param {string} condition
|
|
16
|
+
@return {boolean}
|
|
17
|
+
*/
|
|
18
|
+
function satisfies(condition) {
|
|
19
|
+
// Test with real version
|
|
20
|
+
if (semver_1.default.satisfies(VERSION, condition))
|
|
21
|
+
return true;
|
|
22
|
+
// If plugin require -alpha -beta engine, skip it
|
|
23
|
+
// https://github.com/honkit/honkit/issues/42
|
|
24
|
+
if (/-(\S+)$/.test(condition)) {
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
// Test with future stable release
|
|
28
|
+
return semver_1.default.satisfies(VERSION_STABLE, condition);
|
|
29
|
+
}
|
|
30
|
+
exports.default = {
|
|
31
|
+
version: pkg.version,
|
|
32
|
+
satisfies: satisfies,
|
|
33
|
+
START_TIME: START_TIME,
|
|
34
|
+
};
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
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 extend_1 = __importDefault(require("extend"));
|
|
7
|
+
const browser_1 = __importDefault(require("./browser"));
|
|
8
|
+
const init_1 = __importDefault(require("./init"));
|
|
9
|
+
const node_1 = __importDefault(require("./fs/node"));
|
|
10
|
+
const output_1 = __importDefault(require("./output"));
|
|
11
|
+
const cli_1 = __importDefault(require("./cli"));
|
|
12
|
+
exports.default = extend_1.default({
|
|
13
|
+
initBook: init_1.default,
|
|
14
|
+
createNodeFS: node_1.default,
|
|
15
|
+
Output: output_1.default,
|
|
16
|
+
commands: cli_1.default,
|
|
17
|
+
}, browser_1.default);
|
package/lib/init.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
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 node_1 = __importDefault(require("./fs/node"));
|
|
8
|
+
const fs_1 = __importDefault(require("./utils/fs"));
|
|
9
|
+
const promise_1 = __importDefault(require("./utils/promise"));
|
|
10
|
+
const file_1 = __importDefault(require("./models/file"));
|
|
11
|
+
const readme_1 = __importDefault(require("./models/readme"));
|
|
12
|
+
const book_1 = __importDefault(require("./models/book"));
|
|
13
|
+
const parse_1 = __importDefault(require("./parse"));
|
|
14
|
+
/**
|
|
15
|
+
Initialize folder structure for a book
|
|
16
|
+
Read SUMMARY to created the right chapter
|
|
17
|
+
|
|
18
|
+
@param {Book}
|
|
19
|
+
@param {string}
|
|
20
|
+
@return {Promise}
|
|
21
|
+
*/
|
|
22
|
+
function initBook(rootFolder) {
|
|
23
|
+
const extension = ".md";
|
|
24
|
+
return (fs_1.default
|
|
25
|
+
.mkdirp(rootFolder)
|
|
26
|
+
// Parse the summary and readme
|
|
27
|
+
.then(() => {
|
|
28
|
+
const fs = node_1.default(rootFolder);
|
|
29
|
+
const book = book_1.default.createForFS(fs);
|
|
30
|
+
return (parse_1.default.parseReadme(book)
|
|
31
|
+
// Setup default readme if doesn't found one
|
|
32
|
+
.fail(() => {
|
|
33
|
+
const readmeFile = file_1.default.createWithFilepath(`README${extension}`);
|
|
34
|
+
// @ts-expect-error ts-migrate(2339) FIXME: Property 'create' does not exist on type 'Class'.
|
|
35
|
+
const readme = readme_1.default.create(readmeFile);
|
|
36
|
+
return book.setReadme(readme);
|
|
37
|
+
}));
|
|
38
|
+
})
|
|
39
|
+
.then(parse_1.default.parseSummary)
|
|
40
|
+
.then((book) => {
|
|
41
|
+
const logger = book.getLogger();
|
|
42
|
+
const summary = book.getSummary();
|
|
43
|
+
const summaryFile = summary.getFile();
|
|
44
|
+
const summaryFilename = summaryFile.getPath() || `SUMMARY${extension}`;
|
|
45
|
+
const articles = summary.getArticlesAsList();
|
|
46
|
+
// Write pages
|
|
47
|
+
return (promise_1.default.forEach(articles, (article) => {
|
|
48
|
+
const articlePath = article.getPath();
|
|
49
|
+
const filePath = articlePath ? path_1.default.join(rootFolder, articlePath) : null;
|
|
50
|
+
if (!filePath) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
return fs_1.default.assertFile(filePath, () => {
|
|
54
|
+
return fs_1.default.ensureFile(filePath).then(() => {
|
|
55
|
+
logger.info.ln("create", article.getPath());
|
|
56
|
+
return fs_1.default.writeFile(filePath, `# ${article.getTitle()}\n\n`);
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
})
|
|
60
|
+
// Write summary
|
|
61
|
+
.then(() => {
|
|
62
|
+
const filePath = path_1.default.join(rootFolder, summaryFilename);
|
|
63
|
+
return fs_1.default
|
|
64
|
+
.ensureFile(filePath)
|
|
65
|
+
.then(() => {
|
|
66
|
+
logger.info.ln(`create ${path_1.default.basename(filePath)}`);
|
|
67
|
+
return summary.toText(extension);
|
|
68
|
+
})
|
|
69
|
+
.then((content) => {
|
|
70
|
+
return fs_1.default.writeFile(filePath, content);
|
|
71
|
+
});
|
|
72
|
+
})
|
|
73
|
+
// Log end
|
|
74
|
+
.then(() => {
|
|
75
|
+
logger.info.ln("initialization is finished");
|
|
76
|
+
}));
|
|
77
|
+
}));
|
|
78
|
+
}
|
|
79
|
+
exports.default = initBook;
|
|
@@ -0,0 +1,41 @@
|
|
|
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 extend_1 = __importDefault(require("extend"));
|
|
7
|
+
const honkit_1 = __importDefault(require("../honkit"));
|
|
8
|
+
const encodeSummary_1 = __importDefault(require("./encodeSummary"));
|
|
9
|
+
const encodeGlossary_1 = __importDefault(require("./encodeGlossary"));
|
|
10
|
+
const encodeReadme_1 = __importDefault(require("./encodeReadme"));
|
|
11
|
+
const encodeLanguages_1 = __importDefault(require("./encodeLanguages"));
|
|
12
|
+
/**
|
|
13
|
+
Encode a book to JSON
|
|
14
|
+
|
|
15
|
+
@param {Book}
|
|
16
|
+
@return {Object}
|
|
17
|
+
*/
|
|
18
|
+
function encodeBookToJson(book) {
|
|
19
|
+
const config = book.getConfig();
|
|
20
|
+
const language = book.getLanguage();
|
|
21
|
+
const variables = config.getValue("variables", {});
|
|
22
|
+
return {
|
|
23
|
+
summary: encodeSummary_1.default(book.getSummary()),
|
|
24
|
+
glossary: encodeGlossary_1.default(book.getGlossary()),
|
|
25
|
+
readme: encodeReadme_1.default(book.getReadme()),
|
|
26
|
+
config: book.getConfig().getValues().toJS(),
|
|
27
|
+
languages: book.isMultilingual() ? encodeLanguages_1.default(book.getLanguages()) : undefined,
|
|
28
|
+
gitbook: {
|
|
29
|
+
version: honkit_1.default.version,
|
|
30
|
+
time: honkit_1.default.START_TIME,
|
|
31
|
+
},
|
|
32
|
+
honkit: {
|
|
33
|
+
version: honkit_1.default.version,
|
|
34
|
+
time: honkit_1.default.START_TIME,
|
|
35
|
+
},
|
|
36
|
+
book: extend_1.default({
|
|
37
|
+
language: language ? language : undefined,
|
|
38
|
+
}, variables.toJS()),
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
exports.default = encodeBookToJson;
|