@argos-ci/core 0.3.0 → 0.4.0
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/index.d.ts +3 -0
- package/dist/index.mjs +41 -6
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import * as sharp from 'sharp';
|
|
2
|
+
|
|
1
3
|
interface UploadParameters {
|
|
2
4
|
/** Globs matching image file paths to upload */
|
|
3
5
|
files?: string[];
|
|
@@ -33,6 +35,7 @@ declare const upload: (params: UploadParameters) => Promise<{
|
|
|
33
35
|
};
|
|
34
36
|
screenshots: {
|
|
35
37
|
optimizedPath: string;
|
|
38
|
+
format: keyof sharp.FormatEnum;
|
|
36
39
|
hash: any;
|
|
37
40
|
name: string;
|
|
38
41
|
path: string;
|
package/dist/index.mjs
CHANGED
|
@@ -200,12 +200,33 @@ const discoverScreenshots = async (patterns, { root =process.cwd() , ignore } =
|
|
|
200
200
|
};
|
|
201
201
|
|
|
202
202
|
const tmpFile = promisify(tmp.file);
|
|
203
|
-
const
|
|
203
|
+
const getImageFormat = async (filepath)=>{
|
|
204
|
+
const metadata = await sharp(filepath).metadata();
|
|
205
|
+
if (!metadata.format) {
|
|
206
|
+
throw new Error(`Could not get image format for ${filepath}`);
|
|
207
|
+
}
|
|
208
|
+
return metadata.format;
|
|
209
|
+
};
|
|
210
|
+
const optimizeScreenshot = async (filepath, format)=>{
|
|
204
211
|
const resultFilePath = await tmpFile();
|
|
205
|
-
|
|
212
|
+
const optimization = sharp(filepath).resize(2048, 20480, {
|
|
206
213
|
fit: "inside",
|
|
207
214
|
withoutEnlargement: true
|
|
208
|
-
})
|
|
215
|
+
});
|
|
216
|
+
switch(format){
|
|
217
|
+
case "jpeg":
|
|
218
|
+
case "jpg":
|
|
219
|
+
{
|
|
220
|
+
optimization.jpeg();
|
|
221
|
+
break;
|
|
222
|
+
}
|
|
223
|
+
case "png":
|
|
224
|
+
{
|
|
225
|
+
optimization.png();
|
|
226
|
+
break;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
await optimization.toFile(resultFilePath);
|
|
209
230
|
return resultFilePath;
|
|
210
231
|
};
|
|
211
232
|
|
|
@@ -259,6 +280,17 @@ const createArgosApiClient = (options)=>{
|
|
|
259
280
|
};
|
|
260
281
|
};
|
|
261
282
|
|
|
283
|
+
const formatToContentType = (format)=>{
|
|
284
|
+
switch(format){
|
|
285
|
+
case "jpeg":
|
|
286
|
+
case "jpg":
|
|
287
|
+
return "image/jpeg";
|
|
288
|
+
case "png":
|
|
289
|
+
return "image/png";
|
|
290
|
+
default:
|
|
291
|
+
throw new Error(`Unsupported format ${format}`);
|
|
292
|
+
}
|
|
293
|
+
};
|
|
262
294
|
const upload$1 = async (input)=>{
|
|
263
295
|
const file = await readFile(input.path);
|
|
264
296
|
await axios({
|
|
@@ -266,7 +298,7 @@ const upload$1 = async (input)=>{
|
|
|
266
298
|
url: input.url,
|
|
267
299
|
data: file,
|
|
268
300
|
headers: {
|
|
269
|
-
"Content-Type":
|
|
301
|
+
"Content-Type": formatToContentType(input.format)
|
|
270
302
|
}
|
|
271
303
|
});
|
|
272
304
|
};
|
|
@@ -314,11 +346,13 @@ const getConfigFromOptions = (options)=>{
|
|
|
314
346
|
});
|
|
315
347
|
// Optimize & compute hashes
|
|
316
348
|
const screenshots = await Promise.all(foundScreenshots.map(async (screenshot)=>{
|
|
317
|
-
const
|
|
349
|
+
const format = await getImageFormat(screenshot.path);
|
|
350
|
+
const optimizedPath = await optimizeScreenshot(screenshot.path, format);
|
|
318
351
|
const hash = await hashFile(optimizedPath);
|
|
319
352
|
return {
|
|
320
353
|
...screenshot,
|
|
321
354
|
optimizedPath,
|
|
355
|
+
format,
|
|
322
356
|
hash
|
|
323
357
|
};
|
|
324
358
|
}));
|
|
@@ -346,7 +380,8 @@ const getConfigFromOptions = (options)=>{
|
|
|
346
380
|
}
|
|
347
381
|
await upload$1({
|
|
348
382
|
url: putUrl,
|
|
349
|
-
path: screenshot.optimizedPath
|
|
383
|
+
path: screenshot.optimizedPath,
|
|
384
|
+
format: screenshot.format
|
|
350
385
|
});
|
|
351
386
|
}));
|
|
352
387
|
// Update build
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@argos-ci/core",
|
|
3
3
|
"description": "Visual testing solution to avoid visual regression. The core component of Argos SDK that handles build creation.",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.4.0",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"prebuild": "rm -rf dist",
|
|
7
7
|
"build": "rollup -c",
|
|
@@ -60,5 +60,5 @@
|
|
|
60
60
|
"rollup-plugin-dts": "^4.2.2",
|
|
61
61
|
"rollup-plugin-swc3": "^0.3.0"
|
|
62
62
|
},
|
|
63
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "e0f6d67663b59b5f00180988ccbb0736a8755aa4"
|
|
64
64
|
}
|