markdown_link_checker_sc 0.0.8 → 0.0.9
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.
- package/index.js +38 -13
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -22,9 +22,14 @@ program
|
|
|
22
22
|
)
|
|
23
23
|
.option("-l, --log [value]", "Export some logs for debugging. ", false)
|
|
24
24
|
.option(
|
|
25
|
-
"-f, --files <
|
|
26
|
-
"
|
|
27
|
-
|
|
25
|
+
"-f, --files <path>",
|
|
26
|
+
"JSON file with array of files to report on (default is all files). Paths are relative relative to -d by default, but -r can be used to set a different root.",
|
|
27
|
+
""
|
|
28
|
+
)
|
|
29
|
+
.option(
|
|
30
|
+
"-r, --root <path>",
|
|
31
|
+
"Directory to prepend before file paths in the JSON directory. Default is same as directory. Useful if directory is not your repo root",
|
|
32
|
+
""
|
|
28
33
|
)
|
|
29
34
|
.parse(process.argv);
|
|
30
35
|
|
|
@@ -33,9 +38,22 @@ program
|
|
|
33
38
|
|
|
34
39
|
const options = program.opts();
|
|
35
40
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
41
|
+
// Function for loading JSON file that contains files to report on
|
|
42
|
+
async function loadJSONFileToReportOn(filePath) {
|
|
43
|
+
try {
|
|
44
|
+
const fileContent = await fs.promises.readFile(filePath, "utf8");
|
|
45
|
+
let filesArray = JSON.parse(fileContent);
|
|
46
|
+
// Values default to option directory if not specified
|
|
47
|
+
if (!options.root) {
|
|
48
|
+
options.root = options.directory;
|
|
49
|
+
}
|
|
50
|
+
// Prepend the full path.
|
|
51
|
+
filesArray = filesArray.map((str) => path.join(options.root, str));
|
|
52
|
+
//console.log(filesArray);
|
|
53
|
+
return filesArray;
|
|
54
|
+
} catch (error) {
|
|
55
|
+
console.error(`Error reading file: ${error.message}`);
|
|
56
|
+
process.exit(1);
|
|
39
57
|
}
|
|
40
58
|
}
|
|
41
59
|
|
|
@@ -384,18 +402,14 @@ function filterErrors(errors) {
|
|
|
384
402
|
// This method filters all errors against settings in the command line - such as pages to output.
|
|
385
403
|
let filteredErrors = errors;
|
|
386
404
|
// Filter results on specified file names (if any specified)
|
|
405
|
+
console.log(`Number pages to filter: ${options.files.length}`);
|
|
387
406
|
if (options.files.length > 0) {
|
|
388
407
|
filteredErrors = errors.filter((error) => {
|
|
389
408
|
//console.log(`Error: ${error}`);
|
|
390
409
|
//console.log(JSON.stringify(error, null, 2));
|
|
391
410
|
//console.log(`Error page: ${error.page}`);
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
if (pathOnly.startsWith("/") || pathOnly.startsWith("\\")) {
|
|
395
|
-
pathOnly = pathOnly.slice(1);
|
|
396
|
-
}
|
|
397
|
-
//console.log(`Pathonly: ${pathOnly}`);
|
|
398
|
-
return options.files.includes(pathOnly);
|
|
411
|
+
|
|
412
|
+
return options.files.includes(error.page);
|
|
399
413
|
});
|
|
400
414
|
}
|
|
401
415
|
// Filter on other things - such as errors.
|
|
@@ -477,6 +491,17 @@ function outputErrors(results) {
|
|
|
477
491
|
}
|
|
478
492
|
|
|
479
493
|
(async () => {
|
|
494
|
+
options.files
|
|
495
|
+
? (options.files = await loadJSONFileToReportOn(options.files))
|
|
496
|
+
: (options.files = []);
|
|
497
|
+
if (options.log == "quick") {
|
|
498
|
+
for (const file of options.files) {
|
|
499
|
+
console.log(file);
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
//const object = filesToProcessJSONFilePath ? await convertFileToObject(filePath) : [];
|
|
504
|
+
|
|
480
505
|
const results = await processDirectory(
|
|
481
506
|
options.directory,
|
|
482
507
|
options.headingAnchorSlugify
|