Skip to content

Commit

Permalink
Merge pull request #34 from paceaux/develop
Browse files Browse the repository at this point in the history
Improve the logging experience and fix screen grabs
  • Loading branch information
paceaux authored Oct 24, 2023
2 parents f6c89e9 + fa5a5fe commit e871bd3
Show file tree
Hide file tree
Showing 11 changed files with 4,491 additions and 12,555 deletions.
50 changes: 24 additions & 26 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,16 @@ async function main(config) {
}
try {
const startMessage = `
| Looking...
| Sitemap: ${mainConfig.sitemap},
| limit: ${limit === 0 ? 'None' : limit}
${mainConfig.cssFile ? `| cssFile (${cssFile})` : ''}
${mainConfig.selector && !mainConfig.cssFile ? `| CSS Selector (${mainConfig.selector})` : ''}
${mainConfig.isSpa ? '| Handle as Single Page Application' : ''}
${mainConfig.takeScreenshots ? '| Take Screenshots' : ''}
${mainConfig.useExportedSitemap ? '' : '| Ignore any existing .sitemap.json file and fetch a sitemap or recrawl'}
๐Ÿ”๐Ÿ• SelectorHound is looking...
๐Ÿ“ƒ Sitemap: ${mainConfig.sitemap}
๐Ÿ›‘ limit: ${limit === 0 ? 'None' : limit}
${mainConfig.cssFile ? `๐Ÿ“‚ cssFile: ${cssFile}` : ''}
${mainConfig.selector && !mainConfig.cssFile ? `๐ŸŽฏ CSS Selector: ${mainConfig.selector}` : ''}
${mainConfig.showElementDetails ? '๐Ÿ’ก Show full details for matching elements' : ''}
${mainConfig.isSpa ? '๐Ÿ’ก Handle as Single Page Application' : ''}
${mainConfig.takeScreenshots ? '๐Ÿ“ท Take Screenshots' : ''}
${mainConfig.useExportedSitemap ? '' : '๐Ÿ’ก Ignore any existing .sitemap.json file and make a new one'}
`;
await log
.toConsole(startMessage)
Expand All @@ -209,26 +211,20 @@ ${mainConfig.useExportedSitemap ? '' : '| Ignore any existing .sitemap.json file
useExportedSitemap: mainConfig.useExportedSitemap,
},
);
await log.toConsole(`
||> ${mainConfig.crawl ? 'Crawling site' : 'Fetching sitemap'}
||> ${mainConfig.crawl ? 'Starting on' : 'using'} ${siteCrawler.config.startPage}
log.toConsole(`
๐Ÿ• ${mainConfig.crawl ? 'Crawling site' : 'Fetching sitemap'} ${mainConfig.crawl ? 'starting on ๐Ÿ' : 'from ๐Ÿฆด'} ${siteCrawler.config.startPage}
`);
await siteCrawler.produceSiteLinks();

const numberOfSiteLinks = siteCrawler.linkSet.size;
if (!mainConfig.useExportedSitemap) {
await log.toConsole(`
||-> ${numberOfSiteLinks} URLs exported to ${siteCrawler.exportFileName}.sitemap.json
`);
} else {
await log.toConsole(`
||-> ${numberOfSiteLinks} URLs read from ${siteCrawler.exportFileName}.sitemap.json
`);
}
const isNotExported = !mainConfig.useExportedSitemap;
const siteLinksMessage = `๐Ÿ”— ${numberOfSiteLinks} URLs ${isNotExported ? 'exported to' : 'read from'} ๐Ÿ’พ ${siteCrawler.exportFileName}.sitemap.json`;

log.toConsole(siteLinksMessage);

if (siteCrawler.linkSet.size === 0) {
const noLinksMessage = `
||-> No links found. Nothing To search.`;
๐Ÿšซ๐Ÿ”— No links found. Nothing To search.`;
await log
.toConsole(noLinksMessage)
.infoToFileAsync(noLinksMessage);
Expand All @@ -251,11 +247,13 @@ ${mainConfig.useExportedSitemap ? '' : '| Ignore any existing .sitemap.json file
const { elapsedTime } = log;
const friendlyTime = elapsedTime > 300 ? `${(elapsedTime / 60).toFixed(2)}m` : `${elapsedTime}s`;
const endMessage = `
| Finished after ${friendlyTime}
| Pages Scanned: ${totalPagesSearched}
| Pages with a Match: ${pagesWithSelector.length}
| Total Results: ${totalMatches}
| FileName: ${outputFileName}
๐Ÿถ SelectorHound is finished!
โฑ Time lapsed: ${friendlyTime}
๐Ÿ”— Pages Scanned: ${totalPagesSearched}
๐ŸŽฏ Pages with a Match: ${pagesWithSelector.length}
๐Ÿงฎ Total Results: ${totalMatches} ${totalMatches > pagesWithSelector.length ? '(multiple matches on a page)' : ''}
๐Ÿ’พ Results File: ${outputFileName}${outputFileName !== 'pages.json' ? '.pages.json' : ''}
`;
await log.toConsole(endMessage, true).infoToFileAsync();
} catch (mainFunctionError) {
Expand Down
Loading

0 comments on commit e871bd3

Please sign in to comment.