Skip to content

Commit

Permalink
Add message if no links are found
Browse files Browse the repository at this point in the history
  • Loading branch information
spookyuser committed Jan 2, 2025
1 parent 67060bb commit d760c38
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
28 changes: 15 additions & 13 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import fs from "fs";
import path from "path";
import arg from "arg";
import invariant from "tiny-invariant";
import console from "console";

const urlRegex =
/((?<!\+)https?:\/\/(?:www\.)?(?:[-\p{Letter}.]+?[.@][a-zA-Z\d]{2,}|localhost)(?:[-\w\p{Letter}.:%+~#*$!?&/=@]*?(?:,(?!\s))*?)*)/gu;
Expand Down Expand Up @@ -34,19 +35,20 @@ function processFile(filePath: string, shouldRemove: boolean) {
let fileContent = fs.readFileSync(filePath, "utf-8");
const jsLinks = extractJsLinks(fileContent);

if (jsLinks.length > 0) {
console.log(`JS link(s) found in ${filePath}:`);
console.log(jsLinks);

if (shouldRemove) {
for (const link of jsLinks) {
fileContent = fileContent.replace(link, "");
}
fs.writeFileSync(filePath, fileContent);
console.log(`JS link(s) removed from ${filePath}`);
} else {
console.error("Links found (use --remove to remove them).");
}
if (jsLinks.length === 0) {
console.log(`No JS link(s) found in ${filePath}`);
return;
}

console.log(`JS link(s) found in ${filePath}:`);
console.log(jsLinks);

if (shouldRemove) {
jsLinks.forEach((link) => (fileContent = fileContent.replace(link, "")));
fs.writeFileSync(filePath, fileContent);
console.log(`JS link(s) removed from ${filePath}`);
} else {
console.error("Links found (use --remove to remove them).");
}
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "badlinks",
"version": "1.1.0",
"version": "1.1.1",
"description": "A fast way to scan a package for links that might upset the chrome webstore team",
"scripts": {
"build": "bun run build.ts",
Expand Down

0 comments on commit d760c38

Please sign in to comment.