@d-zero/archaeologist 1.1.1 → 1.1.2
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/dist/analyze.js +23 -39
- package/dist/archaeologist.js +3 -3
- package/dist/get-data.d.ts +1 -1
- package/dist/output-utils.d.ts +0 -2
- package/dist/output-utils.js +0 -3
- package/dist/utils.d.ts +0 -1
- package/dist/utils.js +0 -3
- package/package.json +11 -10
package/dist/analyze.js
CHANGED
|
@@ -1,43 +1,31 @@
|
|
|
1
1
|
import { writeFile, mkdir } from 'node:fs/promises';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
-
import { deal } from '@d-zero/dealer';
|
|
3
|
+
import { deal } from '@d-zero/puppeteer-dealer';
|
|
4
4
|
import c from 'ansi-colors';
|
|
5
|
-
import puppeteer from 'puppeteer';
|
|
6
5
|
import { analyzeUrlList } from './analize-url.js';
|
|
7
6
|
import { diffImages } from './diff-images.js';
|
|
8
7
|
import { diffTree } from './diff-tree.js';
|
|
9
8
|
import { getData } from './get-data.js';
|
|
10
|
-
import {
|
|
9
|
+
import { score } from './output-utils.js';
|
|
11
10
|
export async function analyze(list, options) {
|
|
12
|
-
const urlInfo = analyzeUrlList(list);
|
|
13
|
-
const useOldMode = urlInfo.hasAuth && urlInfo.hasNoSSL;
|
|
14
|
-
const browser = await puppeteer.launch({
|
|
15
|
-
headless: useOldMode ? 'shell' : true,
|
|
16
|
-
args: [
|
|
17
|
-
//
|
|
18
|
-
'--lang=ja',
|
|
19
|
-
'--no-zygote',
|
|
20
|
-
'--ignore-certificate-errors',
|
|
21
|
-
],
|
|
22
|
-
});
|
|
23
11
|
const results = [];
|
|
24
12
|
const dir = path.resolve(process.cwd(), '.archaeologist');
|
|
25
13
|
await mkdir(dir, { recursive: true }).catch(() => { });
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
14
|
+
const urlInfo = analyzeUrlList(list);
|
|
15
|
+
const useOldMode = urlInfo.hasAuth || urlInfo.hasNoSSL;
|
|
16
|
+
await deal(list.map(([urlA]) => ({ id: null, url: urlA })), (_, done, total) => {
|
|
17
|
+
return `${c.bold.magenta('🕵️ Archaeologist')} ${done}/${total}`;
|
|
18
|
+
}, {
|
|
19
|
+
async deal(page, _, urlA, logger, index) {
|
|
20
|
+
const urlPair = list.find(([url]) => url === urlA);
|
|
21
|
+
if (!urlPair) {
|
|
22
|
+
throw new Error(`Failed to find urlPair: ${urlA}`);
|
|
23
|
+
}
|
|
36
24
|
const dataPair = [];
|
|
37
25
|
for (const url of urlPair) {
|
|
38
26
|
const data = await getData(page, url, {
|
|
39
27
|
...options,
|
|
40
|
-
},
|
|
28
|
+
}, logger);
|
|
41
29
|
dataPair.push(data);
|
|
42
30
|
await delay(600);
|
|
43
31
|
}
|
|
@@ -46,10 +34,10 @@ export async function analyze(list, options) {
|
|
|
46
34
|
throw new Error('Failed to get screenshots');
|
|
47
35
|
}
|
|
48
36
|
const screenshotResult = {};
|
|
49
|
-
const outputUrl = c.gray(urlPair
|
|
37
|
+
const outputUrl = 'vs ' + c.gray(urlPair[1]);
|
|
50
38
|
for (const [name, screenshotA] of Object.entries(a.screenshots)) {
|
|
51
39
|
const screenshotB = b.screenshots[name];
|
|
52
|
-
const sizeName =
|
|
40
|
+
const sizeName = c.bgMagenta(` ${name} `);
|
|
53
41
|
const id = `${index}_${name}`;
|
|
54
42
|
if (!screenshotB) {
|
|
55
43
|
throw new Error(`Failed to get screenshotB: ${id}`);
|
|
@@ -57,28 +45,28 @@ export async function analyze(list, options) {
|
|
|
57
45
|
const imageDiff = await diffImages(screenshotA, screenshotB, (phase, data) => {
|
|
58
46
|
switch (phase) {
|
|
59
47
|
case 'create': {
|
|
60
|
-
|
|
48
|
+
logger(`${sizeName} ${outputUrl} 🖼️ Create images`);
|
|
61
49
|
break;
|
|
62
50
|
}
|
|
63
51
|
case 'resize': {
|
|
64
52
|
const { width, height } = data;
|
|
65
|
-
|
|
53
|
+
logger(`${sizeName} ${outputUrl} ↔️ Resize images to ${width}x${height}`);
|
|
66
54
|
break;
|
|
67
55
|
}
|
|
68
56
|
case 'diff': {
|
|
69
|
-
|
|
57
|
+
logger(`${sizeName} ${outputUrl} 📊 Compare images`);
|
|
70
58
|
break;
|
|
71
59
|
}
|
|
72
60
|
}
|
|
73
61
|
});
|
|
74
62
|
let image = null;
|
|
75
63
|
if (imageDiff) {
|
|
76
|
-
|
|
64
|
+
logger(`${sizeName} ${outputUrl} 🧩 Matches ${score(imageDiff.matches, 0.9)}`);
|
|
77
65
|
await delay(1500);
|
|
78
66
|
await writeFile(path.resolve(dir, `${id}_a.png`), imageDiff.images.a);
|
|
79
67
|
await writeFile(path.resolve(dir, `${id}_b.png`), imageDiff.images.b);
|
|
80
68
|
const outFilePath = path.resolve(dir, `${id}_diff.png`);
|
|
81
|
-
|
|
69
|
+
logger(`${sizeName} ${outputUrl} 📊 Save diff image to ${path.relative(dir, outFilePath)}`);
|
|
82
70
|
await writeFile(outFilePath, imageDiff.images.diff);
|
|
83
71
|
image = {
|
|
84
72
|
matches: imageDiff.matches,
|
|
@@ -102,15 +90,11 @@ export async function analyze(list, options) {
|
|
|
102
90
|
screenshots: screenshotResult,
|
|
103
91
|
};
|
|
104
92
|
results.push(result);
|
|
105
|
-
};
|
|
106
|
-
}, {
|
|
107
|
-
limit: options?.limit,
|
|
108
|
-
debug: options?.debug,
|
|
109
|
-
header(_, done, total) {
|
|
110
|
-
return `${c.bold.magenta('🕵️ Archaeologist')} ${done}/${total}`;
|
|
111
93
|
},
|
|
94
|
+
}, {
|
|
95
|
+
...options,
|
|
96
|
+
headless: useOldMode ? 'shell' : true,
|
|
112
97
|
});
|
|
113
|
-
await browser.close();
|
|
114
98
|
return results;
|
|
115
99
|
}
|
|
116
100
|
function delay(ms) {
|
package/dist/archaeologist.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import c from 'ansi-colors';
|
|
2
2
|
import { analyze } from './analyze.js';
|
|
3
|
-
import {
|
|
3
|
+
import { score } from './output-utils.js';
|
|
4
4
|
export async function archaeologist(list, options) {
|
|
5
5
|
const results = await analyze(list, options);
|
|
6
6
|
const output = [];
|
|
@@ -9,9 +9,9 @@ export async function archaeologist(list, options) {
|
|
|
9
9
|
for (const [sizeName, { image, dom }] of Object.entries(result.screenshots)) {
|
|
10
10
|
if (image) {
|
|
11
11
|
const { matches, file } = image;
|
|
12
|
-
output.push(` ${
|
|
12
|
+
output.push(` ${c.bgMagenta(` ${sizeName} `)} ${score(matches, 0.9)} ${file}`);
|
|
13
13
|
}
|
|
14
|
-
output.push(` ${
|
|
14
|
+
output.push(` ${c.bgBlueBright(' HTML ')}: ${score(dom.matches, 0.995)} ${dom.file}`);
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
process.stdout.write(output.join('\n') + '\n');
|
package/dist/get-data.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { PageData } from './types.js';
|
|
2
|
+
import type { Page } from '@d-zero/puppeteer-page';
|
|
2
3
|
import type { PageHook } from '@d-zero/puppeteer-screenshot';
|
|
3
|
-
import type { Page } from 'puppeteer';
|
|
4
4
|
export interface GetDataOptions {
|
|
5
5
|
readonly hooks?: readonly PageHook[];
|
|
6
6
|
readonly htmlDiffOnly?: boolean;
|
package/dist/output-utils.d.ts
CHANGED
package/dist/output-utils.js
CHANGED
package/dist/utils.d.ts
CHANGED
package/dist/utils.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@d-zero/archaeologist",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "Uncover visual and HTML differences in web pages with precision",
|
|
5
5
|
"author": "D-ZERO",
|
|
6
6
|
"license": "MIT",
|
|
@@ -23,14 +23,15 @@
|
|
|
23
23
|
],
|
|
24
24
|
"scripts": {
|
|
25
25
|
"build": "tsc",
|
|
26
|
+
"watch": "tsc --watch",
|
|
26
27
|
"clean": "tsc --build --clean"
|
|
27
28
|
},
|
|
28
29
|
"dependencies": {
|
|
29
|
-
"@d-zero/
|
|
30
|
-
"@d-zero/
|
|
31
|
-
"@d-zero/puppeteer-page-scan": "
|
|
32
|
-
"@d-zero/puppeteer-screenshot": "
|
|
33
|
-
"@d-zero/readtext": "1.1.
|
|
30
|
+
"@d-zero/html-distiller": "1.0.1",
|
|
31
|
+
"@d-zero/puppeteer-dealer": "0.2.0",
|
|
32
|
+
"@d-zero/puppeteer-page-scan": "2.0.0",
|
|
33
|
+
"@d-zero/puppeteer-screenshot": "2.0.0",
|
|
34
|
+
"@d-zero/readtext": "1.1.1",
|
|
34
35
|
"ansi-colors": "4.1.3",
|
|
35
36
|
"diff": "7.0.0",
|
|
36
37
|
"front-matter": "4.0.2",
|
|
@@ -38,13 +39,13 @@
|
|
|
38
39
|
"minimist": "1.2.8",
|
|
39
40
|
"parse-diff": "0.11.1",
|
|
40
41
|
"pixelmatch": "6.0.0",
|
|
41
|
-
"pngjs": "7.0.0"
|
|
42
|
-
"puppeteer": "23.5.0"
|
|
42
|
+
"pngjs": "7.0.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@
|
|
45
|
+
"@d-zero/puppeteer-page": "0.2.0",
|
|
46
|
+
"@types/diff": "6.0.0",
|
|
46
47
|
"@types/pixelmatch": "5.2.6",
|
|
47
48
|
"@types/pngjs": "6.0.5"
|
|
48
49
|
},
|
|
49
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "1eb1c03400580040119121e11ffb33acd876fe1b"
|
|
50
51
|
}
|