@diplodoc/cli 4.0.0

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 (74) hide show
  1. package/CHANGELOG.md +785 -0
  2. package/LICENSE +21 -0
  3. package/README.md +62 -0
  4. package/README.ru.md +63 -0
  5. package/build/app.client.css +47 -0
  6. package/build/app.client.js +3 -0
  7. package/build/index.js +3993 -0
  8. package/build/index.js.map +7 -0
  9. package/build/lib.js +3374 -0
  10. package/build/lib.js.map +7 -0
  11. package/build/linter.js +1265 -0
  12. package/build/linter.js.map +7 -0
  13. package/package.json +126 -0
  14. package/src/cmd/build/index.ts +304 -0
  15. package/src/cmd/index.ts +4 -0
  16. package/src/cmd/publish/index.ts +92 -0
  17. package/src/cmd/publish/upload.ts +61 -0
  18. package/src/cmd/translate/index.ts +261 -0
  19. package/src/cmd/xliff/compose.ts +222 -0
  20. package/src/cmd/xliff/extract.ts +237 -0
  21. package/src/cmd/xliff/index.ts +27 -0
  22. package/src/constants.ts +122 -0
  23. package/src/globals.d.ts +1 -0
  24. package/src/index.ts +54 -0
  25. package/src/models.ts +249 -0
  26. package/src/packages/credentials/index.ts +1 -0
  27. package/src/packages/credentials/yandex-oauth.ts +42 -0
  28. package/src/resolvers/index.ts +3 -0
  29. package/src/resolvers/lintPage.ts +119 -0
  30. package/src/resolvers/md2html.ts +142 -0
  31. package/src/resolvers/md2md.ts +147 -0
  32. package/src/services/argv.ts +38 -0
  33. package/src/services/authors.ts +64 -0
  34. package/src/services/contributors.ts +104 -0
  35. package/src/services/includers/batteries/common.ts +34 -0
  36. package/src/services/includers/batteries/generic.ts +130 -0
  37. package/src/services/includers/batteries/index.ts +3 -0
  38. package/src/services/includers/batteries/sourcedocs.ts +33 -0
  39. package/src/services/includers/batteries/unarchive.ts +97 -0
  40. package/src/services/includers/index.ts +157 -0
  41. package/src/services/index.ts +6 -0
  42. package/src/services/leading.ts +88 -0
  43. package/src/services/metadata.ts +249 -0
  44. package/src/services/plugins.ts +76 -0
  45. package/src/services/preset.ts +55 -0
  46. package/src/services/tocs.ts +401 -0
  47. package/src/services/utils.ts +151 -0
  48. package/src/steps/index.ts +6 -0
  49. package/src/steps/processAssets.ts +36 -0
  50. package/src/steps/processExcludedFiles.ts +47 -0
  51. package/src/steps/processLinter.ts +100 -0
  52. package/src/steps/processLogs.ts +18 -0
  53. package/src/steps/processMapFile.ts +35 -0
  54. package/src/steps/processPages.ts +312 -0
  55. package/src/steps/processServiceFiles.ts +95 -0
  56. package/src/steps/publishFilesToS3.ts +47 -0
  57. package/src/utils/file.ts +17 -0
  58. package/src/utils/glob.ts +14 -0
  59. package/src/utils/index.ts +8 -0
  60. package/src/utils/logger.ts +42 -0
  61. package/src/utils/markup.ts +125 -0
  62. package/src/utils/path.ts +24 -0
  63. package/src/utils/presets.ts +20 -0
  64. package/src/utils/singlePage.ts +228 -0
  65. package/src/utils/toc.ts +87 -0
  66. package/src/utils/url.ts +3 -0
  67. package/src/utils/worker.ts +10 -0
  68. package/src/validator.ts +150 -0
  69. package/src/vcs-connector/client/github.ts +52 -0
  70. package/src/vcs-connector/connector-models.ts +76 -0
  71. package/src/vcs-connector/connector-validator.ts +114 -0
  72. package/src/vcs-connector/github.ts +333 -0
  73. package/src/vcs-connector/index.ts +15 -0
  74. package/src/workers/linter/index.ts +62 -0
@@ -0,0 +1,1265 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __defProps = Object.defineProperties;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
7
+ var __getOwnPropNames = Object.getOwnPropertyNames;
8
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
9
+ var __getProtoOf = Object.getPrototypeOf;
10
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
11
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
12
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
13
+ var __spreadValues = (a, b) => {
14
+ for (var prop in b || (b = {}))
15
+ if (__hasOwnProp.call(b, prop))
16
+ __defNormalProp(a, prop, b[prop]);
17
+ if (__getOwnPropSymbols)
18
+ for (var prop of __getOwnPropSymbols(b)) {
19
+ if (__propIsEnum.call(b, prop))
20
+ __defNormalProp(a, prop, b[prop]);
21
+ }
22
+ return a;
23
+ };
24
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
25
+ var __objRest = (source, exclude) => {
26
+ var target = {};
27
+ for (var prop in source)
28
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
29
+ target[prop] = source[prop];
30
+ if (source != null && __getOwnPropSymbols)
31
+ for (var prop of __getOwnPropSymbols(source)) {
32
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
33
+ target[prop] = source[prop];
34
+ }
35
+ return target;
36
+ };
37
+ var __commonJS = (cb, mod) => function __require() {
38
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
39
+ };
40
+ var __export = (target, all) => {
41
+ for (var name4 in all)
42
+ __defProp(target, name4, { get: all[name4], enumerable: true });
43
+ };
44
+ var __copyProps = (to, from, except, desc) => {
45
+ if (from && typeof from === "object" || typeof from === "function") {
46
+ for (let key of __getOwnPropNames(from))
47
+ if (!__hasOwnProp.call(to, key) && key !== except)
48
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
49
+ }
50
+ return to;
51
+ };
52
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
53
+ // If the importer is in node compatibility mode or this is not an ESM
54
+ // file that has been converted to a CommonJS file using a Babel-
55
+ // compatible transform (i.e. "__esModule" has not been set), then set
56
+ // "default" to the CommonJS "module.exports" for node compatibility.
57
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
58
+ mod
59
+ ));
60
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
61
+ var __async = (__this, __arguments, generator) => {
62
+ return new Promise((resolve10, reject) => {
63
+ var fulfilled = (value) => {
64
+ try {
65
+ step(generator.next(value));
66
+ } catch (e) {
67
+ reject(e);
68
+ }
69
+ };
70
+ var rejected = (value) => {
71
+ try {
72
+ step(generator.throw(value));
73
+ } catch (e) {
74
+ reject(e);
75
+ }
76
+ };
77
+ var step = (x) => x.done ? resolve10(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
78
+ step((generator = generator.apply(__this, __arguments)).next());
79
+ });
80
+ };
81
+
82
+ // scripts/client.js
83
+ var require_client = __commonJS({
84
+ "scripts/client.js"(exports, module2) {
85
+ "use strict";
86
+ var path = require("path");
87
+ var CLIENT_PATH = path.dirname(require.resolve("@diplodoc/client"));
88
+ var BUILD_PATH = path.resolve(__dirname, "..", "build");
89
+ var BUNDLE_JS_FILENAME = "app.client.js";
90
+ var BUNDLE_CSS_FILENAME = "app.client.css";
91
+ var src = (target) => path.resolve(CLIENT_PATH, target);
92
+ var dst = (target) => path.resolve(BUILD_PATH, target);
93
+ module2.exports = {
94
+ dst: {
95
+ js: dst(BUNDLE_JS_FILENAME),
96
+ css: dst(BUNDLE_CSS_FILENAME)
97
+ },
98
+ src: {
99
+ js: src(BUNDLE_JS_FILENAME),
100
+ css: src(BUNDLE_CSS_FILENAME)
101
+ },
102
+ bundle: {
103
+ js(bundlePath) {
104
+ return path.join(bundlePath, BUNDLE_JS_FILENAME);
105
+ },
106
+ css(bundlePath) {
107
+ return path.join(bundlePath, BUNDLE_CSS_FILENAME);
108
+ }
109
+ }
110
+ };
111
+ }
112
+ });
113
+
114
+ // src/workers/linter/index.ts
115
+ var linter_exports = {};
116
+ module.exports = __toCommonJS(linter_exports);
117
+ var import_log7 = __toESM(require("@doc-tools/transform/lib/log"));
118
+ var import_path19 = require("path");
119
+ var import_observable = require("threads/observable");
120
+ var import_threads = require("threads");
121
+
122
+ // src/services/tocs.ts
123
+ var import_path12 = require("path");
124
+ var import_fs3 = require("fs");
125
+ var import_js_yaml3 = require("js-yaml");
126
+ var import_shelljs2 = __toESM(require("shelljs"));
127
+ var import_walk_sync = __toESM(require("walk-sync"));
128
+ var import_liquid2 = __toESM(require("@doc-tools/transform/lib/liquid"));
129
+ var import_log2 = __toESM(require("@doc-tools/transform/lib/log"));
130
+ var import_chalk2 = require("chalk");
131
+
132
+ // src/services/metadata.ts
133
+ var import_js_yaml = require("js-yaml");
134
+
135
+ // src/utils/logger.ts
136
+ var import_log = __toESM(require("@doc-tools/transform/lib/log"));
137
+ var import_chalk = require("chalk");
138
+ function writeLog(msg, fatal = false) {
139
+ const { quiet } = argv_default.getConfig();
140
+ if (quiet && !fatal) {
141
+ return;
142
+ }
143
+ console.log(msg);
144
+ }
145
+ var logger = {
146
+ info: function(pathToFile, extraMessage) {
147
+ writeLog(`${(0, import_chalk.grey)("INFO")} ${extraMessage} ${pathToFile}`);
148
+ },
149
+ proc: function(pathToFile) {
150
+ writeLog(`${(0, import_chalk.blue)("PROC")} Processing file ${pathToFile}`);
151
+ },
152
+ copy: function(pathToFile) {
153
+ writeLog(`${(0, import_chalk.green)("COPY")} Copying file ${pathToFile}`);
154
+ },
155
+ upload: function(pathToFile) {
156
+ writeLog(`${(0, import_chalk.green)("UPLOAD")} Uploading file ${pathToFile}`);
157
+ },
158
+ warn: function(pathToFile, extraMessage) {
159
+ const message = `${(0, import_chalk.yellow)("WARNING")} file: ${pathToFile} error: ${extraMessage}`;
160
+ writeLog(message);
161
+ import_log.default.warn(`file: ${pathToFile} ${extraMessage}`);
162
+ },
163
+ error: function(pathToFile, extraMessage) {
164
+ const message = `${(0, import_chalk.red)("ERROR")} file: ${pathToFile} error: ${extraMessage}`;
165
+ writeLog(message, true);
166
+ import_log.default.error(`file: ${pathToFile} ${extraMessage}`);
167
+ }
168
+ };
169
+
170
+ // src/utils/markup.ts
171
+ var import_process = require("process");
172
+
173
+ // src/constants.ts
174
+ var import_path = require("path");
175
+ var os = require("os");
176
+ var notes = require("@doc-tools/transform/lib/plugins/notes");
177
+ var anchors = require("@doc-tools/transform/lib/plugins/anchors");
178
+ var code = require("@doc-tools/transform/lib/plugins/code");
179
+ var cut = require("@doc-tools/transform/lib/plugins/cut");
180
+ var deflist = require("@doc-tools/transform/lib/plugins/deflist");
181
+ var imsize = require("@doc-tools/transform/lib/plugins/imsize");
182
+ var meta = require("@doc-tools/transform/lib/plugins/meta");
183
+ var sup = require("@doc-tools/transform/lib/plugins/sup");
184
+ var tabs = require("@doc-tools/transform/lib/plugins/tabs");
185
+ var video = require("@doc-tools/transform/lib/plugins/video");
186
+ var includes = require("@doc-tools/transform/lib/plugins/includes");
187
+ var links = require("@doc-tools/transform/lib/plugins/links");
188
+ var images = require("@doc-tools/transform/lib/plugins/images");
189
+ var monospace = require("@doc-tools/transform/lib/plugins/monospace");
190
+ var table = require("@doc-tools/transform/lib/plugins/table");
191
+ var term = require("@doc-tools/transform/lib/plugins/term");
192
+ var changelog = require("@doc-tools/transform/lib/plugins/changelog");
193
+ var mermaid = require("@diplodoc/mermaid-extension");
194
+ var openapi = require("@diplodoc/openapi-extension");
195
+ includes.collect = require("@doc-tools/transform/lib/plugins/includes/collect");
196
+ images.collect = require("@doc-tools/transform/lib/plugins/images/collect");
197
+ changelog.collect = require("@doc-tools/transform/lib/plugins/changelog/collect");
198
+ var BUILD_FOLDER_PATH = (0, import_path.dirname)(require.resolve("@diplodoc/client"));
199
+ var YFM_PLUGINS = [
200
+ meta,
201
+ deflist,
202
+ includes,
203
+ cut,
204
+ links,
205
+ images,
206
+ notes,
207
+ anchors,
208
+ tabs,
209
+ code,
210
+ imsize,
211
+ sup,
212
+ video,
213
+ monospace,
214
+ table,
215
+ term,
216
+ openapi.transform(),
217
+ mermaid.transform(),
218
+ changelog
219
+ ];
220
+ var REGEXP_INCLUDE_CONTENTS = new RegExp("(?<=[{%]\\sinclude\\s).+(?=\\s[%}])", "gm");
221
+ var REGEXP_INCLUDE_FILE_PATH = new RegExp("(?<=[(]).+(?=[)])", "g");
222
+ var REGEXP_AUTHOR = new RegExp("(?<=author:\\s).+(?=\\r?\\n)", "g");
223
+ var MIN_CHUNK_SIZE = Number(process.env.MIN_CHUNK_SIZE) || 1e3;
224
+ var WORKERS_COUNT = Number(process.env.WORKERS_COUNT) || os.cpus().length - 1;
225
+ var metadataBorder = "---";
226
+
227
+ // src/utils/singlePage.ts
228
+ var import_node_html_parser = require("node-html-parser");
229
+ var import_path2 = require("path");
230
+ var import_utilsFS = require("@doc-tools/transform/lib/utilsFS");
231
+ var import_url = __toESM(require("url"));
232
+ var import_lodash = __toESM(require("lodash"));
233
+
234
+ // src/utils/url.ts
235
+ function isExternalHref(href) {
236
+ return href.startsWith("http") || href.startsWith("//");
237
+ }
238
+
239
+ // src/utils/markup.ts
240
+ var import_client = require("@diplodoc/client");
241
+ var import_client2 = __toESM(require_client());
242
+ var \u0441arriage = import_process.platform === "win32" /* WINDOWS */ ? "\r\n" : "\n";
243
+
244
+ // src/utils/path.ts
245
+ var import_path3 = require("path");
246
+
247
+ // src/utils/toc.ts
248
+ var import_path4 = require("path");
249
+
250
+ // src/services/utils.ts
251
+ var import_evaluation = __toESM(require("@doc-tools/transform/lib/liquid/evaluation"));
252
+ var import_liquid = __toESM(require("@doc-tools/transform/lib/liquid"));
253
+ function filterFiles(items, itemsKey, vars, options) {
254
+ if (!Array.isArray(items)) {
255
+ return [];
256
+ }
257
+ const reducer = (results, item) => {
258
+ if (shouldProcessItem(item, vars, options)) {
259
+ const prop = item[itemsKey];
260
+ if (prop) {
261
+ const filteredProperty = filterFiles(prop, itemsKey, vars, options);
262
+ if (filteredProperty.length) {
263
+ results.push(__spreadProps(__spreadValues({}, item), {
264
+ [itemsKey]: filteredProperty
265
+ }));
266
+ }
267
+ } else {
268
+ results.push(item);
269
+ }
270
+ }
271
+ return results;
272
+ };
273
+ return items.reduce(reducer, []);
274
+ }
275
+ function filterTextItems(items, vars, options) {
276
+ if (!Array.isArray(items)) {
277
+ return items;
278
+ }
279
+ return items.reduce((result, item) => {
280
+ if (!isObject(item)) {
281
+ result.push(item);
282
+ return result;
283
+ }
284
+ const useItem = shouldProcessItem(item, vars, options);
285
+ if (useItem) {
286
+ if (Array.isArray(item.text)) {
287
+ result.push(...item.text);
288
+ } else {
289
+ result.push(item.text);
290
+ }
291
+ }
292
+ return result;
293
+ }, []);
294
+ }
295
+ function firstFilterTextItems(items, vars, options) {
296
+ const filteredItems = filterTextItems(items, vars, options);
297
+ if (!Array.isArray(filteredItems)) {
298
+ return filteredItems || "";
299
+ }
300
+ return filteredItems[0] || "";
301
+ }
302
+ function shouldProcessItem(item, vars, options) {
303
+ const { resolveConditions, removeHiddenTocItems } = options || {};
304
+ let useItem = true;
305
+ if (resolveConditions) {
306
+ const { when } = item;
307
+ useItem = when === true || when === void 0 || typeof when === "string" && (0, import_evaluation.default)(when, vars);
308
+ delete item.when;
309
+ }
310
+ if (useItem && removeHiddenTocItems) {
311
+ useItem = !item.hidden;
312
+ delete item.hidden;
313
+ }
314
+ return useItem;
315
+ }
316
+ function liquidField(input, vars, path) {
317
+ const { applyPresets, resolveConditions } = argv_default.getConfig();
318
+ if (!applyPresets && !resolveConditions) {
319
+ return input;
320
+ }
321
+ return (0, import_liquid.default)(input, vars, path, {
322
+ substitutions: applyPresets,
323
+ conditions: resolveConditions,
324
+ keepNotVar: true,
325
+ withSourceMap: false
326
+ });
327
+ }
328
+ function isObject(o) {
329
+ return typeof o === "object" && o !== null;
330
+ }
331
+
332
+ // src/utils/presets.ts
333
+ var import_path5 = require("path");
334
+ function getVarsPerFile(filePath) {
335
+ const { vars: argVars } = argv_default.getConfig();
336
+ return __spreadValues(__spreadValues({}, preset_default.get((0, import_path5.dirname)(filePath))), argVars);
337
+ }
338
+ function getVarsPerRelativeFile(filePath) {
339
+ const { input } = argv_default.getConfig();
340
+ const root = (0, import_path5.resolve)(input);
341
+ const relativeFilePath = (0, import_path5.relative)(root, filePath);
342
+ return getVarsPerFile(relativeFilePath);
343
+ }
344
+
345
+ // src/utils/glob.ts
346
+ var import_glob = __toESM(require("glob"));
347
+ var glob = (pattern, options) => __async(void 0, null, function* () {
348
+ return new Promise((res, rej) => {
349
+ const state = (0, import_glob.default)(
350
+ pattern,
351
+ options,
352
+ (err) => err ? rej(err) : res({ state })
353
+ );
354
+ });
355
+ });
356
+
357
+ // src/utils/file.ts
358
+ var import_path6 = require("path");
359
+ var import_shelljs = __toESM(require("shelljs"));
360
+ var import_fs = require("fs");
361
+
362
+ // src/services/contributors.ts
363
+ var import_promises = require("fs/promises");
364
+ var import_path7 = require("path");
365
+
366
+ // src/services/metadata.ts
367
+ var import_path8 = require("path");
368
+ function getContentWithUpdatedStaticMetadata({
369
+ fileContent,
370
+ sourcePath,
371
+ addSystemMeta,
372
+ addSourcePath,
373
+ resources,
374
+ systemVars
375
+ }) {
376
+ const newMetadatas = [];
377
+ if ((!addSystemMeta || !systemVars) && !addSourcePath && !resources) {
378
+ return fileContent;
379
+ }
380
+ const matches = matchMetadata(fileContent);
381
+ if (addSystemMeta && systemVars && isObject(systemVars)) {
382
+ newMetadatas.push(getSystemVarsMetadataString(systemVars));
383
+ }
384
+ if (resources) {
385
+ newMetadatas.push((0, import_js_yaml.dump)(resources));
386
+ }
387
+ if (addSourcePath && sourcePath) {
388
+ const sourcePathMetadataString = `sourcePath: ${sourcePath}`;
389
+ newMetadatas.push(sourcePathMetadataString);
390
+ }
391
+ if (matches && matches.length > 0) {
392
+ const [, fileMetadata, , fileMainContent] = matches;
393
+ return `${getUpdatedMetadataString(newMetadatas, fileMetadata)}${fileMainContent}`;
394
+ }
395
+ return `${getUpdatedMetadataString(newMetadatas)}${fileContent}`;
396
+ }
397
+ function matchMetadata(fileContent) {
398
+ if (!fileContent.startsWith("---")) {
399
+ return null;
400
+ }
401
+ const regexpMetadata = "(?<=-{3}\\r?\\n)((.*\\r?\\n)*?)(?=-{3}\\r?\\n)";
402
+ const regexpFileContent = "-{3}((.*[\r?\n]*)*)";
403
+ const regexpParseFileContent = new RegExp(`${regexpMetadata}${regexpFileContent}`, "gm");
404
+ return regexpParseFileContent.exec(fileContent);
405
+ }
406
+ function getUpdatedMetadataString(newMetadatas, defaultMetadata = "") {
407
+ const newMetadata = newMetadatas.join(\u0441arriage) + (newMetadatas.length ? \u0441arriage : "");
408
+ const preparedDefaultMetadata = defaultMetadata.trimRight();
409
+ const defaultMetadata\u0421arriage = preparedDefaultMetadata ? \u0441arriage : "";
410
+ const updatedMetadata = `${preparedDefaultMetadata}${defaultMetadata\u0421arriage}${newMetadata}`;
411
+ return `${metadataBorder}${\u0441arriage}${updatedMetadata}${metadataBorder}${defaultMetadata.length ? "" : \u0441arriage}`;
412
+ }
413
+ function getSystemVarsMetadataString(systemVars) {
414
+ return `__system: ${JSON.stringify(systemVars)}`;
415
+ }
416
+
417
+ // src/services/includers/index.ts
418
+ var includers_exports = {};
419
+ __export(includers_exports, {
420
+ IncludersError: () => IncludersError,
421
+ applyIncluders: () => applyIncluders,
422
+ init: () => init
423
+ });
424
+ var import_path11 = require("path");
425
+ var import_lodash3 = require("lodash");
426
+
427
+ // src/services/includers/batteries/generic.ts
428
+ var generic_exports = {};
429
+ __export(generic_exports, {
430
+ default: () => generic_default,
431
+ includerFunction: () => includerFunction,
432
+ name: () => name
433
+ });
434
+ var import_promises2 = require("fs/promises");
435
+ var import_path9 = require("path");
436
+ var import_lodash2 = require("lodash");
437
+ var import_js_yaml2 = require("js-yaml");
438
+ var GenericIncluderError = class extends Error {
439
+ constructor(message, path) {
440
+ super(message);
441
+ this.name = "GenericIncluderError";
442
+ this.path = path;
443
+ }
444
+ };
445
+ var name = "generic";
446
+ var MD_GLOB = "**/*.md";
447
+ function includerFunction(params) {
448
+ return __async(this, null, function* () {
449
+ var _a, _b;
450
+ const { readBasePath, writeBasePath, tocPath, item, passedParams: { input, leadingPage }, index } = params;
451
+ if (!(input == null ? void 0 : input.length) || !((_a = item.include) == null ? void 0 : _a.path)) {
452
+ throw new GenericIncluderError("provide includer with input parameter", tocPath);
453
+ }
454
+ try {
455
+ const leadingPageName = (_b = leadingPage == null ? void 0 : leadingPage.name) != null ? _b : "Overview";
456
+ const tocDirPath = (0, import_path9.dirname)(tocPath);
457
+ const contentPath = index === 0 ? (0, import_path9.join)(writeBasePath, tocDirPath, input) : (0, import_path9.join)(readBasePath, tocDirPath, input);
458
+ let cache = {};
459
+ let found = [];
460
+ ({ state: { found, cache } } = yield glob(MD_GLOB, {
461
+ cwd: contentPath,
462
+ nosort: true,
463
+ nocase: true,
464
+ cache
465
+ }));
466
+ const writePath = (0, import_path9.join)(writeBasePath, tocDirPath, item.include.path);
467
+ yield (0, import_promises2.mkdir)(writePath, { recursive: true });
468
+ for (const filePath of found) {
469
+ const file = yield (0, import_promises2.readFile)((0, import_path9.join)(contentPath, filePath));
470
+ yield (0, import_promises2.mkdir)((0, import_path9.dirname)((0, import_path9.join)(writePath, filePath)), { recursive: true });
471
+ yield (0, import_promises2.writeFile)((0, import_path9.join)(writePath, filePath), file);
472
+ }
473
+ const graph = createGraphFromPaths(found);
474
+ const toc = createToc(leadingPageName, item.include.path)(graph, []);
475
+ yield (0, import_promises2.writeFile)((0, import_path9.join)(writePath, "toc.yaml"), (0, import_js_yaml2.dump)(toc));
476
+ } catch (err) {
477
+ throw new GenericIncluderError(err.toString(), tocPath);
478
+ }
479
+ });
480
+ }
481
+ function createGraphFromPaths(paths) {
482
+ const graph = {};
483
+ for (const path of paths) {
484
+ const chunks = path.split("/").filter(Boolean);
485
+ if (chunks.length < 2) {
486
+ if (chunks.length === 1) {
487
+ graph.files = chunks;
488
+ }
489
+ continue;
490
+ }
491
+ const file = chunks.pop();
492
+ (0, import_lodash2.updateWith)(graph, chunks, (old) => {
493
+ return old ? { files: [...old.files, file] } : { files: [file] };
494
+ }, Object);
495
+ }
496
+ return graph;
497
+ }
498
+ function createToc(leadingPageName, tocName) {
499
+ return function createTocRec(graph, cursor) {
500
+ var _a, _b;
501
+ const handler = (file) => ({
502
+ name: (0, import_path9.parse)(file).name === "index" ? leadingPageName : file,
503
+ href: (0, import_path9.join)(...cursor, file)
504
+ });
505
+ const recurse = (key) => createTocRec(graph[key], [...cursor, key]);
506
+ const current = {
507
+ name: (_a = cursor[cursor.length - 1]) != null ? _a : tocName,
508
+ items: [
509
+ ...((_b = graph.files) != null ? _b : []).map(handler),
510
+ ...Object.keys(graph).filter((key) => key !== "files").map(recurse)
511
+ ]
512
+ };
513
+ return current;
514
+ };
515
+ }
516
+ var generic_default = { name, includerFunction };
517
+
518
+ // src/services/includers/batteries/sourcedocs.ts
519
+ var sourcedocs_exports = {};
520
+ __export(sourcedocs_exports, {
521
+ default: () => sourcedocs_default,
522
+ includerFunction: () => includerFunction2,
523
+ name: () => name2
524
+ });
525
+ var name2 = "sourcedocs";
526
+ var usage = `include:
527
+ path: <path-where-to-include>
528
+ includers:
529
+ - name: generic
530
+ input: <path-to-directory-with-markdown>
531
+ leadingPage:
532
+ name: <leading-page-name>
533
+ `;
534
+ function includerFunction2(params) {
535
+ return __async(this, null, function* () {
536
+ logger.warn(params.tocPath, `sourcedocs inlcuder is getting depricated in favor of generic includer
537
+ ${usage}`);
538
+ yield generic_default.includerFunction(params);
539
+ });
540
+ }
541
+ var sourcedocs_default = { name: name2, includerFunction: includerFunction2 };
542
+
543
+ // src/services/includers/batteries/unarchive.ts
544
+ var unarchive_exports = {};
545
+ __export(unarchive_exports, {
546
+ default: () => unarchive_default,
547
+ includerFunction: () => includerFunction3,
548
+ name: () => name3
549
+ });
550
+ var import_fs2 = require("fs");
551
+ var import_path10 = require("path");
552
+ var import_tar_stream = require("tar-stream");
553
+ var name3 = "unarchive";
554
+ var UnarchiveIncluderError = class extends Error {
555
+ constructor(message, path) {
556
+ super(message);
557
+ this.name = "UnarchiveIncluderError";
558
+ this.path = path;
559
+ }
560
+ };
561
+ function pipeline(readPath, writeBasePath) {
562
+ return new Promise((res, rej) => {
563
+ const reader = (0, import_fs2.createReadStream)(readPath);
564
+ reader.on("error", (err) => {
565
+ rej(err);
566
+ });
567
+ const extractor = (0, import_tar_stream.extract)();
568
+ extractor.on("error", (err) => {
569
+ rej(err);
570
+ });
571
+ (0, import_fs2.mkdirSync)(writeBasePath, { recursive: true });
572
+ extractor.on("entry", (header, stream, next) => {
573
+ const { type, name: name4 } = header;
574
+ const writePath = (0, import_path10.join)(writeBasePath, name4);
575
+ const writeDirPath = type === "directory" ? writePath : (0, import_path10.dirname)(writePath);
576
+ (0, import_fs2.mkdirSync)(writeDirPath, { recursive: true });
577
+ if (type !== "directory") {
578
+ const writer = (0, import_fs2.createWriteStream)(writePath, { flags: "w" });
579
+ writer.on("error", (err) => {
580
+ rej(err);
581
+ });
582
+ stream.pipe(writer);
583
+ }
584
+ stream.on("end", () => {
585
+ next();
586
+ });
587
+ stream.resume();
588
+ });
589
+ reader.pipe(extractor).on("finish", () => {
590
+ res();
591
+ });
592
+ });
593
+ }
594
+ function includerFunction3(params) {
595
+ return __async(this, null, function* () {
596
+ const { readBasePath, writeBasePath, tocPath, passedParams: { input, output }, index } = params;
597
+ if (!(input == null ? void 0 : input.length) || !(output == null ? void 0 : output.length)) {
598
+ throw new UnarchiveIncluderError("provide includer with input parameter", tocPath);
599
+ }
600
+ const contentPath = index === 0 ? (0, import_path10.join)(writeBasePath, input) : (0, import_path10.join)(readBasePath, input);
601
+ const writePath = (0, import_path10.join)(writeBasePath, output);
602
+ try {
603
+ yield pipeline(contentPath, writePath);
604
+ } catch (err) {
605
+ throw new UnarchiveIncluderError(err.toString(), tocPath);
606
+ }
607
+ });
608
+ }
609
+ var unarchive_default = { name: name3, includerFunction: includerFunction3 };
610
+
611
+ // src/services/includers/index.ts
612
+ var includersUsage = `include:
613
+ path: <path-where-to-include>
614
+ includers:
615
+ - name: <includer-name-0>
616
+ <includer-parameter>: <value-for-includer-parameter>
617
+ - name: <includer-name-1>
618
+ <includer-parameter>: <value-for-includer-parameter>
619
+ `;
620
+ var includersMap;
621
+ var IncludersError = class extends Error {
622
+ constructor(message, path) {
623
+ super(message);
624
+ this.name = "IncludersError";
625
+ this.path = path;
626
+ }
627
+ };
628
+ function init(custom = []) {
629
+ if (includersMap) {
630
+ return;
631
+ }
632
+ includersMap = { generic: generic_exports, sourcedocs: sourcedocs_exports, unarchive: unarchive_exports };
633
+ for (const includer of custom) {
634
+ includersMap[includer.name] = includer;
635
+ }
636
+ }
637
+ function applyIncluders(path, item, vars) {
638
+ return __async(this, null, function* () {
639
+ var _a;
640
+ if (!((_a = item.include) == null ? void 0 : _a.includers)) {
641
+ return;
642
+ }
643
+ if (!includeValid(item.include)) {
644
+ throw new IncludersError("include doesn't comply with includers standard", path);
645
+ }
646
+ item.include.mode = "link" /* LINK */;
647
+ const { status, message } = includersValid(item.include.includers);
648
+ if (!status) {
649
+ throw new IncludersError(message != null ? message : "", path);
650
+ }
651
+ let index = 0;
652
+ for (const _b of item.include.includers) {
653
+ const _c = _b, { name: name4 } = _c, rest = __objRest(_c, ["name"]);
654
+ const includer = getIncluder(name4);
655
+ const passedParams = __spreadValues({}, rest);
656
+ yield applyIncluder({ path, item, includer, passedParams, index, vars });
657
+ }
658
+ item.include.path = (0, import_path11.join)(item.include.path, "toc.yaml");
659
+ index++;
660
+ });
661
+ }
662
+ function includeValid(include) {
663
+ var _a;
664
+ return (include.mode === "link" /* LINK */ || !include.mode) && ((_a = include.path) == null ? void 0 : _a.length);
665
+ }
666
+ function includersValid(includers) {
667
+ for (const includer of includers) {
668
+ const { status, message } = includerValid(includer);
669
+ if (!status) {
670
+ return { status, message };
671
+ }
672
+ }
673
+ return { status: true };
674
+ }
675
+ function includerValid(includer) {
676
+ if ((0, import_lodash3.isObject)(includer)) {
677
+ if (typeof includer.name !== "string") {
678
+ return {
679
+ status: false,
680
+ message: "use string in the includer.name to specify includers name"
681
+ };
682
+ }
683
+ if (includerExists(includer)) {
684
+ return { status: true };
685
+ }
686
+ return { status: false, message: `includer ${includer.name} not implemented` };
687
+ }
688
+ return {
689
+ status: false,
690
+ message: `use appropriate includers format:
691
+ ${includersUsage}`
692
+ };
693
+ }
694
+ function getIncluder(includerName) {
695
+ return includersMap[includerName];
696
+ }
697
+ function includerExists(includer) {
698
+ return includersMap[includer.name];
699
+ }
700
+ function applyIncluder(args) {
701
+ return __async(this, null, function* () {
702
+ const { rootInput: readBasePath, input: writeBasePath } = argv_default.getConfig();
703
+ const { path, item, includer, passedParams, index, vars } = args;
704
+ const params = {
705
+ tocPath: path,
706
+ passedParams,
707
+ index,
708
+ item,
709
+ readBasePath,
710
+ writeBasePath,
711
+ vars
712
+ };
713
+ return yield includer.includerFunction(params);
714
+ });
715
+ }
716
+
717
+ // src/services/tocs.ts
718
+ var storage = /* @__PURE__ */ new Map();
719
+ var navigationPaths = [];
720
+ var includedTocPaths = /* @__PURE__ */ new Set();
721
+ function add(path) {
722
+ return __async(this, null, function* () {
723
+ const {
724
+ input: inputFolderPath,
725
+ output: outputFolderPath,
726
+ outputFormat,
727
+ ignoreStage,
728
+ vars
729
+ } = argv_default.getConfig();
730
+ const pathToDir = (0, import_path12.dirname)(path);
731
+ const content = (0, import_fs3.readFileSync)((0, import_path12.resolve)(inputFolderPath, path), "utf8");
732
+ const parsedToc = (0, import_js_yaml3.load)(content);
733
+ if (parsedToc.stage === ignoreStage) {
734
+ return;
735
+ }
736
+ const combinedVars = __spreadValues(__spreadValues({}, preset_default.get(pathToDir)), vars);
737
+ if (parsedToc.title) {
738
+ parsedToc.title = firstFilterTextItems(
739
+ parsedToc.title,
740
+ combinedVars,
741
+ { resolveConditions: true }
742
+ );
743
+ }
744
+ if (typeof parsedToc.title === "string") {
745
+ parsedToc.title = liquidField(parsedToc.title, combinedVars, path);
746
+ }
747
+ parsedToc.items = yield processTocItems(
748
+ path,
749
+ parsedToc.items,
750
+ (0, import_path12.join)(inputFolderPath, pathToDir),
751
+ (0, import_path12.resolve)(inputFolderPath),
752
+ combinedVars
753
+ );
754
+ storage.set(path, parsedToc);
755
+ parsedToc.base = pathToDir;
756
+ if (outputFormat === "md") {
757
+ const outputPath = (0, import_path12.resolve)(outputFolderPath, path);
758
+ const outputToc = (0, import_js_yaml3.dump)(parsedToc);
759
+ import_shelljs2.default.mkdir("-p", (0, import_path12.dirname)(outputPath));
760
+ (0, import_fs3.writeFileSync)(outputPath, outputToc);
761
+ }
762
+ prepareNavigationPaths(parsedToc, pathToDir);
763
+ });
764
+ }
765
+ function processTocItems(path, items, tocDir, sourcesDir, vars) {
766
+ return __async(this, null, function* () {
767
+ const {
768
+ resolveConditions,
769
+ removeHiddenTocItems
770
+ } = argv_default.getConfig();
771
+ let preparedItems = items;
772
+ if (resolveConditions || removeHiddenTocItems) {
773
+ try {
774
+ preparedItems = filterFiles(items, "items", vars, {
775
+ resolveConditions,
776
+ removeHiddenTocItems
777
+ });
778
+ } catch (error) {
779
+ import_log2.default.error(`Error while filtering toc file: ${path}. Error message: ${error}`);
780
+ }
781
+ }
782
+ return _replaceIncludes(path, preparedItems, tocDir, sourcesDir, vars);
783
+ });
784
+ }
785
+ function getForPath(path) {
786
+ return storage.get(path);
787
+ }
788
+ function getNavigationPaths() {
789
+ return [...navigationPaths];
790
+ }
791
+ function getIncludedTocPaths() {
792
+ return [...includedTocPaths];
793
+ }
794
+ function prepareNavigationPaths(parsedToc, dirPath) {
795
+ function processItems(items, pathToDir) {
796
+ items.forEach((item) => {
797
+ if (!parsedToc.singlePage && item.items) {
798
+ const preparedSubItems = item.items.map((yfmToc, index) => {
799
+ yfmToc.id = `${yfmToc.name}-${index}-${Math.random()}`;
800
+ return yfmToc;
801
+ });
802
+ processItems(preparedSubItems, pathToDir);
803
+ }
804
+ if (item.href && !isExternalHref(item.href)) {
805
+ const href = (0, import_path12.join)(pathToDir, item.href);
806
+ storage.set(href, parsedToc);
807
+ const navigationPath = _normalizeHref(href);
808
+ navigationPaths.push(navigationPath);
809
+ }
810
+ });
811
+ }
812
+ processItems([parsedToc], dirPath);
813
+ }
814
+ function _normalizeHref(href) {
815
+ const preparedHref = (0, import_path12.normalize)(href);
816
+ if (preparedHref.endsWith(".md") || preparedHref.endsWith(".yaml")) {
817
+ return preparedHref;
818
+ }
819
+ if (preparedHref.endsWith(import_path12.sep)) {
820
+ return `${preparedHref}index.yaml`;
821
+ }
822
+ return `${preparedHref}.md`;
823
+ }
824
+ function _copyTocDir(tocPath, destDir) {
825
+ const { input: inputFolderPath } = argv_default.getConfig();
826
+ const { dir: tocDir } = (0, import_path12.parse)(tocPath);
827
+ const files = (0, import_walk_sync.default)(tocDir, {
828
+ globs: ["**/*.*"],
829
+ ignore: ["**/toc.yaml"],
830
+ directories: false
831
+ });
832
+ files.forEach((relPath) => {
833
+ const from = (0, import_path12.resolve)(tocDir, relPath);
834
+ const to = (0, import_path12.resolve)(destDir, relPath);
835
+ const fileExtension = (0, import_path12.extname)(relPath);
836
+ const isMdFile = fileExtension === ".md";
837
+ import_shelljs2.default.mkdir("-p", (0, import_path12.parse)(to).dir);
838
+ if (isMdFile) {
839
+ const fileContent = (0, import_fs3.readFileSync)(from, "utf8");
840
+ const sourcePath = (0, import_path12.relative)(inputFolderPath, from);
841
+ const updatedFileContent = getContentWithUpdatedStaticMetadata({
842
+ fileContent,
843
+ sourcePath,
844
+ addSourcePath: true
845
+ });
846
+ (0, import_fs3.writeFileSync)(to, updatedFileContent);
847
+ } else {
848
+ (0, import_fs3.copyFileSync)(from, to);
849
+ }
850
+ });
851
+ }
852
+ function _replaceIncludesHrefs(items, includeTocDir, tocDir) {
853
+ return items.reduce((acc, tocItem) => {
854
+ if (tocItem.href) {
855
+ tocItem.href = (0, import_path12.relative)(tocDir, (0, import_path12.resolve)(includeTocDir, tocItem.href));
856
+ }
857
+ if (tocItem.items) {
858
+ tocItem.items = _replaceIncludesHrefs(tocItem.items, includeTocDir, tocDir);
859
+ }
860
+ if (tocItem.include) {
861
+ const { path } = tocItem.include;
862
+ tocItem.include.path = (0, import_path12.relative)(tocDir, (0, import_path12.resolve)(includeTocDir, path));
863
+ }
864
+ return acc.concat(tocItem);
865
+ }, []);
866
+ }
867
+ function _liquidSubstitutions(input, vars, path) {
868
+ const { outputFormat, applyPresets } = argv_default.getConfig();
869
+ if (outputFormat === "md" && !applyPresets) {
870
+ return input;
871
+ }
872
+ return (0, import_liquid2.default)(input, vars, path, {
873
+ conditions: false,
874
+ substitutions: true
875
+ });
876
+ }
877
+ function addIncludeTocPath(includeTocPath) {
878
+ includedTocPaths.add(includeTocPath);
879
+ }
880
+ function _replaceIncludes(path, items, tocDir, sourcesDir, vars) {
881
+ return __async(this, null, function* () {
882
+ const result = [];
883
+ for (const item of items) {
884
+ let includedInlineItems = null;
885
+ if (item.name) {
886
+ const tocPath = (0, import_path12.join)(tocDir, "toc.yaml");
887
+ item.name = _liquidSubstitutions(item.name, vars, tocPath);
888
+ }
889
+ try {
890
+ yield applyIncluders(path, item, vars);
891
+ } catch (err) {
892
+ if (err instanceof Error || err instanceof IncludersError) {
893
+ const message = err.toString();
894
+ const file = err instanceof IncludersError ? err.path : path;
895
+ logger.error(file, message);
896
+ }
897
+ }
898
+ if (item.include) {
899
+ const { mode = "root_merge" /* ROOT_MERGE */ } = item.include;
900
+ const includeTocPath = mode === "root_merge" /* ROOT_MERGE */ ? (0, import_path12.resolve)(sourcesDir, item.include.path) : (0, import_path12.resolve)(tocDir, item.include.path);
901
+ const includeTocDir = (0, import_path12.dirname)(includeTocPath);
902
+ try {
903
+ const includeToc = (0, import_js_yaml3.load)((0, import_fs3.readFileSync)(includeTocPath, "utf8"));
904
+ if (includeToc.stage === "tech-preview" /* TECH_PREVIEW */) {
905
+ continue;
906
+ }
907
+ if (mode === "merge" /* MERGE */ || mode === "root_merge" /* ROOT_MERGE */) {
908
+ _copyTocDir(includeTocPath, tocDir);
909
+ }
910
+ addIncludeTocPath(includeTocPath);
911
+ let includedTocItems = (item.items || []).concat(includeToc.items);
912
+ const baseTocDir = mode === "link" /* LINK */ ? includeTocDir : tocDir;
913
+ includedTocItems = yield processTocItems(path, includedTocItems, baseTocDir, sourcesDir, vars);
914
+ if (mode === "link" /* LINK */) {
915
+ includedTocItems = _replaceIncludesHrefs(includedTocItems, includeTocDir, tocDir);
916
+ }
917
+ if (item.name) {
918
+ item.items = includedTocItems;
919
+ } else {
920
+ includedInlineItems = includedTocItems;
921
+ }
922
+ } catch (err) {
923
+ const message = `Error while including toc: ${(0, import_chalk2.bold)(includeTocPath)} to ${(0, import_chalk2.bold)((0, import_path12.join)(tocDir, "toc.yaml"))}`;
924
+ import_log2.default.error(message);
925
+ continue;
926
+ } finally {
927
+ delete item.include;
928
+ }
929
+ } else if (item.items) {
930
+ item.items = yield processTocItems(path, item.items, tocDir, sourcesDir, vars);
931
+ }
932
+ if (includedInlineItems) {
933
+ result.push(...includedInlineItems);
934
+ } else {
935
+ result.push(item);
936
+ }
937
+ }
938
+ return result;
939
+ });
940
+ }
941
+ function getTocDir(pagePath) {
942
+ const { input: inputFolderPath } = argv_default.getConfig();
943
+ const tocDir = (0, import_path12.dirname)(pagePath);
944
+ const tocPath = (0, import_path12.resolve)(tocDir, "toc.yaml");
945
+ if (!tocDir.includes(inputFolderPath)) {
946
+ throw new Error("Error while finding toc dir");
947
+ }
948
+ if ((0, import_fs3.existsSync)(tocPath)) {
949
+ return tocDir;
950
+ }
951
+ return getTocDir(tocDir);
952
+ }
953
+ function setNavigationPaths(paths) {
954
+ navigationPaths = paths;
955
+ }
956
+ var tocs_default = {
957
+ add,
958
+ getForPath,
959
+ getNavigationPaths,
960
+ getTocDir,
961
+ getIncludedTocPaths,
962
+ setNavigationPaths
963
+ };
964
+
965
+ // src/services/preset.ts
966
+ var import_path13 = require("path");
967
+ var presetStorage = /* @__PURE__ */ new Map();
968
+ function add2(parsedPreset, path, varsPreset) {
969
+ const combinedValues = __spreadValues(__spreadValues({}, parsedPreset.default || {}), parsedPreset[varsPreset] || {});
970
+ const key = (0, import_path13.dirname)((0, import_path13.normalize)(path));
971
+ presetStorage.set(key, combinedValues);
972
+ }
973
+ function get(path) {
974
+ let combinedValues = {};
975
+ let localPath = (0, import_path13.normalize)(path);
976
+ while (localPath !== ".") {
977
+ const presetValues = presetStorage.get(localPath) || {};
978
+ localPath = (0, import_path13.dirname)(localPath);
979
+ combinedValues = __spreadValues(__spreadValues({}, presetValues), combinedValues);
980
+ }
981
+ combinedValues = __spreadValues(__spreadValues({}, presetStorage.get(".")), combinedValues);
982
+ return combinedValues;
983
+ }
984
+ function getPresetStorage() {
985
+ return presetStorage;
986
+ }
987
+ function setPresetStorage(preset) {
988
+ presetStorage = preset;
989
+ }
990
+ var preset_default = {
991
+ add: add2,
992
+ get,
993
+ getPresetStorage,
994
+ setPresetStorage
995
+ };
996
+
997
+ // src/services/argv.ts
998
+ var import_path14 = require("path");
999
+ var import_fs4 = require("fs");
1000
+ var _argv;
1001
+ function getConfig() {
1002
+ return _argv;
1003
+ }
1004
+ function init2(argv) {
1005
+ _argv = __spreadProps(__spreadValues({}, argv), {
1006
+ ignore: Array.isArray(argv.ignore) ? argv.ignore : []
1007
+ });
1008
+ if (argv.vars) {
1009
+ _argv.vars = JSON.parse(argv.vars);
1010
+ }
1011
+ try {
1012
+ const ignorefile = (0, import_fs4.readFileSync)((0, import_path14.join)(_argv.rootInput, ".yfmignore"), "utf8");
1013
+ const ignore = ignorefile.split("\n");
1014
+ _argv.ignore = _argv.ignore.concat(ignore);
1015
+ } catch (e) {
1016
+ }
1017
+ }
1018
+ function set(argv) {
1019
+ _argv = argv;
1020
+ }
1021
+ var argv_default = {
1022
+ getConfig,
1023
+ init: init2,
1024
+ set
1025
+ };
1026
+
1027
+ // src/services/leading.ts
1028
+ var import_path15 = require("path");
1029
+ var import_fs5 = require("fs");
1030
+ var import_js_yaml4 = require("js-yaml");
1031
+ var import_log3 = __toESM(require("@doc-tools/transform/lib/log"));
1032
+
1033
+ // src/services/plugins.ts
1034
+ var plugins_exports = {};
1035
+ __export(plugins_exports, {
1036
+ getCollectOfPlugins: () => getCollectOfPlugins,
1037
+ getCustomLintRules: () => getCustomLintRules,
1038
+ getDefaultLintConfig: () => getDefaultLintConfig,
1039
+ getHeadContent: () => getHeadContent,
1040
+ getPlugins: () => getPlugins,
1041
+ setPlugins: () => setPlugins
1042
+ });
1043
+ var plugins;
1044
+ var collectionOfPlugins;
1045
+ function setPlugins() {
1046
+ plugins = getAllPlugins();
1047
+ collectionOfPlugins = makeCollectOfPlugins();
1048
+ }
1049
+ function getPlugins() {
1050
+ return plugins;
1051
+ }
1052
+ function getCollectOfPlugins() {
1053
+ return collectionOfPlugins;
1054
+ }
1055
+ function makeCollectOfPlugins() {
1056
+ const pluginsWithCollect = plugins.filter((plugin) => {
1057
+ return typeof plugin.collect === "function";
1058
+ });
1059
+ return (output, options) => {
1060
+ let collectsOutput = output;
1061
+ pluginsWithCollect.forEach((plugin) => {
1062
+ const collectOutput = plugin.collect(collectsOutput, options);
1063
+ collectsOutput = typeof collectOutput === "string" ? collectOutput : collectsOutput;
1064
+ });
1065
+ return collectsOutput;
1066
+ };
1067
+ }
1068
+ function getAllPlugins() {
1069
+ const customPlugins = getCustomPlugins();
1070
+ return [...YFM_PLUGINS, ...customPlugins];
1071
+ }
1072
+ function getCustomPlugins() {
1073
+ try {
1074
+ const customPlugins = require(require.resolve("./plugins"));
1075
+ return Array.isArray(customPlugins) ? customPlugins : [];
1076
+ } catch (e) {
1077
+ return [];
1078
+ }
1079
+ }
1080
+ function getHeadContent() {
1081
+ try {
1082
+ return require(require.resolve("./head-content.js"));
1083
+ } catch (e) {
1084
+ return "";
1085
+ }
1086
+ }
1087
+ function getCustomLintRules() {
1088
+ try {
1089
+ return require(require.resolve("./lint-rules"));
1090
+ } catch (e) {
1091
+ return [];
1092
+ }
1093
+ }
1094
+ function getDefaultLintConfig() {
1095
+ try {
1096
+ return require(require.resolve("./default-lint-config"));
1097
+ } catch (e) {
1098
+ return void 0;
1099
+ }
1100
+ }
1101
+
1102
+ // src/resolvers/md2md.ts
1103
+ var import_fs6 = require("fs");
1104
+ var import_path16 = require("path");
1105
+ var import_shelljs3 = __toESM(require("shelljs"));
1106
+ var import_log4 = __toESM(require("@doc-tools/transform/lib/log"));
1107
+ var import_liquid3 = __toESM(require("@doc-tools/transform/lib/liquid"));
1108
+ function liquidMd2Md(input, vars, path) {
1109
+ const {
1110
+ applyPresets,
1111
+ resolveConditions,
1112
+ conditionsInCode
1113
+ } = argv_default.getConfig();
1114
+ return (0, import_liquid3.default)(input, vars, path, {
1115
+ conditions: resolveConditions,
1116
+ substitutions: applyPresets,
1117
+ conditionsInCode,
1118
+ withSourceMap: true,
1119
+ keepNotVar: true
1120
+ });
1121
+ }
1122
+
1123
+ // src/resolvers/md2html.ts
1124
+ var import_path17 = require("path");
1125
+ var import_fs7 = require("fs");
1126
+ var import_js_yaml5 = __toESM(require("js-yaml"));
1127
+ var import_transform = __toESM(require("@doc-tools/transform"));
1128
+ var import_log5 = __toESM(require("@doc-tools/transform/lib/log"));
1129
+ var import_liquid4 = __toESM(require("@doc-tools/transform/lib/liquid"));
1130
+ function liquidMd2Html(input, vars, path) {
1131
+ const { conditionsInCode } = argv_default.getConfig();
1132
+ return (0, import_liquid4.default)(input, vars, path, {
1133
+ conditionsInCode,
1134
+ withSourceMap: true
1135
+ });
1136
+ }
1137
+
1138
+ // src/resolvers/lintPage.ts
1139
+ var import_path18 = require("path");
1140
+ var import_log6 = __toESM(require("@doc-tools/transform/lib/log"));
1141
+ var import_yfmlint = __toESM(require("@doc-tools/transform/lib/yfmlint"));
1142
+ var import_fs8 = require("fs");
1143
+ var import_chalk3 = require("chalk");
1144
+ var FileLinter = {
1145
+ ".md": MdFileLinter
1146
+ };
1147
+ function lintPage(options) {
1148
+ const { inputPath, fileExtension, onFinish } = options;
1149
+ const { input } = argv_default.getConfig();
1150
+ const resolvedPath = (0, import_path18.resolve)(input, inputPath);
1151
+ try {
1152
+ const content = (0, import_fs8.readFileSync)(resolvedPath, "utf8");
1153
+ const lintFn = FileLinter[fileExtension];
1154
+ if (!lintFn) {
1155
+ return;
1156
+ }
1157
+ lintFn(content, { path: inputPath });
1158
+ } catch (e) {
1159
+ const message = `No such file or has no access to ${(0, import_chalk3.bold)(resolvedPath)}`;
1160
+ console.error(message, e);
1161
+ import_log6.default.error(message);
1162
+ }
1163
+ if (onFinish) {
1164
+ onFinish();
1165
+ }
1166
+ }
1167
+ function MdFileLinter(content, lintOptions) {
1168
+ const _a = argv_default.getConfig(), {
1169
+ input,
1170
+ lintConfig,
1171
+ disableLiquid,
1172
+ outputFormat
1173
+ } = _a, options = __objRest(_a, [
1174
+ "input",
1175
+ "lintConfig",
1176
+ "disableLiquid",
1177
+ "outputFormat"
1178
+ ]);
1179
+ const { path: filePath } = lintOptions;
1180
+ const plugins2 = outputFormat === "md" ? [] : plugins_exports.getPlugins();
1181
+ const vars = getVarsPerFile(filePath);
1182
+ const root = (0, import_path18.resolve)(input);
1183
+ const path = (0, import_path18.resolve)(input, filePath);
1184
+ let preparedContent = content;
1185
+ const assetsPublicPath = (0, import_path18.relative)((0, import_path18.dirname)(path), root);
1186
+ const lintMarkdown = function lintMarkdown2(opts) {
1187
+ const { input: localInput, path: localPath, sourceMap: sourceMap2 } = opts;
1188
+ const pluginOptions = __spreadProps(__spreadValues({}, options), {
1189
+ vars,
1190
+ root,
1191
+ path: localPath,
1192
+ lintMarkdown: lintMarkdown2,
1193
+ // Should pass the function for linting included files
1194
+ assetsPublicPath,
1195
+ disableLiquid,
1196
+ log: import_log6.default,
1197
+ getVarsPerFile: getVarsPerRelativeFile
1198
+ });
1199
+ (0, import_yfmlint.default)({
1200
+ input: localInput,
1201
+ lintConfig,
1202
+ pluginOptions,
1203
+ plugins: plugins2,
1204
+ defaultLintConfig: plugins_exports.getDefaultLintConfig(),
1205
+ customLintRules: plugins_exports.getCustomLintRules(),
1206
+ sourceMap: sourceMap2
1207
+ });
1208
+ };
1209
+ let sourceMap;
1210
+ if (!disableLiquid) {
1211
+ let liquidResult;
1212
+ if (outputFormat === "md") {
1213
+ liquidResult = liquidMd2Md(content, vars, path);
1214
+ } else {
1215
+ liquidResult = liquidMd2Html(content, vars, path);
1216
+ }
1217
+ preparedContent = liquidResult.output;
1218
+ sourceMap = liquidResult.sourceMap;
1219
+ }
1220
+ lintMarkdown({
1221
+ input: preparedContent,
1222
+ path,
1223
+ sourceMap
1224
+ });
1225
+ }
1226
+
1227
+ // src/workers/linter/index.ts
1228
+ var processedPages = new import_observable.Subject();
1229
+ function run(_0) {
1230
+ return __async(this, arguments, function* ({
1231
+ argvConfig,
1232
+ presetStorage: presetStorage2,
1233
+ navigationPaths: navigationPaths2
1234
+ }) {
1235
+ argv_default.set(argvConfig);
1236
+ preset_default.setPresetStorage(presetStorage2);
1237
+ tocs_default.setNavigationPaths(navigationPaths2);
1238
+ plugins_exports.setPlugins();
1239
+ tocs_default.getNavigationPaths().forEach((pathToFile) => {
1240
+ lintPage({
1241
+ inputPath: pathToFile,
1242
+ fileExtension: (0, import_path19.extname)(pathToFile),
1243
+ onFinish: () => {
1244
+ processedPages.next(pathToFile);
1245
+ }
1246
+ });
1247
+ });
1248
+ });
1249
+ }
1250
+ function finish() {
1251
+ return __async(this, null, function* () {
1252
+ processedPages.complete();
1253
+ processedPages = new import_observable.Subject();
1254
+ return import_log7.default.get();
1255
+ });
1256
+ }
1257
+ function getProcessedPages() {
1258
+ return import_observable.Observable.from(processedPages);
1259
+ }
1260
+ (0, import_threads.expose)({
1261
+ run,
1262
+ finish,
1263
+ getProcessedPages
1264
+ });
1265
+ //# sourceMappingURL=linter.js.map