Skip to content

Commit

Permalink
Merge pull request #31 from maddevsio/inputUrls
Browse files Browse the repository at this point in the history
Minor fixes for inputUrls
  • Loading branch information
denisoed authored Mar 31, 2024
2 parents 6f9e65d + 748172b commit 3b10b33
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 43 deletions.
4 changes: 3 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ yarn-error.log*
*.ntvs*
*.njsproj
*.sln
babel.config.js
preview.png
.eslintrc.js
.eslintignore
.prettierrc
preview.jpg
.babelrc
.github/
node_modules/
example/
src/
Expand Down
4 changes: 2 additions & 2 deletions example/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ new SeoAnalyzer()
.ignoreFiles(['example/html/team.html'])
.ignoreUrls(['/#/product/2'])
// ------- Input methods -------- //
.inputFolders(['example'])
// .inputUrls(['https://maddevs.io'])
// .inputFolders(['example'])
.inputUrls(['https://maddevs.io'])
// .inputFiles(['example/html/index.html'])
// .inputSpaFolder('example/spa', 'sitemap.xml')
// .inputHTMLStrings([
Expand Down
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
{
"name": "seo-analyzer",
"version": "3.0.8",
"version": "3.0.9",
"description": "A library for analyze a HTML files to show all of the SEO defects",
"main": "dist/seo-analyzer.js",
"module": "dist/seo-analyzer.mjs",
"browser": "dist/seo-analyzer.min.js",
"types": "dist/seo-analyzer.d.ts",
"repository": "https://github.com/maddevsio/seo-analyzer",
"homepage": "https://github.com/maddevsio/seo-analyzer",
Expand Down
25 changes: 0 additions & 25 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,13 @@ const globals = {
};

export default [
{
external,
input,
output: {
file: pkg.module,
format: 'es',
globals,
inlineDynamicImports: true
},
plugins: [terser()]
},
{
external,
input,
output: {
file: pkg.main,
format: 'umd',
name,
sourcemap: true,
globals,
inlineDynamicImports: true
},
plugins: [terser()]
},
{
external,
input,
output: {
file: pkg.browser,
format: 'umd',
name,
sourcemap: true,
globals,
inlineDynamicImports: true
},
Expand Down
25 changes: 14 additions & 11 deletions src/modules/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ import Scraper from './scraper';
* @typedef {Array<JSDOM>} ListDom
*/

const BAD_TYPE_MESSAGE =
'The inputFiles function takes an array only ["index.html", "...", "..."]';
const EMPTY_LIST_MESSAGE =
'You need to pass an array to the inputFiles function ["index.html", "...", "..."]';

class Input {
constructor(logger) {
this.logger = logger ?? new Logger();
Expand All @@ -25,10 +30,6 @@ class Input {
barIncompleteChar: '\u2591',
hideCursor: true
});
this.badType =
'The inputFiles function takes an array only ["index.html", "...", "..."]';
this.emptyList =
'You need to pass an array to the inputFiles function ["index.html", "...", "..."]';
this.ignoreFolders = [];
this.ignoreFiles = [];
}
Expand All @@ -55,14 +56,14 @@ class Input {

this.logger.info('\n🚀 Parsing files\n');
if (files.length === 0) {
this.logger.error(this.emptyList);
this.logger.error(EMPTY_LIST_MESSAGE);
}
if (!Array.isArray(files)) {
this.logger.error(this.badType);
this.logger.error(BAD_TYPE_MESSAGE);
}
this.ignoreFiles = ignoreFiles;
const listTexts = await this._getHtml(files);
const listDOM = await this.getDom(listTexts);
const listDOM = await this._getDom(listTexts);
return listDOM;
}

Expand Down Expand Up @@ -107,7 +108,7 @@ class Input {
*/
async spa(port, ignoreUrls = [], sitemap) {
const listTexts = await this.scraper.run(port, ignoreUrls, sitemap);
const htmlDoms = await this.getDom(listTexts);
const htmlDoms = await this._getDom(listTexts);
return htmlDoms;
}

Expand All @@ -117,8 +118,10 @@ class Input {
* @returns {Promise<ListDom>} [{ window: {}, document: {}, ... }, { window: {}, document: {}, ... }, ...]
*/
async urls(urls) {
const listTexts = await this.scraper.urls(urls);
const htmlDoms = await this.getDom(listTexts);
const rawDoms = await this.scraper.urls(urls);
if (!rawDoms.length)
this.logger.error('\n❌ Please check your urls.\n', true);
const htmlDoms = await this._getDom(rawDoms);
return htmlDoms;
}

Expand Down Expand Up @@ -227,7 +230,7 @@ class Input {
* @returns {Promise<ListDom>} [{ window: {}, document: {}, ... }, { window: {}, document: {}, ... }, ...]
* @private
*/
getDom(list) {
_getDom(list) {
const doms = [];
const proccess =
this.logger.level <= 4 &&
Expand Down
2 changes: 1 addition & 1 deletion src/modules/scraper.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class Scanner {
.catch(error => {
const err =
(error && error.response && error.response.status) || 500;
this.logger.error(`Error: ${error} - ${link}`);
this.logger.error(`\n\n${error} - ${link}`);
this.logger.error(
`\n${_colors.yellow('==>')} ${_colors.white(link)} ${_colors.red(
err
Expand Down

0 comments on commit 3b10b33

Please sign in to comment.