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

Prasad #6

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
28 changes: 16 additions & 12 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ module.exports.exec = (
},
]
) => {
//right now URL is just string
//TODO : Check the type of URL, if string then below code, if list i.e multiple URLs then handle that
// Resolution will be a list of list in that case or Better have a dictionary and iterate over that
return (() => {
console.log("Running...")
var auditState = webReview.auditState;
Expand All @@ -32,19 +29,26 @@ module.exports.exec = (
auditState.url = -1;
return;
}
webReview.lh(
urlList[auditState.url].url,
urlList[auditState.url].category
);
urlList[auditState.url].url.forEach(url => {
webReview.lh(
url,
urlList[auditState.url].category
);
});
});

for (const key in urlList) {
const urlObj = urlList[key];
var dir = new URL(urlObj.url).hostname;
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir);
}
webReview.ss(urlObj.url, urlObj.resolution);
urlObj.url.forEach(url =>{
var urlNewObj = new URL(url);
var dir = urlNewObj.hostname + "/" + urlNewObj.pathname;
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir,{recursive:true},(err) => {
if(err) throw new err;
});
}
webReview.ss(url, urlObj.resolution);
});
}
//begin auditing
if (auditState.url === -1) auditState.url = 0;
Expand Down
26 changes: 21 additions & 5 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,15 @@ module.exports.ss = (
//TODO : Check the type of URL, if string then below code, if list i.e multiple URLs then handle that
// Resolution will be a list of list in that case or Better have a dictionary and iterate over that
return (async () => {
var dir = "./" + new URL(url).hostname + "/screenshots";
var urlObj = new URL(url);
const hostname = urlObj.hostname;
const path = urlObj.pathname
var dir = "./"
if(hostname && hostname != "") dir = dir + hostname;
if(path && path != "") dir = dir + "/" + path;
dir = dir + "/screenshots"
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir);
fs.mkdirSync(dir,{recursive:true});
}
await new Pageres({ delay: 2 }).src(url, resolution).dest(dir).run();

Expand All @@ -80,11 +86,18 @@ module.exports.lh = (url = "https://github.com", categories = []) => {
// console.log(opts);
launchChromeAndRunLighthouse(url, opts).then((results) => {
const html = ReportGenerator.generateReport(results, "html");
var filename = new URL(url).hostname;
var urlObj = new URL(url);
const hostname = urlObj.hostname
const path = urlObj.pathname
var dir = "./"
var filename = ""
if(hostname && hostname != "") {dir = dir + hostname; filename = filename + hostname}
if(path && path!="") {dir = dir + "/" + path; filename = filename + "." + path}
dir = dir+"/reports"
filename += ".html";
var dir = "./" + new URL(url).hostname + "/reports";
filename = filename.replace(/\//g,'')
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir);
fs.mkdirSync(dir,{recursive:true});
}
fs.writeFile(Path.join(dir, filename), html, function (err) {
if (err) {
Expand All @@ -93,6 +106,9 @@ module.exports.lh = (url = "https://github.com", categories = []) => {
console.log("Finished Generating Audit Report for " + url);
auditState.url += 1;
});
}).catch((err) => {
console.log("Unable to launch chrome and run lighthouse for url",url)
console.log(err);
});
};

Expand Down
4 changes: 2 additions & 2 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const webReview = require("./src/index");
webReview.exec([
{
url: "https://www.github.com/",
url: ["https://www.github.com/marketplace"],
resolution: [
"480x320",
"1024x768",
Expand All @@ -11,7 +11,7 @@ webReview.exec([
],
},
{
url: "https://www.google.com",
url: ["https://www.google.com"],
resolution: [
"480x320",
"1024x768",
Expand Down