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,87 @@
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 read_installed_1 = __importDefault(require("read-installed"));
7
+ const immutable_1 = __importDefault(require("immutable"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const promise_1 = __importDefault(require("../utils/promise"));
10
+ const fs_1 = __importDefault(require("../utils/fs"));
11
+ const plugin_1 = __importDefault(require("../models/plugin"));
12
+ const pluginPrefix_1 = __importDefault(require("../constants/pluginPrefix"));
13
+ /**
14
+ * Validate if a package name is a GitBook/HonKit plugin
15
+ *
16
+ * @return {boolean}
17
+ */
18
+ function validateId(name) {
19
+ return name && name.indexOf(pluginPrefix_1.default) === 0;
20
+ }
21
+ /**
22
+ * List all packages installed inside a folder
23
+ *
24
+ * @param {string} folder
25
+ * @return {OrderedMap<String:Plugin>}
26
+ */
27
+ function findInstalled(folder) {
28
+ const options = {
29
+ dev: false,
30
+ log: function () { },
31
+ depth: 4,
32
+ };
33
+ let results = immutable_1.default.OrderedMap();
34
+ function onPackage(pkg, parent) {
35
+ if (!pkg.name)
36
+ return;
37
+ const name = pkg.name;
38
+ const version = pkg.version;
39
+ const pkgPath = pkg.realPath;
40
+ const depth = pkg.depth;
41
+ const dependencies = pkg.dependencies;
42
+ const pluginName = name.slice(pluginPrefix_1.default.length);
43
+ if (!validateId(name)) {
44
+ if (parent)
45
+ return;
46
+ }
47
+ else {
48
+ results = results.set(pluginName, new plugin_1.default({
49
+ name: pluginName,
50
+ version: version,
51
+ path: pkgPath,
52
+ depth: depth,
53
+ parent: parent,
54
+ }));
55
+ }
56
+ immutable_1.default.Map(dependencies).forEach((dep) => {
57
+ onPackage(dep, pluginName);
58
+ });
59
+ }
60
+ // Search for gitbook-plugins in node_modules folder
61
+ const node_modules = path_1.default.join(folder, "node_modules");
62
+ // List all folders in node_modules
63
+ return fs_1.default
64
+ .readdir(node_modules)
65
+ .fail(() => {
66
+ return promise_1.default([]);
67
+ })
68
+ .then((modules) => {
69
+ return promise_1.default.serie(modules, (module) => {
70
+ // Not a gitbook-plugin
71
+ if (!validateId(module)) {
72
+ return promise_1.default();
73
+ }
74
+ // Read gitbook-plugin package details
75
+ const module_folder = path_1.default.join(node_modules, module);
76
+ return promise_1.default.nfcall(read_installed_1.default, module_folder, options).then((data) => {
77
+ // @ts-expect-error ts-migrate(2554) FIXME: Expected 2 arguments, but got 1.
78
+ onPackage(data);
79
+ });
80
+ });
81
+ })
82
+ .then(() => {
83
+ // Return installed plugins
84
+ return results;
85
+ });
86
+ }
87
+ exports.default = findInstalled;
@@ -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 loadForBook_1 = __importDefault(require("./loadForBook"));
7
+ const validateConfig_1 = __importDefault(require("./validateConfig"));
8
+ const listResources_1 = __importDefault(require("./listResources"));
9
+ const listBlocks_1 = __importDefault(require("./listBlocks"));
10
+ const listFilters_1 = __importDefault(require("./listFilters"));
11
+ exports.default = {
12
+ loadForBook: loadForBook_1.default,
13
+ validateConfig: validateConfig_1.default,
14
+ listResources: listResources_1.default,
15
+ listBlocks: listBlocks_1.default,
16
+ listFilters: listFilters_1.default,
17
+ };
@@ -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 immutable_1 = __importDefault(require("immutable"));
7
+ /**
8
+ List blocks from a list of plugins
9
+
10
+ @param {OrderedMap<String:Plugin>}
11
+ @return {Map<String:TemplateBlock>}
12
+ */
13
+ function listBlocks(plugins) {
14
+ return plugins.reverse().reduce((result, plugin) => {
15
+ const blocks = plugin.getBlocks();
16
+ return result.merge(blocks);
17
+ }, immutable_1.default.Map());
18
+ }
19
+ exports.default = listBlocks;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const defaultPlugins_1 = __importDefault(require("../constants/defaultPlugins"));
7
+ const sortDependencies_1 = __importDefault(require("./sortDependencies"));
8
+ /**
9
+ * List all dependencies for a book, including default plugins.
10
+ * It returns a concat with default plugins and remove disabled ones.
11
+ *
12
+ * @param {List<PluginDependency>} deps
13
+ * @return {List<PluginDependency>}
14
+ */
15
+ function listDependencies(deps) {
16
+ // Extract list of plugins to disable (starting with -)
17
+ const toRemove = deps
18
+ .filter((plugin) => {
19
+ return !plugin.isEnabled();
20
+ })
21
+ .map((plugin) => {
22
+ return plugin.getName();
23
+ });
24
+ // Concat with default plugins
25
+ deps = deps.concat(defaultPlugins_1.default);
26
+ // Remove plugins
27
+ deps = deps.filterNot((plugin) => {
28
+ return toRemove.includes(plugin.getName());
29
+ });
30
+ // Sort
31
+ return sortDependencies_1.default(deps);
32
+ }
33
+ exports.default = listDependencies;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const listDependencies_1 = __importDefault(require("./listDependencies"));
7
+ /**
8
+ * List all plugin requirements for a book.
9
+ * It can be different from the final list of plugins,
10
+ * since plugins can have their own dependencies
11
+ *
12
+ * @param {Book}
13
+ * @return {List<PluginDependency>}
14
+ */
15
+ function listDepsForBook(book) {
16
+ const config = book.getConfig();
17
+ const plugins = config.getPluginDependencies();
18
+ return listDependencies_1.default(plugins);
19
+ }
20
+ exports.default = listDepsForBook;
@@ -0,0 +1,18 @@
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
+ List filters from a list of plugins
9
+
10
+ @param {OrderedMap<String:Plugin>}
11
+ @return {Map<String:Function>}
12
+ */
13
+ function listFilters(plugins) {
14
+ return plugins.reverse().reduce((result, plugin) => {
15
+ return result.merge(plugin.getFilters());
16
+ }, immutable_1.default.Map());
17
+ }
18
+ exports.default = listFilters;
@@ -0,0 +1,44 @@
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 path_1 = __importDefault(require("path"));
8
+ const location_1 = __importDefault(require("../utils/location"));
9
+ const pluginResources_1 = __importDefault(require("../constants/pluginResources"));
10
+ /**
11
+ List all resources from a list of plugins
12
+
13
+ @param {OrderedMap<String:Plugin>}
14
+ @param {string} type
15
+ @return {Map<String:List<{url, path}>}
16
+ */
17
+ function listResources(plugins, resources) {
18
+ return plugins.reduce((result, plugin) => {
19
+ const npmId = plugin.getNpmID();
20
+ const pluginResources = resources.get(plugin.getName());
21
+ pluginResources_1.default.forEach((resourceType) => {
22
+ let assets = pluginResources.get(resourceType);
23
+ if (!assets)
24
+ return;
25
+ let list = result.get(resourceType) || immutable_1.default.List();
26
+ assets = assets.map((assetFile) => {
27
+ if (location_1.default.isExternal(assetFile)) {
28
+ return {
29
+ url: assetFile,
30
+ };
31
+ }
32
+ else {
33
+ return {
34
+ path: location_1.default.normalize(path_1.default.join(npmId, assetFile)),
35
+ };
36
+ }
37
+ });
38
+ list = list.concat(assets);
39
+ result = result.set(resourceType, list);
40
+ });
41
+ return result;
42
+ }, immutable_1.default.Map());
43
+ }
44
+ exports.default = listResources;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const listDepsForBook_1 = __importDefault(require("./listDepsForBook"));
7
+ const loadPlugin_1 = require("./loadPlugin");
8
+ const PluginResolver_1 = require("./PluginResolver");
9
+ /**
10
+ * Load all plugins in a book
11
+ *
12
+ * @param {Book}
13
+ * @return {Promise<Map<String:Plugin>}
14
+ */
15
+ function loadForBook(book) {
16
+ const logger = book.getLogger();
17
+ // List the dependencies are defined in book.js
18
+ /**
19
+ * @type {List<PluginDependency>}
20
+ */
21
+ const requirements = listDepsForBook_1.default(book);
22
+ const pluginResolver = new PluginResolver_1.PluginResolver();
23
+ const installedPlugins = requirements.map((dep) => {
24
+ const name = dep.getName();
25
+ return dep.merge({
26
+ path: pluginResolver.resolvePluginPackageName(name),
27
+ });
28
+ });
29
+ // Log state
30
+ logger.info.ln(`${installedPlugins.size} plugins are installed`);
31
+ if (requirements.size !== installedPlugins.length) {
32
+ logger.info.ln(`${requirements.size} explicitly listed`);
33
+ }
34
+ return Promise.all(installedPlugins.map((plugin) => {
35
+ return loadPlugin_1.loadPlugin(book, plugin);
36
+ }));
37
+ }
38
+ exports.default = loadForBook;
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.loadPlugin = void 0;
7
+ const path_1 = __importDefault(require("path"));
8
+ const resolve_1 = __importDefault(require("resolve"));
9
+ const immutable_1 = __importDefault(require("immutable"));
10
+ const promise_1 = __importDefault(require("../utils/promise"));
11
+ const error_1 = __importDefault(require("../utils/error"));
12
+ const timing_1 = __importDefault(require("../utils/timing"));
13
+ const validatePlugin_1 = __importDefault(require("./validatePlugin"));
14
+ const plugin_1 = __importDefault(require("../models/plugin"));
15
+ // Return true if an error is a "module not found"
16
+ // Wait on https://github.com/substack/node-resolve/pull/81 to be merged
17
+ function isModuleNotFound(err) {
18
+ return err.code == "MODULE_NOT_FOUND" || err.message.indexOf("Cannot find module") >= 0;
19
+ }
20
+ /**
21
+ Load a plugin in a book
22
+
23
+ @param {Book} book
24
+ @param {PluginDependency[]} plugin
25
+ @param {string} pkgPath (optional)
26
+ @return {Promise<Plugin>}
27
+ */
28
+ function loadPlugin(book, plugin) {
29
+ const logger = book.getLogger();
30
+ const name = plugin.getName();
31
+ let pkgPath = plugin.getPath();
32
+ // Try loading plugins from different location
33
+ let p = promise_1.default()
34
+ .then(() => {
35
+ let packageContent;
36
+ let packageMain;
37
+ let content;
38
+ // Locate plugin and load package.json
39
+ try {
40
+ const res = resolve_1.default.sync("./package.json", { basedir: pkgPath });
41
+ pkgPath = path_1.default.dirname(res);
42
+ packageContent = require(res);
43
+ }
44
+ catch (err) {
45
+ if (!isModuleNotFound(err))
46
+ throw err;
47
+ packageContent = undefined;
48
+ content = undefined;
49
+ return;
50
+ }
51
+ // Locate the main package
52
+ try {
53
+ const indexJs = path_1.default.normalize(packageContent.main || "index.js");
54
+ packageMain = resolve_1.default.sync(`./${indexJs}`, { basedir: pkgPath });
55
+ }
56
+ catch (err) {
57
+ if (!isModuleNotFound(err))
58
+ throw err;
59
+ packageMain = undefined;
60
+ }
61
+ // Load plugin JS content
62
+ if (packageMain) {
63
+ try {
64
+ content = require(packageMain);
65
+ }
66
+ catch (err) {
67
+ throw new error_1.default.PluginError(err, {
68
+ plugin: name,
69
+ });
70
+ }
71
+ }
72
+ // Update plugin
73
+ return new plugin_1.default({
74
+ name: name,
75
+ version: packageContent.version || "*",
76
+ path: pkgPath,
77
+ package: immutable_1.default.fromJS(packageContent),
78
+ content: immutable_1.default.fromJS(content || {}),
79
+ });
80
+ })
81
+ .then((plugin) => validatePlugin_1.default(plugin))
82
+ .then((plugin) => {
83
+ logger.info(`plugin "${plugin.get("name")}" is loaded\n`);
84
+ return plugin;
85
+ });
86
+ p = timing_1.default.measure("plugin.load", p);
87
+ return p;
88
+ }
89
+ exports.loadPlugin = loadPlugin;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.removePrefixFromPackageName = exports.createFullPackageName = void 0;
4
+ /**
5
+ * Remove `prefix` from `text`.
6
+ */
7
+ const removePrefixFromPackageName = (prefixList, packageName) => {
8
+ for (let i = 0; i < prefixList.length; i++) {
9
+ const prefix = prefixList[i];
10
+ // @scope/name -> @scope/name
11
+ // @scope/textlint-rule-name -> @scope/name
12
+ if (packageName.charAt(0) === "@") {
13
+ const [namespace, name] = packageName.split("/");
14
+ if (name.startsWith(prefix)) {
15
+ return `${namespace}/${name.slice(prefix.length)}`;
16
+ }
17
+ }
18
+ // name -> name
19
+ // textlint-rule-name -> name
20
+ else if (packageName.startsWith(prefix)) {
21
+ return packageName.slice(prefix.length);
22
+ }
23
+ }
24
+ // No match
25
+ return packageName;
26
+ };
27
+ exports.removePrefixFromPackageName = removePrefixFromPackageName;
28
+ /**
29
+ * Create full package name and return
30
+ * @param {string} prefix
31
+ * @param {string} name
32
+ * @returns {string}
33
+ */
34
+ const createFullPackageName = (prefix, name) => {
35
+ if (name.charAt(0) === "@") {
36
+ const scopedPackageNameRegex = new RegExp(`^${prefix}(-|$)`);
37
+ // if @scope/<name> -> @scope/<prefix><name>
38
+ if (!scopedPackageNameRegex.test(name.split("/")[1])) {
39
+ /*
40
+ * for scoped packages, insert the textlint-rule after the first / unless
41
+ * the path is already @scope/<name> or @scope/textlint-rule-<name>
42
+ */
43
+ return name.replace(/^@([^/]+)\/(.*)$/, `@$1/${prefix}$2`);
44
+ }
45
+ }
46
+ return `${prefix}${name}`;
47
+ };
48
+ exports.createFullPackageName = createFullPackageName;
@@ -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 immutable_1 = __importDefault(require("immutable"));
7
+ const themePrefix_1 = __importDefault(require("../constants/themePrefix"));
8
+ const TYPE_PLUGIN = "plugin";
9
+ const TYPE_THEME = "theme";
10
+ /**
11
+ * Returns the type of a plugin given its name
12
+ * @param {Plugin} plugin
13
+ * @return {string}
14
+ */
15
+ function pluginType(plugin) {
16
+ const name = plugin.getName();
17
+ return name && name.indexOf(themePrefix_1.default) === 0 ? TYPE_THEME : TYPE_PLUGIN;
18
+ }
19
+ /**
20
+ * Sort the list of dependencies to match list in book.json
21
+ * The themes should always be loaded after the plugins
22
+ *
23
+ * @param {List<PluginDependency>} deps
24
+ * @return {List<PluginDependency>}
25
+ */
26
+ function sortDependencies(plugins) {
27
+ const byTypes = plugins.groupBy(pluginType);
28
+ return byTypes.get(TYPE_PLUGIN, immutable_1.default.List()).concat(byTypes.get(TYPE_THEME, immutable_1.default.List()));
29
+ }
30
+ exports.default = sortDependencies;