afterbefore 0.1.13 → 0.1.15
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/cli.js +22 -20
- package/dist/cli.js.map +1 -1
- package/dist/index.js +21 -19
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -116,16 +116,15 @@ var Logger = class {
|
|
|
116
116
|
this.log("info", `Pipeline ${finished ? "completed" : "stopped"}`);
|
|
117
117
|
if (this.spinner) {
|
|
118
118
|
if (finished) {
|
|
119
|
-
this.spinner.stop();
|
|
120
119
|
const bar = "\u2588".repeat(BAR_WIDTH);
|
|
121
|
-
|
|
120
|
+
this.spinner.succeed(` ${bar}`);
|
|
122
121
|
} else {
|
|
123
122
|
this.spinner.stop();
|
|
124
123
|
}
|
|
125
124
|
this.spinner = null;
|
|
126
125
|
} else if (finished) {
|
|
127
126
|
const bar = "\u2588".repeat(BAR_WIDTH);
|
|
128
|
-
console.
|
|
127
|
+
console.error(`${chalk.green("\u2714")} ${bar}`);
|
|
129
128
|
}
|
|
130
129
|
this.pipelineTotal = 0;
|
|
131
130
|
this.lastStep = 0;
|
|
@@ -1657,34 +1656,37 @@ async function captureRoutes(tasks, beforeUrl, afterUrl, outputDir, options) {
|
|
|
1657
1656
|
|
|
1658
1657
|
// src/stages/compare.ts
|
|
1659
1658
|
import { join as join7, dirname as dirname2 } from "path";
|
|
1660
|
-
import {
|
|
1659
|
+
import { unlinkSync } from "fs";
|
|
1661
1660
|
import { ODiffServer } from "odiff-bin";
|
|
1662
1661
|
import sharp from "sharp";
|
|
1663
|
-
function
|
|
1664
|
-
const
|
|
1665
|
-
return { width:
|
|
1662
|
+
async function trimImage(path) {
|
|
1663
|
+
const { data, info } = await sharp(path).trim({ threshold: 50 }).toBuffer({ resolveWithObject: true });
|
|
1664
|
+
return { data, width: info.width, height: info.height };
|
|
1666
1665
|
}
|
|
1667
1666
|
async function generateComposite(beforePath, afterPath, outputPath, bgColor) {
|
|
1668
|
-
const
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
const
|
|
1673
|
-
const
|
|
1667
|
+
const [beforeTrimmed, afterTrimmed] = await Promise.all([
|
|
1668
|
+
trimImage(beforePath),
|
|
1669
|
+
trimImage(afterPath)
|
|
1670
|
+
]);
|
|
1671
|
+
const imgW = Math.max(beforeTrimmed.width, afterTrimmed.width);
|
|
1672
|
+
const imgH = Math.max(beforeTrimmed.height, afterTrimmed.height);
|
|
1673
|
+
const PADDING = 40;
|
|
1674
|
+
const GAP = 40;
|
|
1674
1675
|
const LABEL_H = 70;
|
|
1675
1676
|
const canvasW = Math.max(600, Math.min(2400, imgW * 2 + GAP + PADDING * 2));
|
|
1676
1677
|
const canvasH = Math.max(300, Math.min(2400, imgH + LABEL_H + PADDING * 2));
|
|
1677
1678
|
const maxImgH = canvasH - PADDING * 2 - LABEL_H;
|
|
1678
1679
|
const colW = Math.floor((canvasW - PADDING * 2 - GAP) / 2);
|
|
1679
|
-
const [beforeBuf, afterBuf] = await Promise.all(
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1680
|
+
const [beforeBuf, afterBuf] = await Promise.all(
|
|
1681
|
+
[beforeTrimmed, afterTrimmed].map(async (trimmed) => {
|
|
1682
|
+
return await sharp(trimmed.data).resize(colW, maxImgH, { fit: "inside" }).toBuffer({ resolveWithObject: true });
|
|
1683
|
+
})
|
|
1684
|
+
);
|
|
1683
1685
|
const beforeLeft = PADDING + Math.floor((colW - beforeBuf.info.width) / 2);
|
|
1684
1686
|
const beforeTop = PADDING + Math.floor((maxImgH - beforeBuf.info.height) / 2);
|
|
1685
1687
|
const afterLeft = PADDING + colW + GAP + Math.floor((colW - afterBuf.info.width) / 2);
|
|
1686
1688
|
const afterTop = PADDING + Math.floor((maxImgH - afterBuf.info.height) / 2);
|
|
1687
|
-
const labelY = PADDING + maxImgH +
|
|
1689
|
+
const labelY = PADDING + maxImgH + 20;
|
|
1688
1690
|
const beforeLabelX = PADDING + Math.floor(colW / 2);
|
|
1689
1691
|
const afterLabelX = PADDING + colW + GAP + Math.floor(colW / 2);
|
|
1690
1692
|
const labelSvg = Buffer.from(
|
|
@@ -1939,7 +1941,7 @@ async function runPipeline(options) {
|
|
|
1939
1941
|
const outputDir = resolve4(cwd, output, sessionName);
|
|
1940
1942
|
const startTime = Date.now();
|
|
1941
1943
|
try {
|
|
1942
|
-
const version = true ? "0.1.
|
|
1944
|
+
const version = true ? "0.1.15" : "dev";
|
|
1943
1945
|
console.log(`
|
|
1944
1946
|
afterbefore v${version} \xB7 Comparing against ${base}
|
|
1945
1947
|
`);
|
|
@@ -2084,7 +2086,7 @@ afterbefore v${version} \xB7 Comparing against ${base}
|
|
|
2084
2086
|
var program = new Command();
|
|
2085
2087
|
program.name("afterbefore").description(
|
|
2086
2088
|
"Automatic before/after screenshot capture for PRs. Git diff is the config."
|
|
2087
|
-
).version("0.1.
|
|
2089
|
+
).version("0.1.15").option("--base <ref>", "Base branch or ref to compare against", "main").option("--output <dir>", "Output directory for screenshots", ".afterbefore").option("--post", "Post results as a PR comment via gh CLI", false).option(
|
|
2088
2090
|
"--threshold <percent>",
|
|
2089
2091
|
"Diff threshold percentage (changes below this are ignored)",
|
|
2090
2092
|
"0.1"
|