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,102 @@
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 promise_1 = __importDefault(require("../utils/promise"));
8
+ class Parser extends immutable_1.default.Record({
9
+ name: String(),
10
+ // List of extensions that can be processed using this parser
11
+ extensions: immutable_1.default.List(),
12
+ // Parsing functions
13
+ readme: Function(),
14
+ langs: Function(),
15
+ summary: Function(),
16
+ glossary: Function(),
17
+ page: Function(),
18
+ inline: Function(),
19
+ }) {
20
+ getName() {
21
+ return this.get("name");
22
+ }
23
+ getExtensions() {
24
+ return this.get("extensions");
25
+ }
26
+ // PARSE
27
+ parseReadme(content) {
28
+ const readme = this.get("readme");
29
+ return promise_1.default(readme(content));
30
+ }
31
+ parseSummary(content) {
32
+ const summary = this.get("summary");
33
+ return promise_1.default(summary(content));
34
+ }
35
+ parseGlossary(content) {
36
+ const glossary = this.get("glossary");
37
+ return promise_1.default(glossary(content));
38
+ }
39
+ preparePage(content) {
40
+ const page = this.get("page");
41
+ if (!page.prepare) {
42
+ return promise_1.default(content);
43
+ }
44
+ return promise_1.default(page.prepare(content));
45
+ }
46
+ parsePage(content) {
47
+ const page = this.get("page");
48
+ return promise_1.default(page(content));
49
+ }
50
+ parseInline(content) {
51
+ const inline = this.get("inline");
52
+ return promise_1.default(inline(content));
53
+ }
54
+ parseLanguages(content) {
55
+ const langs = this.get("langs");
56
+ return promise_1.default(langs(content));
57
+ }
58
+ // TO TEXT
59
+ renderLanguages(content) {
60
+ const langs = this.get("langs");
61
+ return promise_1.default(langs.toText(content));
62
+ }
63
+ renderSummary(content) {
64
+ const summary = this.get("summary");
65
+ return promise_1.default(summary.toText(content));
66
+ }
67
+ renderGlossary(content) {
68
+ const glossary = this.get("glossary");
69
+ return promise_1.default(glossary.toText(content));
70
+ }
71
+ /**
72
+ Test if this parser matches an extension
73
+
74
+ @param {string} ext
75
+ @return {boolean}
76
+ */
77
+ matchExtension(ext) {
78
+ const exts = this.getExtensions();
79
+ return exts.includes(ext.toLowerCase());
80
+ }
81
+ /**
82
+ Create a new parser using a module (gitbook-markdown, etc)
83
+
84
+ @param {string} name
85
+ @param {Array<String>} extensions
86
+ @param {Object} module
87
+ @return {Parser}
88
+ */
89
+ static create(name, extensions, module) {
90
+ return new Parser({
91
+ name: name,
92
+ extensions: immutable_1.default.List(extensions),
93
+ readme: module.readme,
94
+ langs: module.langs,
95
+ summary: module.summary,
96
+ glossary: module.glossary,
97
+ page: module.page,
98
+ inline: module.inline,
99
+ });
100
+ }
101
+ }
102
+ exports.default = Parser;
@@ -0,0 +1,139 @@
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 templateBlock_1 = __importDefault(require("./templateBlock"));
8
+ const pluginDependency_1 = __importDefault(require("./pluginDependency"));
9
+ const themePrefix_1 = __importDefault(require("../constants/themePrefix"));
10
+ const DEFAULT_VERSION = "*";
11
+ class Plugin extends immutable_1.default.Record({
12
+ name: String(),
13
+ // Requirement version (ex: ">1.0.0")
14
+ version: String(DEFAULT_VERSION),
15
+ // Path to load this plugin
16
+ path: String(),
17
+ // Depth of this plugin in the dependency tree
18
+ depth: Number(0),
19
+ // Parent depending on this plugin
20
+ parent: String(),
21
+ // Content of the "package.json"
22
+ package: immutable_1.default.Map(),
23
+ // Content of the package itself
24
+ content: immutable_1.default.Map(),
25
+ }, "Plugin") {
26
+ getName() {
27
+ return this.get("name");
28
+ }
29
+ getPath() {
30
+ return this.get("path");
31
+ }
32
+ getVersion() {
33
+ return this.get("version");
34
+ }
35
+ getPackage() {
36
+ return this.get("package");
37
+ }
38
+ getContent() {
39
+ return this.get("content");
40
+ }
41
+ getDepth() {
42
+ return this.get("depth");
43
+ }
44
+ getParent() {
45
+ return this.get("parent");
46
+ }
47
+ /**
48
+ * Return the ID on NPM for this plugin
49
+ * @return {string}
50
+ */
51
+ getNpmID() {
52
+ return pluginDependency_1.default.nameToNpmID(this.getName());
53
+ }
54
+ /**
55
+ * Check if a plugin is loaded
56
+ * @return {boolean}
57
+ */
58
+ isLoaded() {
59
+ return Boolean(this.getPackage().size > 0);
60
+ }
61
+ /**
62
+ * Check if a plugin is a theme given its name
63
+ * @return {boolean}
64
+ */
65
+ isTheme() {
66
+ const name = this.getName();
67
+ return name && name.indexOf(themePrefix_1.default) === 0;
68
+ }
69
+ /**
70
+ * Return map of hooks
71
+ */
72
+ getHooks() {
73
+ return this.getContent().get("hooks") || immutable_1.default.Map();
74
+ }
75
+ /**
76
+ * Return infos about resources for a specific type
77
+ * @param {string} type
78
+ * @return {Map<String:Mixed>}
79
+ */
80
+ getResources(type) {
81
+ if (type != "website" && type != "ebook") {
82
+ throw new Error(`Invalid assets type ${type}`);
83
+ }
84
+ const content = this.getContent();
85
+ return content.get(type) || (type == "website" ? content.get("book") : null) || immutable_1.default.Map();
86
+ }
87
+ /**
88
+ * Return map of filters
89
+ * @return {Map<String:Function>}
90
+ */
91
+ getFilters() {
92
+ return this.getContent().get("filters");
93
+ }
94
+ /**
95
+ * Return map of blocks
96
+ * @return {Map<String:TemplateBlock>}
97
+ */
98
+ getBlocks() {
99
+ let blocks = this.getContent().get("blocks");
100
+ blocks = blocks || immutable_1.default.Map();
101
+ return blocks.map((block, blockName) => {
102
+ return templateBlock_1.default.create(blockName, block);
103
+ });
104
+ }
105
+ /**
106
+ * Return a specific hook
107
+ * @param {string} name
108
+ * @return {Function|undefined}
109
+ */
110
+ getHook(name) {
111
+ return this.getHooks().get(name);
112
+ }
113
+ /**
114
+ * Create a plugin from a string
115
+ * @param {string}
116
+ * @return {Plugin}
117
+ */
118
+ static createFromString(s) {
119
+ const parts = s.split("@");
120
+ const name = parts[0];
121
+ const version = parts.slice(1).join("@");
122
+ return new Plugin({
123
+ name: name,
124
+ version: version || DEFAULT_VERSION,
125
+ });
126
+ }
127
+ /**
128
+ * Create a plugin from a dependency
129
+ * @return {Plugin}
130
+ */
131
+ static createFromDep(dep) {
132
+ return new Plugin({
133
+ name: dep.getName(),
134
+ version: dep.getVersion(),
135
+ });
136
+ }
137
+ }
138
+ Plugin.nameToNpmID = pluginDependency_1.default.nameToNpmID;
139
+ exports.default = Plugin;
@@ -0,0 +1,192 @@
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 is_1 = __importDefault(require("is"));
7
+ const semver_1 = __importDefault(require("semver"));
8
+ const immutable_1 = __importDefault(require("immutable"));
9
+ const pluginPrefix_1 = __importDefault(require("../constants/pluginPrefix"));
10
+ const DEFAULT_VERSION = "*";
11
+ /*
12
+ * PluginDependency represents the informations about a plugin
13
+ * stored in config.plugins
14
+ */
15
+ class PluginDependency extends immutable_1.default.Record({
16
+ name: String(),
17
+ // Requirement version (ex: ">1.0.0")
18
+ version: String(DEFAULT_VERSION),
19
+ // path to package
20
+ path: String(),
21
+ // Is this plugin enabled or disabled?
22
+ enabled: Boolean(true),
23
+ }, "PluginDependency") {
24
+ getName() {
25
+ return this.get("name");
26
+ }
27
+ getVersion() {
28
+ return this.get("version");
29
+ }
30
+ getPath() {
31
+ return this.get("path");
32
+ }
33
+ isEnabled() {
34
+ return this.get("enabled");
35
+ }
36
+ /**
37
+ * Toggle this plugin state
38
+ * @return {PluginDependency}
39
+ */
40
+ toggle(state) {
41
+ if (state === undefined) {
42
+ state = !this.isEnabled();
43
+ }
44
+ return this.set("enabled", state);
45
+ }
46
+ /**
47
+ * Return NPM ID for the dependency
48
+ * @return {string}
49
+ */
50
+ getNpmID() {
51
+ return PluginDependency.nameToNpmID(this.getName());
52
+ }
53
+ /**
54
+ * Is the plugin using a git dependency
55
+ * @return {boolean}
56
+ */
57
+ isGitDependency() {
58
+ return !semver_1.default.validRange(this.getVersion());
59
+ }
60
+ /**
61
+ * Create a plugin with a name and a plugin
62
+ * @param {string}
63
+ * @return {Plugin|undefined}
64
+ */
65
+ static create(name, version, enabled) {
66
+ if (is_1.default.undefined(enabled)) {
67
+ enabled = true;
68
+ }
69
+ return new PluginDependency({
70
+ name: name,
71
+ version: version || DEFAULT_VERSION,
72
+ enabled: Boolean(enabled),
73
+ });
74
+ }
75
+ /**
76
+ * Create a plugin from a string
77
+ * @param {string} s
78
+ * @return {Plugin|undefined}
79
+ */
80
+ static createFromString(s) {
81
+ /*
82
+ HonKit will support following format
83
+ pkg
84
+ @scope/pkg
85
+ -pkg - Disable package
86
+ -@scope/pkg - Disable package
87
+ */
88
+ const packagePattern = /^(?<disabled>-)?(?<name>.+)$/;
89
+ const scopedPackagePattern = /^(?<disabled>-)?(?<name>@[^/]+\/.+)$/;
90
+ if (packagePattern.test(s) && !s.includes("@")) {
91
+ const match = s.match(packagePattern);
92
+ const enabled = !match.groups.disabled;
93
+ return new PluginDependency({
94
+ name: match.groups.name,
95
+ version: DEFAULT_VERSION,
96
+ enabled: enabled,
97
+ });
98
+ }
99
+ else if (scopedPackagePattern.test(s)) {
100
+ const match = s.match(scopedPackagePattern);
101
+ const enabled = !match.groups.disabled;
102
+ return new PluginDependency({
103
+ name: match.groups.name,
104
+ version: DEFAULT_VERSION,
105
+ enabled: enabled,
106
+ });
107
+ }
108
+ else {
109
+ /*
110
+ Deprecated It is only for backward compatible
111
+ This is original GitBook logic supports
112
+
113
+ pkg@version - backward compatible with GitBook
114
+ pkg@>=version - backward compatible with GitBook
115
+ hello@git+ssh://samy@github.com/GitbookIO/plugin-ga.git
116
+
117
+ Note: This logic does not support scoped module
118
+ */
119
+ const parts = s.split("@");
120
+ let name = parts[0];
121
+ const version = parts.slice(1).join("@");
122
+ let enabled = true;
123
+ if (name[0] === "-") {
124
+ enabled = false;
125
+ name = name.slice(1);
126
+ }
127
+ return new PluginDependency({
128
+ name: name,
129
+ version: version || DEFAULT_VERSION,
130
+ enabled: enabled,
131
+ });
132
+ }
133
+ }
134
+ /**
135
+ * Create a PluginDependency from a string
136
+ * @param {string}
137
+ * @return {List<PluginDependency>}
138
+ */
139
+ static listFromString(s) {
140
+ const parts = s.split(",");
141
+ return PluginDependency.listFromArray(parts);
142
+ }
143
+ /**
144
+ * Create a PluginDependency from an array
145
+ */
146
+ static listFromArray(arr) {
147
+ return immutable_1.default.List(arr)
148
+ .map((entry) => {
149
+ if (typeof entry === "string") {
150
+ return PluginDependency.createFromString(entry);
151
+ }
152
+ else {
153
+ return new PluginDependency({
154
+ name: entry.get("name"),
155
+ version: entry.get("version"),
156
+ });
157
+ }
158
+ })
159
+ .filter((dep) => {
160
+ return Boolean(dep.getName());
161
+ });
162
+ }
163
+ /**
164
+ * Export plugin dependencies as an array
165
+ * @param {List<PluginDependency>} list
166
+ * @return {Array<String>}
167
+ */
168
+ static listToArray(list) {
169
+ return list
170
+ .map((dep) => {
171
+ let result = "";
172
+ if (!dep.isEnabled()) {
173
+ result += "-";
174
+ }
175
+ result += dep.getName();
176
+ if (dep.getVersion() !== DEFAULT_VERSION) {
177
+ result += `@${dep.getVersion()}`;
178
+ }
179
+ return result;
180
+ })
181
+ .toJS();
182
+ }
183
+ /**
184
+ * Return NPM id for a plugin name
185
+ * @param {string}
186
+ * @return {string}
187
+ */
188
+ static nameToNpmID(s) {
189
+ return pluginPrefix_1.default + s;
190
+ }
191
+ }
192
+ exports.default = PluginDependency;
@@ -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 immutable_1 = __importDefault(require("immutable"));
7
+ const file_1 = __importDefault(require("./file"));
8
+ class Readme extends immutable_1.default.Record({
9
+ file: new file_1.default(),
10
+ title: String(),
11
+ description: String(),
12
+ }) {
13
+ getFile() {
14
+ return this.get("file");
15
+ }
16
+ getTitle() {
17
+ return this.get("title");
18
+ }
19
+ getDescription() {
20
+ return this.get("description");
21
+ }
22
+ /**
23
+ Create a new readme
24
+
25
+ @param {File} file
26
+ @param {Object} def
27
+ @return {Readme}
28
+ */
29
+ static create(file, def) {
30
+ def = def || {};
31
+ return new Readme({
32
+ file: file,
33
+ title: def.title || "",
34
+ description: def.description || "",
35
+ });
36
+ }
37
+ }
38
+ exports.default = Readme;