Skip to content

Commit

Permalink
Merge branch 'issue-11'
Browse files Browse the repository at this point in the history
  • Loading branch information
hyunjiLeeTech committed Oct 8, 2020
2 parents 8c7bd73 + c0bcf56 commit 83e84fd
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 6 deletions.
32 changes: 26 additions & 6 deletions index.js
Expand Up @@ -4,8 +4,12 @@ const request = require("request");
const path = require("path");
const colors = require("colors");
const fs = require("fs");
const regex = /(http(s)?:\/\/.)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/g
const linkRegex = /(http(s)?:\/\/.)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/g
const goodRegex = /\-\-good/;
const badRegex = /\-\-bad/;
const allRegex = /\-\-all/;
let exitFlag = true;
let statusFlag = 1; // 1: all, 2: good, 3: bad

// If the user doesn't enter any arguments/filenames, it exits the process
if (process.argv.length === 2) {
Expand Down Expand Up @@ -36,6 +40,14 @@ for (let i = 2; i < process.argv.length; i++) {
console.log("Version: 0.1")
}
}

if (arg.match(goodRegex)) {
statusFlag = 2;
} else if (arg.match(badRegex)) {
statusFlag = 3;
} else if (arg.match(allRegex)) {
statusFlag = 1;
}
}

// If the user enters any arguments/filenames, starts process.
Expand All @@ -50,7 +62,7 @@ for (let i = 2; i < process.argv.length; i++) {
exitFlag = false;
process.exit(1);
}
let links = data.match(regex);
let links = data.match(linkRegex);
for (let i = 0; i < links.length; i++) {
let link = links[i];
if (link.startsWith("https://")) {
Expand Down Expand Up @@ -80,15 +92,23 @@ function checkUrl(url) {
request({ method: 'HEAD', uri: url }, function (err, res, body) {
if (err) {
exitFlag = false;
console.log(colors.yellow(`${err} ${url}`));
if (statusFlag != 2) {
console.log(colors.yellow(`${err} ${url}`));
}
} else if (res.statusCode == 200) {
console.log(colors.green(`[PASSED] [200] ${url}`));
if (statusFlag != 3) {
console.log(colors.green(`[PASSED] [200] ${url}`));
}
} else if (res.statusCode == 404 || res.statusCode == 400) {
exitFlag = false;
console.log(colors.red(`[FAILED] [${res.statusCode}] ${url}`));
if (statusFlag != 2) {
console.log(colors.red(`[FAILED] [${res.statusCode}] ${url}`));
}
} else {
exitFlag = false;
console.log(colors.grey(`[UNKNOWN] [${res.statusCode}] ${url}`))
if (statusFlag != 2) {
console.log(colors.grey(`[UNKNOWN] [${res.statusCode}] ${url}`))
}
}
})
}
27 changes: 27 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 83e84fd

Please sign in to comment.