Skip to content

Commit 5380ea6

Browse files
feat: continue on URL failures
1 parent b5d710f commit 5380ea6

File tree

1 file changed

+61
-9
lines changed

1 file changed

+61
-9
lines changed

cli.js

Lines changed: 61 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -185,24 +185,41 @@ function getUrlList(options) {
185185
async function validateUrlAccessibility(urls) {
186186
console.log(chalk.blue("🔍 Checking URL accessibility..."));
187187

188+
const accessibleUrls = [];
188189
const inaccessibleUrls = [];
189190

190191
for (const url of urls) {
192+
process.stdout.write(` Checking ${url}... `);
191193
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("❌"));
193199
inaccessibleUrls.push(url);
194200
}
195201
}
196202

197203
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+
)
200208
);
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"));
202214
process.exit(1);
203215
}
204216

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;
206223
}
207224

208225
async function runLighthouse(url) {
@@ -232,13 +249,27 @@ async function runLighthouse(url) {
232249

233250
const urls = getUrlList(options);
234251

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}...`));
237265

238-
for (const url of urls) {
239266
try {
267+
console.log(chalk.gray(" └─ Launching browser..."));
240268
const { lhr, report } = await runLighthouse(url);
269+
console.log(chalk.gray(" └─ Analysis complete!"));
270+
241271
formatMetrics(lhr);
272+
successCount++;
242273

243274
if (options.json) {
244275
console.log(JSON.stringify(lhr, null, 2));
@@ -247,6 +278,7 @@ async function runLighthouse(url) {
247278
if (options.output) {
248279
const safeUrl = url.replace(/https?:\/\//, "").replace(/[^\w]/g, "_");
249280
fs.writeFileSync(`${safeUrl}.html`, report);
281+
console.log(chalk.gray(` └─ HTML report saved to ${safeUrl}.html`));
250282
}
251283

252284
if (options.markdown) {
@@ -266,8 +298,28 @@ async function runLighthouse(url) {
266298
}
267299
}
268300
} catch (err) {
269-
console.error(`❌ Failed for ${url}:`, err.message);
301+
console.error(chalk.red(` └─ ❌ Failed: ${err.message}`));
302+
failureCount++;
270303
process.exitCode = 1;
271304
}
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+
);
272324
}
273325
})();

0 commit comments

Comments
 (0)