Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance Improvements #20

Merged
merged 1 commit into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@ if (path === "help") {
process.exit(0);
}

scanLinks(path);
scanLinks(path).then(() => {
process.exit(0);
}).catch(() => {
process.exit(1);
});
38 changes: 24 additions & 14 deletions bin/scan/scanLinks.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const help = require("../help.js");
const fs = require('fs');

// path is <file/directory path>
function links(path) {
async function scanLinks(path) {
// Error: path does not exist
if (!fs.existsSync(path)) {
console.error('Error:', path, 'does not exist');
Expand All @@ -26,21 +26,31 @@ function links(path) {
const lastSlashIndex = removeSlash.lastIndexOf('/');
const fluff = removeSlash.substring(0, lastSlashIndex + 1);

filePaths.forEach(async (filePath) => {
// gets content of path
const fileContent = readFile(filePath);

// gets array of links from fileContent
const links = getLinks(fileContent);
console.log("If nothing is output below, no broken links where found");

// if any broken links are found, it writes
// them to an "output" folder
if (links !== null) {
await writeBrokenLinks(links, filePath, fluff);
}
let promises = filePaths.map(filePath => {
return new Promise(async (resolve, reject) => {
try {
const fileContent = readFile(filePath);
const links = getLinks(fileContent);

if (links !== null) {
await writeBrokenLinks(links, filePath, fluff);
}
resolve();
} catch (error) {
reject(error);
}
});
});

console.log("If nothing is output below, no broken links where found");
await Promise.all(promises)
.then(() => {
console.log("Finished!");
})
.catch(error => {
console.error("An error occurred:", error);
});
}

module.exports = links;
module.exports = scanLinks;
3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
"version": "1.1.0",
"description": "A npx package that automatically scans files and directories broken links.",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"bin": {
"link-inspector": "bin/index.js"
},
Expand Down