Skip to content

Commit 7e53dba

Browse files
committed
πŸŽ‰ feat(app): ζ›΄ζ–°
1 parent c5cfba4 commit 7e53dba

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

β€Žsrc/index.tsβ€Ž

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import type { CAC } from "cac";
2+
import { ACTIVATION, execCommand, loggerInfo } from "code-genius";
3+
import fs from "fs-extra";
4+
5+
async function getReportfile(url: string) {
6+
const _url = new URL(url);
7+
const files = await fs.readdirSync(process.cwd());
8+
return files.filter(
9+
(f) => f.startsWith(_url.hostname) && f.endsWith("report.html"),
10+
);
11+
}
12+
13+
const lighthouse = async (url: string) => {
14+
if (ACTIVATION) {
15+
loggerInfo(`lighthouse 参数俑息: \n ${url}`);
16+
}
17+
18+
const histories = await getReportfile(url);
19+
for (const history of histories) {
20+
await fs.removeSync(history);
21+
}
22+
23+
await execCommand(
24+
"npx",
25+
[
26+
"lighthouse",
27+
url,
28+
"--output=html",
29+
`--output-path=./${new URL(url).hostname}-report.html`,
30+
"--view",
31+
],
32+
{
33+
stdio: "inherit",
34+
},
35+
);
36+
};
37+
38+
const lighthouseInstaller = () => {
39+
return {
40+
name: "lighthouseInstaller",
41+
setup: (cli: CAC) => {
42+
cli
43+
.command("lighthouse", "运葌 lighthouse εˆ†ζžεŠζ”Άι›† Web εΊ”η”¨ηš„ζ€§θƒ½ζŒ‡ζ ‡")
44+
.option("--url <url>", "Web εΊ”η”¨εœ°ε€")
45+
.action(async (options) => {
46+
if (options.url) {
47+
await lighthouse(options.url);
48+
}
49+
});
50+
},
51+
};
52+
};
53+
54+
export { lighthouse, lighthouseInstaller };

0 commit comments

Comments
Β (0)