File tree Expand file tree Collapse file tree 1 file changed +54
-0
lines changed Expand file tree Collapse file tree 1 file changed +54
-0
lines changed Original file line number Diff line number Diff line change
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 } ;
You canβt perform that action at this time.
0 commit comments