@@ -185,24 +185,41 @@ function getUrlList(options) {
185
185
async function validateUrlAccessibility ( urls ) {
186
186
console . log ( chalk . blue ( "🔍 Checking URL accessibility..." ) ) ;
187
187
188
+ const accessibleUrls = [ ] ;
188
189
const inaccessibleUrls = [ ] ;
189
190
190
191
for ( const url of urls ) {
192
+ process . stdout . write ( ` Checking ${ url } ... ` ) ;
191
193
const isAccessible = await checkUrlAccessibility ( url ) ;
192
- if ( ! isAccessible ) {
194
+ if ( isAccessible ) {
195
+ console . log ( chalk . green ( "✅" ) ) ;
196
+ accessibleUrls . push ( url ) ;
197
+ } else {
198
+ console . log ( chalk . red ( "❌" ) ) ;
193
199
inaccessibleUrls . push ( url ) ;
194
200
}
195
201
}
196
202
197
203
if ( inaccessibleUrls . length > 0 ) {
198
- console . error (
199
- chalk . red ( `❌ Error: The following URLs are not accessible:` )
204
+ console . warn (
205
+ chalk . yellow (
206
+ `⚠️ Warning: ${ inaccessibleUrls . length } URL(s) are not accessible and will be skipped:`
207
+ )
200
208
) ;
201
- inaccessibleUrls . forEach ( ( url ) => console . error ( ` - ${ url } ` ) ) ;
209
+ inaccessibleUrls . forEach ( ( url ) => console . warn ( ` - ${ url } ` ) ) ;
210
+ }
211
+
212
+ if ( accessibleUrls . length === 0 ) {
213
+ console . error ( chalk . red ( "❌ Error: No accessible URLs found" ) ) ;
202
214
process . exit ( 1 ) ;
203
215
}
204
216
205
- console . log ( chalk . green ( "✅ All URLs are accessible" ) ) ;
217
+ console . log (
218
+ chalk . green (
219
+ `✅ ${ accessibleUrls . length } URL(s) are accessible and will be analyzed\n`
220
+ )
221
+ ) ;
222
+ return accessibleUrls ;
206
223
}
207
224
208
225
async function runLighthouse ( url ) {
@@ -232,13 +249,27 @@ async function runLighthouse(url) {
232
249
233
250
const urls = getUrlList ( options ) ;
234
251
235
- // Check URL accessibility
236
- await validateUrlAccessibility ( urls ) ;
252
+ // Check URL accessibility and get only accessible ones
253
+ const accessibleUrls = await validateUrlAccessibility ( urls ) ;
254
+
255
+ console . log ( chalk . blue . bold ( "🚀 Starting Lighthouse analysis...\n" ) ) ;
256
+
257
+ let successCount = 0 ;
258
+ let failureCount = 0 ;
259
+
260
+ for ( let i = 0 ; i < accessibleUrls . length ; i ++ ) {
261
+ const url = accessibleUrls [ i ] ;
262
+ const progress = `[${ i + 1 } /${ accessibleUrls . length } ]` ;
263
+
264
+ console . log ( chalk . blue ( `${ progress } 🔍 Analyzing ${ url } ...` ) ) ;
237
265
238
- for ( const url of urls ) {
239
266
try {
267
+ console . log ( chalk . gray ( " └─ Launching browser..." ) ) ;
240
268
const { lhr, report } = await runLighthouse ( url ) ;
269
+ console . log ( chalk . gray ( " └─ Analysis complete!" ) ) ;
270
+
241
271
formatMetrics ( lhr ) ;
272
+ successCount ++ ;
242
273
243
274
if ( options . json ) {
244
275
console . log ( JSON . stringify ( lhr , null , 2 ) ) ;
@@ -247,6 +278,7 @@ async function runLighthouse(url) {
247
278
if ( options . output ) {
248
279
const safeUrl = url . replace ( / h t t p s ? : \/ \/ / , "" ) . replace ( / [ ^ \w ] / g, "_" ) ;
249
280
fs . writeFileSync ( `${ safeUrl } .html` , report ) ;
281
+ console . log ( chalk . gray ( ` └─ HTML report saved to ${ safeUrl } .html` ) ) ;
250
282
}
251
283
252
284
if ( options . markdown ) {
@@ -266,8 +298,28 @@ async function runLighthouse(url) {
266
298
}
267
299
}
268
300
} catch ( err ) {
269
- console . error ( `❌ Failed for ${ url } :` , err . message ) ;
301
+ console . error ( chalk . red ( ` └─ ❌ Failed: ${ err . message } ` ) ) ;
302
+ failureCount ++ ;
270
303
process . exitCode = 1 ;
271
304
}
305
+
306
+ // Add spacing between analyses
307
+ if ( i < accessibleUrls . length - 1 ) {
308
+ console . log ( ) ;
309
+ }
310
+ }
311
+
312
+ // Final summary
313
+ console . log ( chalk . blue . bold ( "\n📋 Analysis Summary:" ) ) ;
314
+ console . log ( `${ chalk . green ( "✅ Successful:" ) } ${ successCount } ` ) ;
315
+ console . log ( `${ chalk . red ( "❌ Failed:" ) } ${ failureCount } ` ) ;
316
+ console . log ( `${ chalk . blue ( "📊 Total analyzed:" ) } ${ accessibleUrls . length } ` ) ;
317
+
318
+ if ( urls . length > accessibleUrls . length ) {
319
+ console . log (
320
+ `${ chalk . yellow ( "⚠️ Skipped (inaccessible):" ) } ${
321
+ urls . length - accessibleUrls . length
322
+ } `
323
+ ) ;
272
324
}
273
325
} ) ( ) ;
0 commit comments