This repository has been archived by the owner on Jun 26, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
117 lines (93 loc) · 3.6 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
const fs = require('fs');
const path = require('path');
const inquirer = require('inquirer');
// Set the path of the project folder base on whether it is run with nodejs or as an executable
let project_folder;
if(process.pkg){
// It is run as an executable
project_folder = path.dirname(process.execPath)
}else{
// It is run with nodejs
project_folder = __dirname
}
let source;
let sourceFileName;
inquirer
.prompt([
{
name: 'sourceFileName',
message: '\n Enter entry point:',
default: 'index.html'
}
])
.then(answers => {
sourceFileName = answers.sourceFileName;
if (!fs.existsSync(path.join(project_folder, '/checker/', sourceFileName))) {
console.log(`\n \x1b[31m\x1b[1mNo source file found!\x1b[0m\n`);
console.log(` Place a valid html file along with assets in the 'checker' folder and try again...`);
} else {
source = fs.readFileSync(path.join(project_folder, '/checker/', sourceFileName), 'utf8');
/*
<img src="djaksd.webm">
url(lol.jpg)
[img[a32edc/asdje\ade.mp4]]
[img[hom e.svg]]
[img[home.webp][Home]]
[img[home.jpeg][Home][$done to true]]
[img[Go home|home.jpg]]
[img[Go home|home.png][Home]]
[img[Go home|home.gif][Home][$done to true]]
*/
let imgRegex = /(?:(?:\-\>)|(?:\|)|(?:\")|(?:\[)|(?:\()|(?:\"\;))([0-9a-zA-Z\\\/\^\&\'\@\{\}\,\$\=\!\-\#\(\)\.\%\+\~\_ ]+?\.(?:(?:png)|(?:jpg)|(?:jpeg)|(?:gif)|(?:svg)|(?:webp)|(?:webm)|(?:mp4)))(?:(?:\<\-)|(?:\")|(?:\])|(?:\))|(?:\"\;))/gi;
let imgSources = [...source.matchAll(imgRegex)];
let found = [];
let missing = [];
if (imgSources !== null) {
for (let i = 0; i < imgSources.length; i++) {
let ipath = imgSources[i][1].replace(/\\/gi, "/").trim();
let prj = path.join(project_folder, '/checker/');
_ipath = (ipath.substr(0,2) === "./") ? prj+ipath.substr(2) : prj+ipath;
if (fs.existsSync(_ipath)) {
found.push(ipath);
} else {
missing.push(ipath);
}
}
}
let unique = (value, index, self) => {
return self.indexOf(value) === index;
}
found = found.filter(unique);
missing = missing.filter(unique).sort(function(a, b){
return b.length - a.length;
});
let falsePositives = [];
console.log(`\n Reference(s) found : ${found.length + missing.length}`);
console.log(` Working sources : ${found.length}`);
console.log(` Missing sources : ${missing.length}\n`);
if (missing.length !== 0) {
console.log(` =======================================`);
console.log(` The following source(s) is/are missing:`);
console.log(` =======================================\n`);
for (let m = 0; m < missing.length; m++) {
if (!missing[m].includes("/")) {
falsePositives = [...falsePositives, missing[m]];
} else {
console.log(` \x1b[31m\x1b[1m"${missing[m]}"\x1b[0m`);
}
}
}
if (falsePositives.length !== 0) {
console.log(`\n ======================`);
console.log(` Possible false alarms:`);
console.log(` ======================\n`);
for (let p = 0; p < falsePositives.length; p++) {
console.log(` \x1b[33m\x1b[1m"${falsePositives[p]}"\x1b[0m`);
}
}
}
console.log(`\n Press any key to exit...`);
process.stdin.setRawMode(true);
process.stdin.resume();
process.stdin.on('data', process.exit.bind(process, 0));
});