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,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 templateEngine_1 = __importDefault(require("../templateEngine"));
7
+ describe("TemplateBlock", () => {
8
+ describe("create", () => {
9
+ test("must initialize with a list of filters", () => {
10
+ const engine = templateEngine_1.default.create({
11
+ filters: {
12
+ hello: function (name) {
13
+ return `Hello ${name}!`;
14
+ },
15
+ },
16
+ });
17
+ const env = engine.toNunjucks();
18
+ const res = env.renderString('{{ "Luke"|hello }}', {});
19
+ expect(res).toBe("Hello Luke!");
20
+ });
21
+ test("must initialize with a list of globals", () => {
22
+ const engine = templateEngine_1.default.create({
23
+ globals: {
24
+ hello: function (name) {
25
+ return `Hello ${name}!`;
26
+ },
27
+ },
28
+ });
29
+ const env = engine.toNunjucks();
30
+ const res = env.renderString('{{ hello("Luke") }}', {});
31
+ expect(res).toBe("Hello Luke!");
32
+ });
33
+ test("must pass context to filters and blocks", () => {
34
+ const engine = templateEngine_1.default.create({
35
+ filters: {
36
+ hello: function (name) {
37
+ return `Hello ${name} ${this.lastName}!`;
38
+ },
39
+ },
40
+ context: {
41
+ lastName: "Skywalker",
42
+ },
43
+ });
44
+ const env = engine.toNunjucks();
45
+ const res = env.renderString('{{ "Luke"|hello }}', {});
46
+ expect(res).toBe("Hello Luke Skywalker!");
47
+ });
48
+ });
49
+ });
@@ -0,0 +1,312 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const path_1 = __importDefault(require("path"));
7
+ const immutable_1 = __importDefault(require("immutable"));
8
+ const logger_1 = __importDefault(require("../utils/logger"));
9
+ const fs_1 = __importDefault(require("./fs"));
10
+ const config_1 = __importDefault(require("./config"));
11
+ const readme_1 = __importDefault(require("./readme"));
12
+ const summary_1 = __importDefault(require("./summary"));
13
+ const glossary_1 = __importDefault(require("./glossary"));
14
+ const languages_1 = __importDefault(require("./languages"));
15
+ const ignore_1 = __importDefault(require("./ignore"));
16
+ class Book extends immutable_1.default.Record({
17
+ // Logger for outptu message
18
+ // @ts-expect-error ts-migrate(2554) FIXME: Expected 2 arguments, but got 0.
19
+ logger: logger_1.default(),
20
+ // Filesystem binded to the book scope to read files/directories
21
+ fs: new fs_1.default(),
22
+ // Ignore files parser
23
+ ignore: new ignore_1.default(),
24
+ // Structure files
25
+ config: new config_1.default(),
26
+ readme: new readme_1.default(),
27
+ summary: new summary_1.default(),
28
+ glossary: new glossary_1.default(),
29
+ languages: new languages_1.default(),
30
+ // ID of the language for language books
31
+ language: String(),
32
+ // List of children, if multilingual (String -> Book)
33
+ books: immutable_1.default.OrderedMap(),
34
+ }) {
35
+ getLogger() {
36
+ return this.get("logger");
37
+ }
38
+ getFS() {
39
+ return this.get("fs");
40
+ }
41
+ getIgnore() {
42
+ return this.get("ignore");
43
+ }
44
+ getConfig() {
45
+ return this.get("config");
46
+ }
47
+ getReadme() {
48
+ return this.get("readme");
49
+ }
50
+ getSummary() {
51
+ return this.get("summary");
52
+ }
53
+ getGlossary() {
54
+ return this.get("glossary");
55
+ }
56
+ getLanguages() {
57
+ return this.get("languages");
58
+ }
59
+ getBooks() {
60
+ return this.get("books");
61
+ }
62
+ getLanguage() {
63
+ return this.get("language");
64
+ }
65
+ /**
66
+ Return FS instance to access the content
67
+
68
+ @return {FS}
69
+ */
70
+ getContentFS() {
71
+ const fs = this.getFS();
72
+ const config = this.getConfig();
73
+ const rootFolder = config.getValue("root");
74
+ if (rootFolder) {
75
+ return fs_1.default.reduceScope(fs, rootFolder);
76
+ }
77
+ return fs;
78
+ }
79
+ /**
80
+ Return root of the book
81
+
82
+ @return {string}
83
+ */
84
+ getRoot() {
85
+ const fs = this.getFS();
86
+ return fs.getRoot();
87
+ }
88
+ /**
89
+ Return root for content of the book
90
+
91
+ @return {string}
92
+ */
93
+ getContentRoot() {
94
+ const fs = this.getContentFS();
95
+ return fs.getRoot();
96
+ }
97
+ /**
98
+ Check if a file is ignore (should not being parsed, etc)
99
+
100
+ @param {string} ref
101
+ @return {Page|undefined}
102
+ */
103
+ isFileIgnored(filename) {
104
+ const ignore = this.getIgnore();
105
+ const language = this.getLanguage();
106
+ // Ignore is always relative to the root of the main book
107
+ if (language) {
108
+ filename = path_1.default.join(language, filename);
109
+ }
110
+ return ignore.isFileIgnored(filename);
111
+ }
112
+ /**
113
+ Check if a content file is ignore (should not being parsed, etc)
114
+
115
+ @param {string} ref
116
+ @return {Page|undefined}
117
+ */
118
+ isContentFileIgnored(filename) {
119
+ const config = this.getConfig();
120
+ const rootFolder = config.getValue("root");
121
+ if (rootFolder) {
122
+ filename = path_1.default.join(rootFolder, filename);
123
+ }
124
+ return this.isFileIgnored(filename);
125
+ }
126
+ /**
127
+ Is this book the parent of language's books
128
+
129
+ @return {boolean}
130
+ */
131
+ isMultilingual() {
132
+ return this.getLanguages().getCount() > 0;
133
+ }
134
+ /**
135
+ Return true if book is associated to a language
136
+
137
+ @return {boolean}
138
+ */
139
+ isLanguageBook() {
140
+ return Boolean(this.getLanguage());
141
+ }
142
+ /**
143
+ Return a languages book
144
+
145
+ @param {string} language
146
+ @return {Book}
147
+ */
148
+ getLanguageBook(language) {
149
+ const books = this.getBooks();
150
+ return books.get(language);
151
+ }
152
+ /**
153
+ Add a new language book
154
+
155
+ @param {string} language
156
+ @param {Book} book
157
+ @return {Book}
158
+ */
159
+ addLanguageBook(language, book) {
160
+ let books = this.getBooks();
161
+ books = books.set(language, book);
162
+ return this.set("books", books);
163
+ }
164
+ /**
165
+ Set the summary for this book
166
+
167
+ @param {Summary}
168
+ @return {Book}
169
+ */
170
+ setSummary(summary) {
171
+ return this.set("summary", summary);
172
+ }
173
+ /**
174
+ Set the readme for this book
175
+
176
+ @param {Readme}
177
+ @return {Book}
178
+ */
179
+ setReadme(readme) {
180
+ return this.set("readme", readme);
181
+ }
182
+ /**
183
+ Set the configuration for this book
184
+
185
+ @param {Config}
186
+ @return {Book}
187
+ */
188
+ setConfig(config) {
189
+ return this.set("config", config);
190
+ }
191
+ /**
192
+ Set the ignore instance for this book
193
+
194
+ @param {Ignore}
195
+ @return {Book}
196
+ */
197
+ setIgnore(ignore) {
198
+ return this.set("ignore", ignore);
199
+ }
200
+ /**
201
+ Change log level
202
+
203
+ @param {string} level
204
+ @return {Book}
205
+ */
206
+ setLogLevel(level) {
207
+ this.getLogger().setLevel(level);
208
+ return this;
209
+ }
210
+ /**
211
+ Create a book using a filesystem
212
+
213
+ @param {FS} fs
214
+ @return {Book}
215
+ */
216
+ static createForFS(fs) {
217
+ return new Book({
218
+ fs: fs,
219
+ });
220
+ }
221
+ /**
222
+ Infers the default extension for files
223
+ @return {string}
224
+ */
225
+ getDefaultExt() {
226
+ // Inferring sources
227
+ const clues = [this.getReadme(), this.getSummary(), this.getGlossary()];
228
+ // List their extensions
229
+ const exts = clues.map((clue) => {
230
+ const file = clue.getFile();
231
+ if (file.exists()) {
232
+ return file.getParser().getExtensions().first();
233
+ }
234
+ else {
235
+ return null;
236
+ }
237
+ });
238
+ // Adds the general default extension
239
+ exts.push(".md");
240
+ // Choose the first non null
241
+ return exts.find((e) => {
242
+ return e !== null;
243
+ });
244
+ }
245
+ /**
246
+ Infer the default path for a Readme.
247
+ @param {boolean} [absolute=false] False for a path relative to
248
+ this book's content root
249
+ @return {string}
250
+ */
251
+ getDefaultReadmePath(absolute) {
252
+ const defaultPath = `README${this.getDefaultExt()}`;
253
+ if (absolute) {
254
+ return path_1.default.join(this.getContentRoot(), defaultPath);
255
+ }
256
+ else {
257
+ return defaultPath;
258
+ }
259
+ }
260
+ /**
261
+ Infer the default path for a Summary.
262
+ @param {boolean} [absolute=false] False for a path relative to
263
+ this book's content root
264
+ @return {string}
265
+ */
266
+ getDefaultSummaryPath(absolute) {
267
+ const defaultPath = `SUMMARY${this.getDefaultExt()}`;
268
+ if (absolute) {
269
+ return path_1.default.join(this.getContentRoot(), defaultPath);
270
+ }
271
+ else {
272
+ return defaultPath;
273
+ }
274
+ }
275
+ /**
276
+ Infer the default path for a Glossary.
277
+ @param {boolean} [absolute=false] False for a path relative to
278
+ this book's content root
279
+ @return {string}
280
+ */
281
+ getDefaultGlossaryPath(absolute) {
282
+ const defaultPath = `GLOSSARY${this.getDefaultExt()}`;
283
+ if (absolute) {
284
+ return path_1.default.join(this.getContentRoot(), defaultPath);
285
+ }
286
+ else {
287
+ return defaultPath;
288
+ }
289
+ }
290
+ /**
291
+ Create a language book from a parent
292
+
293
+ @param {Book} parent
294
+ @param {string} language
295
+ @return {Book}
296
+ */
297
+ static createFromParent(parent, language) {
298
+ const ignore = parent.getIgnore();
299
+ let config = parent.getConfig();
300
+ // Set language in configuration
301
+ config = config.setValue("language", language);
302
+ return new Book({
303
+ // Inherits config. logegr and list of ignored files
304
+ logger: parent.getLogger(),
305
+ config: config,
306
+ ignore: ignore,
307
+ language: language,
308
+ fs: fs_1.default.reduceScope(parent.getContentFS(), language),
309
+ });
310
+ }
311
+ }
312
+ exports.default = Book;
@@ -0,0 +1,152 @@
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 file_1 = __importDefault(require("./file"));
8
+ const pluginDependency_1 = __importDefault(require("./pluginDependency"));
9
+ const configDefault_1 = __importDefault(require("../constants/configDefault"));
10
+ const reducedObject_1 = __importDefault(require("../utils/reducedObject"));
11
+ class Config extends immutable_1.default.Record({
12
+ file: new file_1.default(),
13
+ values: configDefault_1.default,
14
+ }, "Config") {
15
+ getFile() {
16
+ return this.get("file");
17
+ }
18
+ getValues() {
19
+ return this.get("values");
20
+ }
21
+ /**
22
+ * Return minimum version of configuration,
23
+ * Basically it returns the current config minus the default one
24
+ * @return {Map}
25
+ */
26
+ toReducedVersion() {
27
+ return reducedObject_1.default(configDefault_1.default, this.getValues());
28
+ }
29
+ /**
30
+ * Render config as text
31
+ * @return {Promise<String>}
32
+ */
33
+ toText() {
34
+ return JSON.stringify(this.toReducedVersion().toJS(), null, 4);
35
+ }
36
+ /**
37
+ * Change the file for the configuration
38
+ * @param {File} file
39
+ * @return {Config}
40
+ */
41
+ setFile(file) {
42
+ return this.set("file", file);
43
+ }
44
+ /**
45
+ * Return a configuration value by its key path
46
+ */
47
+ getValue(keyPath, def) {
48
+ const values = this.getValues();
49
+ keyPath = Config.keyToKeyPath(keyPath);
50
+ if (!values.hasIn(keyPath)) {
51
+ return immutable_1.default.fromJS(def);
52
+ }
53
+ return values.getIn(keyPath);
54
+ }
55
+ /**
56
+ * Update a configuration value
57
+ * @return {Config}
58
+ */
59
+ setValue(keyPath, value) {
60
+ keyPath = Config.keyToKeyPath(keyPath);
61
+ value = immutable_1.default.fromJS(value);
62
+ let values = this.getValues();
63
+ values = values.setIn(keyPath, value);
64
+ return this.set("values", values);
65
+ }
66
+ /**
67
+ * Return a list of plugin dependencies
68
+ * @return {List<PluginDependency>}
69
+ */
70
+ getPluginDependencies() {
71
+ const plugins = this.getValue("plugins");
72
+ if (typeof plugins === "string") {
73
+ return pluginDependency_1.default.listFromString(plugins);
74
+ }
75
+ else {
76
+ return pluginDependency_1.default.listFromArray(plugins);
77
+ }
78
+ }
79
+ /**
80
+ * Return a plugin dependency by its name
81
+ * @param {string} name
82
+ * @return {PluginDependency}
83
+ */
84
+ getPluginDependency(name) {
85
+ const plugins = this.getPluginDependencies();
86
+ return plugins.find((dep) => {
87
+ return dep.getName() === name;
88
+ });
89
+ }
90
+ /**
91
+ * Update the list of plugins dependencies
92
+ * @param {List<PluginDependency>}
93
+ * @return {Config}
94
+ */
95
+ setPluginDependencies(deps) {
96
+ const plugins = pluginDependency_1.default.listToArray(deps);
97
+ return this.setValue("plugins", plugins);
98
+ }
99
+ /**
100
+ * Update values for an existing configuration
101
+ * @param {Object} values
102
+ * @returns {Config}
103
+ */
104
+ updateValues(values) {
105
+ values = immutable_1.default.fromJS(values);
106
+ return this.set("values", values);
107
+ }
108
+ /**
109
+ * Update values for an existing configuration
110
+ * @param {Config} config
111
+ * @param {Object} values
112
+ * @returns {Config}
113
+ */
114
+ mergeValues(values) {
115
+ let currentValues = this.getValues();
116
+ values = immutable_1.default.fromJS(values);
117
+ currentValues = currentValues.mergeDeep(values);
118
+ return this.set("values", currentValues);
119
+ }
120
+ /**
121
+ * Create a new config for a file
122
+ * @param {File} file
123
+ * @param {Object} values
124
+ * @returns {Config}
125
+ */
126
+ static create(file, values) {
127
+ return new Config({
128
+ file: file,
129
+ values: immutable_1.default.fromJS(values),
130
+ });
131
+ }
132
+ /**
133
+ * Create a new config
134
+ * @param {Object} values
135
+ * @returns {Config}
136
+ */
137
+ static createWithValues(values) {
138
+ return new Config({
139
+ values: immutable_1.default.fromJS(values),
140
+ });
141
+ }
142
+ /**
143
+ * Convert a keyPath to an array of keys
144
+ */
145
+ static keyToKeyPath(keyPath) {
146
+ if (typeof keyPath === "string") {
147
+ return keyPath.split(".");
148
+ }
149
+ return keyPath;
150
+ }
151
+ }
152
+ exports.default = Config;