stack-analyze 1.2.0 → 1.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/about.js +19 -11
- package/api/webApis.js +25 -0
- package/cli.js +141 -382
- package/functions/animeInfo.js +13 -14
- package/functions/bitly.js +16 -16
- package/functions/cryptoList.js +9 -15
- package/functions/gitUser.js +18 -18
- package/functions/hardware.js +96 -177
- package/functions/moviesInfo.js +10 -6
- package/functions/multipleStack.js +19 -28
- package/functions/pageSpeed.js +64 -96
- package/functions/password.js +10 -11
- package/functions/scraping.js +123 -143
- package/functions/singleStack.js +10 -9
- package/functions/twitch.js +43 -15
- package/hash/infoTools.js +46 -0
- package/hash/queryTools.js +52 -0
- package/hash/utilityTools.js +21 -0
- package/hash/webTools.js +58 -0
- package/index.cjs +117 -163
- package/index.mjs +120 -168
- package/package.json +9 -9
- package/scraping.json +6 -0
- package/utils.js +78 -4
- package/validations/infoValidations.js +37 -0
- package/validations/webValidations.js +33 -0
package/functions/cryptoList.js
CHANGED
|
@@ -6,23 +6,19 @@ import colors from "colors";
|
|
|
6
6
|
import { printTable } from "console-table-printer";
|
|
7
7
|
|
|
8
8
|
// currency format
|
|
9
|
-
import { currency } from "../utils.js";
|
|
9
|
+
import { currency, stackSave } from "../utils.js";
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
13
12
|
* @descripiton call the crypto market list
|
|
13
|
+
* @async
|
|
14
14
|
* @returns { Promise<void> } - return results search
|
|
15
|
-
*
|
|
16
15
|
*/
|
|
17
|
-
|
|
16
|
+
export default async function cryptoMarket() {
|
|
18
17
|
try {
|
|
19
18
|
// start crypto
|
|
20
19
|
const { data } = await axios.get(
|
|
21
20
|
"https://api.coingecko.com/api/v3/coins/markets", {
|
|
22
|
-
params: {
|
|
23
|
-
vs_currency: "usd",
|
|
24
|
-
per_page: 10
|
|
25
|
-
}
|
|
21
|
+
params: { vs_currency: "usd" }
|
|
26
22
|
}
|
|
27
23
|
);
|
|
28
24
|
|
|
@@ -37,18 +33,16 @@ const cryptoMarket = async () => {
|
|
|
37
33
|
symbol,
|
|
38
34
|
name,
|
|
39
35
|
price: currency.format(current_price),
|
|
40
|
-
priceChanged: price_change_percentage_24h
|
|
41
|
-
? colors.green(price_change_percentage_24h)
|
|
42
|
-
: colors.red(price_change_percentage_24h),
|
|
36
|
+
priceChanged: `${price_change_percentage_24h.toFixed(2)} %`,
|
|
43
37
|
lastUpdated: format(last_updated)
|
|
44
38
|
}));
|
|
45
39
|
|
|
46
40
|
// print table
|
|
47
|
-
printTable(coinList);
|
|
41
|
+
printTable(coinList.slice(0, 10));
|
|
42
|
+
|
|
43
|
+
stackSave("crypto-list.json", JSON.stringify(coinList, null, 2));
|
|
48
44
|
} catch (err) {
|
|
49
45
|
// print err message
|
|
50
46
|
console.error(colors.red(err.message));
|
|
51
47
|
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export default cryptoMarket;
|
|
48
|
+
}
|
package/functions/gitUser.js
CHANGED
|
@@ -3,35 +3,35 @@ import { default as axios } from "axios";
|
|
|
3
3
|
import { format } from "timeago.js";
|
|
4
4
|
import colors from "colors";
|
|
5
5
|
|
|
6
|
+
// save git user
|
|
7
|
+
import { stackSave } from "../utils.js";
|
|
8
|
+
|
|
6
9
|
/**
|
|
7
10
|
*
|
|
8
11
|
* @description call github info user
|
|
12
|
+
* @async
|
|
9
13
|
* @param { string } user - get github user info
|
|
10
14
|
* @returns { Promise<void> } - return results info
|
|
11
15
|
*
|
|
12
16
|
*/
|
|
13
17
|
export default async function githubInfo(user) {
|
|
14
18
|
try {
|
|
15
|
-
const { data
|
|
19
|
+
const { data } = await axios.get(`https://api.github.com/users/${user}`);
|
|
16
20
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
repos: data.public_repos,
|
|
28
|
-
gists: data.public_gists
|
|
29
|
-
};
|
|
21
|
+
const info = {
|
|
22
|
+
username: data.login,
|
|
23
|
+
fullName: data?.name ?? "no info",
|
|
24
|
+
userFollowers: data.followers,
|
|
25
|
+
userFollowing: data.following,
|
|
26
|
+
accountAge: format(data.created_at),
|
|
27
|
+
twitter: data?.twitter_username ?? "no info",
|
|
28
|
+
repos: data.public_repos,
|
|
29
|
+
gists: data.public_gists
|
|
30
|
+
};
|
|
30
31
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
32
|
+
console.table(info);
|
|
33
|
+
|
|
34
|
+
stackSave(`${user}-info.json`, JSON.stringify(info, null, 2))
|
|
35
35
|
} catch(err) {
|
|
36
36
|
console.error(colors.red(err.message));
|
|
37
37
|
}
|
package/functions/hardware.js
CHANGED
|
@@ -8,194 +8,113 @@ import {
|
|
|
8
8
|
bios
|
|
9
9
|
} from "systeminformation";
|
|
10
10
|
import colors from "colors";
|
|
11
|
-
import { printTable } from "console-table-printer";
|
|
12
11
|
|
|
13
|
-
|
|
14
|
-
const hardwareTools = {
|
|
15
|
-
async cpuInfo() {
|
|
16
|
-
console.clear();
|
|
12
|
+
import { stackSave } from "../utils.js";
|
|
17
13
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
processors,
|
|
26
|
-
vendor,
|
|
27
|
-
family,
|
|
28
|
-
model
|
|
29
|
-
} = await cpu();
|
|
14
|
+
/**
|
|
15
|
+
*
|
|
16
|
+
* @param {number} size
|
|
17
|
+
* @param {number} [base = 1073741824]
|
|
18
|
+
* @returns {string}
|
|
19
|
+
*/
|
|
20
|
+
const gigabyteConvert = (size, base=1073741824) => (size / base).toFixed(2);
|
|
30
21
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
console.clear();
|
|
49
|
-
|
|
50
|
-
try {
|
|
51
|
-
const {
|
|
52
|
-
total,
|
|
53
|
-
free,
|
|
54
|
-
used,
|
|
55
|
-
active,
|
|
56
|
-
available
|
|
57
|
-
} = await mem();
|
|
22
|
+
/**
|
|
23
|
+
*
|
|
24
|
+
* @async
|
|
25
|
+
* @returns {Promise<void>}
|
|
26
|
+
*/
|
|
27
|
+
export default async function hardware() {
|
|
28
|
+
try {
|
|
29
|
+
// Map object
|
|
30
|
+
const hardware = new Map();
|
|
31
|
+
|
|
32
|
+
// info
|
|
33
|
+
const biosInfo = await bios()
|
|
34
|
+
const cpuInfo = await cpu()
|
|
35
|
+
const ram = await mem()
|
|
36
|
+
const os = await osInfo()
|
|
37
|
+
const disks = await diskLayout()
|
|
38
|
+
const { displays, controllers } = await graphics();
|
|
58
39
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
active_mem: `${(active / 1073741824).toFixed(2)} GB`,
|
|
65
|
-
available_mem: `${(available / 1073741824).toFixed(2)} GB`
|
|
66
|
-
});
|
|
67
|
-
} catch (err) {
|
|
68
|
-
console.error(colors.red(err.message));
|
|
40
|
+
// omit falsy values
|
|
41
|
+
for(const key in biosInfo) {
|
|
42
|
+
if(!biosInfo[key]) {
|
|
43
|
+
delete biosInfo[key];
|
|
44
|
+
}
|
|
69
45
|
}
|
|
70
|
-
},
|
|
71
|
-
async osDetail() {
|
|
72
|
-
console.clear();
|
|
73
46
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
distro,
|
|
79
|
-
release,
|
|
80
|
-
kernel,
|
|
81
|
-
arch,
|
|
82
|
-
serial,
|
|
83
|
-
uefi
|
|
84
|
-
} = await osInfo();
|
|
85
|
-
|
|
86
|
-
// show results
|
|
87
|
-
console.table({
|
|
88
|
-
hostname,
|
|
89
|
-
platform,
|
|
90
|
-
distro,
|
|
91
|
-
release,
|
|
92
|
-
kernel,
|
|
93
|
-
arch,
|
|
94
|
-
serial,
|
|
95
|
-
uefi
|
|
96
|
-
});
|
|
97
|
-
} catch (err) {
|
|
98
|
-
console.error(colors.red(err.message));
|
|
47
|
+
for(const key in cpuInfo) {
|
|
48
|
+
if(!cpuInfo[key]) {
|
|
49
|
+
delete cpuInfo[key];
|
|
50
|
+
}
|
|
99
51
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
const disks = await diskLayout();
|
|
106
|
-
|
|
107
|
-
const disksList = disks.map(({
|
|
108
|
-
type,
|
|
109
|
-
name,
|
|
110
|
-
vendor,
|
|
111
|
-
size,
|
|
112
|
-
interfaceType
|
|
113
|
-
}) => ({
|
|
114
|
-
type,
|
|
115
|
-
name,
|
|
116
|
-
vendor,
|
|
117
|
-
diskSize: `${(size / 1073741824).toFixed(2)} GB`,
|
|
118
|
-
interfaceType
|
|
119
|
-
}));
|
|
120
|
-
|
|
121
|
-
printTable(disksList);
|
|
122
|
-
|
|
123
|
-
} catch (err) {
|
|
124
|
-
console.error(colors.red(err.message));
|
|
52
|
+
|
|
53
|
+
for(const key in cpuInfo.cache) {
|
|
54
|
+
if(!cpuInfo.cache[key]) {
|
|
55
|
+
delete cpuInfo.cache[key];
|
|
56
|
+
}
|
|
125
57
|
}
|
|
126
|
-
},
|
|
127
|
-
async controllerInfo() {
|
|
128
|
-
console.clear();
|
|
129
58
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
model,
|
|
135
|
-
vendor,
|
|
136
|
-
vram
|
|
137
|
-
}) => ({
|
|
138
|
-
model,
|
|
139
|
-
vendor,
|
|
140
|
-
vramSize: vram < 1024
|
|
141
|
-
? `${vram} MB`
|
|
142
|
-
: `${(vram / 1024).toFixed(2)} GB`
|
|
143
|
-
}));
|
|
144
|
-
|
|
145
|
-
// show results
|
|
146
|
-
printTable(controllersList);
|
|
147
|
-
} catch (err) {
|
|
148
|
-
console.error(colors.red(err.message));
|
|
59
|
+
for(const key in os) {
|
|
60
|
+
if(!os[key]) {
|
|
61
|
+
delete os[key];
|
|
62
|
+
}
|
|
149
63
|
}
|
|
150
|
-
},
|
|
151
|
-
async displayInfo() {
|
|
152
|
-
console.clear();
|
|
153
64
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
const displayList = displays.map(({
|
|
158
|
-
model,
|
|
159
|
-
main,
|
|
160
|
-
connection,
|
|
161
|
-
resolutionX,
|
|
162
|
-
resolutionY
|
|
163
|
-
}) => ({
|
|
164
|
-
model,
|
|
165
|
-
main,
|
|
166
|
-
connection,
|
|
167
|
-
resolutionX,
|
|
168
|
-
resolutionY
|
|
169
|
-
}));
|
|
170
|
-
|
|
171
|
-
// show results
|
|
172
|
-
printTable(displayList);
|
|
173
|
-
} catch (err) {
|
|
174
|
-
console.error(colors.red(err.message));
|
|
65
|
+
for(const key in ram) {
|
|
66
|
+
ram[key] = `${gigabyteConvert(ram[key])} GB`;
|
|
175
67
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
68
|
+
|
|
69
|
+
disks.forEach(disk => {
|
|
70
|
+
for(const key in disk) {
|
|
71
|
+
if(!disk[key]) {
|
|
72
|
+
delete disk[key];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if(typeof disk[key] === "number") {
|
|
76
|
+
disk[key] = `${gigabyteConvert(ram[key])} GB`;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
controllers.forEach(controller => {
|
|
82
|
+
for(const key in controller) {
|
|
83
|
+
if(!controller[key]) {
|
|
84
|
+
delete controller[key];
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if(typeof controller[key] === "number") {
|
|
88
|
+
controller[key] = controller[key] < 1024
|
|
89
|
+
? `${controller[key]} MB`
|
|
90
|
+
: `${gigabyteConvert(controller[key])} GB`;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
displays.forEach(display => {
|
|
96
|
+
for(const key in display) {
|
|
97
|
+
if(!display[key]) {
|
|
98
|
+
delete display[key];
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
// add values
|
|
104
|
+
hardware.set("bios", biosInfo);
|
|
105
|
+
hardware.set("cpu", cpuInfo);
|
|
106
|
+
hardware.set("ram", ram);
|
|
107
|
+
hardware.set("os", os);
|
|
108
|
+
hardware.set("disks", disks);
|
|
109
|
+
hardware.set("graphics", controllers);
|
|
110
|
+
hardware.set("displays", displays);
|
|
179
111
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
console.table({
|
|
189
|
-
releaseDate,
|
|
190
|
-
vendor,
|
|
191
|
-
bios_revision: revision === "" ? "no info" : revision,
|
|
192
|
-
version
|
|
193
|
-
});
|
|
194
|
-
} catch (err) {
|
|
195
|
-
console.error(colors.red(err.message));
|
|
196
|
-
}
|
|
112
|
+
// save file
|
|
113
|
+
stackSave("hardware.json", JSON.stringify(Object.fromEntries(hardware), null, 2));
|
|
114
|
+
|
|
115
|
+
// finish
|
|
116
|
+
console.info("finish the hardware information file");
|
|
117
|
+
} catch (err) {
|
|
118
|
+
console.error(colors.red(err.message));
|
|
197
119
|
}
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
// exports modules
|
|
201
|
-
export default hardwareTools;
|
|
120
|
+
}
|
package/functions/moviesInfo.js
CHANGED
|
@@ -3,12 +3,17 @@ import { default as axios } from "axios";
|
|
|
3
3
|
import colors from "colors";
|
|
4
4
|
import { printTable } from "console-table-printer";
|
|
5
5
|
|
|
6
|
+
// save movies
|
|
7
|
+
import { stackSave } from "../utils.js";
|
|
8
|
+
|
|
6
9
|
/**
|
|
7
10
|
* @description movie info tool
|
|
11
|
+
* @async
|
|
8
12
|
* @param { string } query - search any movie
|
|
13
|
+
* @param { string } token
|
|
9
14
|
* @returns { Promise<void> } - return movie lisy
|
|
10
15
|
*/
|
|
11
|
-
|
|
16
|
+
export default async function movieDB(query, token) {
|
|
12
17
|
try {
|
|
13
18
|
const { data } = await axios.get("https://api.themoviedb.org/3/search/movie", {
|
|
14
19
|
params: {
|
|
@@ -39,13 +44,12 @@ const movieDB = async (query, token) => {
|
|
|
39
44
|
|
|
40
45
|
return primaryDate.getTime() - secondaryDate.getTime();
|
|
41
46
|
})
|
|
42
|
-
.filter((
|
|
47
|
+
.filter((data) => data?.release_date);
|
|
43
48
|
|
|
44
49
|
printTable(movieData);
|
|
50
|
+
|
|
51
|
+
stackSave("movie-list.json", JSON.stringify(movieData, null, 2));
|
|
45
52
|
} catch (err) {
|
|
46
53
|
console.error(colors.red(err.message));
|
|
47
54
|
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// export
|
|
51
|
-
export default movieDB;
|
|
55
|
+
}
|
|
@@ -1,39 +1,31 @@
|
|
|
1
1
|
// modules
|
|
2
|
-
import figlet from "figlet";
|
|
3
|
-
import Wappalyzer from "wappalyzer";
|
|
4
2
|
import colors from "colors";
|
|
5
3
|
import { printTable } from "console-table-printer";
|
|
4
|
+
import { wappalyzer } from "../api/webApis.js";
|
|
6
5
|
|
|
7
6
|
// list format
|
|
8
|
-
import { listFormat } from "../utils.js";
|
|
7
|
+
import { listFormat, stackSave } from "../utils.js";
|
|
9
8
|
|
|
10
9
|
/**
|
|
11
10
|
*
|
|
12
11
|
* @description call multiple websites tech stack analyze
|
|
13
|
-
* @param { string[] }
|
|
12
|
+
* @param { string[] } urlList - tech analyze in multiples websites
|
|
14
13
|
* @returns { Promise<void> } - async results in multiples websites
|
|
15
14
|
*
|
|
16
15
|
*/
|
|
17
|
-
|
|
18
|
-
const wappalyzer = await new Wappalyzer();
|
|
19
|
-
|
|
16
|
+
export default async function multipleStack(urlList) {
|
|
20
17
|
try {
|
|
21
18
|
await wappalyzer.init();
|
|
22
19
|
|
|
23
|
-
const results = await Promise.all(
|
|
24
|
-
urls.map(async (url) => {
|
|
25
|
-
const { technologies } = await wappalyzer.open(url).analyze();
|
|
26
|
-
|
|
27
|
-
return {
|
|
28
|
-
url,
|
|
29
|
-
technologies
|
|
30
|
-
};
|
|
31
|
-
}));
|
|
32
|
-
|
|
33
20
|
console.info("multiple websites tech stack \n");
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
21
|
+
|
|
22
|
+
const stacks = {};
|
|
23
|
+
|
|
24
|
+
for await (const url of urlList) {
|
|
25
|
+
console.info(url.green);
|
|
26
|
+
|
|
27
|
+
const { technologies } = await wappalyzer.open(url).analyze();
|
|
28
|
+
|
|
37
29
|
const stackResult = technologies.map(({
|
|
38
30
|
name,
|
|
39
31
|
website,
|
|
@@ -47,16 +39,15 @@ const multipleStack = async (urls) => {
|
|
|
47
39
|
};
|
|
48
40
|
});
|
|
49
41
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
42
|
+
printTable(stackResult.slice(0, 10));
|
|
43
|
+
|
|
44
|
+
stacks[url] = stackResult;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
stackSave("multiple-stack.json", JSON.stringify(stacks, null, 2));
|
|
55
48
|
} catch (err) {
|
|
56
49
|
console.error(colors.red(err.message));
|
|
57
50
|
}
|
|
58
51
|
|
|
59
52
|
await wappalyzer.destroy();
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export default multipleStack;
|
|
53
|
+
}
|
package/functions/pageSpeed.js
CHANGED
|
@@ -1,116 +1,84 @@
|
|
|
1
1
|
// modules
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
2
|
+
import { MultiBar, Presets } from "cli-progress";
|
|
3
|
+
import figlet from "figlet";
|
|
4
4
|
import colors from "colors";
|
|
5
5
|
|
|
6
|
+
// save file
|
|
7
|
+
import { stackSave } from "../utils.js";
|
|
8
|
+
|
|
9
|
+
// pagespeed api
|
|
10
|
+
import { pagespeedApi } from "../api/webApis.js";
|
|
11
|
+
|
|
12
|
+
const maxScore = 100;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* It takes a score and a bar, and returns a color based on the score
|
|
16
|
+
* @param {number} score - The score of the current test.
|
|
17
|
+
* @returns {string} A function that takes two parameters, score and bar.
|
|
18
|
+
*/
|
|
19
|
+
const barColor = score => {
|
|
20
|
+
const bar = "{bar}";
|
|
21
|
+
|
|
22
|
+
switch (true) {
|
|
23
|
+
case score === 1 || score <= 49:
|
|
24
|
+
return bar.red;
|
|
25
|
+
case score === 50 || score <= 89:
|
|
26
|
+
return bar.yellow;
|
|
27
|
+
case score >= 90 || score === maxScore:
|
|
28
|
+
return bar.green;
|
|
29
|
+
default:
|
|
30
|
+
return bar.magenta;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
6
34
|
/**
|
|
7
35
|
* @description async function mobile website pagespeed
|
|
36
|
+
* @async
|
|
8
37
|
* @param { string } url - website from pagespeed mobile results
|
|
9
38
|
* @returns { Promise<void> } - return async mobile results
|
|
10
39
|
*/
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
params: {
|
|
14
|
-
url,
|
|
15
|
-
key: "AIzaSyBEDaW4FxSZ2s1vz5CdD5Ai6PGZGdAzij0",
|
|
16
|
-
strategy: "mobile"
|
|
17
|
-
}
|
|
18
|
-
});
|
|
40
|
+
export default async function pagespeed(url) {
|
|
41
|
+
console.info(url.green);
|
|
19
42
|
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
});
|
|
43
|
+
const multibar = new MultiBar({
|
|
44
|
+
format: "{type} | {bar} | {value}/{total}",
|
|
45
|
+
hideCursor: true,
|
|
46
|
+
clearOnComplete: false
|
|
47
|
+
}, Presets.legacy);
|
|
27
48
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
49
|
+
try {
|
|
50
|
+
// start api
|
|
51
|
+
const { data: resMobile } = await pagespeedApi(url, "mobile");
|
|
52
|
+
const { data: resDesktop } = await pagespeedApi(url, "desktop");
|
|
31
53
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
54
|
+
// extract results
|
|
55
|
+
const mobile = Math.round(resMobile.lighthouseResult.categories.performance.score * 100);
|
|
56
|
+
const desktop = Math.round(resDesktop.lighthouseResult.categories.performance.score * 100);
|
|
35
57
|
|
|
36
|
-
|
|
58
|
+
// result pagespeed color bar
|
|
59
|
+
const b1 = multibar.create(maxScore, 0, { type: "mobile" }, {
|
|
60
|
+
format: `{type} | ${barColor(mobile)} | {value}/{total}`
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
const b2 = multibar.create(maxScore, 0, { type: "desktop" }, {
|
|
64
|
+
format: `{type} | ${barColor(desktop)} | {value}/{total}`
|
|
65
|
+
});
|
|
37
66
|
|
|
38
|
-
// valid results
|
|
39
|
-
switch (true) {
|
|
40
|
-
case (mobile === 1 || mobile <= 49):
|
|
41
|
-
case (desktop === 1 || desktop <= 49):
|
|
42
|
-
b1 = new SingleBar({
|
|
43
|
-
format: "Mobile Result | {bar} || {value}/{total} || bad".red,
|
|
44
|
-
barCompleteChar: "\u2588",
|
|
45
|
-
barIncompleteChar: "\u2591",
|
|
46
|
-
hideCursor: true
|
|
47
|
-
});
|
|
48
|
-
b2 = new SingleBar({
|
|
49
|
-
format: "Desktop Result | {bar} || {value}/{total} || bad".red,
|
|
50
|
-
barCompleteChar: "\u2588",
|
|
51
|
-
barIncompleteChar: "\u2591",
|
|
52
|
-
hideCursor: true
|
|
53
|
-
});
|
|
54
|
-
break;
|
|
55
|
-
case (mobile === 50 || mobile <= 89):
|
|
56
|
-
case (desktop === 50 || desktop <= 89):
|
|
57
|
-
b1 = new SingleBar({
|
|
58
|
-
format: "Mobile Result | {bar} || {value}/{total} || decent".yellow,
|
|
59
|
-
barCompleteChar: "\u2588",
|
|
60
|
-
barIncompleteChar: "\u2591",
|
|
61
|
-
hideCursor: true
|
|
62
|
-
});
|
|
63
|
-
b2 = new SingleBar({
|
|
64
|
-
format: "Desktop Result | {bar} || {value}/{total} || decent".yellow,
|
|
65
|
-
barCompleteChar: "\u2588",
|
|
66
|
-
barIncompleteChar: "\u2591",
|
|
67
|
-
hideCursor: true
|
|
68
|
-
});
|
|
69
|
-
break;
|
|
70
|
-
case (mobile >= 90 || mobile === 100):
|
|
71
|
-
case (desktop >= 90 || desktop === 100):
|
|
72
|
-
b1 = new SingleBar({
|
|
73
|
-
format: "Mobile Result | {bar} || {value}/{total} || excelent".green,
|
|
74
|
-
barCompleteChar: "\u2588",
|
|
75
|
-
barIncompleteChar: "\u2591",
|
|
76
|
-
hideCursor: true
|
|
77
|
-
});
|
|
78
|
-
b2 = new SingleBar({
|
|
79
|
-
format: "Desktop Result | {bar} || {value}/{total} || excelent".green,
|
|
80
|
-
barCompleteChar: "\u2588",
|
|
81
|
-
barIncompleteChar: "\u2591",
|
|
82
|
-
hideCursor: true
|
|
83
|
-
});
|
|
84
|
-
break;
|
|
85
|
-
default:
|
|
86
|
-
b1 = new SingleBar({
|
|
87
|
-
format: "Mobile Result | {bar} || {value}/{total} || undifined",
|
|
88
|
-
barCompleteChar: "\u2588",
|
|
89
|
-
barIncompleteChar: "\u2591",
|
|
90
|
-
hideCursor: true
|
|
91
|
-
});
|
|
92
|
-
b2 = new SingleBar({
|
|
93
|
-
format: "Desktop Result | {bar} || {value}/{total} || undifined",
|
|
94
|
-
barCompleteChar: "\u2588",
|
|
95
|
-
barIncompleteChar: "\u2591",
|
|
96
|
-
hideCursor: true
|
|
97
|
-
});
|
|
98
|
-
break;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
67
|
// initials bars
|
|
102
|
-
b1.start(100, 0);
|
|
103
|
-
b2.start(100, 0);
|
|
104
|
-
|
|
105
68
|
b1.update(mobile);
|
|
106
69
|
b2.update(desktop);
|
|
107
70
|
|
|
108
|
-
// stop
|
|
109
|
-
|
|
110
|
-
|
|
71
|
+
// stop multibar
|
|
72
|
+
multibar.stop();
|
|
73
|
+
|
|
74
|
+
const resultTxt = `
|
|
75
|
+
${figlet.textSync(url)} \n
|
|
76
|
+
mobile: ${mobile}/100 \n
|
|
77
|
+
desktop: ${desktop}/100
|
|
78
|
+
`;
|
|
79
|
+
|
|
80
|
+
stackSave("pagespeed.txt", resultTxt);
|
|
111
81
|
} catch (err) {
|
|
112
82
|
console.error(colors.red(err.message));
|
|
113
83
|
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
export default pageSpeed;
|
|
84
|
+
}
|