-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
72 lines (60 loc) · 1.66 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
const fs = require("fs");
const { promisify } = require("util");
const inquirer = require("inquirer");
const open = require("open");
require("dotenv").config();
const Page = require("./helpers/Page");
const { runLighthouse, runCLS } = require("./helpers/functions");
const { inputPrompt, clsPrompt } = require("./helpers/prompts");
const { fetchSheet } = require("./sheets");
let currentFile = "";
/**
* @param {array} url list
*/
async function askForURL(arr) {
try {
const { url } = await inquirer.prompt([
{
name: "url",
type: "list",
message: "Select a url",
choices: [...arr.map(({ url }) => url), "Or enter URL"],
},
]);
if (url === "Or enter URL") {
const { url, filename } = await inquirer.prompt(inputPrompt);
const page = new Page("Entered URL", filename, url);
if (!page.filename) {
page.createFilename();
}
return page;
}
return arr.find((page) => page.url === url);
} catch (err) {
console.log(err);
}
}
async function askForCLS(page) {
const { cls } = await inquirer.prompt(clsPrompt);
if (cls) {
page.cls = true;
}
return;
}
(async () => {
const urls = await fetchSheet(process.env.SHEET_NAME);
const pages = urls.map((url) => {
const page = new Page("temp", "temp", url);
page.createFilename();
return page;
});
const input = await askForURL(pages);
await askForCLS(input);
await runLighthouse(input);
console.log("\nLighthouse report opened in default browser\n");
if (input.cls) {
await runCLS(input);
await open(`${input.filename}.gif`);
console.log("\nCLS gif opened in default photo viewer\n");
}
})();