@percy/cli-upload 1.10.4 → 1.11.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/upload.js CHANGED
@@ -73,41 +73,40 @@ export const upload = command('upload', {
73
73
  default: imageSize
74
74
  } = await import('image-size');
75
75
  let {
76
- createImageResources
77
- } = await import('./resources.js'); // the internal upload queue shares a concurrency with the snapshot queue
76
+ getImageResources
77
+ } = await import('./utils.js'); // the internal discovery queue shares a concurrency with the snapshots queue
78
78
 
79
- percy.setConfig({
79
+ percy.set({
80
80
  discovery: {
81
81
  concurrency: config.concurrency
82
82
  }
83
83
  });
84
84
  yield* percy.yield.start();
85
85
 
86
- for (let filename of pathnames) {
87
- let file = path.parse(filename);
88
- let name = config.stripExtensions ? path.join(file.dir, file.name) : filename;
89
-
90
- if (!ALLOWED_FILE_TYPES.test(filename)) {
91
- log.info(`Skipping unsupported file type: ${filename}`);
86
+ for (let relativePath of pathnames) {
87
+ if (!ALLOWED_FILE_TYPES.test(relativePath)) {
88
+ log.info(`Skipping unsupported file type: ${relativePath}`);
92
89
  } else {
93
- if (percy.dryRun) log.info(`Snapshot found: ${name}`);
94
-
95
- percy._scheduleUpload(filename, async () => {
96
- let filepath = path.resolve(args.dirname, filename);
97
- let buffer = fs.readFileSync(filepath); // width and height is clamped to API min and max
98
-
99
- let size = imageSize(filepath);
100
- let widths = [Math.max(10, Math.min(size.width, 2000))];
101
- let minHeight = Math.max(10, Math.min(size.height, 2000));
102
- let resources = createImageResources(filename, buffer, size);
103
- return {
104
- name,
105
- widths,
106
- minHeight,
107
- resources
108
- };
109
- }).then(() => {
110
- log.info(`Snapshot uploaded: ${name}`);
90
+ let absolutePath = path.resolve(args.dirname, relativePath);
91
+ let img = {
92
+ relativePath,
93
+ absolutePath,
94
+ ...imageSize(absolutePath)
95
+ };
96
+ let {
97
+ dir,
98
+ name,
99
+ ext
100
+ } = path.parse(relativePath);
101
+ img.type = ext === '.png' ? 'png' : 'jpeg';
102
+ img.name = path.join(dir, name);
103
+ percy.upload({
104
+ name: config.stripExtensions ? img.name : relativePath,
105
+ // width and height is clamped to API min and max
106
+ widths: [Math.max(10, Math.min(img.width, 2000))],
107
+ minHeight: Math.max(10, Math.min(img.height, 2000)),
108
+ // resources are read from the filesystem as needed
109
+ resources: () => getImageResources(img)
111
110
  });
112
111
  }
113
112
  }
package/dist/utils.js ADDED
@@ -0,0 +1,35 @@
1
+ import fs from 'fs';
2
+ import { createResource, createRootResource } from '@percy/cli-command/utils';
3
+ export { yieldAll } from '@percy/cli-command/utils'; // Returns root resource and image resource objects based on image properties. The root resource is
4
+ // a generated DOM designed to display an image at it's native size without margins or padding.
5
+
6
+ export async function getImageResources({
7
+ name,
8
+ type,
9
+ width,
10
+ height,
11
+ relativePath,
12
+ absolutePath
13
+ }) {
14
+ let rootUrl = `http://localhost/${encodeURIComponent(name)}`;
15
+ let imageUrl = `http://localhost/${encodeURIComponent(relativePath)}`;
16
+ let content = await fs.promises.readFile(absolutePath);
17
+ let mimetype = `image/${type}`;
18
+ return [createRootResource(rootUrl, `
19
+ <!doctype html>
20
+ <html lang="en">
21
+ <head>
22
+ <meta charset="utf-8">
23
+ <title>${name}</title>
24
+ <style>
25
+ *, *::before, *::after { margin: 0; padding: 0; font-size: 0; }
26
+ html, body { width: 100%; }
27
+ img { max-width: 100%; }
28
+ </style>
29
+ </head>
30
+ <body>
31
+ <img src="${imageUrl}" width="${width}px" height="${height}px"/>
32
+ </body>
33
+ </html>
34
+ `), createResource(imageUrl, content, mimetype)];
35
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@percy/cli-upload",
3
- "version": "1.10.4",
3
+ "version": "1.11.0",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -32,9 +32,9 @@
32
32
  ]
33
33
  },
34
34
  "dependencies": {
35
- "@percy/cli-command": "1.10.4",
35
+ "@percy/cli-command": "1.11.0",
36
36
  "fast-glob": "^3.2.11",
37
37
  "image-size": "^1.0.0"
38
38
  },
39
- "gitHead": "16a9a410bfcb8eab51b86a08cff12d8d35e4747e"
39
+ "gitHead": "0a5043cd677266390889063924f342af9b347055"
40
40
  }
package/dist/resources.js DELETED
@@ -1,54 +0,0 @@
1
- import path from 'path';
2
- import { sha256hash } from '@percy/client/utils'; // Returns a root resource object with a sha and mimetype.
3
-
4
- function createRootResource(url, content) {
5
- return {
6
- url,
7
- content,
8
- sha: sha256hash(content),
9
- mimetype: 'text/html',
10
- root: true
11
- };
12
- } // Returns an image resource object with a sha.
13
-
14
-
15
- function createImageResource(url, content, mimetype) {
16
- return {
17
- url,
18
- content,
19
- sha: sha256hash(content),
20
- mimetype
21
- };
22
- } // Returns root resource and image resource objects based on an image's
23
- // filename, contents, and dimensions. The root resource is a generated DOM
24
- // designed to display an image at it's native size without margins or padding.
25
-
26
-
27
- export function createImageResources(filename, content, size) {
28
- let {
29
- dir,
30
- name,
31
- ext
32
- } = path.parse(filename);
33
- let rootUrl = `/${encodeURIComponent(path.join(dir, name))}`;
34
- let imageUrl = `/${encodeURIComponent(filename)}`;
35
- let mimetype = ext === '.png' ? 'image/png' : 'image/jpeg';
36
- return [createRootResource(rootUrl, `
37
- <!doctype html>
38
- <html lang="en">
39
- <head>
40
- <meta charset="utf-8">
41
- <title>${filename}</title>
42
- <style>
43
- *, *::before, *::after { margin: 0; padding: 0; font-size: 0; }
44
- html, body { width: 100%; }
45
- img { max-width: 100%; }
46
- </style>
47
- </head>
48
- <body>
49
- <img src="${imageUrl}" width="${size.width}px" height="${size.height}px"/>
50
- </body>
51
- </html>
52
- `), createImageResource(imageUrl, content, mimetype)];
53
- }
54
- export default createImageResources;