@qualweb/core 0.7.20 → 0.8.0-alpha2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +14 -14
- package/README.md +497 -497
- package/dist/index.d.ts +19 -19
- package/dist/index.js +232 -232
- package/package.json +101 -100
package/dist/index.d.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
/// <reference types="@qualweb/types" />
|
|
2
|
-
import { LaunchOptions, BrowserLaunchArgumentOptions, BrowserConnectOptions, Viewport } from 'puppeteer';
|
|
3
|
-
import { QualwebOptions, Evaluations, PuppeteerPlugins, ClusterOptions, LoadEvent } from '@qualweb/core';
|
|
4
|
-
import { generateEARLReport } from '@qualweb/earl-reporter';
|
|
5
|
-
import { CrawlOptions } from '@qualweb/crawler';
|
|
6
|
-
import 'colors';
|
|
7
|
-
declare class QualWeb {
|
|
8
|
-
private cluster?;
|
|
9
|
-
constructor(plugins?: PuppeteerPlugins);
|
|
10
|
-
start(clusterOptions?: ClusterOptions, puppeteerOptions?: LaunchOptions & BrowserLaunchArgumentOptions & BrowserConnectOptions): Promise<void>;
|
|
11
|
-
stop(): Promise<void>;
|
|
12
|
-
evaluate(options: QualwebOptions): Promise<Evaluations>;
|
|
13
|
-
crawl(domain: string, options?: CrawlOptions, viewport?: Viewport, waitUntil?: LoadEvent | Array<LoadEvent>): Promise<Array<string>>;
|
|
14
|
-
private checkUrls;
|
|
15
|
-
private handleLocales;
|
|
16
|
-
private verifyTranslationObject;
|
|
17
|
-
}
|
|
18
|
-
declare function getFileUrls(file: string): Promise<Array<string>>;
|
|
19
|
-
export { QualWeb, generateEARLReport, getFileUrls };
|
|
1
|
+
/// <reference types="@qualweb/types" />
|
|
2
|
+
import { LaunchOptions, BrowserLaunchArgumentOptions, BrowserConnectOptions, Viewport } from 'puppeteer';
|
|
3
|
+
import { QualwebOptions, Evaluations, PuppeteerPlugins, ClusterOptions, LoadEvent } from '@qualweb/core';
|
|
4
|
+
import { generateEARLReport } from '@qualweb/earl-reporter';
|
|
5
|
+
import { CrawlOptions } from '@qualweb/crawler';
|
|
6
|
+
import 'colors';
|
|
7
|
+
declare class QualWeb {
|
|
8
|
+
private cluster?;
|
|
9
|
+
constructor(plugins?: PuppeteerPlugins);
|
|
10
|
+
start(clusterOptions?: ClusterOptions, puppeteerOptions?: LaunchOptions & BrowserLaunchArgumentOptions & BrowserConnectOptions): Promise<void>;
|
|
11
|
+
stop(): Promise<void>;
|
|
12
|
+
evaluate(options: QualwebOptions): Promise<Evaluations>;
|
|
13
|
+
crawl(domain: string, options?: CrawlOptions, viewport?: Viewport, waitUntil?: LoadEvent | Array<LoadEvent>): Promise<Array<string>>;
|
|
14
|
+
private checkUrls;
|
|
15
|
+
private handleLocales;
|
|
16
|
+
private verifyTranslationObject;
|
|
17
|
+
}
|
|
18
|
+
declare function getFileUrls(file: string): Promise<Array<string>>;
|
|
19
|
+
export { QualWeb, generateEARLReport, getFileUrls };
|
|
20
20
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,233 +1,233 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getFileUrls = exports.generateEARLReport = exports.QualWeb = void 0;
|
|
7
|
-
const puppeteer_extra_1 = __importDefault(require("puppeteer-extra"));
|
|
8
|
-
const puppeteer_cluster_1 = require("puppeteer-cluster");
|
|
9
|
-
const puppeteer_extra_plugin_stealth_1 = __importDefault(require("puppeteer-extra-plugin-stealth"));
|
|
10
|
-
const puppeteer_extra_plugin_adblocker_1 = __importDefault(require("puppeteer-extra-plugin-adblocker"));
|
|
11
|
-
const earl_reporter_1 = require("@qualweb/earl-reporter");
|
|
12
|
-
Object.defineProperty(exports, "generateEARLReport", { enumerable: true, get: function () { return earl_reporter_1.generateEARLReport; } });
|
|
13
|
-
const dom_1 = require("@qualweb/dom");
|
|
14
|
-
const evaluation_1 = require("@qualweb/evaluation");
|
|
15
|
-
const crawler_1 = require("@qualweb/crawler");
|
|
16
|
-
const locale_1 = __importDefault(require("@qualweb/locale"));
|
|
17
|
-
const fs_1 = require("fs");
|
|
18
|
-
const path_1 = __importDefault(require("path"));
|
|
19
|
-
require("colors");
|
|
20
|
-
class QualWeb {
|
|
21
|
-
constructor(plugins) {
|
|
22
|
-
if (plugins === null || plugins === void 0 ? void 0 : plugins.stealth) {
|
|
23
|
-
puppeteer_extra_1.default.use((0, puppeteer_extra_plugin_stealth_1.default)());
|
|
24
|
-
}
|
|
25
|
-
if (plugins === null || plugins === void 0 ? void 0 : plugins.adBlock) {
|
|
26
|
-
puppeteer_extra_1.default.use((0, puppeteer_extra_plugin_adblocker_1.default)({ blockTrackers: true }));
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
async start(clusterOptions, puppeteerOptions) {
|
|
30
|
-
var _a, _b, _c;
|
|
31
|
-
this.cluster = await puppeteer_cluster_1.Cluster.launch({
|
|
32
|
-
concurrency: puppeteer_cluster_1.Cluster.CONCURRENCY_CONTEXT,
|
|
33
|
-
maxConcurrency: (_a = clusterOptions === null || clusterOptions === void 0 ? void 0 : clusterOptions.maxConcurrency) !== null && _a !== void 0 ? _a : 1,
|
|
34
|
-
puppeteerOptions: puppeteerOptions,
|
|
35
|
-
puppeteer: puppeteer_extra_1.default,
|
|
36
|
-
timeout: (_b = clusterOptions === null || clusterOptions === void 0 ? void 0 : clusterOptions.timeout) !== null && _b !== void 0 ? _b : 60 * 1000,
|
|
37
|
-
monitor: (_c = clusterOptions === null || clusterOptions === void 0 ? void 0 : clusterOptions.monitor) !== null && _c !== void 0 ? _c : false
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
async stop() {
|
|
41
|
-
var _a;
|
|
42
|
-
await ((_a = this.cluster) === null || _a === void 0 ? void 0 : _a.close());
|
|
43
|
-
}
|
|
44
|
-
async evaluate(options) {
|
|
45
|
-
var _a, _b, _c, _d, _e, _f;
|
|
46
|
-
const modulesToExecute = {
|
|
47
|
-
act: true,
|
|
48
|
-
wcag: true,
|
|
49
|
-
bp: true,
|
|
50
|
-
wappalyzer: false,
|
|
51
|
-
counter: false
|
|
52
|
-
};
|
|
53
|
-
const urls = await this.checkUrls(options);
|
|
54
|
-
if ((options.html === undefined || options.html.trim() === '') && urls.length === 0) {
|
|
55
|
-
throw new Error('Invalid input method');
|
|
56
|
-
}
|
|
57
|
-
this.handleLocales(options);
|
|
58
|
-
if (options.execute) {
|
|
59
|
-
modulesToExecute.act = !!options.execute.act;
|
|
60
|
-
modulesToExecute.wcag = !!options.execute.wcag;
|
|
61
|
-
modulesToExecute.bp = !!options.execute.bp;
|
|
62
|
-
modulesToExecute.wappalyzer = !!options.execute.wappalyzer;
|
|
63
|
-
modulesToExecute.counter = !!options.execute.counter;
|
|
64
|
-
}
|
|
65
|
-
const evaluations = {};
|
|
66
|
-
let foundError = false;
|
|
67
|
-
const timestamp = new Date().getTime();
|
|
68
|
-
handleError(options, 'Evaluation errors', new Date(timestamp).toISOString().replace(/T/, ' ').replace(/\..+/, '') + '\n-----------', timestamp);
|
|
69
|
-
(_a = this.cluster) === null || _a === void 0 ? void 0 : _a.on('taskerror', (err, data) => {
|
|
70
|
-
foundError = true;
|
|
71
|
-
handleError(options, data.url, err.message + '\n-----------', timestamp);
|
|
72
|
-
});
|
|
73
|
-
await ((_b = this.cluster) === null || _b === void 0 ? void 0 : _b.task(async ({ page, data: { url, html } }) => {
|
|
74
|
-
const dom = new dom_1.Dom(page, options.validator);
|
|
75
|
-
const { sourceHtml, validation } = await dom.process(options, url !== null && url !== void 0 ? url : '', html !== null && html !== void 0 ? html : '');
|
|
76
|
-
const evaluation = new evaluation_1.Evaluation(url, page, modulesToExecute);
|
|
77
|
-
const evaluationReport = await evaluation.evaluatePage(sourceHtml, options, validation);
|
|
78
|
-
evaluations[url || 'customHtml'] = evaluationReport.getFinalReport();
|
|
79
|
-
}));
|
|
80
|
-
for (const url of urls) {
|
|
81
|
-
(_c = this.cluster) === null || _c === void 0 ? void 0 : _c.queue({ url });
|
|
82
|
-
}
|
|
83
|
-
if (options.html) {
|
|
84
|
-
(_d = this.cluster) === null || _d === void 0 ? void 0 : _d.queue({ html: options.html });
|
|
85
|
-
}
|
|
86
|
-
await ((_e = this.cluster) === null || _e === void 0 ? void 0 : _e.idle());
|
|
87
|
-
if ((_f = options.log) === null || _f === void 0 ? void 0 : _f.file) {
|
|
88
|
-
if (foundError) {
|
|
89
|
-
console.warn('One or more urls failed to evaluate. Check the error.log for more information.'.yellow);
|
|
90
|
-
}
|
|
91
|
-
else {
|
|
92
|
-
deleteErrorLogFile(timestamp);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
return evaluations;
|
|
96
|
-
}
|
|
97
|
-
async crawl(domain, options, viewport, waitUntil) {
|
|
98
|
-
const browser = await puppeteer_extra_1.default.launch();
|
|
99
|
-
const incognito = await browser.createIncognitoBrowserContext();
|
|
100
|
-
const crawler = new crawler_1.Crawler(incognito, domain, viewport, waitUntil);
|
|
101
|
-
await crawler.crawl(options);
|
|
102
|
-
return crawler.getResults();
|
|
103
|
-
}
|
|
104
|
-
async checkUrls(options) {
|
|
105
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
106
|
-
const urls = new Array();
|
|
107
|
-
if (options.url) {
|
|
108
|
-
urls.push(decodeURIComponent(options.url).trim());
|
|
109
|
-
}
|
|
110
|
-
if (options.urls) {
|
|
111
|
-
urls.push(...options.urls.map((url) => decodeURIComponent(url).trim()));
|
|
112
|
-
}
|
|
113
|
-
if (options.file) {
|
|
114
|
-
urls.push(...(await getFileUrls(options.file)));
|
|
115
|
-
}
|
|
116
|
-
if (options.crawl) {
|
|
117
|
-
const viewport = {
|
|
118
|
-
width: 0,
|
|
119
|
-
height: 0,
|
|
120
|
-
isMobile: false,
|
|
121
|
-
isLandscape: true
|
|
122
|
-
};
|
|
123
|
-
if (options.viewport) {
|
|
124
|
-
viewport.width = (_c = (_b = (_a = options === null || options === void 0 ? void 0 : options.viewport) === null || _a === void 0 ? void 0 : _a.resolution) === null || _b === void 0 ? void 0 : _b.width) !== null && _c !== void 0 ? _c : 0;
|
|
125
|
-
viewport.height = (_f = (_e = (_d = options === null || options === void 0 ? void 0 : options.viewport) === null || _d === void 0 ? void 0 : _d.resolution) === null || _e === void 0 ? void 0 : _e.height) !== null && _f !== void 0 ? _f : 0;
|
|
126
|
-
viewport.isMobile = (_h = (_g = options === null || options === void 0 ? void 0 : options.viewport) === null || _g === void 0 ? void 0 : _g.mobile) !== null && _h !== void 0 ? _h : false;
|
|
127
|
-
viewport.isLandscape = (_k = (_j = options === null || options === void 0 ? void 0 : options.viewport) === null || _j === void 0 ? void 0 : _j.landscape) !== null && _k !== void 0 ? _k : true;
|
|
128
|
-
}
|
|
129
|
-
urls.push(...(await this.crawl(options.crawl, options.crawlOptions, viewport.width + viewport.height !== 0 ? viewport : undefined, options.waitUntil)));
|
|
130
|
-
}
|
|
131
|
-
return urls;
|
|
132
|
-
}
|
|
133
|
-
handleLocales(options) {
|
|
134
|
-
if (options.translate) {
|
|
135
|
-
if (typeof options.translate === 'string') {
|
|
136
|
-
if (Object.keys(locale_1.default).includes(options.translate)) {
|
|
137
|
-
options.translate = {
|
|
138
|
-
translate: locale_1.default[options.translate],
|
|
139
|
-
fallback: locale_1.default.en
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
else {
|
|
143
|
-
throw new Error(`Locale "${options.translate}" not supported.`);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
else if (Object.keys(options.translate).includes('translate')) {
|
|
147
|
-
this.verifyTranslationObject(options);
|
|
148
|
-
}
|
|
149
|
-
else {
|
|
150
|
-
options.translate = {
|
|
151
|
-
translate: options.translate,
|
|
152
|
-
fallback: locale_1.default.en
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
else {
|
|
157
|
-
options.translate = {
|
|
158
|
-
translate: locale_1.default.en,
|
|
159
|
-
fallback: locale_1.default.en
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
verifyTranslationObject(options) {
|
|
164
|
-
if (typeof options.translate.translate === 'string') {
|
|
165
|
-
if (Object.keys(locale_1.default).includes(options.translate.translate)) {
|
|
166
|
-
options.translate = {
|
|
167
|
-
translate: locale_1.default[options.translate.translate],
|
|
168
|
-
fallback: locale_1.default.en
|
|
169
|
-
};
|
|
170
|
-
}
|
|
171
|
-
else {
|
|
172
|
-
throw new Error(`Locale "${options.translate.translate}" not supported.`);
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
if (typeof options.translate.fallback === 'string') {
|
|
176
|
-
if (Object.keys(locale_1.default).includes(options.translate.fallback)) {
|
|
177
|
-
options.translate.fallback =
|
|
178
|
-
locale_1.default[options.translate.fallback];
|
|
179
|
-
}
|
|
180
|
-
else {
|
|
181
|
-
throw new Error(`Locale "${options.translate.fallback}" not supported.`);
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
exports.QualWeb = QualWeb;
|
|
187
|
-
async function getFileUrls(file) {
|
|
188
|
-
const content = await readFileData(file);
|
|
189
|
-
return content
|
|
190
|
-
.split('\n')
|
|
191
|
-
.map((url) => {
|
|
192
|
-
try {
|
|
193
|
-
return decodeURIComponent(url).trim();
|
|
194
|
-
}
|
|
195
|
-
catch (_err) {
|
|
196
|
-
return '';
|
|
197
|
-
}
|
|
198
|
-
})
|
|
199
|
-
.filter((url) => url.trim() !== '');
|
|
200
|
-
}
|
|
201
|
-
exports.getFileUrls = getFileUrls;
|
|
202
|
-
function readFileData(file) {
|
|
203
|
-
return new Promise((resolve, reject) => {
|
|
204
|
-
(0, fs_1.readFile)(file, (err, data) => {
|
|
205
|
-
if (err) {
|
|
206
|
-
reject(err);
|
|
207
|
-
}
|
|
208
|
-
else {
|
|
209
|
-
resolve(data.toString('utf-8'));
|
|
210
|
-
}
|
|
211
|
-
});
|
|
212
|
-
});
|
|
213
|
-
}
|
|
214
|
-
function handleError(options, url, message, timestamp) {
|
|
215
|
-
if (options.log && options.log.file) {
|
|
216
|
-
(0, fs_1.writeFile)(path_1.default.resolve(process.cwd(), `qualweb-errors-${timestamp}.log`), url + ' : ' + message + '\n', { flag: 'a', encoding: 'utf-8' }, (err) => {
|
|
217
|
-
if (err) {
|
|
218
|
-
console.error(err);
|
|
219
|
-
}
|
|
220
|
-
});
|
|
221
|
-
}
|
|
222
|
-
if (options.log && options.log.console) {
|
|
223
|
-
console.error(url + ' : ' + message + '\n');
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
function deleteErrorLogFile(timestamp) {
|
|
227
|
-
(0, fs_1.unlink)(path_1.default.resolve(process.cwd(), `qualweb-errors-${timestamp}.log`), (err) => {
|
|
228
|
-
if (err) {
|
|
229
|
-
throw err;
|
|
230
|
-
}
|
|
231
|
-
});
|
|
232
|
-
}
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getFileUrls = exports.generateEARLReport = exports.QualWeb = void 0;
|
|
7
|
+
const puppeteer_extra_1 = __importDefault(require("puppeteer-extra"));
|
|
8
|
+
const puppeteer_cluster_1 = require("puppeteer-cluster");
|
|
9
|
+
const puppeteer_extra_plugin_stealth_1 = __importDefault(require("puppeteer-extra-plugin-stealth"));
|
|
10
|
+
const puppeteer_extra_plugin_adblocker_1 = __importDefault(require("puppeteer-extra-plugin-adblocker"));
|
|
11
|
+
const earl_reporter_1 = require("@qualweb/earl-reporter");
|
|
12
|
+
Object.defineProperty(exports, "generateEARLReport", { enumerable: true, get: function () { return earl_reporter_1.generateEARLReport; } });
|
|
13
|
+
const dom_1 = require("@qualweb/dom");
|
|
14
|
+
const evaluation_1 = require("@qualweb/evaluation");
|
|
15
|
+
const crawler_1 = require("@qualweb/crawler");
|
|
16
|
+
const locale_1 = __importDefault(require("@qualweb/locale"));
|
|
17
|
+
const fs_1 = require("fs");
|
|
18
|
+
const path_1 = __importDefault(require("path"));
|
|
19
|
+
require("colors");
|
|
20
|
+
class QualWeb {
|
|
21
|
+
constructor(plugins) {
|
|
22
|
+
if (plugins === null || plugins === void 0 ? void 0 : plugins.stealth) {
|
|
23
|
+
puppeteer_extra_1.default.use((0, puppeteer_extra_plugin_stealth_1.default)());
|
|
24
|
+
}
|
|
25
|
+
if (plugins === null || plugins === void 0 ? void 0 : plugins.adBlock) {
|
|
26
|
+
puppeteer_extra_1.default.use((0, puppeteer_extra_plugin_adblocker_1.default)({ blockTrackers: true }));
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
async start(clusterOptions, puppeteerOptions) {
|
|
30
|
+
var _a, _b, _c;
|
|
31
|
+
this.cluster = await puppeteer_cluster_1.Cluster.launch({
|
|
32
|
+
concurrency: puppeteer_cluster_1.Cluster.CONCURRENCY_CONTEXT,
|
|
33
|
+
maxConcurrency: (_a = clusterOptions === null || clusterOptions === void 0 ? void 0 : clusterOptions.maxConcurrency) !== null && _a !== void 0 ? _a : 1,
|
|
34
|
+
puppeteerOptions: puppeteerOptions,
|
|
35
|
+
puppeteer: puppeteer_extra_1.default,
|
|
36
|
+
timeout: (_b = clusterOptions === null || clusterOptions === void 0 ? void 0 : clusterOptions.timeout) !== null && _b !== void 0 ? _b : 60 * 1000,
|
|
37
|
+
monitor: (_c = clusterOptions === null || clusterOptions === void 0 ? void 0 : clusterOptions.monitor) !== null && _c !== void 0 ? _c : false
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
async stop() {
|
|
41
|
+
var _a;
|
|
42
|
+
await ((_a = this.cluster) === null || _a === void 0 ? void 0 : _a.close());
|
|
43
|
+
}
|
|
44
|
+
async evaluate(options) {
|
|
45
|
+
var _a, _b, _c, _d, _e, _f;
|
|
46
|
+
const modulesToExecute = {
|
|
47
|
+
act: true,
|
|
48
|
+
wcag: true,
|
|
49
|
+
bp: true,
|
|
50
|
+
wappalyzer: false,
|
|
51
|
+
counter: false
|
|
52
|
+
};
|
|
53
|
+
const urls = await this.checkUrls(options);
|
|
54
|
+
if ((options.html === undefined || options.html.trim() === '') && urls.length === 0) {
|
|
55
|
+
throw new Error('Invalid input method');
|
|
56
|
+
}
|
|
57
|
+
this.handleLocales(options);
|
|
58
|
+
if (options.execute) {
|
|
59
|
+
modulesToExecute.act = !!options.execute.act;
|
|
60
|
+
modulesToExecute.wcag = !!options.execute.wcag;
|
|
61
|
+
modulesToExecute.bp = !!options.execute.bp;
|
|
62
|
+
modulesToExecute.wappalyzer = !!options.execute.wappalyzer;
|
|
63
|
+
modulesToExecute.counter = !!options.execute.counter;
|
|
64
|
+
}
|
|
65
|
+
const evaluations = {};
|
|
66
|
+
let foundError = false;
|
|
67
|
+
const timestamp = new Date().getTime();
|
|
68
|
+
handleError(options, 'Evaluation errors', new Date(timestamp).toISOString().replace(/T/, ' ').replace(/\..+/, '') + '\n-----------', timestamp);
|
|
69
|
+
(_a = this.cluster) === null || _a === void 0 ? void 0 : _a.on('taskerror', (err, data) => {
|
|
70
|
+
foundError = true;
|
|
71
|
+
handleError(options, data.url, err.message + '\n-----------', timestamp);
|
|
72
|
+
});
|
|
73
|
+
await ((_b = this.cluster) === null || _b === void 0 ? void 0 : _b.task(async ({ page, data: { url, html } }) => {
|
|
74
|
+
const dom = new dom_1.Dom(page, options.validator);
|
|
75
|
+
const { sourceHtml, validation } = await dom.process(options, url !== null && url !== void 0 ? url : '', html !== null && html !== void 0 ? html : '');
|
|
76
|
+
const evaluation = new evaluation_1.Evaluation(url, page, modulesToExecute);
|
|
77
|
+
const evaluationReport = await evaluation.evaluatePage(sourceHtml, options, validation);
|
|
78
|
+
evaluations[url || 'customHtml'] = evaluationReport.getFinalReport();
|
|
79
|
+
}));
|
|
80
|
+
for (const url of urls) {
|
|
81
|
+
(_c = this.cluster) === null || _c === void 0 ? void 0 : _c.queue({ url });
|
|
82
|
+
}
|
|
83
|
+
if (options.html) {
|
|
84
|
+
(_d = this.cluster) === null || _d === void 0 ? void 0 : _d.queue({ html: options.html });
|
|
85
|
+
}
|
|
86
|
+
await ((_e = this.cluster) === null || _e === void 0 ? void 0 : _e.idle());
|
|
87
|
+
if ((_f = options.log) === null || _f === void 0 ? void 0 : _f.file) {
|
|
88
|
+
if (foundError) {
|
|
89
|
+
console.warn('One or more urls failed to evaluate. Check the error.log for more information.'.yellow);
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
deleteErrorLogFile(timestamp);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return evaluations;
|
|
96
|
+
}
|
|
97
|
+
async crawl(domain, options, viewport, waitUntil) {
|
|
98
|
+
const browser = await puppeteer_extra_1.default.launch();
|
|
99
|
+
const incognito = await browser.createIncognitoBrowserContext();
|
|
100
|
+
const crawler = new crawler_1.Crawler(incognito, domain, viewport, waitUntil);
|
|
101
|
+
await crawler.crawl(options);
|
|
102
|
+
return crawler.getResults();
|
|
103
|
+
}
|
|
104
|
+
async checkUrls(options) {
|
|
105
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
106
|
+
const urls = new Array();
|
|
107
|
+
if (options.url) {
|
|
108
|
+
urls.push(decodeURIComponent(options.url).trim());
|
|
109
|
+
}
|
|
110
|
+
if (options.urls) {
|
|
111
|
+
urls.push(...options.urls.map((url) => decodeURIComponent(url).trim()));
|
|
112
|
+
}
|
|
113
|
+
if (options.file) {
|
|
114
|
+
urls.push(...(await getFileUrls(options.file)));
|
|
115
|
+
}
|
|
116
|
+
if (options.crawl) {
|
|
117
|
+
const viewport = {
|
|
118
|
+
width: 0,
|
|
119
|
+
height: 0,
|
|
120
|
+
isMobile: false,
|
|
121
|
+
isLandscape: true
|
|
122
|
+
};
|
|
123
|
+
if (options.viewport) {
|
|
124
|
+
viewport.width = (_c = (_b = (_a = options === null || options === void 0 ? void 0 : options.viewport) === null || _a === void 0 ? void 0 : _a.resolution) === null || _b === void 0 ? void 0 : _b.width) !== null && _c !== void 0 ? _c : 0;
|
|
125
|
+
viewport.height = (_f = (_e = (_d = options === null || options === void 0 ? void 0 : options.viewport) === null || _d === void 0 ? void 0 : _d.resolution) === null || _e === void 0 ? void 0 : _e.height) !== null && _f !== void 0 ? _f : 0;
|
|
126
|
+
viewport.isMobile = (_h = (_g = options === null || options === void 0 ? void 0 : options.viewport) === null || _g === void 0 ? void 0 : _g.mobile) !== null && _h !== void 0 ? _h : false;
|
|
127
|
+
viewport.isLandscape = (_k = (_j = options === null || options === void 0 ? void 0 : options.viewport) === null || _j === void 0 ? void 0 : _j.landscape) !== null && _k !== void 0 ? _k : true;
|
|
128
|
+
}
|
|
129
|
+
urls.push(...(await this.crawl(options.crawl, options.crawlOptions, viewport.width + viewport.height !== 0 ? viewport : undefined, options.waitUntil)));
|
|
130
|
+
}
|
|
131
|
+
return urls;
|
|
132
|
+
}
|
|
133
|
+
handleLocales(options) {
|
|
134
|
+
if (options.translate) {
|
|
135
|
+
if (typeof options.translate === 'string') {
|
|
136
|
+
if (Object.keys(locale_1.default).includes(options.translate)) {
|
|
137
|
+
options.translate = {
|
|
138
|
+
translate: locale_1.default[options.translate],
|
|
139
|
+
fallback: locale_1.default.en
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
throw new Error(`Locale "${options.translate}" not supported.`);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
else if (Object.keys(options.translate).includes('translate')) {
|
|
147
|
+
this.verifyTranslationObject(options);
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
options.translate = {
|
|
151
|
+
translate: options.translate,
|
|
152
|
+
fallback: locale_1.default.en
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
options.translate = {
|
|
158
|
+
translate: locale_1.default.en,
|
|
159
|
+
fallback: locale_1.default.en
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
verifyTranslationObject(options) {
|
|
164
|
+
if (typeof options.translate.translate === 'string') {
|
|
165
|
+
if (Object.keys(locale_1.default).includes(options.translate.translate)) {
|
|
166
|
+
options.translate = {
|
|
167
|
+
translate: locale_1.default[options.translate.translate],
|
|
168
|
+
fallback: locale_1.default.en
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
throw new Error(`Locale "${options.translate.translate}" not supported.`);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
if (typeof options.translate.fallback === 'string') {
|
|
176
|
+
if (Object.keys(locale_1.default).includes(options.translate.fallback)) {
|
|
177
|
+
options.translate.fallback =
|
|
178
|
+
locale_1.default[options.translate.fallback];
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
throw new Error(`Locale "${options.translate.fallback}" not supported.`);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
exports.QualWeb = QualWeb;
|
|
187
|
+
async function getFileUrls(file) {
|
|
188
|
+
const content = await readFileData(file);
|
|
189
|
+
return content
|
|
190
|
+
.split('\n')
|
|
191
|
+
.map((url) => {
|
|
192
|
+
try {
|
|
193
|
+
return decodeURIComponent(url).trim();
|
|
194
|
+
}
|
|
195
|
+
catch (_err) {
|
|
196
|
+
return '';
|
|
197
|
+
}
|
|
198
|
+
})
|
|
199
|
+
.filter((url) => url.trim() !== '');
|
|
200
|
+
}
|
|
201
|
+
exports.getFileUrls = getFileUrls;
|
|
202
|
+
function readFileData(file) {
|
|
203
|
+
return new Promise((resolve, reject) => {
|
|
204
|
+
(0, fs_1.readFile)(file, (err, data) => {
|
|
205
|
+
if (err) {
|
|
206
|
+
reject(err);
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
resolve(data.toString('utf-8'));
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
function handleError(options, url, message, timestamp) {
|
|
215
|
+
if (options.log && options.log.file) {
|
|
216
|
+
(0, fs_1.writeFile)(path_1.default.resolve(process.cwd(), `qualweb-errors-${timestamp}.log`), url + ' : ' + message + '\n', { flag: 'a', encoding: 'utf-8' }, (err) => {
|
|
217
|
+
if (err) {
|
|
218
|
+
console.error(err);
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
if (options.log && options.log.console) {
|
|
223
|
+
console.error(url + ' : ' + message + '\n');
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
function deleteErrorLogFile(timestamp) {
|
|
227
|
+
(0, fs_1.unlink)(path_1.default.resolve(process.cwd(), `qualweb-errors-${timestamp}.log`), (err) => {
|
|
228
|
+
if (err) {
|
|
229
|
+
throw err;
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
233
|
//# sourceMappingURL=index.js.map
|