85.index.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. "use strict";
  2. exports.id = 85;
  3. exports.ids = [85];
  4. exports.modules = {
  5. /***/ 21085:
  6. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7. Object.defineProperty(exports, "__esModule", ({ value: true }));
  8. exports.findHelpFile = void 0;
  9. const fs = __webpack_require__(35747);
  10. const path = __webpack_require__(85622);
  11. const markdown_renderer_1 = __webpack_require__(99387);
  12. function findHelpFile(helpArgs, helpFolderPath = '../../help/cli-commands') {
  13. while (helpArgs.length > 0) {
  14. // cleanse the filename to only contain letters
  15. // aka: /\W/g but figured this was easier to read
  16. const file = `${helpArgs.join('-').replace(/[^a-z0-9-]/gi, '')}.md`;
  17. const testHelpAbsolutePath = path.resolve(__dirname, helpFolderPath, file);
  18. if (fs.existsSync(testHelpAbsolutePath)) {
  19. return testHelpAbsolutePath;
  20. }
  21. helpArgs = helpArgs.slice(0, -1);
  22. }
  23. return path.resolve(__dirname, helpFolderPath, `README.md`); // Default help file
  24. }
  25. exports.findHelpFile = findHelpFile;
  26. async function help(...args) {
  27. const helpArgs = args.filter((arg) => typeof arg === 'string');
  28. const helpFileAbsolutePath = findHelpFile(helpArgs);
  29. return markdown_renderer_1.renderMarkdown(fs.readFileSync(helpFileAbsolutePath, 'utf8'));
  30. }
  31. exports.default = help;
  32. /***/ }),
  33. /***/ 99387:
  34. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  35. Object.defineProperty(exports, "__esModule", ({ value: true }));
  36. exports.renderMarkdown = void 0;
  37. const marked_1 = __webpack_require__(30970);
  38. const chalk_1 = __webpack_require__(32589);
  39. const reflow_text_1 = __webpack_require__(67211);
  40. // stateful variable to control left-padding by header level
  41. let currentHeader = 1;
  42. const listItemSeparator = 'LISTITEMSEPARATOR'; // Helper string for rendering ListItems
  43. /**
  44. * @description get padding spaces depending on the last header level used
  45. * @returns string
  46. */
  47. function getLeftTextPadding() {
  48. return ' '.repeat(currentHeader === 1 || currentHeader === 2 ? 1 : currentHeader - 1);
  49. }
  50. /**
  51. * @description Reads current terminal width if available to limit column width for text-reflowing
  52. * @returns {number}
  53. */
  54. const defaultMaximumLineWidth = 100;
  55. function getIdealTextWidth(maximumLineWidth = defaultMaximumLineWidth) {
  56. if (typeof process.stdout.columns === 'number') {
  57. if (process.stdout.columns < maximumLineWidth) {
  58. return process.stdout.columns - getLeftTextPadding().length - 5;
  59. }
  60. }
  61. return maximumLineWidth - getLeftTextPadding().length;
  62. }
  63. // Marked custom renderer class
  64. const renderer = {
  65. em(text) {
  66. return chalk_1.default.italic(text);
  67. },
  68. strong(text) {
  69. return chalk_1.default.bold(text);
  70. },
  71. link(href, title, text) {
  72. // Don't render links to relative paths (like local files)
  73. if (href.startsWith('./') || !href.includes('://')) {
  74. return text;
  75. }
  76. const renderedLink = chalk_1.default.bold.blueBright(href);
  77. if (text && text !== href) {
  78. return `${text} ${renderedLink}`;
  79. }
  80. return renderedLink;
  81. },
  82. blockquote(quote) {
  83. return quote;
  84. },
  85. list(body, ordered, start) {
  86. return (body
  87. .split(listItemSeparator)
  88. .map((listItem, listItemIndex) => {
  89. const bulletPoint = ordered ? `${listItemIndex + start}. ` : '- ';
  90. return reflow_text_1.reflowText(listItem, getIdealTextWidth())
  91. .split('\n')
  92. .map((listItemLine, listItemLineIndex) => {
  93. if (!listItemLine) {
  94. return '';
  95. }
  96. return `${getLeftTextPadding()}${listItemLineIndex === 0 ? bulletPoint : ' '}${listItemLine}`;
  97. })
  98. .join('\n');
  99. })
  100. .join('\n') + '\n');
  101. },
  102. listitem(text) {
  103. return text + listItemSeparator;
  104. },
  105. paragraph(text) {
  106. return (reflow_text_1.reflowText(text, getIdealTextWidth())
  107. .split('\n')
  108. .map((s) => getLeftTextPadding() + chalk_1.default.reset() + s)
  109. .join('\n') + '\n\n');
  110. },
  111. codespan(text) {
  112. return chalk_1.default.italic.blueBright(`${text}`);
  113. },
  114. code(code) {
  115. return (code
  116. .split('\n')
  117. .map((s) => getLeftTextPadding() + chalk_1.default.reset() + s)
  118. .join('\n') + '\n\n');
  119. },
  120. heading(text, level) {
  121. currentHeader = level;
  122. let coloring;
  123. switch (level) {
  124. case 1:
  125. coloring = chalk_1.default.bold.underline;
  126. break;
  127. case 3:
  128. case 4:
  129. coloring = chalk_1.default;
  130. break;
  131. default:
  132. coloring = chalk_1.default.bold;
  133. break;
  134. }
  135. return `${' '.repeat(level === 1 ? 0 : currentHeader - 2)}${coloring(text)}\n`;
  136. },
  137. };
  138. marked_1.marked.use({ renderer });
  139. marked_1.marked.setOptions({
  140. mangle: false,
  141. });
  142. const htmlUnescapes = {
  143. '&amp;': '&',
  144. '&lt;': '<',
  145. '&gt;': '>',
  146. '&quot;': '"',
  147. '&#39;': "'",
  148. '&#96;': '`',
  149. '&#x20;': '',
  150. };
  151. /**
  152. * @description Replace HTML entities with their non-encoded variant
  153. * @param {string} text
  154. * @returns {string}
  155. */
  156. function unescape(text) {
  157. Object.entries(htmlUnescapes).forEach(([escapedChar, unescapedChar]) => {
  158. const escapedCharRegExp = new RegExp(escapedChar, 'g');
  159. text = text.replace(escapedCharRegExp, unescapedChar);
  160. });
  161. return text;
  162. }
  163. function renderMarkdown(markdown) {
  164. return unescape(marked_1.marked.parse(markdown));
  165. }
  166. exports.renderMarkdown = renderMarkdown;
  167. /***/ }),
  168. /***/ 67211:
  169. /***/ ((__unused_webpack_module, exports) => {
  170. /**
  171. Code in this file is adapted from mikaelbr/marked-terminal
  172. https://github.com/mikaelbr/marked-terminal/blob/7501b8bb24a5ed52ec7d9114d4aeefa14f1bf5e6/index.js#L234-L330
  173. MIT License
  174. Copyright (c) 2017 Mikael Brevik
  175. Permission is hereby granted, free of charge, to any person obtaining a copy
  176. of this software and associated documentation files (the "Software"), to deal
  177. in the Software without restriction, including without limitation the rights
  178. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  179. copies of the Software, and to permit persons to whom the Software is
  180. furnished to do so, subject to the following conditions:
  181. The above copyright notice and this permission notice shall be included in all
  182. copies or substantial portions of the Software.
  183. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  184. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  185. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  186. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  187. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  188. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  189. SOFTWARE.
  190. */
  191. Object.defineProperty(exports, "__esModule", ({ value: true }));
  192. exports.reflowText = void 0;
  193. // Compute length of str not including ANSI escape codes.
  194. // See http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
  195. function textLength(str) {
  196. // eslint-disable-next-line no-control-regex
  197. return str.replace(/\u001b\[(?:\d{1,3})(?:;\d{1,3})*m/g, '').length;
  198. }
  199. // Munge \n's and spaces in "text" so that the number of
  200. // characters between \n's is less than or equal to "width".
  201. function reflowText(text, width) {
  202. const HARD_RETURN = '\r|\n';
  203. const HARD_RETURN_GFM_RE = new RegExp(HARD_RETURN + '|<br ?/?>');
  204. const splitRe = HARD_RETURN_GFM_RE;
  205. const sections = text.split(splitRe);
  206. const reflowed = [];
  207. sections.forEach((section) => {
  208. // Split the section by escape codes so that we can
  209. // deal with them separately.
  210. // eslint-disable-next-line no-control-regex
  211. const fragments = section.split(/(\u001b\[(?:\d{1,3})(?:;\d{1,3})*m)/g);
  212. let column = 0;
  213. let currentLine = '';
  214. let lastWasEscapeChar = false;
  215. while (fragments.length) {
  216. const fragment = fragments[0];
  217. if (fragment === '') {
  218. fragments.splice(0, 1);
  219. lastWasEscapeChar = false;
  220. continue;
  221. }
  222. // This is an escape code - leave it whole and
  223. // move to the next fragment.
  224. if (!textLength(fragment)) {
  225. currentLine += fragment;
  226. fragments.splice(0, 1);
  227. lastWasEscapeChar = true;
  228. continue;
  229. }
  230. const words = fragment.split(/[ \t\n]+/);
  231. for (let i = 0; i < words.length; i++) {
  232. let word = words[i];
  233. let addSpace = column != 0;
  234. if (lastWasEscapeChar)
  235. addSpace = false;
  236. // If adding the new word overflows the required width
  237. if (column + word.length > width) {
  238. if (word.length <= width) {
  239. // If the new word is smaller than the required width
  240. // just add it at the beginning of a new line
  241. reflowed.push(currentLine);
  242. currentLine = word;
  243. column = word.length;
  244. }
  245. else {
  246. // If the new word is longer than the required width
  247. // split this word into smaller parts.
  248. const w = word.substr(0, width - column);
  249. if (addSpace)
  250. currentLine += ' ';
  251. currentLine += w;
  252. reflowed.push(currentLine);
  253. currentLine = '';
  254. column = 0;
  255. word = word.substr(w.length);
  256. while (word.length) {
  257. const w = word.substr(0, width);
  258. if (!w.length)
  259. break;
  260. if (w.length < width) {
  261. currentLine = w;
  262. column = w.length;
  263. break;
  264. }
  265. else {
  266. reflowed.push(w);
  267. word = word.substr(width);
  268. }
  269. }
  270. }
  271. }
  272. else {
  273. if (addSpace) {
  274. currentLine += ' ';
  275. column++;
  276. }
  277. currentLine += word;
  278. column += word.length;
  279. }
  280. lastWasEscapeChar = false;
  281. }
  282. fragments.splice(0, 1);
  283. }
  284. if (textLength(currentLine))
  285. reflowed.push(currentLine);
  286. });
  287. return reflowed.join('\n');
  288. }
  289. exports.reflowText = reflowText;
  290. /***/ })
  291. };
  292. ;
  293. //# sourceMappingURL=85.index.js.map