markdown_link_checker_sc 0.0.7 → 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 +39 -16
- 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,11 +38,23 @@ program
|
|
|
33
38
|
|
|
34
39
|
const options = program.opts();
|
|
35
40
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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);
|
|
57
|
+
}
|
|
41
58
|
}
|
|
42
59
|
|
|
43
60
|
const isMarkdown = (file) => path.extname(file).toLowerCase() === ".md";
|
|
@@ -385,18 +402,14 @@ function filterErrors(errors) {
|
|
|
385
402
|
// This method filters all errors against settings in the command line - such as pages to output.
|
|
386
403
|
let filteredErrors = errors;
|
|
387
404
|
// Filter results on specified file names (if any specified)
|
|
405
|
+
console.log(`Number pages to filter: ${options.files.length}`);
|
|
388
406
|
if (options.files.length > 0) {
|
|
389
407
|
filteredErrors = errors.filter((error) => {
|
|
390
408
|
//console.log(`Error: ${error}`);
|
|
391
409
|
//console.log(JSON.stringify(error, null, 2));
|
|
392
410
|
//console.log(`Error page: ${error.page}`);
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
if (pathOnly.startsWith("/") || pathOnly.startsWith("\\")) {
|
|
396
|
-
pathOnly = pathOnly.slice(1);
|
|
397
|
-
}
|
|
398
|
-
//console.log(`Pathonly: ${pathOnly}`);
|
|
399
|
-
return options.files.includes(pathOnly);
|
|
411
|
+
|
|
412
|
+
return options.files.includes(error.page);
|
|
400
413
|
});
|
|
401
414
|
}
|
|
402
415
|
// Filter on other things - such as errors.
|
|
@@ -405,7 +418,6 @@ function filterErrors(errors) {
|
|
|
405
418
|
return filteredErrors;
|
|
406
419
|
}
|
|
407
420
|
|
|
408
|
-
|
|
409
421
|
function outputErrors(results) {
|
|
410
422
|
//console.log(results.allErrors);
|
|
411
423
|
|
|
@@ -479,6 +491,17 @@ function outputErrors(results) {
|
|
|
479
491
|
}
|
|
480
492
|
|
|
481
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
|
+
|
|
482
505
|
const results = await processDirectory(
|
|
483
506
|
options.directory,
|
|
484
507
|
options.headingAnchorSlugify
|