honkit 6.0.4 → 6.1.5

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 (186) hide show
  1. package/lib/__tests__/__fixtures__/honkit/book.d.ts +7 -0
  2. package/lib/__tests__/__fixtures__/honkit/book.d.ts.map +1 -0
  3. package/lib/__tests__/__fixtures__/honkit/book.js +9 -0
  4. package/lib/__tests__/e2e.test.d.ts +2 -0
  5. package/lib/__tests__/e2e.test.d.ts.map +1 -0
  6. package/lib/__tests__/e2e.test.js +81 -0
  7. package/lib/__tests__/init.d.ts +2 -0
  8. package/lib/__tests__/init.d.ts.map +1 -0
  9. package/lib/__tests__/init.js +19 -0
  10. package/lib/__tests__/satisfies.d.ts +2 -0
  11. package/lib/__tests__/satisfies.d.ts.map +1 -0
  12. package/lib/__tests__/satisfies.js +11 -0
  13. package/lib/__tests__/snapshot-asciidoc.d.ts +2 -0
  14. package/lib/__tests__/snapshot-asciidoc.d.ts.map +1 -0
  15. package/lib/__tests__/snapshot-asciidoc.js +48 -0
  16. package/lib/__tests__/snapshot-honkit.d.ts +2 -0
  17. package/lib/__tests__/snapshot-honkit.d.ts.map +1 -0
  18. package/lib/__tests__/snapshot-honkit.js +48 -0
  19. package/lib/cli/__tests__/watch.test.d.ts +2 -0
  20. package/lib/cli/__tests__/watch.test.d.ts.map +1 -0
  21. package/lib/cli/__tests__/watch.test.js +194 -0
  22. package/lib/cli/serve.d.ts.map +1 -1
  23. package/lib/cli/serve.js +49 -43
  24. package/lib/cli/watch.d.ts +22 -6
  25. package/lib/cli/watch.d.ts.map +1 -1
  26. package/lib/cli/watch.js +24 -10
  27. package/lib/constants/__tests__/configSchema.d.ts +2 -0
  28. package/lib/constants/__tests__/configSchema.d.ts.map +1 -0
  29. package/lib/constants/__tests__/configSchema.js +41 -0
  30. package/lib/fs/__tests__/mock.d.ts +2 -0
  31. package/lib/fs/__tests__/mock.d.ts.map +1 -0
  32. package/lib/fs/__tests__/mock.js +68 -0
  33. package/lib/models/__tests__/config.d.ts +2 -0
  34. package/lib/models/__tests__/config.d.ts.map +1 -0
  35. package/lib/models/__tests__/config.js +164 -0
  36. package/lib/models/__tests__/glossary.d.ts +2 -0
  37. package/lib/models/__tests__/glossary.d.ts.map +1 -0
  38. package/lib/models/__tests__/glossary.js +38 -0
  39. package/lib/models/__tests__/glossaryEntry.d.ts +2 -0
  40. package/lib/models/__tests__/glossaryEntry.d.ts.map +1 -0
  41. package/lib/models/__tests__/glossaryEntry.js +16 -0
  42. package/lib/models/__tests__/page.d.ts +2 -0
  43. package/lib/models/__tests__/page.d.ts.map +1 -0
  44. package/lib/models/__tests__/page.js +26 -0
  45. package/lib/models/__tests__/plugin.d.ts +2 -0
  46. package/lib/models/__tests__/plugin.d.ts.map +1 -0
  47. package/lib/models/__tests__/plugin.js +50 -0
  48. package/lib/models/__tests__/pluginDependency.d.ts +2 -0
  49. package/lib/models/__tests__/pluginDependency.d.ts.map +1 -0
  50. package/lib/models/__tests__/pluginDependency.js +71 -0
  51. package/lib/models/__tests__/summary.d.ts +2 -0
  52. package/lib/models/__tests__/summary.d.ts.map +1 -0
  53. package/lib/models/__tests__/summary.js +115 -0
  54. package/lib/models/__tests__/summaryArticle.d.ts +2 -0
  55. package/lib/models/__tests__/summaryArticle.d.ts.map +1 -0
  56. package/lib/models/__tests__/summaryArticle.js +117 -0
  57. package/lib/models/__tests__/summaryPart.d.ts +2 -0
  58. package/lib/models/__tests__/summaryPart.d.ts.map +1 -0
  59. package/lib/models/__tests__/summaryPart.js +24 -0
  60. package/lib/models/__tests__/templateBlock.d.ts +2 -0
  61. package/lib/models/__tests__/templateBlock.d.ts.map +1 -0
  62. package/lib/models/__tests__/templateBlock.js +172 -0
  63. package/lib/models/__tests__/templateEngine.d.ts +2 -0
  64. package/lib/models/__tests__/templateEngine.d.ts.map +1 -0
  65. package/lib/models/__tests__/templateEngine.js +49 -0
  66. package/lib/modifiers/config/__tests__/addPlugin.d.ts +2 -0
  67. package/lib/modifiers/config/__tests__/addPlugin.d.ts.map +1 -0
  68. package/lib/modifiers/config/__tests__/addPlugin.js +30 -0
  69. package/lib/modifiers/config/__tests__/removePlugin.d.ts +2 -0
  70. package/lib/modifiers/config/__tests__/removePlugin.d.ts.map +1 -0
  71. package/lib/modifiers/config/__tests__/removePlugin.js +29 -0
  72. package/lib/modifiers/config/__tests__/togglePlugin.d.ts +2 -0
  73. package/lib/modifiers/config/__tests__/togglePlugin.d.ts.map +1 -0
  74. package/lib/modifiers/config/__tests__/togglePlugin.js +28 -0
  75. package/lib/modifiers/summary/__tests__/editPartTitle.d.ts +2 -0
  76. package/lib/modifiers/summary/__tests__/editPartTitle.d.ts.map +1 -0
  77. package/lib/modifiers/summary/__tests__/editPartTitle.js +41 -0
  78. package/lib/modifiers/summary/__tests__/insertArticle.d.ts +2 -0
  79. package/lib/modifiers/summary/__tests__/insertArticle.d.ts.map +1 -0
  80. package/lib/modifiers/summary/__tests__/insertArticle.js +72 -0
  81. package/lib/modifiers/summary/__tests__/insertPart.d.ts +2 -0
  82. package/lib/modifiers/summary/__tests__/insertPart.d.ts.map +1 -0
  83. package/lib/modifiers/summary/__tests__/insertPart.js +56 -0
  84. package/lib/modifiers/summary/__tests__/mergeAtLevel.d.ts +2 -0
  85. package/lib/modifiers/summary/__tests__/mergeAtLevel.d.ts.map +1 -0
  86. package/lib/modifiers/summary/__tests__/mergeAtLevel.js +45 -0
  87. package/lib/modifiers/summary/__tests__/moveArticle.d.ts +2 -0
  88. package/lib/modifiers/summary/__tests__/moveArticle.d.ts.map +1 -0
  89. package/lib/modifiers/summary/__tests__/moveArticle.js +66 -0
  90. package/lib/modifiers/summary/__tests__/moveArticleAfter.d.ts +2 -0
  91. package/lib/modifiers/summary/__tests__/moveArticleAfter.d.ts.map +1 -0
  92. package/lib/modifiers/summary/__tests__/moveArticleAfter.js +75 -0
  93. package/lib/modifiers/summary/__tests__/removeArticle.d.ts +2 -0
  94. package/lib/modifiers/summary/__tests__/removeArticle.d.ts.map +1 -0
  95. package/lib/modifiers/summary/__tests__/removeArticle.js +54 -0
  96. package/lib/output/__tests__/ebook.d.ts +2 -0
  97. package/lib/output/__tests__/ebook.d.ts.map +1 -0
  98. package/lib/output/__tests__/ebook.js +17 -0
  99. package/lib/output/__tests__/json.d.ts +2 -0
  100. package/lib/output/__tests__/json.d.ts.map +1 -0
  101. package/lib/output/__tests__/json.js +43 -0
  102. package/lib/output/__tests__/plugin-hooks.d.ts +2 -0
  103. package/lib/output/__tests__/plugin-hooks.d.ts.map +1 -0
  104. package/lib/output/__tests__/plugin-hooks.js +57 -0
  105. package/lib/output/__tests__/website.d.ts +2 -0
  106. package/lib/output/__tests__/website.d.ts.map +1 -0
  107. package/lib/output/__tests__/website.js +121 -0
  108. package/lib/output/modifiers/__tests__/addHeadingId.d.ts +2 -0
  109. package/lib/output/modifiers/__tests__/addHeadingId.d.ts.map +1 -0
  110. package/lib/output/modifiers/__tests__/addHeadingId.js +23 -0
  111. package/lib/output/modifiers/__tests__/annotateText.d.ts +2 -0
  112. package/lib/output/modifiers/__tests__/annotateText.d.ts.map +1 -0
  113. package/lib/output/modifiers/__tests__/annotateText.js +71 -0
  114. package/lib/output/modifiers/__tests__/fetchRemoteImages.d.ts +2 -0
  115. package/lib/output/modifiers/__tests__/fetchRemoteImages.d.ts.map +1 -0
  116. package/lib/output/modifiers/__tests__/fetchRemoteImages.js +69 -0
  117. package/lib/output/modifiers/__tests__/highlightCode.d.ts +2 -0
  118. package/lib/output/modifiers/__tests__/highlightCode.d.ts.map +1 -0
  119. package/lib/output/modifiers/__tests__/highlightCode.js +48 -0
  120. package/lib/output/modifiers/__tests__/inlinePng.d.ts +2 -0
  121. package/lib/output/modifiers/__tests__/inlinePng.d.ts.map +1 -0
  122. package/lib/output/modifiers/__tests__/inlinePng.js +22 -0
  123. package/lib/output/modifiers/__tests__/inlineSvg.d.ts +2 -0
  124. package/lib/output/modifiers/__tests__/inlineSvg.d.ts.map +1 -0
  125. package/lib/output/modifiers/__tests__/inlineSvg.js +42 -0
  126. package/lib/output/modifiers/__tests__/resolveImages.d.ts +2 -0
  127. package/lib/output/modifiers/__tests__/resolveImages.d.ts.map +1 -0
  128. package/lib/output/modifiers/__tests__/resolveImages.js +39 -0
  129. package/lib/output/modifiers/__tests__/resolveLinks.d.ts +2 -0
  130. package/lib/output/modifiers/__tests__/resolveLinks.d.ts.map +1 -0
  131. package/lib/output/modifiers/__tests__/resolveLinks.js +81 -0
  132. package/lib/output/modifiers/__tests__/svgToImg.d.ts +2 -0
  133. package/lib/output/modifiers/__tests__/svgToImg.d.ts.map +1 -0
  134. package/lib/output/modifiers/__tests__/svgToImg.js +29 -0
  135. package/lib/output/website/__tests__/i18n.d.ts +2 -0
  136. package/lib/output/website/__tests__/i18n.d.ts.map +1 -0
  137. package/lib/output/website/__tests__/i18n.js +40 -0
  138. package/lib/parse/__tests__/listAssets.d.ts +2 -0
  139. package/lib/parse/__tests__/listAssets.d.ts.map +1 -0
  140. package/lib/parse/__tests__/listAssets.js +63 -0
  141. package/lib/parse/__tests__/parseBook.d.ts +2 -0
  142. package/lib/parse/__tests__/parseBook.d.ts.map +1 -0
  143. package/lib/parse/__tests__/parseBook.js +77 -0
  144. package/lib/parse/__tests__/parseGlossary.d.ts +2 -0
  145. package/lib/parse/__tests__/parseGlossary.d.ts.map +1 -0
  146. package/lib/parse/__tests__/parseGlossary.js +32 -0
  147. package/lib/parse/__tests__/parseIgnore.d.ts +2 -0
  148. package/lib/parse/__tests__/parseIgnore.d.ts.map +1 -0
  149. package/lib/parse/__tests__/parseIgnore.js +37 -0
  150. package/lib/parse/__tests__/parsePageFromString.d.ts +2 -0
  151. package/lib/parse/__tests__/parsePageFromString.d.ts.map +1 -0
  152. package/lib/parse/__tests__/parsePageFromString.js +34 -0
  153. package/lib/parse/__tests__/parseReadme.d.ts +2 -0
  154. package/lib/parse/__tests__/parseReadme.d.ts.map +1 -0
  155. package/lib/parse/__tests__/parseReadme.js +33 -0
  156. package/lib/parse/__tests__/parseSummary.d.ts +2 -0
  157. package/lib/parse/__tests__/parseSummary.d.ts.map +1 -0
  158. package/lib/parse/__tests__/parseSummary.js +30 -0
  159. package/lib/plugins/__tests__/listDependencies.d.ts +2 -0
  160. package/lib/plugins/__tests__/listDependencies.d.ts.map +1 -0
  161. package/lib/plugins/__tests__/listDependencies.js +28 -0
  162. package/lib/plugins/__tests__/sortDependencies.d.ts +2 -0
  163. package/lib/plugins/__tests__/sortDependencies.d.ts.map +1 -0
  164. package/lib/plugins/__tests__/sortDependencies.js +28 -0
  165. package/lib/plugins/__tests__/validatePlugin.d.ts +2 -0
  166. package/lib/plugins/__tests__/validatePlugin.d.ts.map +1 -0
  167. package/lib/plugins/__tests__/validatePlugin.js +99 -0
  168. package/lib/templating/__tests__/conrefsLoader.d.ts +2 -0
  169. package/lib/templating/__tests__/conrefsLoader.d.ts.map +1 -0
  170. package/lib/templating/__tests__/conrefsLoader.js +90 -0
  171. package/lib/templating/__tests__/postRender.d.ts +2 -0
  172. package/lib/templating/__tests__/postRender.d.ts.map +1 -0
  173. package/lib/templating/__tests__/postRender.js +52 -0
  174. package/lib/templating/__tests__/replaceShortcuts.d.ts +2 -0
  175. package/lib/templating/__tests__/replaceShortcuts.d.ts.map +1 -0
  176. package/lib/templating/__tests__/replaceShortcuts.js +27 -0
  177. package/lib/utils/__tests__/git.d.ts +2 -0
  178. package/lib/utils/__tests__/git.d.ts.map +1 -0
  179. package/lib/utils/__tests__/git.js +46 -0
  180. package/lib/utils/__tests__/location.d.ts +2 -0
  181. package/lib/utils/__tests__/location.d.ts.map +1 -0
  182. package/lib/utils/__tests__/location.js +81 -0
  183. package/lib/utils/__tests__/path.d.ts +2 -0
  184. package/lib/utils/__tests__/path.d.ts.map +1 -0
  185. package/lib/utils/__tests__/path.js +19 -0
  186. package/package.json +17 -19
@@ -0,0 +1,7 @@
1
+ export let root: string;
2
+ export let title: string;
3
+ export let gitbook: string;
4
+ export namespace variables {
5
+ let version: string;
6
+ }
7
+ //# sourceMappingURL=book.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"book.d.ts","sourceRoot":"","sources":["../../../../src/__tests__/__fixtures__/honkit/book.js"],"names":[],"mappings":""}
@@ -0,0 +1,9 @@
1
+ module.exports = {
2
+ root: "./docs",
3
+ title: "HonKit Documentation",
4
+ // Enforce use of HonKit v3
5
+ gitbook: "3.1.1",
6
+ variables: {
7
+ version: "3.1.1",
8
+ },
9
+ };
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=e2e.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"e2e.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/e2e.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,81 @@
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 bin_1 = require("../bin");
7
+ const path_1 = __importDefault(require("path"));
8
+ const jest_mock_process_1 = require("jest-mock-process");
9
+ const jest_serializer_strip_ansi_1 = require("@relmify/jest-serializer-strip-ansi");
10
+ const CWD = process.cwd();
11
+ const cwdPlugin = {
12
+ test: (value) => typeof value === "string" && value.includes(CWD),
13
+ print: (value, serialize) => {
14
+ if (typeof value === "string") {
15
+ return serialize(value.split(CWD).join("<CWD>").replace(/\\/g, "/"));
16
+ }
17
+ return value;
18
+ },
19
+ };
20
+ expect.addSnapshotSerializer(jest_serializer_strip_ansi_1.stripAnsi);
21
+ expect.addSnapshotSerializer(cwdPlugin);
22
+ describe("e2e", function () {
23
+ let stdoutMock;
24
+ beforeEach(() => {
25
+ stdoutMock = (0, jest_mock_process_1.mockProcessStdout)();
26
+ });
27
+ afterEach(() => {
28
+ stdoutMock.mockRestore();
29
+ });
30
+ it("`honkit parse` for multilang", async () => {
31
+ await (0, bin_1.run)([process.argv[0], "honkit", "parse", path_1.default.join(__dirname, "__fixtures__/multilang")]);
32
+ expect(stdoutMock.mock.calls).toMatchInlineSnapshot(`
33
+ [
34
+ [
35
+ "info: parsing multilingual book, with 2 languages
36
+ ",
37
+ ],
38
+ [
39
+ "warn: no summary file in this book
40
+ ",
41
+ ],
42
+ [
43
+ "warn: no summary file in this book
44
+ ",
45
+ ],
46
+ [
47
+ "info: Book located in: <CWD>/src/__tests__/__fixtures__/multilang
48
+ ",
49
+ ],
50
+ [
51
+ "info: 2 languages
52
+ ",
53
+ ],
54
+ [
55
+ "info: Language: English
56
+ ",
57
+ ],
58
+ [
59
+ "info: Introduction file is README.md
60
+ ",
61
+ ],
62
+ [
63
+ "info:
64
+ ",
65
+ ],
66
+ [
67
+ "info: Language: Japanese
68
+ ",
69
+ ],
70
+ [
71
+ "info: Introduction file is README.md
72
+ ",
73
+ ],
74
+ [
75
+ "info:
76
+ ",
77
+ ],
78
+ ]
79
+ `);
80
+ });
81
+ });
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=init.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/__tests__/init.ts"],"names":[],"mappings":""}
@@ -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 tmp_1 = __importDefault(require("tmp"));
7
+ const init_1 = __importDefault(require("../init"));
8
+ describe("initBook", () => {
9
+ let dir;
10
+ beforeEach(() => {
11
+ dir = tmp_1.default.dirSync();
12
+ });
13
+ test("should create a README and SUMMARY for empty book", () => {
14
+ return (0, init_1.default)(dir.name).then(() => {
15
+ expect(dir.name).toHaveFile("README.md");
16
+ expect(dir.name).toHaveFile("SUMMARY.md");
17
+ });
18
+ });
19
+ });
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=satisfies.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"satisfies.d.ts","sourceRoot":"","sources":["../../src/__tests__/satisfies.ts"],"names":[],"mappings":""}
@@ -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 honkit_1 = __importDefault(require("../honkit"));
7
+ describe("satisfies", () => {
8
+ test("should return true for *", () => {
9
+ expect(honkit_1.default.satisfies("*")).toBe(true);
10
+ });
11
+ });
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=snapshot-asciidoc.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"snapshot-asciidoc.d.ts","sourceRoot":"","sources":["../../src/__tests__/snapshot-asciidoc.ts"],"names":[],"mappings":""}
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ const path_1 = __importDefault(require("path"));
30
+ const internal_test_utils_1 = require("@honkit/internal-test-utils");
31
+ const bin = __importStar(require("../bin"));
32
+ it("asciidoc snapshot", async () => {
33
+ const bookDir = path_1.default.join(__dirname, "__fixtures__/asciidoc");
34
+ const outputDir = path_1.default.join(__dirname, "__fixtures__/asciidoc/_book");
35
+ await bin.run([process.argv[0], ".", "build", bookDir, "--reload"]);
36
+ const maskContent = (content) => {
37
+ return content
38
+ .replace(/gitbook\.page\.hasChanged\(.*\);/g, ``)
39
+ .replace(/<meta name="generator" content="HonKit .*">/g, "");
40
+ };
41
+ for await (const item of (0, internal_test_utils_1.iterateDirectoryContents)({
42
+ baseDir: outputDir,
43
+ allowExtensions: [".html"],
44
+ maskContent
45
+ })) {
46
+ expect(item).toMatchSnapshot(item.filePath);
47
+ }
48
+ }, 60 * 1000);
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=snapshot-honkit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"snapshot-honkit.d.ts","sourceRoot":"","sources":["../../src/__tests__/snapshot-honkit.ts"],"names":[],"mappings":""}
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ const path_1 = __importDefault(require("path"));
30
+ const internal_test_utils_1 = require("@honkit/internal-test-utils");
31
+ const bin = __importStar(require("../bin"));
32
+ it("HonKit snapshots", async () => {
33
+ const bookDir = path_1.default.join(__dirname, "__fixtures__/honkit");
34
+ const outputDir = path_1.default.join(__dirname, "__fixtures__/honkit/_book");
35
+ await bin.run([process.argv[0], ".", "build", bookDir, "--reload"]);
36
+ const maskContent = (content) => {
37
+ return content
38
+ .replace(/gitbook\.page\.hasChanged\(.*\);/g, ``)
39
+ .replace(/<meta name="generator" content="HonKit .*">/g, "");
40
+ };
41
+ for await (const item of (0, internal_test_utils_1.iterateDirectoryContents)({
42
+ baseDir: outputDir,
43
+ allowExtensions: [".html"],
44
+ maskContent
45
+ })) {
46
+ expect(item).toMatchSnapshot(item.filePath);
47
+ }
48
+ }, 60 * 1000);
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=watch.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"watch.test.d.ts","sourceRoot":"","sources":["../../../src/cli/__tests__/watch.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,194 @@
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("fs"));
8
+ const os_1 = __importDefault(require("os"));
9
+ const watch_1 = __importDefault(require("../watch"));
10
+ /**
11
+ * Normalize path separators to forward slashes for cross-platform comparison
12
+ */
13
+ function normalizePath(filepath) {
14
+ return filepath.replace(/\\/g, "/");
15
+ }
16
+ describe("watch", () => {
17
+ // Increase timeout for file system operations (Windows may need more time)
18
+ jest.setTimeout(30000);
19
+ let tempDir;
20
+ let watchers = [];
21
+ beforeEach(() => {
22
+ tempDir = fs_1.default.mkdtempSync(path_1.default.join(os_1.default.tmpdir(), "honkit-watch-test-"));
23
+ });
24
+ afterEach(async () => {
25
+ // Close all watchers
26
+ await Promise.all(watchers.map((w) => w.close()));
27
+ watchers = [];
28
+ // Cleanup temp directory
29
+ if (tempDir && fs_1.default.existsSync(tempDir)) {
30
+ fs_1.default.rmSync(tempDir, { recursive: true, force: true });
31
+ }
32
+ });
33
+ function createFile(relativePath, content = "# Test") {
34
+ const filePath = path_1.default.join(tempDir, relativePath);
35
+ const dir = path_1.default.dirname(filePath);
36
+ if (!fs_1.default.existsSync(dir)) {
37
+ fs_1.default.mkdirSync(dir, { recursive: true });
38
+ }
39
+ fs_1.default.writeFileSync(filePath, content);
40
+ return filePath;
41
+ }
42
+ function modifyFile(relativePath, content) {
43
+ const filePath = path_1.default.join(tempDir, relativePath);
44
+ fs_1.default.writeFileSync(filePath, content);
45
+ return filePath;
46
+ }
47
+ /**
48
+ * Wait for watcher to be ready and stable
49
+ */
50
+ async function waitForReady(watcher) {
51
+ await new Promise((resolve) => {
52
+ watcher.on("ready", resolve);
53
+ });
54
+ // Give the watcher a moment to stabilize after ready event
55
+ // Windows needs more time for file system operations
56
+ await new Promise((resolve) => setTimeout(resolve, 500));
57
+ }
58
+ /**
59
+ * Wait for a file change to be detected that matches the predicate
60
+ * Paths are normalized to forward slashes for cross-platform compatibility
61
+ */
62
+ function waitForChange(watcher, predicate, timeoutMs = 20000) {
63
+ return new Promise((resolve, reject) => {
64
+ const timeout = setTimeout(() => {
65
+ reject(new Error(`Timeout waiting for file change after ${timeoutMs}ms`));
66
+ }, timeoutMs);
67
+ const handler = (_event, filepath) => {
68
+ const fullPath = normalizePath(path_1.default.resolve(tempDir, filepath));
69
+ if (predicate(fullPath)) {
70
+ clearTimeout(timeout);
71
+ watcher.off("all", handler);
72
+ resolve(fullPath);
73
+ }
74
+ };
75
+ watcher.on("all", handler);
76
+ });
77
+ }
78
+ describe("issue #491 - custom output folder handling", () => {
79
+ it("should detect changes in custom output folder when not specified in options", async () => {
80
+ createFile("README.md", "# README");
81
+ createFile("output/orphan.md", "# Orphan in output folder");
82
+ const detectedFiles = [];
83
+ // Start watching WITHOUT specifying output folder
84
+ const watcher = (0, watch_1.default)({
85
+ watchDir: tempDir,
86
+ callback: (error, filepath) => {
87
+ if (error || !filepath)
88
+ return;
89
+ detectedFiles.push(normalizePath(filepath));
90
+ }
91
+ });
92
+ watchers.push(watcher);
93
+ await waitForReady(watcher);
94
+ // Modify file in output folder and wait for detection
95
+ modifyFile("output/orphan.md", "# Modified");
96
+ const detected = await waitForChange(watcher, (f) => f.includes("output/orphan.md"));
97
+ expect(detected).toContain("output/orphan.md");
98
+ });
99
+ it("should NOT detect changes in custom output folder when specified in options", async () => {
100
+ createFile("README.md", "# README");
101
+ createFile("output/orphan.md", "# Orphan in output folder");
102
+ const detectedFiles = [];
103
+ // Start watching WITH output folder specified - it should be ignored
104
+ const watcher = (0, watch_1.default)({
105
+ watchDir: tempDir,
106
+ outputFolder: "output",
107
+ callback: (error, filepath) => {
108
+ if (error || !filepath)
109
+ return;
110
+ detectedFiles.push(normalizePath(filepath));
111
+ }
112
+ });
113
+ watchers.push(watcher);
114
+ await waitForReady(watcher);
115
+ // Modify both files - output should be ignored, README should be detected
116
+ modifyFile("output/orphan.md", "# Modified");
117
+ modifyFile("README.md", "# Modified README");
118
+ // Wait for README change to be detected (proves watcher is working)
119
+ await waitForChange(watcher, (f) => f.includes("README.md"));
120
+ // Verify output folder change was NOT detected
121
+ const outputChanges = detectedFiles.filter((f) => f.includes("output/"));
122
+ expect(outputChanges).toHaveLength(0);
123
+ });
124
+ it("should handle absolute output folder paths", async () => {
125
+ createFile("README.md", "# README");
126
+ createFile("docs-output/file.md", "# File");
127
+ const detectedFiles = [];
128
+ const absoluteOutputPath = path_1.default.join(tempDir, "docs-output");
129
+ const watcher = (0, watch_1.default)({
130
+ watchDir: tempDir,
131
+ outputFolder: absoluteOutputPath,
132
+ callback: (error, filepath) => {
133
+ if (error || !filepath)
134
+ return;
135
+ detectedFiles.push(normalizePath(filepath));
136
+ }
137
+ });
138
+ watchers.push(watcher);
139
+ await waitForReady(watcher);
140
+ // Modify both files
141
+ modifyFile("docs-output/file.md", "# Modified");
142
+ modifyFile("README.md", "# Modified README");
143
+ // Wait for README change
144
+ await waitForChange(watcher, (f) => f.includes("README.md"));
145
+ // Verify docs-output was NOT detected
146
+ const outputChanges = detectedFiles.filter((f) => f.includes("docs-output/"));
147
+ expect(outputChanges).toHaveLength(0);
148
+ });
149
+ });
150
+ describe("default _book folder", () => {
151
+ it("should NOT detect changes in _book folder", async () => {
152
+ createFile("file1.md", "# File 1");
153
+ createFile("file2.md", "# File 2");
154
+ createFile("_book/output.md", "# Output");
155
+ const detectedFiles = [];
156
+ const watcher = (0, watch_1.default)({
157
+ watchDir: tempDir,
158
+ callback: (error, filepath) => {
159
+ if (error || !filepath)
160
+ return;
161
+ detectedFiles.push(normalizePath(filepath));
162
+ }
163
+ });
164
+ watchers.push(watcher);
165
+ await waitForReady(watcher);
166
+ // First modify file1 to ensure watcher is working
167
+ modifyFile("file1.md", "# Modified File 1");
168
+ await waitForChange(watcher, (f) => f.includes("file1.md"));
169
+ // Now modify _book file (should be ignored)
170
+ modifyFile("_book/output.md", "# Modified");
171
+ // Modify file2 to confirm watcher still works
172
+ modifyFile("file2.md", "# Modified File 2");
173
+ await waitForChange(watcher, (f) => f.includes("file2.md"));
174
+ // Verify _book was NOT detected
175
+ const bookChanges = detectedFiles.filter((f) => f.includes("_book"));
176
+ expect(bookChanges).toHaveLength(0);
177
+ });
178
+ });
179
+ describe("source files", () => {
180
+ it("should detect changes to markdown files in source directory", async () => {
181
+ createFile("README.md", "# README");
182
+ createFile("orphan.md", "# Orphan - not in SUMMARY");
183
+ const watcher = (0, watch_1.default)({
184
+ watchDir: tempDir,
185
+ callback: () => { }
186
+ });
187
+ watchers.push(watcher);
188
+ await waitForReady(watcher);
189
+ modifyFile("orphan.md", "# Modified orphan");
190
+ const detected = await waitForChange(watcher, (f) => f.includes("orphan.md"));
191
+ expect(detected).toContain("orphan.md");
192
+ });
193
+ });
194
+ });
@@ -1 +1 @@
1
- {"version":3,"file":"serve.d.ts","sourceRoot":"","sources":["../../src/cli/serve.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AA4IA,wBA6DE"}
1
+ {"version":3,"file":"serve.d.ts","sourceRoot":"","sources":["../../src/cli/serve.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAkJA,wBA6DE"}
package/lib/cli/serve.js CHANGED
@@ -62,51 +62,57 @@ function startServer(args, kwargs) {
62
62
  return waitForCtrlC();
63
63
  }
64
64
  // update book immutably. does not use book again
65
- return (0, watch_1.default)(book.getRoot(), (error, filepath) => {
66
- if (error) {
67
- console.error(error);
68
- return;
69
- }
70
- // If the file does not exist in file system, show a warning and skip
71
- // Probably, the file has been deleted
72
- if (!fs_1.default.existsSync(filepath)) {
73
- logger.warn.ok(`${filepath} does not exist in file system.`);
74
- return;
75
- }
76
- // set livereload path
77
- lrPath = filepath;
78
- // TODO: use parse extension
79
- // Incremental update for pages
80
- if (lastOutput && filepath.endsWith(".md")) {
81
- logger.warn.ok("Rebuild " + filepath);
82
- const changedOutput = lastOutput.reloadPage(lastOutput.book.getContentRoot(), filepath).merge({
83
- incrementalChangeFileSet: immutable_1.default.Set([filepath])
84
- });
85
- return incrementalBuild({
86
- output: changedOutput,
87
- Generator
88
- }).then(() => {
89
- if (lrPath && hasLiveReloading) {
90
- // trigger livereload
91
- lrServer.changed({
92
- body: {
93
- files: [lrPath]
94
- }
95
- });
96
- }
65
+ // Pass outputFolder to watch to prevent infinite rebuild loops
66
+ // https://github.com/honkit/honkit/issues/491
67
+ (0, watch_1.default)({
68
+ watchDir: book.getRoot(),
69
+ outputFolder,
70
+ callback: (error, filepath) => {
71
+ if (error) {
72
+ console.error(error);
73
+ return;
74
+ }
75
+ // If the file does not exist in file system, show a warning and skip
76
+ // Probably, the file has been deleted
77
+ if (!fs_1.default.existsSync(filepath)) {
78
+ logger.warn.ok(`${filepath} does not exist in file system.`);
79
+ return;
80
+ }
81
+ // set livereload path
82
+ lrPath = filepath;
83
+ // TODO: use parse extension
84
+ // Incremental update for pages
85
+ if (lastOutput && filepath.endsWith(".md")) {
86
+ logger.warn.ok("Rebuild " + filepath);
87
+ const changedOutput = lastOutput.reloadPage(lastOutput.book.getContentRoot(), filepath).merge({
88
+ incrementalChangeFileSet: immutable_1.default.Set([filepath])
89
+ });
90
+ return incrementalBuild({
91
+ output: changedOutput,
92
+ Generator
93
+ }).then(() => {
94
+ if (lrPath && hasLiveReloading) {
95
+ // trigger livereload
96
+ lrServer.changed({
97
+ body: {
98
+ files: [lrPath]
99
+ }
100
+ });
101
+ }
102
+ });
103
+ }
104
+ // Asciidoc files are not supported for incremental build
105
+ logger.info.ok("Rebuild " + filepath);
106
+ return generateBook({
107
+ book,
108
+ outputFolder,
109
+ hasLiveReloading,
110
+ Generator,
111
+ reload
112
+ }).then((output) => {
113
+ lastOutput = output;
97
114
  });
98
115
  }
99
- // Asciidoc files are not supported for incremental build
100
- logger.info.ok("Rebuild " + filepath);
101
- return generateBook({
102
- book,
103
- outputFolder,
104
- hasLiveReloading,
105
- Generator,
106
- reload
107
- }).then((output) => {
108
- lastOutput = output;
109
- });
110
116
  });
111
117
  });
112
118
  }
@@ -1,10 +1,26 @@
1
+ import { FSWatcher } from "chokidar";
2
+ export interface WatchOptions {
3
+ /**
4
+ * Directory to watch
5
+ */
6
+ watchDir: string;
7
+ /**
8
+ * Callback when a file is modified
9
+ */
10
+ callback: (error: Error | null, filepath?: string) => void;
11
+ /**
12
+ * Output folder to ignore (in addition to _book and node_modules)
13
+ * This prevents infinite rebuild loops when using custom output folders
14
+ * @see https://github.com/honkit/honkit/issues/491
15
+ */
16
+ outputFolder?: string;
17
+ }
1
18
  /**
2
- Watch a folder and resolve promise once a file is modified
3
-
4
- @param {string} dir
5
- @param callback
6
- @return {Promise}
19
+ * Watch a folder and call callback when a file is modified
20
+ *
21
+ * @param {WatchOptions} options
22
+ * @return {FSWatcher} The chokidar watcher instance
7
23
  */
8
- declare function watch(dir: any, callback: any): void;
24
+ declare function watch(options: WatchOptions): FSWatcher;
9
25
  export default watch;
10
26
  //# sourceMappingURL=watch.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"watch.d.ts","sourceRoot":"","sources":["../../src/cli/watch.ts"],"names":[],"mappings":"AAIA;;;;;;GAMG;AAEH,iBAAS,KAAK,CAAC,GAAG,KAAA,EAAE,QAAQ,KAAA,QAwB3B;AAED,eAAe,KAAK,CAAC"}
1
+ {"version":3,"file":"watch.d.ts","sourceRoot":"","sources":["../../src/cli/watch.ts"],"names":[],"mappings":"AACA,OAAiB,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAG/C,MAAM,WAAW,YAAY;IACzB;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB;;OAEG;IACH,QAAQ,EAAE,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,EAAE,QAAQ,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IAC3D;;;;OAIG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;;;;GAKG;AACH,iBAAS,KAAK,CAAC,OAAO,EAAE,YAAY,GAAG,SAAS,CA0C/C;AAED,eAAe,KAAK,CAAC"}