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,115 @@
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 nunjucks_1 = __importDefault(require("nunjucks"));
7
+ const immutable_1 = __importDefault(require("immutable"));
8
+ class TemplateEngine extends immutable_1.default.Record({
9
+ // Map of {TemplateBlock}
10
+ blocks: immutable_1.default.Map(),
11
+ // Map of Extension
12
+ extensions: immutable_1.default.Map(),
13
+ // Map of filters: {string} name -> {Function} fn
14
+ filters: immutable_1.default.Map(),
15
+ // Map of globals: {string} name -> {Mixed}
16
+ globals: immutable_1.default.Map(),
17
+ // Context for filters / blocks
18
+ context: Object(),
19
+ // Nunjucks loader
20
+ loader: new nunjucks_1.default.FileSystemLoader("views"),
21
+ }, "TemplateEngine") {
22
+ getBlocks() {
23
+ return this.get("blocks");
24
+ }
25
+ getGlobals() {
26
+ return this.get("globals");
27
+ }
28
+ getFilters() {
29
+ return this.get("filters");
30
+ }
31
+ getShortcuts() {
32
+ return this.get("shortcuts");
33
+ }
34
+ getLoader() {
35
+ return this.get("loader");
36
+ }
37
+ getContext() {
38
+ return this.get("context");
39
+ }
40
+ getExtensions() {
41
+ return this.get("extensions");
42
+ }
43
+ /**
44
+ Return a block by its name (or undefined)
45
+
46
+ @param {string} name
47
+ @return {TemplateBlock}
48
+ */
49
+ getBlock(name) {
50
+ const blocks = this.getBlocks();
51
+ return blocks.find((block) => {
52
+ return block.getName() === name;
53
+ });
54
+ }
55
+ /**
56
+ Return a nunjucks environment from this configuration
57
+ */
58
+ toNunjucks(blocksOutput) {
59
+ const loader = this.getLoader();
60
+ const blocks = this.getBlocks();
61
+ const filters = this.getFilters();
62
+ const globals = this.getGlobals();
63
+ const extensions = this.getExtensions();
64
+ const context = this.getContext();
65
+ const env = new nunjucks_1.default.Environment(loader, {
66
+ // Escaping is done after by the asciidoc/markdown parser
67
+ autoescape: false,
68
+ // Syntax
69
+ tags: {
70
+ blockStart: "{%",
71
+ blockEnd: "%}",
72
+ variableStart: "{{",
73
+ variableEnd: "}}",
74
+ commentStart: "{###",
75
+ commentEnd: "###}",
76
+ },
77
+ });
78
+ // Add filters
79
+ filters.forEach((filterFn, filterName) => {
80
+ env.addFilter(filterName, filterFn.bind(context));
81
+ });
82
+ // Add blocks
83
+ blocks.forEach((block) => {
84
+ const extName = block.getExtensionName();
85
+ const Ext = block.toNunjucksExt(context, blocksOutput);
86
+ env.addExtension(extName, new Ext());
87
+ });
88
+ // Add globals
89
+ globals.forEach((globalValue, globalName) => {
90
+ env.addGlobal(globalName, globalValue);
91
+ });
92
+ // Add other extensions
93
+ extensions.forEach((ext, extName) => {
94
+ env.addExtension(extName, ext);
95
+ });
96
+ return env;
97
+ }
98
+ /**
99
+ Create a template engine
100
+
101
+ @param {Object} def
102
+ @return {TemplateEngine}
103
+ */
104
+ static create(def) {
105
+ return new TemplateEngine({
106
+ blocks: immutable_1.default.List(def.blocks || []),
107
+ extensions: immutable_1.default.Map(def.extensions || {}),
108
+ filters: immutable_1.default.Map(def.filters || {}),
109
+ globals: immutable_1.default.Map(def.globals || {}),
110
+ context: def.context,
111
+ loader: def.loader,
112
+ });
113
+ }
114
+ }
115
+ exports.default = TemplateEngine;
@@ -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 immutable_1 = __importDefault(require("immutable"));
7
+ class TemplateOutput extends immutable_1.default.Record({
8
+ // Text content of the template
9
+ content: String(),
10
+ // Map of blocks to replace / post process
11
+ blocks: immutable_1.default.Map(),
12
+ }, "TemplateOutput") {
13
+ getContent() {
14
+ return this.get("content");
15
+ }
16
+ getBlocks() {
17
+ return this.get("blocks");
18
+ }
19
+ /**
20
+ * Update content of this output
21
+ */
22
+ setContent(content) {
23
+ return this.set("content", content);
24
+ }
25
+ /**
26
+ * Create a TemplateOutput from a text content
27
+ * and an object containing block definition
28
+ */
29
+ static create(content, blocks) {
30
+ return new TemplateOutput({
31
+ content: content,
32
+ blocks: immutable_1.default.fromJS(blocks),
33
+ });
34
+ }
35
+ }
36
+ exports.default = TemplateOutput;
@@ -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 immutable_1 = __importDefault(require("immutable"));
7
+ /*
8
+ A TemplateShortcut is defined in plugin's template blocks
9
+ to replace content with a templating block using delimiters.
10
+ */
11
+ class TemplateShortcut extends immutable_1.default.Record({
12
+ // List of parser names accepting this shortcut
13
+ parsers: immutable_1.default.Map(),
14
+ start: String(),
15
+ end: String(),
16
+ startTag: String(),
17
+ endTag: String(),
18
+ }, "TemplateShortcut") {
19
+ getStart() {
20
+ return this.get("start");
21
+ }
22
+ getEnd() {
23
+ return this.get("end");
24
+ }
25
+ getStartTag() {
26
+ return this.get("startTag");
27
+ }
28
+ getEndTag() {
29
+ return this.get("endTag");
30
+ }
31
+ getParsers() {
32
+ return this.get("parsers");
33
+ }
34
+ /**
35
+ Test if this shortcut accept a parser
36
+
37
+ @param {Parser|String} parser
38
+ @return {boolean}
39
+ */
40
+ acceptParser(parser) {
41
+ if (typeof parser !== "string") {
42
+ parser = parser.getName();
43
+ }
44
+ const parserNames = this.get("parsers");
45
+ return parserNames.includes(parser);
46
+ }
47
+ /**
48
+ Create a shortcut for a block
49
+
50
+ @param {TemplateBlock} block
51
+ @param {Map} details
52
+ @return {TemplateShortcut}
53
+ */
54
+ static createForBlock(block, details) {
55
+ details = immutable_1.default.fromJS(details);
56
+ return new TemplateShortcut({
57
+ parsers: details.get("parsers"),
58
+ start: details.get("start"),
59
+ end: details.get("end"),
60
+ startTag: block.getName(),
61
+ endTag: block.getEndTag(),
62
+ });
63
+ }
64
+ }
65
+ exports.default = TemplateShortcut;
@@ -0,0 +1,30 @@
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 addPlugin_1 = __importDefault(require("../addPlugin"));
7
+ const config_1 = __importDefault(require("../../../models/config"));
8
+ describe("addPlugin", () => {
9
+ const config = config_1.default.createWithValues({
10
+ plugins: ["hello", "world", "-disabled"],
11
+ });
12
+ test("should have correct state of dependencies", () => {
13
+ const disabledDep = config.getPluginDependency("disabled");
14
+ expect(disabledDep).toBeDefined();
15
+ expect(disabledDep.getVersion()).toEqual("*");
16
+ expect(disabledDep.isEnabled()).toBeFalsy();
17
+ });
18
+ test("should add the plugin to the list", () => {
19
+ // @ts-expect-error ts-migrate(2554) FIXME: Expected 3 arguments, but got 2.
20
+ const newConfig = addPlugin_1.default(config, "test");
21
+ const testDep = newConfig.getPluginDependency("test");
22
+ expect(testDep).toBeDefined();
23
+ expect(testDep.getVersion()).toEqual("*");
24
+ expect(testDep.isEnabled()).toBeTruthy();
25
+ const disabledDep = newConfig.getPluginDependency("disabled");
26
+ expect(disabledDep).toBeDefined();
27
+ expect(disabledDep.getVersion()).toEqual("*");
28
+ expect(disabledDep.isEnabled()).toBeFalsy();
29
+ });
30
+ });
@@ -0,0 +1,29 @@
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 removePlugin_1 = __importDefault(require("../removePlugin"));
7
+ const config_1 = __importDefault(require("../../../models/config"));
8
+ describe("removePlugin", () => {
9
+ const config = config_1.default.createWithValues({
10
+ plugins: ["hello", "world", "-disabled"],
11
+ });
12
+ test("should remove the plugin from the list", () => {
13
+ const newConfig = removePlugin_1.default(config, "hello");
14
+ const testDep = newConfig.getPluginDependency("hello");
15
+ expect(testDep).toBeUndefined();
16
+ });
17
+ test("should remove the disabled plugin from the list", () => {
18
+ const newConfig = removePlugin_1.default(config, "disabled");
19
+ const testDep = newConfig.getPluginDependency("disabled");
20
+ expect(testDep).toBeUndefined();
21
+ });
22
+ test("should disable default plugin", () => {
23
+ const newConfig = removePlugin_1.default(config, "search");
24
+ const disabledDep = newConfig.getPluginDependency("search");
25
+ expect(disabledDep).toBeDefined();
26
+ expect(disabledDep.getVersion()).toEqual("*");
27
+ expect(disabledDep.isEnabled()).toBeFalsy();
28
+ });
29
+ });
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const togglePlugin_1 = __importDefault(require("../togglePlugin"));
7
+ const config_1 = __importDefault(require("../../../models/config"));
8
+ describe("togglePlugin", () => {
9
+ const config = config_1.default.createWithValues({
10
+ plugins: ["hello", "world", "-disabled"],
11
+ });
12
+ test("should enable plugin", () => {
13
+ // @ts-expect-error ts-migrate(2554) FIXME: Expected 3 arguments, but got 2.
14
+ const newConfig = togglePlugin_1.default(config, "disabled");
15
+ const testDep = newConfig.getPluginDependency("disabled");
16
+ expect(testDep).toBeDefined();
17
+ expect(testDep.getVersion()).toEqual("*");
18
+ expect(testDep.isEnabled()).toBeTruthy();
19
+ });
20
+ test("should disable plugin", () => {
21
+ // @ts-expect-error ts-migrate(2554) FIXME: Expected 3 arguments, but got 2.
22
+ const newConfig = togglePlugin_1.default(config, "world");
23
+ const testDep = newConfig.getPluginDependency("world");
24
+ expect(testDep).toBeDefined();
25
+ expect(testDep.getVersion()).toEqual("*");
26
+ expect(testDep.isEnabled()).toBeFalsy();
27
+ });
28
+ });
@@ -0,0 +1,27 @@
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 pluginDependency_1 = __importDefault(require("../../models/pluginDependency"));
7
+ const togglePlugin_1 = __importDefault(require("./togglePlugin"));
8
+ const isDefaultPlugin_1 = __importDefault(require("./isDefaultPlugin"));
9
+ /**
10
+ * Add a plugin to a book's configuration
11
+ * @param {Config} config
12
+ * @param {string} pluginName
13
+ * @param {string} version (optional)
14
+ * @return {Config}
15
+ */
16
+ function addPlugin(config, pluginName, version) {
17
+ // For default plugin, we only ensure it is enabled
18
+ if (isDefaultPlugin_1.default(pluginName, version)) {
19
+ return togglePlugin_1.default(config, pluginName, true);
20
+ }
21
+ let deps = config.getPluginDependencies();
22
+ // @ts-expect-error ts-migrate(2339) FIXME: Property 'create' does not exist on type 'Class'.
23
+ const dep = pluginDependency_1.default.create(pluginName, version);
24
+ deps = deps.push(dep);
25
+ return config.setPluginDependencies(deps);
26
+ }
27
+ exports.default = addPlugin;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /**
4
+ * Edit configuration of a plugin
5
+ * @param {Config} config
6
+ * @param {string} plugin
7
+ * @param {Object} pluginConfig
8
+ * @return {Config}
9
+ */
10
+ function editPlugin(config, pluginName, pluginConfig) {
11
+ return config.setValue(`pluginsConfig.${pluginName}`, pluginConfig);
12
+ }
13
+ exports.default = editPlugin;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /**
4
+ * Return the configuration for a plugin
5
+ * @param {Config} config
6
+ * @param {string} pluginName
7
+ * @return {Object}
8
+ */
9
+ function getPluginConfig(config, pluginName) {
10
+ const pluginsConfig = config.getValues().get("pluginsConfig");
11
+ if (pluginsConfig === undefined) {
12
+ return {};
13
+ }
14
+ const pluginConf = pluginsConfig.get(pluginName);
15
+ if (pluginConf === undefined) {
16
+ return {};
17
+ }
18
+ else {
19
+ return pluginConf.toJS();
20
+ }
21
+ }
22
+ exports.default = getPluginConfig;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ /**
3
+ * Test if a plugin is listed
4
+ * @param { {List<PluginDependency}} deps
5
+ * @param {string} plugin
6
+ * @param {string} version
7
+ * @return {boolean}
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ function hasPlugin(deps, pluginName, version) {
11
+ return !!deps.find((dep) => {
12
+ return dep.getName() === pluginName && (!version || dep.getVersion() === version);
13
+ });
14
+ }
15
+ exports.default = hasPlugin;
@@ -0,0 +1,21 @@
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 addPlugin_1 = __importDefault(require("./addPlugin"));
7
+ const removePlugin_1 = __importDefault(require("./removePlugin"));
8
+ const togglePlugin_1 = __importDefault(require("./togglePlugin"));
9
+ const editPlugin_1 = __importDefault(require("./editPlugin"));
10
+ const hasPlugin_1 = __importDefault(require("./hasPlugin"));
11
+ const getPluginConfig_1 = __importDefault(require("./getPluginConfig"));
12
+ const isDefaultPlugin_1 = __importDefault(require("./isDefaultPlugin"));
13
+ exports.default = {
14
+ addPlugin: addPlugin_1.default,
15
+ removePlugin: removePlugin_1.default,
16
+ togglePlugin: togglePlugin_1.default,
17
+ editPlugin: editPlugin_1.default,
18
+ hasPlugin: hasPlugin_1.default,
19
+ getPluginConfig: getPluginConfig_1.default,
20
+ isDefaultPlugin: isDefaultPlugin_1.default,
21
+ };
@@ -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 defaultPlugins_1 = __importDefault(require("../../constants/defaultPlugins"));
7
+ const hasPlugin_1 = __importDefault(require("./hasPlugin"));
8
+ /**
9
+ * Test if a plugin is a default one
10
+ * @param {string} plugin
11
+ * @param {string} version
12
+ * @return {boolean}
13
+ */
14
+ function isDefaultPlugin(pluginName, version) {
15
+ return hasPlugin_1.default(defaultPlugins_1.default, pluginName, version);
16
+ }
17
+ exports.default = isDefaultPlugin;
@@ -0,0 +1,27 @@
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 togglePlugin_1 = __importDefault(require("./togglePlugin"));
7
+ const isDefaultPlugin_1 = __importDefault(require("./isDefaultPlugin"));
8
+ /**
9
+ * Remove a plugin from a book's configuration
10
+ * @param {Config} config
11
+ * @param {string} plugin
12
+ * @return {Config}
13
+ */
14
+ function removePlugin(config, pluginName) {
15
+ let deps = config.getPluginDependencies();
16
+ // For default plugin, we have to disable it instead of removing from the list
17
+ // @ts-expect-error ts-migrate(2554) FIXME: Expected 2 arguments, but got 1.
18
+ if (isDefaultPlugin_1.default(pluginName)) {
19
+ return togglePlugin_1.default(config, pluginName, false);
20
+ }
21
+ // Remove the dependency from the list
22
+ deps = deps.filterNot((dep) => {
23
+ return dep.getName() === pluginName;
24
+ });
25
+ return config.setPluginDependencies(deps);
26
+ }
27
+ exports.default = removePlugin;