@percy/cli-upload 1.26.3-beta.1 → 1.27.0-beta.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.
Files changed (2) hide show
  1. package/dist/upload.js +31 -8
  2. package/package.json +3 -3
package/dist/upload.js CHANGED
@@ -3,6 +3,14 @@ import path from 'path';
3
3
  import command from '@percy/cli-command';
4
4
  import * as UploadConfig from './config.js';
5
5
  const ALLOWED_FILE_TYPES = /\.(png|jpg|jpeg)$/i;
6
+ const ALLOWED_TOKEN_TYPES = ['web', 'generic'];
7
+
8
+ // All BYOS screenshots have a fixed comparison tag
9
+ export const BYOS_TAG = {
10
+ name: 'Uploaded Screenshot',
11
+ width: 1,
12
+ height: 1
13
+ };
6
14
  export const upload = command('upload', {
7
15
  description: 'Upload a directory of images to Percy',
8
16
  args: [{
@@ -67,6 +75,10 @@ export const upload = command('upload', {
67
75
  if (!pathnames.length) {
68
76
  exit(1, `No matching files found in '${args.dirname}'`);
69
77
  }
78
+ const tokenType = percy.client.tokenType();
79
+ if (!ALLOWED_TOKEN_TYPES.includes(tokenType)) {
80
+ exit(1, 'Invalid Token Type. Only "web" and "self-managed" token types are allowed.');
81
+ }
70
82
  let {
71
83
  default: imageSize
72
84
  } = await import('image-size');
@@ -98,14 +110,25 @@ export const upload = command('upload', {
98
110
  } = path.parse(relativePath);
99
111
  img.type = ext === '.png' ? 'png' : 'jpeg';
100
112
  img.name = path.join(dir, name);
101
- percy.upload({
102
- name: config.stripExtensions ? img.name : relativePath,
103
- // width and height is clamped to API min and max
104
- widths: [Math.max(10, Math.min(img.width, 2000))],
105
- minHeight: Math.max(10, Math.min(img.height, 2000)),
106
- // resources are read from the filesystem as needed
107
- resources: () => getImageResources(img)
108
- });
113
+ let snapshotName = config.stripExtensions ? img.name : relativePath;
114
+ if (tokenType === 'generic') {
115
+ percy.upload({
116
+ name: snapshotName,
117
+ tag: BYOS_TAG,
118
+ tiles: [{
119
+ filepath: img.absolutePath
120
+ }]
121
+ });
122
+ } else {
123
+ percy.upload({
124
+ name: snapshotName,
125
+ // width and height is clamped to API min and max
126
+ widths: [Math.max(10, Math.min(img.width, 2000))],
127
+ minHeight: Math.max(10, Math.min(img.height, 2000)),
128
+ // resources are read from the filesystem as needed
129
+ resources: () => getImageResources(img)
130
+ });
131
+ }
109
132
  }
110
133
  }
111
134
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@percy/cli-upload",
3
- "version": "1.26.3-beta.1",
3
+ "version": "1.27.0-beta.0",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -33,9 +33,9 @@
33
33
  ]
34
34
  },
35
35
  "dependencies": {
36
- "@percy/cli-command": "1.26.3-beta.1",
36
+ "@percy/cli-command": "1.27.0-beta.0",
37
37
  "fast-glob": "^3.2.11",
38
38
  "image-size": "^1.0.0"
39
39
  },
40
- "gitHead": "6571d4ad016bc8b3b32d49bf8a7da1393c1a5eba"
40
+ "gitHead": "2bc16314f51dddcc1cda459e7aa4b7b2db85f00a"
41
41
  }