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,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 decodeGlobal_1 = require("./decodeGlobal");
7
+ const encodePage_1 = __importDefault(require("./encodePage"));
8
+ const decodePage_1 = __importDefault(require("./decodePage"));
9
+ const encodeGlobal_1 = __importDefault(require("./encodeGlobal"));
10
+ exports.default = {
11
+ encodePage: encodePage_1.default,
12
+ decodePage: decodePage_1.default,
13
+ encodeGlobal: encodeGlobal_1.default,
14
+ decodeGlobal: decodeGlobal_1.decodeGlobal,
15
+ };
package/lib/bin.js ADDED
@@ -0,0 +1,46 @@
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.run = void 0;
7
+ const assert_1 = __importDefault(require("assert"));
8
+ const commander_1 = require("commander");
9
+ const index_1 = __importDefault(require("./index"));
10
+ const pkg = require("../package.json");
11
+ const run = (argv = process.argv) => {
12
+ const program = new commander_1.Command();
13
+ return new Promise((resolve, reject) => {
14
+ program.version(pkg.version);
15
+ index_1.default.commands.forEach((spec) => {
16
+ let subcommand = program.command(spec.name).description(spec.description);
17
+ const options = spec.options || [];
18
+ options.forEach((spec) => {
19
+ if (spec.values) {
20
+ const template = `--${spec.name} <${spec.name}>`;
21
+ const description = `${spec.description} (${spec.values.map(JSON.stringify).join(", ")})`;
22
+ subcommand = subcommand.option(template, description, (value, _dummyPrevious) => {
23
+ assert_1.default(spec.values.includes(value), `Invalid value ${value} for ${spec.name}`);
24
+ return value;
25
+ }, spec.defaults);
26
+ }
27
+ else {
28
+ subcommand = subcommand.option(spec.defaults ? `--${spec.name} <type>` : `--${spec.name}`, spec.description, spec.defaults);
29
+ }
30
+ });
31
+ subcommand = subcommand.action((...joinedArgs) => {
32
+ const args = joinedArgs.slice(0, -1);
33
+ const kwargs = joinedArgs.slice(-1)[0];
34
+ spec.exec(args, kwargs)
35
+ .then(() => {
36
+ resolve();
37
+ })
38
+ .catch((err) => {
39
+ reject(err);
40
+ });
41
+ });
42
+ });
43
+ program.parse(argv);
44
+ });
45
+ };
46
+ exports.run = run;
package/lib/browser.js ADDED
@@ -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 modifiers_1 = __importDefault(require("./modifiers"));
7
+ const parse_1 = __importDefault(require("./parse"));
8
+ const book_1 = __importDefault(require("./models/book"));
9
+ const fs_1 = __importDefault(require("./models/fs"));
10
+ const file_1 = __importDefault(require("./models/file"));
11
+ const summary_1 = __importDefault(require("./models/summary"));
12
+ const glossary_1 = __importDefault(require("./models/glossary"));
13
+ const config_1 = __importDefault(require("./models/config"));
14
+ const page_1 = __importDefault(require("./models/page"));
15
+ const pluginDependency_1 = __importDefault(require("./models/pluginDependency"));
16
+ const configFiles_1 = __importDefault(require("./constants/configFiles"));
17
+ const ignoreFiles_1 = __importDefault(require("./constants/ignoreFiles"));
18
+ const defaultPlugins_1 = __importDefault(require("./constants/defaultPlugins"));
19
+ const extsMarkdown_1 = __importDefault(require("./constants/extsMarkdown"));
20
+ const extsAsciidoc_1 = __importDefault(require("./constants/extsAsciidoc"));
21
+ exports.default = {
22
+ Parse: parse_1.default,
23
+ // Models
24
+ Book: book_1.default,
25
+ FS: fs_1.default,
26
+ File: file_1.default,
27
+ Summary: summary_1.default,
28
+ Glossary: glossary_1.default,
29
+ Config: config_1.default,
30
+ Page: page_1.default,
31
+ PluginDependency: pluginDependency_1.default,
32
+ // Modifiers
33
+ SummaryModifier: modifiers_1.default.Summary,
34
+ ConfigModifier: modifiers_1.default.Config,
35
+ // Constants
36
+ CONFIG_FILES: configFiles_1.default,
37
+ IGNORE_FILES: ignoreFiles_1.default,
38
+ DEFAULT_PLUGINS: defaultPlugins_1.default,
39
+ EXTENSIONS_MARKDOWN: extsMarkdown_1.default,
40
+ EXTENSIONS_ASCIIDOC: extsAsciidoc_1.default,
41
+ };
@@ -0,0 +1,36 @@
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 parse_1 = __importDefault(require("../parse"));
7
+ const output_1 = __importDefault(require("../output"));
8
+ const timing_1 = __importDefault(require("../utils/timing"));
9
+ const options_1 = __importDefault(require("./options"));
10
+ const getBook_1 = __importDefault(require("./getBook"));
11
+ const getOutputFolder_1 = __importDefault(require("./getOutputFolder"));
12
+ const page_cache_1 = require("../output/page-cache");
13
+ exports.default = {
14
+ name: "build [book] [output]",
15
+ description: "build a book",
16
+ options: [options_1.default.log, options_1.default.format, options_1.default.timing, options_1.default.reload],
17
+ exec: function (args, kwargs) {
18
+ const book = getBook_1.default(args, kwargs);
19
+ const outputFolder = getOutputFolder_1.default(args);
20
+ const Generator = output_1.default.getGenerator(kwargs.format);
21
+ if (kwargs.reload) {
22
+ book.getLogger().info.ok(`Clear cache`);
23
+ page_cache_1.clearCache();
24
+ }
25
+ return parse_1.default.parseBook(book)
26
+ .then((resultBook) => {
27
+ return output_1.default.generate(Generator, resultBook, {
28
+ root: outputFolder,
29
+ });
30
+ })
31
+ .fin(() => {
32
+ if (kwargs.timing)
33
+ timing_1.default.dump(book.getLogger());
34
+ });
35
+ },
36
+ };
@@ -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 path_1 = __importDefault(require("path"));
7
+ const tmp_1 = __importDefault(require("tmp"));
8
+ const promise_1 = __importDefault(require("../utils/promise"));
9
+ const fs_1 = __importDefault(require("../utils/fs"));
10
+ const parse_1 = __importDefault(require("../parse"));
11
+ const output_1 = __importDefault(require("../output"));
12
+ const options_1 = __importDefault(require("./options"));
13
+ const getBook_1 = __importDefault(require("./getBook"));
14
+ const page_cache_1 = require("../output/page-cache");
15
+ function default_1(format) {
16
+ return {
17
+ name: `${format} [book] [output]`,
18
+ description: "build a book into an ebook file",
19
+ options: [options_1.default.log],
20
+ exec: function (args, kwargs) {
21
+ const extension = `.${format}`;
22
+ // Output file will be stored in
23
+ const outputFile = args[1] || `book${extension}`;
24
+ // Create temporary directory
25
+ const outputFolder = tmp_1.default.dirSync().name;
26
+ const book = getBook_1.default(args, kwargs);
27
+ const logger = book.getLogger();
28
+ const Generator = output_1.default.getGenerator("ebook");
29
+ if (kwargs.reload) {
30
+ page_cache_1.clearCache();
31
+ }
32
+ return (parse_1.default.parseBook(book)
33
+ .then((resultBook) => {
34
+ return output_1.default.generate(Generator, resultBook, {
35
+ root: outputFolder,
36
+ format: format,
37
+ });
38
+ })
39
+ // Extract ebook file
40
+ .then((output) => {
41
+ const book = output.getBook();
42
+ const languages = book.getLanguages();
43
+ if (book.isMultilingual()) {
44
+ return promise_1.default.forEach(languages.getList(), (lang) => {
45
+ const langID = lang.getID();
46
+ const langOutputFile = path_1.default.join(path_1.default.dirname(outputFile), `${path_1.default.basename(outputFile, extension)}_${langID}${extension}`);
47
+ return fs_1.default.copy(path_1.default.resolve(outputFolder, langID, `index${extension}`), langOutputFile);
48
+ }).thenResolve(languages.getCount());
49
+ }
50
+ else {
51
+ return fs_1.default.copy(path_1.default.resolve(outputFolder, `index${extension}`), outputFile).thenResolve(1);
52
+ }
53
+ })
54
+ // Log end
55
+ .then((count) => {
56
+ logger.info.ok(`${count} file(s) generated`);
57
+ logger.debug("cleaning up... ");
58
+ return logger.debug.promise(fs_1.default.rmDir(outputFolder));
59
+ }));
60
+ },
61
+ };
62
+ }
63
+ exports.default = default_1;
@@ -0,0 +1,24 @@
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 book_1 = __importDefault(require("../models/book"));
8
+ const node_1 = __importDefault(require("../fs/node"));
9
+ /**
10
+ Return a book instance to work on from
11
+ command line args/kwargs
12
+
13
+ @param {Array} args
14
+ @param {Object} kwargs
15
+ @return {Book}
16
+ */
17
+ function getBook(args, kwargs) {
18
+ const input = path_1.default.resolve(args[0] || process.cwd());
19
+ const logLevel = kwargs.log;
20
+ const fs = node_1.default(input);
21
+ const book = book_1.default.createForFS(fs);
22
+ return book.setLogLevel(logLevel);
23
+ }
24
+ exports.default = getBook;
@@ -0,0 +1,19 @@
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
+ /**
8
+ Return path to output folder
9
+
10
+ @param {Array} args
11
+ @return {string}
12
+ */
13
+ function getOutputFolder(args) {
14
+ const bookRoot = path_1.default.resolve(args[0] || process.cwd());
15
+ const defaultOutputRoot = path_1.default.join(bookRoot, "_book");
16
+ const outputFolder = args[1] ? path_1.default.resolve(process.cwd(), args[1]) : defaultOutputRoot;
17
+ return outputFolder;
18
+ }
19
+ exports.default = getOutputFolder;
@@ -0,0 +1,11 @@
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 buildEbook_1 = __importDefault(require("./buildEbook"));
7
+ const build_1 = __importDefault(require("./build"));
8
+ const serve_1 = __importDefault(require("./serve"));
9
+ const parse_1 = __importDefault(require("./parse"));
10
+ const init_1 = __importDefault(require("./init"));
11
+ exports.default = [build_1.default, serve_1.default, parse_1.default, init_1.default, buildEbook_1.default("pdf"), buildEbook_1.default("epub"), buildEbook_1.default("mobi")];
@@ -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 path_1 = __importDefault(require("path"));
7
+ const options_1 = __importDefault(require("./options"));
8
+ const init_1 = __importDefault(require("../init"));
9
+ exports.default = {
10
+ name: "init [book]",
11
+ description: "setup and create files for chapters",
12
+ options: [options_1.default.log],
13
+ exec: function (args, kwargs) {
14
+ const bookRoot = path_1.default.resolve(process.cwd(), args[0] || "./");
15
+ return init_1.default(bookRoot);
16
+ },
17
+ };
@@ -0,0 +1,38 @@
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 logger_1 = __importDefault(require("../utils/logger"));
7
+ const logOptions = {
8
+ name: "log",
9
+ description: "Minimum log level to display",
10
+ values: logger_1.default.LEVELS.keySeq()
11
+ .map((s) => {
12
+ return s.toLowerCase();
13
+ })
14
+ .toJS(),
15
+ defaults: "info",
16
+ };
17
+ const formatOption = {
18
+ name: "format",
19
+ description: "Format to build to",
20
+ values: ["website", "json", "ebook"],
21
+ defaults: "website",
22
+ };
23
+ const timingOption = {
24
+ name: "timing",
25
+ description: "Print timing debug information",
26
+ defaults: false,
27
+ };
28
+ const reloadOption = {
29
+ name: "reload",
30
+ description: "Prune cache. Remove file cache",
31
+ defaults: false,
32
+ };
33
+ exports.default = {
34
+ log: logOptions,
35
+ format: formatOption,
36
+ timing: timingOption,
37
+ reload: reloadOption,
38
+ };
@@ -0,0 +1,65 @@
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 options_1 = __importDefault(require("./options"));
7
+ const getBook_1 = __importDefault(require("./getBook"));
8
+ const parse_1 = __importDefault(require("../parse"));
9
+ function printBook(book) {
10
+ const logger = book.getLogger();
11
+ const config = book.getConfig();
12
+ const configFile = config.getFile();
13
+ const summary = book.getSummary();
14
+ const summaryFile = summary.getFile();
15
+ const readme = book.getReadme();
16
+ const readmeFile = readme.getFile();
17
+ const glossary = book.getGlossary();
18
+ const glossaryFile = glossary.getFile();
19
+ if (configFile.exists()) {
20
+ logger.info.ln("Configuration file is", configFile.getPath());
21
+ }
22
+ if (readmeFile.exists()) {
23
+ logger.info.ln("Introduction file is", readmeFile.getPath());
24
+ }
25
+ if (glossaryFile.exists()) {
26
+ logger.info.ln("Glossary file is", glossaryFile.getPath());
27
+ }
28
+ if (summaryFile.exists()) {
29
+ logger.info.ln("Table of Contents file is", summaryFile.getPath());
30
+ }
31
+ }
32
+ function printMultingualBook(book) {
33
+ const logger = book.getLogger();
34
+ const languages = book.getLanguages();
35
+ const books = book.getBooks();
36
+ logger.info.ln(`${languages.size} languages`);
37
+ languages.forEach((lang) => {
38
+ logger.info.ln("Language:", lang.getTitle());
39
+ printBook(books.get(lang.getID()));
40
+ logger.info.ln("");
41
+ });
42
+ }
43
+ exports.default = {
44
+ name: "parse [book]",
45
+ description: "parse and print debug information about a book",
46
+ options: [options_1.default.log],
47
+ exec: function (args, kwargs) {
48
+ const book = getBook_1.default(args, kwargs);
49
+ const logger = book.getLogger();
50
+ return parse_1.default.parseBook(book).then((resultBook) => {
51
+ const rootFolder = book.getRoot();
52
+ const contentFolder = book.getContentRoot();
53
+ logger.info.ln("Book located in:", rootFolder);
54
+ if (contentFolder != rootFolder) {
55
+ logger.info.ln("Content located in:", contentFolder);
56
+ }
57
+ if (resultBook.isMultilingual()) {
58
+ printMultingualBook(resultBook);
59
+ }
60
+ else {
61
+ printBook(resultBook);
62
+ }
63
+ });
64
+ },
65
+ };
@@ -0,0 +1,184 @@
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 tiny_lr_1 = __importDefault(require("tiny-lr"));
7
+ const open_1 = __importDefault(require("open"));
8
+ const immutable_1 = __importDefault(require("immutable"));
9
+ const parse_1 = __importDefault(require("../parse"));
10
+ const output_1 = __importDefault(require("../output"));
11
+ const modifiers_1 = __importDefault(require("../modifiers"));
12
+ const promise_1 = __importDefault(require("../utils/promise"));
13
+ const options_1 = __importDefault(require("./options"));
14
+ const getBook_1 = __importDefault(require("./getBook"));
15
+ const getOutputFolder_1 = __importDefault(require("./getOutputFolder"));
16
+ const server_1 = __importDefault(require("./server"));
17
+ const watch_1 = __importDefault(require("./watch"));
18
+ const page_cache_1 = require("../output/page-cache");
19
+ let server, lrServer, lrPath;
20
+ function waitForCtrlC() {
21
+ const d = promise_1.default.defer();
22
+ process.on("SIGINT", () => {
23
+ d.resolve();
24
+ });
25
+ return d.promise;
26
+ }
27
+ function startServer(args, kwargs) {
28
+ const outputFolder = getOutputFolder_1.default(args);
29
+ const port = kwargs.port;
30
+ const browser = kwargs["browser"];
31
+ const book = getBook_1.default(args, kwargs);
32
+ const hasWatch = kwargs["watch"];
33
+ const hasOpen = kwargs["open"];
34
+ const hasLiveReloading = kwargs["live"];
35
+ const reload = kwargs["reload"];
36
+ const Generator = output_1.default.getGenerator(kwargs.format);
37
+ console.log("Starting server ...");
38
+ let lastOutput = null;
39
+ return promise_1.default.all([
40
+ server.start(outputFolder, port),
41
+ generateBook({
42
+ book,
43
+ outputFolder,
44
+ hasLiveReloading,
45
+ Generator,
46
+ reload,
47
+ }).then((output) => {
48
+ lastOutput = output;
49
+ return output;
50
+ }),
51
+ ])
52
+ .then(() => {
53
+ console.log(`Serving book on http://localhost:${port}`);
54
+ if (hasOpen) {
55
+ open_1.default(`http://localhost:${port}`, { app: browser });
56
+ }
57
+ })
58
+ .then(() => {
59
+ if (!hasWatch) {
60
+ return waitForCtrlC();
61
+ }
62
+ // update book immutably. does not use book again
63
+ return watch_1.default(book.getRoot(), (error, filepath) => {
64
+ if (error) {
65
+ console.error(error);
66
+ return;
67
+ }
68
+ // set livereload path
69
+ lrPath = filepath;
70
+ // TODO: use parse extension
71
+ // Incremental update for pages
72
+ if (lastOutput && filepath.endsWith(".md")) {
73
+ console.log("Reload after change in file", filepath);
74
+ const changedOutput = lastOutput.reloadPage(lastOutput.book.getContentRoot(), filepath).merge({
75
+ incrementalChangeFileSet: immutable_1.default.Set([filepath]),
76
+ });
77
+ return incrementalBuild({
78
+ output: changedOutput,
79
+ Generator,
80
+ }).then(() => {
81
+ if (lrPath && hasLiveReloading) {
82
+ // trigger livereload
83
+ lrServer.changed({
84
+ body: {
85
+ files: [lrPath],
86
+ },
87
+ });
88
+ }
89
+ });
90
+ }
91
+ console.log("Rebuild after change in file", filepath);
92
+ return generateBook({
93
+ book,
94
+ outputFolder,
95
+ hasLiveReloading,
96
+ Generator,
97
+ reload,
98
+ }).then((output) => {
99
+ lastOutput = output;
100
+ });
101
+ });
102
+ });
103
+ }
104
+ function generateBook({ book, outputFolder, hasLiveReloading, Generator, reload }) {
105
+ // Stop server if running
106
+ if (reload) {
107
+ book.getLogger().info.ok(`Clear cache`);
108
+ page_cache_1.clearCache();
109
+ }
110
+ return parse_1.default.parseBook(book).then((resultBook) => {
111
+ if (hasLiveReloading) {
112
+ // Enable livereload plugin
113
+ let config = resultBook.getConfig();
114
+ // @ts-expect-error ts-migrate(2554) FIXME: Expected 3 arguments, but got 2.
115
+ config = modifiers_1.default.Config.addPlugin(config, "livereload");
116
+ resultBook = resultBook.set("config", config);
117
+ }
118
+ return output_1.default.generate(Generator, resultBook, {
119
+ root: outputFolder,
120
+ });
121
+ });
122
+ }
123
+ function incrementalBuild({ output, Generator }) {
124
+ return output_1.default.incrementalBuild(Generator, output);
125
+ }
126
+ exports.default = {
127
+ name: "serve [book] [output]",
128
+ description: "serve the book as a website for testing",
129
+ options: [
130
+ {
131
+ name: "port",
132
+ description: "Port for server to listen on",
133
+ defaults: 4000,
134
+ },
135
+ {
136
+ name: "lrport",
137
+ description: "Port for livereload server to listen on",
138
+ defaults: 35729,
139
+ },
140
+ {
141
+ name: "watch",
142
+ description: "Enable file watcher and live reloading",
143
+ defaults: true,
144
+ },
145
+ {
146
+ name: "live",
147
+ description: "Enable live reloading",
148
+ defaults: true,
149
+ },
150
+ {
151
+ name: "open",
152
+ description: "Enable opening book in browser",
153
+ defaults: false,
154
+ },
155
+ {
156
+ name: "browser",
157
+ description: "Specify browser for opening book",
158
+ defaults: "",
159
+ },
160
+ options_1.default.log,
161
+ options_1.default.format,
162
+ options_1.default.reload,
163
+ ],
164
+ exec: function (args, kwargs) {
165
+ server = new server_1.default();
166
+ const hasWatch = kwargs["watch"];
167
+ const hasLiveReloading = kwargs["live"];
168
+ return promise_1.default()
169
+ .then(() => {
170
+ if (!hasWatch || !hasLiveReloading) {
171
+ return;
172
+ }
173
+ lrServer = tiny_lr_1.default({});
174
+ return promise_1.default.nfcall(lrServer.listen.bind(lrServer), kwargs.lrport).then(() => {
175
+ console.log("Live reload server started on port:", kwargs.lrport);
176
+ console.log("Press CTRL+C to quit ...");
177
+ console.log("");
178
+ });
179
+ })
180
+ .then(() => {
181
+ return startServer(args, kwargs);
182
+ });
183
+ },
184
+ };