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.
Files changed (278) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +10 -0
  3. package/bin/honkit.js +8 -0
  4. package/lib/BuildGenerator.js +2 -0
  5. package/lib/__tests__/__fixtures__/honkit/book.js +9 -0
  6. package/lib/__tests__/githon.js +11 -0
  7. package/lib/__tests__/init.js +19 -0
  8. package/lib/__tests__/snapshot-honkit.js +45 -0
  9. package/lib/api/decodeConfig.js +17 -0
  10. package/lib/api/decodeGlobal.js +21 -0
  11. package/lib/api/decodePage.js +41 -0
  12. package/lib/api/deprecate.js +113 -0
  13. package/lib/api/encodeConfig.js +30 -0
  14. package/lib/api/encodeGlobal.js +226 -0
  15. package/lib/api/encodeNavigation.js +60 -0
  16. package/lib/api/encodePage.js +37 -0
  17. package/lib/api/encodeProgress.js +58 -0
  18. package/lib/api/encodeSummary.js +52 -0
  19. package/lib/api/index.js +15 -0
  20. package/lib/bin.js +46 -0
  21. package/lib/browser.js +41 -0
  22. package/lib/cli/build.js +36 -0
  23. package/lib/cli/buildEbook.js +63 -0
  24. package/lib/cli/getBook.js +24 -0
  25. package/lib/cli/getOutputFolder.js +19 -0
  26. package/lib/cli/index.js +11 -0
  27. package/lib/cli/init.js +17 -0
  28. package/lib/cli/options.js +38 -0
  29. package/lib/cli/parse.js +65 -0
  30. package/lib/cli/serve.js +184 -0
  31. package/lib/cli/server.js +116 -0
  32. package/lib/cli/watch.js +35 -0
  33. package/lib/constants/__tests__/configSchema.js +41 -0
  34. package/lib/constants/configDefault.js +9 -0
  35. package/lib/constants/configFiles.js +3 -0
  36. package/lib/constants/configSchema.js +235 -0
  37. package/lib/constants/defaultBlocks.js +48 -0
  38. package/lib/constants/defaultFilters.js +18 -0
  39. package/lib/constants/defaultPlugins.js +20 -0
  40. package/lib/constants/extsAsciidoc.js +3 -0
  41. package/lib/constants/extsMarkdown.js +3 -0
  42. package/lib/constants/ignoreFiles.js +3 -0
  43. package/lib/constants/pluginAssetsFolder.js +3 -0
  44. package/lib/constants/pluginHooks.js +3 -0
  45. package/lib/constants/pluginPrefix.js +3 -0
  46. package/lib/constants/pluginResources.js +7 -0
  47. package/lib/constants/templatesFolder.js +3 -0
  48. package/lib/constants/themePrefix.js +3 -0
  49. package/lib/fs/__tests__/mock.js +68 -0
  50. package/lib/fs/mock.js +88 -0
  51. package/lib/fs/node.js +44 -0
  52. package/lib/honkit.js +34 -0
  53. package/lib/index.js +17 -0
  54. package/lib/init.js +79 -0
  55. package/lib/json/encodeBook.js +41 -0
  56. package/lib/json/encodeBookWithPage.js +25 -0
  57. package/lib/json/encodeFile.js +20 -0
  58. package/lib/json/encodeGlossary.js +22 -0
  59. package/lib/json/encodeGlossaryEntry.js +16 -0
  60. package/lib/json/encodeLanguages.js +29 -0
  61. package/lib/json/encodeOutput.js +26 -0
  62. package/lib/json/encodeOutputWithPage.js +26 -0
  63. package/lib/json/encodePage.js +38 -0
  64. package/lib/json/encodeReadme.js +19 -0
  65. package/lib/json/encodeSummary.js +22 -0
  66. package/lib/json/encodeSummaryArticle.js +25 -0
  67. package/lib/json/encodeSummaryPart.js +19 -0
  68. package/lib/json/index.js +27 -0
  69. package/lib/models/__tests__/config.js +164 -0
  70. package/lib/models/__tests__/glossary.js +38 -0
  71. package/lib/models/__tests__/glossaryEntry.js +16 -0
  72. package/lib/models/__tests__/page.js +26 -0
  73. package/lib/models/__tests__/plugin.js +26 -0
  74. package/lib/models/__tests__/pluginDependency.js +71 -0
  75. package/lib/models/__tests__/summary.js +115 -0
  76. package/lib/models/__tests__/summaryArticle.js +62 -0
  77. package/lib/models/__tests__/summaryPart.js +24 -0
  78. package/lib/models/__tests__/templateBlock.js +172 -0
  79. package/lib/models/__tests__/templateEngine.js +49 -0
  80. package/lib/models/book.js +312 -0
  81. package/lib/models/config.js +152 -0
  82. package/lib/models/file.js +83 -0
  83. package/lib/models/fs.js +255 -0
  84. package/lib/models/glossary.js +90 -0
  85. package/lib/models/glossaryEntry.js +34 -0
  86. package/lib/models/hash.js +191 -0
  87. package/lib/models/ignore.js +40 -0
  88. package/lib/models/language.js +22 -0
  89. package/lib/models/languages.js +64 -0
  90. package/lib/models/output.js +109 -0
  91. package/lib/models/page.js +91 -0
  92. package/lib/models/parser.js +102 -0
  93. package/lib/models/plugin.js +139 -0
  94. package/lib/models/pluginDependency.js +192 -0
  95. package/lib/models/readme.js +38 -0
  96. package/lib/models/summary.js +199 -0
  97. package/lib/models/summaryArticle.js +169 -0
  98. package/lib/models/summaryPart.js +53 -0
  99. package/lib/models/templateBlock.js +230 -0
  100. package/lib/models/templateEngine.js +115 -0
  101. package/lib/models/templateOutput.js +36 -0
  102. package/lib/models/templateShortcut.js +65 -0
  103. package/lib/modifiers/config/__tests__/addPlugin.js +30 -0
  104. package/lib/modifiers/config/__tests__/removePlugin.js +29 -0
  105. package/lib/modifiers/config/__tests__/togglePlugin.js +28 -0
  106. package/lib/modifiers/config/addPlugin.js +27 -0
  107. package/lib/modifiers/config/editPlugin.js +13 -0
  108. package/lib/modifiers/config/getPluginConfig.js +22 -0
  109. package/lib/modifiers/config/hasPlugin.js +15 -0
  110. package/lib/modifiers/config/index.js +21 -0
  111. package/lib/modifiers/config/isDefaultPlugin.js +17 -0
  112. package/lib/modifiers/config/removePlugin.js +27 -0
  113. package/lib/modifiers/config/togglePlugin.js +32 -0
  114. package/lib/modifiers/index.js +11 -0
  115. package/lib/modifiers/summary/__tests__/editPartTitle.js +41 -0
  116. package/lib/modifiers/summary/__tests__/insertArticle.js +72 -0
  117. package/lib/modifiers/summary/__tests__/insertPart.js +56 -0
  118. package/lib/modifiers/summary/__tests__/mergeAtLevel.js +45 -0
  119. package/lib/modifiers/summary/__tests__/moveArticle.js +66 -0
  120. package/lib/modifiers/summary/__tests__/moveArticleAfter.js +75 -0
  121. package/lib/modifiers/summary/__tests__/removeArticle.js +54 -0
  122. package/lib/modifiers/summary/editArticleRef.js +20 -0
  123. package/lib/modifiers/summary/editArticleTitle.js +20 -0
  124. package/lib/modifiers/summary/editPartTitle.js +21 -0
  125. package/lib/modifiers/summary/index.js +27 -0
  126. package/lib/modifiers/summary/indexArticleLevels.js +21 -0
  127. package/lib/modifiers/summary/indexLevels.js +18 -0
  128. package/lib/modifiers/summary/indexPartLevels.js +25 -0
  129. package/lib/modifiers/summary/insertArticle.js +47 -0
  130. package/lib/modifiers/summary/insertPart.js +21 -0
  131. package/lib/modifiers/summary/mergeAtLevel.js +68 -0
  132. package/lib/modifiers/summary/moveArticle.js +27 -0
  133. package/lib/modifiers/summary/moveArticleAfter.js +59 -0
  134. package/lib/modifiers/summary/removeArticle.js +36 -0
  135. package/lib/modifiers/summary/removePart.js +18 -0
  136. package/lib/modifiers/summary/unshiftArticle.js +27 -0
  137. package/lib/output/__tests__/ebook.js +17 -0
  138. package/lib/output/__tests__/json.js +43 -0
  139. package/lib/output/__tests__/plugin-hooks.js +57 -0
  140. package/lib/output/__tests__/website.js +121 -0
  141. package/lib/output/callHook.js +51 -0
  142. package/lib/output/callPageHook.js +23 -0
  143. package/lib/output/createTemplateEngine.js +42 -0
  144. package/lib/output/ebook/getConvertOptions.js +69 -0
  145. package/lib/output/ebook/getCoverPath.js +30 -0
  146. package/lib/output/ebook/getPDFTemplate.js +40 -0
  147. package/lib/output/ebook/index.js +16 -0
  148. package/lib/output/ebook/onFinish.js +84 -0
  149. package/lib/output/ebook/onPage.js +23 -0
  150. package/lib/output/ebook/options.js +17 -0
  151. package/lib/output/generateAssets.js +26 -0
  152. package/lib/output/generateBook.js +167 -0
  153. package/lib/output/generatePage.js +90 -0
  154. package/lib/output/generatePages.js +52 -0
  155. package/lib/output/getModifiers.js +63 -0
  156. package/lib/output/helper/fileToOutput.js +30 -0
  157. package/lib/output/helper/fileToURL.js +30 -0
  158. package/lib/output/helper/index.js +3 -0
  159. package/lib/output/helper/resolveFileToURL.js +25 -0
  160. package/lib/output/helper/writeFile.js +26 -0
  161. package/lib/output/index.js +27 -0
  162. package/lib/output/json/index.js +14 -0
  163. package/lib/output/json/onFinish.js +39 -0
  164. package/lib/output/json/onPage.js +37 -0
  165. package/lib/output/json/options.js +11 -0
  166. package/lib/output/modifiers/__tests__/addHeadingId.js +23 -0
  167. package/lib/output/modifiers/__tests__/annotateText.js +39 -0
  168. package/lib/output/modifiers/__tests__/fetchRemoteImages.js +32 -0
  169. package/lib/output/modifiers/__tests__/highlightCode.js +48 -0
  170. package/lib/output/modifiers/__tests__/inlinePng.js +22 -0
  171. package/lib/output/modifiers/__tests__/inlineSvg.js +42 -0
  172. package/lib/output/modifiers/__tests__/resolveImages.js +39 -0
  173. package/lib/output/modifiers/__tests__/resolveLinks.js +81 -0
  174. package/lib/output/modifiers/__tests__/svgToImg.js +29 -0
  175. package/lib/output/modifiers/addHeadingId.js +26 -0
  176. package/lib/output/modifiers/annotateText.js +76 -0
  177. package/lib/output/modifiers/editHTMLElement.js +17 -0
  178. package/lib/output/modifiers/fetchRemoteImages.js +42 -0
  179. package/lib/output/modifiers/highlightCode.js +59 -0
  180. package/lib/output/modifiers/index.js +26 -0
  181. package/lib/output/modifiers/inlineAssets.js +29 -0
  182. package/lib/output/modifiers/inlinePng.js +43 -0
  183. package/lib/output/modifiers/inlineSvg.js +39 -0
  184. package/lib/output/modifiers/modifyHTML.js +27 -0
  185. package/lib/output/modifiers/resolveImages.js +30 -0
  186. package/lib/output/modifiers/resolveLinks.js +46 -0
  187. package/lib/output/modifiers/svgToImg.js +58 -0
  188. package/lib/output/page-cache.js +15 -0
  189. package/lib/output/prepareAssets.js +22 -0
  190. package/lib/output/preparePages.js +25 -0
  191. package/lib/output/preparePlugins.js +36 -0
  192. package/lib/output/testing/createMock.js +39 -0
  193. package/lib/output/testing/generateMock.js +55 -0
  194. package/lib/output/website/__tests__/i18n.js +40 -0
  195. package/lib/output/website/copyPluginAssets.js +92 -0
  196. package/lib/output/website/createTemplateEngine.js +136 -0
  197. package/lib/output/website/index.js +22 -0
  198. package/lib/output/website/listSearchPaths.js +20 -0
  199. package/lib/output/website/onAsset.js +29 -0
  200. package/lib/output/website/onFinish.js +35 -0
  201. package/lib/output/website/onInit.js +19 -0
  202. package/lib/output/website/onPage.js +73 -0
  203. package/lib/output/website/options.js +15 -0
  204. package/lib/output/website/prepareI18n.js +28 -0
  205. package/lib/output/website/prepareResources.js +49 -0
  206. package/lib/output/website/state.js +20 -0
  207. package/lib/parse/__tests__/listAssets.js +63 -0
  208. package/lib/parse/__tests__/parseBook.js +77 -0
  209. package/lib/parse/__tests__/parseGlossary.js +32 -0
  210. package/lib/parse/__tests__/parseIgnore.js +37 -0
  211. package/lib/parse/__tests__/parsePageFromString.js +34 -0
  212. package/lib/parse/__tests__/parseReadme.js +33 -0
  213. package/lib/parse/__tests__/parseSummary.js +30 -0
  214. package/lib/parse/findParsableFile.js +33 -0
  215. package/lib/parse/index.js +31 -0
  216. package/lib/parse/listAssets.js +36 -0
  217. package/lib/parse/lookupStructureFile.js +21 -0
  218. package/lib/parse/parseBook.js +68 -0
  219. package/lib/parse/parseConfig.js +52 -0
  220. package/lib/parse/parseGlossary.js +25 -0
  221. package/lib/parse/parseIgnore.js +43 -0
  222. package/lib/parse/parseLanguages.js +26 -0
  223. package/lib/parse/parsePage.js +21 -0
  224. package/lib/parse/parsePageFromString.js +25 -0
  225. package/lib/parse/parsePagesList.js +80 -0
  226. package/lib/parse/parseReadme.js +26 -0
  227. package/lib/parse/parseStructureFile.js +64 -0
  228. package/lib/parse/parseSummary.js +43 -0
  229. package/lib/parse/validateConfig.js +31 -0
  230. package/lib/parse/walkSummary.js +34 -0
  231. package/lib/parsers.js +60 -0
  232. package/lib/plugins/PluginResolver.js +84 -0
  233. package/lib/plugins/__tests__/findInstalled.js +25 -0
  234. package/lib/plugins/__tests__/listDependencies.js +28 -0
  235. package/lib/plugins/__tests__/sortDependencies.js +28 -0
  236. package/lib/plugins/__tests__/validatePlugin.js +99 -0
  237. package/lib/plugins/findInstalled.js +87 -0
  238. package/lib/plugins/index.js +17 -0
  239. package/lib/plugins/listBlocks.js +19 -0
  240. package/lib/plugins/listDependencies.js +33 -0
  241. package/lib/plugins/listDepsForBook.js +20 -0
  242. package/lib/plugins/listFilters.js +18 -0
  243. package/lib/plugins/listResources.js +44 -0
  244. package/lib/plugins/loadForBook.js +38 -0
  245. package/lib/plugins/loadPlugin.js +89 -0
  246. package/lib/plugins/package-name-util.js +48 -0
  247. package/lib/plugins/sortDependencies.js +30 -0
  248. package/lib/plugins/toNames.js +16 -0
  249. package/lib/plugins/validateConfig.js +60 -0
  250. package/lib/plugins/validatePlugin.js +36 -0
  251. package/lib/templating/__tests__/conrefsLoader.js +93 -0
  252. package/lib/templating/__tests__/postRender.js +52 -0
  253. package/lib/templating/__tests__/replaceShortcuts.js +27 -0
  254. package/lib/templating/conrefsLoader.js +88 -0
  255. package/lib/templating/index.js +19 -0
  256. package/lib/templating/listShortcuts.js +29 -0
  257. package/lib/templating/postRender.js +46 -0
  258. package/lib/templating/render.js +41 -0
  259. package/lib/templating/renderFile.js +39 -0
  260. package/lib/templating/replaceShortcuts.js +36 -0
  261. package/lib/templating/themesLoader.js +98 -0
  262. package/lib/utils/__tests__/git.js +47 -0
  263. package/lib/utils/__tests__/location.js +81 -0
  264. package/lib/utils/__tests__/path.js +19 -0
  265. package/lib/utils/command.js +104 -0
  266. package/lib/utils/error.js +88 -0
  267. package/lib/utils/fs.js +163 -0
  268. package/lib/utils/genKey.js +13 -0
  269. package/lib/utils/git.js +116 -0
  270. package/lib/utils/images.js +22 -0
  271. package/lib/utils/location.js +129 -0
  272. package/lib/utils/logger.js +158 -0
  273. package/lib/utils/mergeDefaults.js +18 -0
  274. package/lib/utils/path.js +62 -0
  275. package/lib/utils/promise.js +142 -0
  276. package/lib/utils/reducedObject.js +31 -0
  277. package/lib/utils/timing.js +90 -0
  278. package/package.json +112 -0
@@ -0,0 +1,73 @@
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
+ exports.onPage = void 0;
7
+ const path_1 = __importDefault(require("path"));
8
+ const omit_keys_1 = __importDefault(require("omit-keys"));
9
+ const templating_1 = __importDefault(require("../../templating"));
10
+ const plugins_1 = __importDefault(require("../../plugins"));
11
+ const json_1 = __importDefault(require("../../json"));
12
+ const location_1 = __importDefault(require("../../utils/location"));
13
+ const modifiers_1 = __importDefault(require("../modifiers"));
14
+ const writeFile_1 = __importDefault(require("../helper/writeFile"));
15
+ const getModifiers_1 = __importDefault(require("../getModifiers"));
16
+ const createTemplateEngine_1 = __importDefault(require("./createTemplateEngine"));
17
+ const fileToOutput_1 = __importDefault(require("../helper/fileToOutput"));
18
+ /**
19
+ * Write a page as a json file
20
+ *
21
+ * @param {Output} output
22
+ * @param {Page} page
23
+ */
24
+ function onPage(output, page) {
25
+ const options = output.getOptions();
26
+ const prefix = options.get("prefix");
27
+ const file = page.getFile();
28
+ const book = output.getBook();
29
+ const plugins = output.getPlugins();
30
+ const state = output.getState();
31
+ const resources = state.getResources();
32
+ const engine = createTemplateEngine_1.default(output, page.getPath());
33
+ // Output file path
34
+ const filePath = fileToOutput_1.default(output, file.getPath());
35
+ // Calcul relative path to the root
36
+ const outputDirName = path_1.default.dirname(filePath);
37
+ const basePath = location_1.default.normalize(path_1.default.relative(outputDirName, "./"));
38
+ return modifiers_1.default.modifyHTML(page, getModifiers_1.default(output, page)).then((resultPage) => {
39
+ // Generate the context
40
+ const context = json_1.default.encodeOutputWithPage(output, resultPage);
41
+ // @ts-expect-error ts-migrate(2339) FIXME: Property 'plugins' does not exist on type '{ summa... Remove this comment to see the full error message
42
+ context.plugins = {
43
+ resources: plugins_1.default.listResources(plugins, resources).toJS(),
44
+ };
45
+ // @ts-expect-error ts-migrate(2339) FIXME: Property 'template' does not exist on type '{ summ... Remove this comment to see the full error message
46
+ context.template = {
47
+ getJSContext: function () {
48
+ return {
49
+ // @ts-expect-error ts-migrate(2339) FIXME: Property 'page' does not exist on type '{ summary:... Remove this comment to see the full error message
50
+ page: omit_keys_1.default(context.page, "content"),
51
+ config: context.config,
52
+ // @ts-expect-error ts-migrate(2339) FIXME: Property 'file' does not exist on type '{ summary:... Remove this comment to see the full error message
53
+ file: context.file,
54
+ gitbook: context.gitbook,
55
+ basePath: basePath,
56
+ book: {
57
+ language: book.getLanguage(),
58
+ },
59
+ };
60
+ },
61
+ };
62
+ // We should probabbly move it to "template" or a "site" namespace
63
+ // @ts-expect-error ts-migrate(2339) FIXME: Property 'basePath' does not exist on type '{ summ... Remove this comment to see the full error message
64
+ context.basePath = basePath;
65
+ // Render the theme
66
+ return (templating_1.default.renderFile(engine, `${prefix}/page.html`, context)
67
+ // Write it to the disk
68
+ .then((tplOut) => {
69
+ return writeFile_1.default(output, filePath, tplOut.getContent());
70
+ }));
71
+ });
72
+ }
73
+ exports.onPage = onPage;
@@ -0,0 +1,15 @@
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 Options = immutable_1.default.Record({
8
+ // Root folder for the output
9
+ root: String(),
10
+ // Prefix for generation
11
+ prefix: String("website"),
12
+ // Use directory index url instead of "index.html"
13
+ directoryIndex: Boolean(true),
14
+ });
15
+ exports.default = Options;
@@ -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 path_1 = __importDefault(require("path"));
7
+ const fs_1 = __importDefault(require("../../utils/fs"));
8
+ const promise_1 = __importDefault(require("../../utils/promise"));
9
+ const listSearchPaths_1 = __importDefault(require("./listSearchPaths"));
10
+ /**
11
+ * Prepare i18n, load translations from plugins and book
12
+ *
13
+ * @param {Output}
14
+ * @return {Promise<Output>}
15
+ */
16
+ function prepareI18n(output) {
17
+ const state = output.getState();
18
+ const i18n = state.getI18n();
19
+ const searchPaths = listSearchPaths_1.default(output);
20
+ searchPaths.reverse().forEach((searchPath) => {
21
+ const i18nRoot = path_1.default.resolve(searchPath, "_i18n");
22
+ if (!fs_1.default.existsSync(i18nRoot))
23
+ return;
24
+ i18n.load(i18nRoot);
25
+ });
26
+ return promise_1.default(output);
27
+ }
28
+ exports.default = prepareI18n;
@@ -0,0 +1,49 @@
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 is_1 = __importDefault(require("is"));
7
+ const immutable_1 = __importDefault(require("immutable"));
8
+ const promise_1 = __importDefault(require("../../utils/promise"));
9
+ const api_1 = __importDefault(require("../../api"));
10
+ /**
11
+ Prepare plugins resources, add all output corresponding type resources
12
+
13
+ @param {Output}
14
+ @return {Promise<Output>}
15
+ */
16
+ function prepareResources(output) {
17
+ const plugins = output.getPlugins();
18
+ const options = output.getOptions();
19
+ const type = options.get("prefix");
20
+ let state = output.getState();
21
+ const context = api_1.default.encodeGlobal(output);
22
+ let result = immutable_1.default.Map();
23
+ return promise_1.default.forEach(plugins, (plugin) => {
24
+ const pluginResources = plugin.getResources(type);
25
+ return promise_1.default()
26
+ .then(() => {
27
+ // Apply resources if is a function
28
+ if (is_1.default.fn(pluginResources)) {
29
+ return promise_1.default().then(pluginResources.bind(context));
30
+ }
31
+ else {
32
+ return pluginResources;
33
+ }
34
+ })
35
+ .then((resources) => {
36
+ result = result.set(plugin.getName(), immutable_1.default.Map(resources));
37
+ });
38
+ }).then(() => {
39
+ // Set output resources
40
+ state = state.merge({
41
+ resources: result,
42
+ });
43
+ output = output.merge({
44
+ state: state,
45
+ });
46
+ return output;
47
+ });
48
+ }
49
+ exports.default = prepareResources;
@@ -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 i18n_t_1 = __importDefault(require("i18n-t"));
7
+ const immutable_1 = __importDefault(require("immutable"));
8
+ class GeneratorState extends immutable_1.default.Record({
9
+ i18n: i18n_t_1.default(),
10
+ // List of plugins' resources
11
+ resources: immutable_1.default.Map(),
12
+ }) {
13
+ getI18n() {
14
+ return this.get("i18n");
15
+ }
16
+ getResources() {
17
+ return this.get("resources");
18
+ }
19
+ }
20
+ exports.default = GeneratorState;
@@ -0,0 +1,63 @@
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 mock_1 = __importDefault(require("../../fs/mock"));
8
+ const book_1 = __importDefault(require("../../models/book"));
9
+ const listAssets_1 = __importDefault(require("../listAssets"));
10
+ const parseGlossary_1 = __importDefault(require("../parseGlossary"));
11
+ const parseBook_1 = __importDefault(require("../parseBook"));
12
+ describe("listAssets", () => {
13
+ test("should not list glossary as asset", () => {
14
+ const fs = mock_1.default({
15
+ "GLOSSARY.md": "# Glossary\n\n## Hello\nDescription for hello",
16
+ "assetFile.js": "",
17
+ assets: {
18
+ "file.js": "",
19
+ },
20
+ });
21
+ const book = book_1.default.createForFS(fs);
22
+ return parseGlossary_1.default(book)
23
+ .then((resultBook) => {
24
+ return listAssets_1.default(resultBook, immutable_1.default.Map());
25
+ })
26
+ .then((assets) => {
27
+ expect(assets.size).toBe(2);
28
+ expect(assets.includes("assetFile.js"));
29
+ expect(assets.includes("assets/file.js"));
30
+ });
31
+ });
32
+ test("should not list README.md of pages as asset", () => {
33
+ const fs = mock_1.default({
34
+ "book.json": JSON.stringify({
35
+ root: "./test",
36
+ }),
37
+ test: {
38
+ "SUMMARY.md": `# Summary
39
+
40
+ * [top](README.md)
41
+ * [sub](sub/README-sub.md)
42
+ * [subsub](sub/sub/README-subsub.md)
43
+
44
+ `,
45
+ "README.md": "top",
46
+ "sub/README-sub.md": "in sub",
47
+ "sub/sub/README-subsub.md": "in sub/sub",
48
+ },
49
+ });
50
+ const pages = new Map()
51
+ .set("README.md", "top")
52
+ .set("sub/README-sub.md", "sub")
53
+ .set("sub/sub/README-subsub.md", "sub/sub");
54
+ const book = book_1.default.createForFS(fs);
55
+ return parseBook_1.default(book)
56
+ .then((resultBook) => {
57
+ return listAssets_1.default(resultBook, pages);
58
+ })
59
+ .then((assets) => {
60
+ expect(assets.size).toBe(0);
61
+ });
62
+ });
63
+ });
@@ -0,0 +1,77 @@
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 book_1 = __importDefault(require("../../models/book"));
7
+ const mock_1 = __importDefault(require("../../fs/mock"));
8
+ const parseBook_1 = __importDefault(require("../parseBook"));
9
+ describe("parseBook", () => {
10
+ test("should parse multilingual book", () => {
11
+ const fs = mock_1.default({
12
+ "LANGS.md": "# Languages\n\n* [en](en)\n* [fr](fr)",
13
+ en: {
14
+ "README.md": "Hello",
15
+ },
16
+ fr: {
17
+ "README.md": "Bonjour",
18
+ },
19
+ });
20
+ const book = book_1.default.createForFS(fs);
21
+ return parseBook_1.default(book).then((resultBook) => {
22
+ const languages = resultBook.getLanguages();
23
+ const books = resultBook.getBooks();
24
+ expect(resultBook.isMultilingual()).toBe(true);
25
+ expect(languages.getList().size).toBe(2);
26
+ expect(books.size).toBe(2);
27
+ });
28
+ });
29
+ test("should extend configuration for multilingual book", () => {
30
+ const fs = mock_1.default({
31
+ "LANGS.md": "# Languages\n\n* [en](en)\n* [fr](fr)",
32
+ "book.json": '{ "title": "Test", "author": "HonKit" }',
33
+ en: {
34
+ "README.md": "Hello",
35
+ "book.json": '{ "title": "Test EN" }',
36
+ },
37
+ fr: {
38
+ "README.md": "Bonjour",
39
+ },
40
+ });
41
+ const book = book_1.default.createForFS(fs);
42
+ return parseBook_1.default(book).then((resultBook) => {
43
+ const books = resultBook.getBooks();
44
+ expect(resultBook.isMultilingual()).toBe(true);
45
+ expect(books.size).toBe(2);
46
+ const en = books.get("en");
47
+ const fr = books.get("fr");
48
+ const enConfig = en.getConfig();
49
+ const frConfig = fr.getConfig();
50
+ expect(enConfig.getValue("title")).toBe("Test EN");
51
+ expect(enConfig.getValue("author")).toBe("HonKit");
52
+ expect(frConfig.getValue("title")).toBe("Test");
53
+ expect(frConfig.getValue("author")).toBe("HonKit");
54
+ });
55
+ });
56
+ test("should parse book in a directory", () => {
57
+ const fs = mock_1.default({
58
+ "book.json": JSON.stringify({
59
+ root: "./test",
60
+ }),
61
+ test: {
62
+ "README.md": "Hello World",
63
+ "SUMMARY.md": "# Summary\n\n* [Page](page.md)\n",
64
+ "page.md": "Page",
65
+ },
66
+ });
67
+ const book = book_1.default.createForFS(fs);
68
+ return parseBook_1.default(book).then((resultBook) => {
69
+ const readme = resultBook.getReadme();
70
+ const summary = resultBook.getSummary();
71
+ const articles = summary.getArticlesAsList();
72
+ expect(summary.getFile().exists()).toBe(true);
73
+ expect(readme.getFile().exists()).toBe(true);
74
+ expect(articles.size).toBe(2);
75
+ });
76
+ });
77
+ });
@@ -0,0 +1,32 @@
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 book_1 = __importDefault(require("../../models/book"));
7
+ const mock_1 = __importDefault(require("../../fs/mock"));
8
+ const parseGlossary_1 = __importDefault(require("../parseGlossary"));
9
+ describe("parseGlossary", () => {
10
+ test("should parse glossary if exists", () => {
11
+ const fs = mock_1.default({
12
+ "GLOSSARY.md": "# Glossary\n\n## Hello\nDescription for hello",
13
+ });
14
+ const book = book_1.default.createForFS(fs);
15
+ return parseGlossary_1.default(book).then((resultBook) => {
16
+ const glossary = resultBook.getGlossary();
17
+ const file = glossary.getFile();
18
+ const entries = glossary.getEntries();
19
+ expect(file.exists()).toBeTruthy();
20
+ expect(entries.size).toBe(1);
21
+ });
22
+ });
23
+ test("should not fail if doesn't exist", () => {
24
+ const fs = mock_1.default({});
25
+ const book = book_1.default.createForFS(fs);
26
+ return parseGlossary_1.default(book).then((resultBook) => {
27
+ const glossary = resultBook.getGlossary();
28
+ const file = glossary.getFile();
29
+ expect(file.exists()).toBeFalsy();
30
+ });
31
+ });
32
+ });
@@ -0,0 +1,37 @@
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 book_1 = __importDefault(require("../../models/book"));
7
+ const mock_1 = __importDefault(require("../../fs/mock"));
8
+ const parseIgnore_1 = __importDefault(require("../parseIgnore"));
9
+ describe("parseIgnore", () => {
10
+ const fs = mock_1.default({
11
+ ".ignore": "test-1.js",
12
+ ".gitignore": "test-2.js\ntest-3.js",
13
+ ".bookignore": "!test-3.js",
14
+ "test-1.js": "1",
15
+ "test-2.js": "2",
16
+ "test-3.js": "3",
17
+ });
18
+ function getBook() {
19
+ const book = book_1.default.createForFS(fs);
20
+ return parseIgnore_1.default(book);
21
+ }
22
+ test("should load rules from .ignore", () => {
23
+ return getBook().then((book) => {
24
+ expect(book.isFileIgnored("test-1.js")).toBeTruthy();
25
+ });
26
+ });
27
+ test("should load rules from .gitignore", () => {
28
+ return getBook().then((book) => {
29
+ expect(book.isFileIgnored("test-2.js")).toBeTruthy();
30
+ });
31
+ });
32
+ test("should load rules from .bookignore", () => {
33
+ return getBook().then((book) => {
34
+ expect(book.isFileIgnored("test-3.js")).toBeFalsy();
35
+ });
36
+ });
37
+ });
@@ -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 parsePageFromString_1 = __importDefault(require("../parsePageFromString"));
7
+ const page_1 = __importDefault(require("../../models/page"));
8
+ describe("parsePageFromString", () => {
9
+ const page = new page_1.default();
10
+ test("should parse YAML frontmatter", () => {
11
+ const CONTENT = "---\nhello: true\nworld: \"cool\"\n---\n# Hello World\n";
12
+ const newPage = parsePageFromString_1.default(page, CONTENT);
13
+ expect(newPage.getDir()).toBe("ltr");
14
+ expect(newPage.getContent()).toBe("# Hello World\n");
15
+ const attrs = newPage.getAttributes();
16
+ expect(attrs.size).toBe(2);
17
+ expect(attrs.get("hello")).toBe(true);
18
+ expect(attrs.get("world")).toBe("cool");
19
+ });
20
+ test("should parse text direction (english)", () => {
21
+ const CONTENT = "Hello World";
22
+ const newPage = parsePageFromString_1.default(page, CONTENT);
23
+ expect(newPage.getDir()).toBe("ltr");
24
+ expect(newPage.getContent()).toBe("Hello World");
25
+ expect(newPage.getAttributes().size).toBe(0);
26
+ });
27
+ test("should parse text direction (arab)", () => {
28
+ const CONTENT = "مرحبا بالعالم";
29
+ const newPage = parsePageFromString_1.default(page, CONTENT);
30
+ expect(newPage.getDir()).toBe("rtl");
31
+ expect(newPage.getContent()).toBe("مرحبا بالعالم");
32
+ expect(newPage.getAttributes().size).toBe(0);
33
+ });
34
+ });
@@ -0,0 +1,33 @@
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 mock_1 = __importDefault(require("../../fs/mock"));
8
+ const book_1 = __importDefault(require("../../models/book"));
9
+ const parseReadme_1 = __importDefault(require("../parseReadme"));
10
+ describe("parseReadme", () => {
11
+ test("should parse summary if exists", () => {
12
+ const fs = mock_1.default({
13
+ "README.md": "# Hello\n\nAnd here is the description.",
14
+ });
15
+ const book = book_1.default.createForFS(fs);
16
+ return parseReadme_1.default(book).then((resultBook) => {
17
+ const readme = resultBook.getReadme();
18
+ const file = readme.getFile();
19
+ expect(file.exists()).toBeTruthy();
20
+ expect(readme.getTitle()).toBe("Hello");
21
+ expect(readme.getDescription()).toBe("And here is the description.");
22
+ });
23
+ });
24
+ test("should fail if doesn't exist", () => {
25
+ const fs = mock_1.default({});
26
+ const book = book_1.default.createForFS(fs);
27
+ return parseReadme_1.default(book).then((resultBook) => {
28
+ throw new Error("It should have fail");
29
+ }, () => {
30
+ return promise_1.default();
31
+ });
32
+ });
33
+ });