@percy/cli-upload 1.0.0-beta.76 → 1.0.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/package.json +11 -11
- package/dist/config.js +0 -59
- package/dist/index.js +0 -3
- package/dist/resources.js +0 -69
- package/dist/upload.js +0 -150
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@percy/cli-upload",
|
|
3
|
-
"version": "1.0.0
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -10,13 +10,15 @@
|
|
|
10
10
|
"publishConfig": {
|
|
11
11
|
"access": "public"
|
|
12
12
|
},
|
|
13
|
-
"main": "dist/index.js",
|
|
14
|
-
"files": [
|
|
15
|
-
"dist"
|
|
16
|
-
],
|
|
17
13
|
"engines": {
|
|
18
|
-
"node": ">=
|
|
14
|
+
"node": ">=14"
|
|
19
15
|
},
|
|
16
|
+
"files": [
|
|
17
|
+
"./dist"
|
|
18
|
+
],
|
|
19
|
+
"main": "./dist/index.js",
|
|
20
|
+
"type": "module",
|
|
21
|
+
"exports": "./dist/index.js",
|
|
20
22
|
"scripts": {
|
|
21
23
|
"build": "node ../../scripts/build",
|
|
22
24
|
"lint": "eslint --ignore-path ../../.gitignore .",
|
|
@@ -30,11 +32,9 @@
|
|
|
30
32
|
]
|
|
31
33
|
},
|
|
32
34
|
"dependencies": {
|
|
33
|
-
"@percy/cli-command": "1.0.0
|
|
34
|
-
"
|
|
35
|
-
"@percy/logger": "1.0.0-beta.76",
|
|
36
|
-
"globby": "^11.0.4",
|
|
35
|
+
"@percy/cli-command": "1.0.0",
|
|
36
|
+
"fast-glob": "^3.2.11",
|
|
37
37
|
"image-size": "^1.0.0"
|
|
38
38
|
},
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "6df509421a60144e4f9f5d59dc57a5675372a0b2"
|
|
40
40
|
}
|
package/dist/config.js
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.migration = migration;
|
|
7
|
-
exports.schema = void 0;
|
|
8
|
-
const schema = {
|
|
9
|
-
upload: {
|
|
10
|
-
type: 'object',
|
|
11
|
-
additionalProperties: false,
|
|
12
|
-
properties: {
|
|
13
|
-
files: {
|
|
14
|
-
anyOf: [{
|
|
15
|
-
type: 'string'
|
|
16
|
-
}, {
|
|
17
|
-
type: 'array',
|
|
18
|
-
items: {
|
|
19
|
-
type: 'string'
|
|
20
|
-
}
|
|
21
|
-
}],
|
|
22
|
-
default: '**/*.{png,jpg,jpeg}'
|
|
23
|
-
},
|
|
24
|
-
ignore: {
|
|
25
|
-
anyOf: [{
|
|
26
|
-
type: 'string'
|
|
27
|
-
}, {
|
|
28
|
-
type: 'array',
|
|
29
|
-
items: {
|
|
30
|
-
type: 'string'
|
|
31
|
-
}
|
|
32
|
-
}],
|
|
33
|
-
default: ''
|
|
34
|
-
},
|
|
35
|
-
stripExtensions: {
|
|
36
|
-
type: 'boolean',
|
|
37
|
-
default: false
|
|
38
|
-
},
|
|
39
|
-
concurrency: {
|
|
40
|
-
type: 'number',
|
|
41
|
-
minimum: 1
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
exports.schema = schema;
|
|
47
|
-
|
|
48
|
-
function migration(config, {
|
|
49
|
-
map,
|
|
50
|
-
del
|
|
51
|
-
}) {
|
|
52
|
-
/* eslint-disable curly */
|
|
53
|
-
if (config.version < 2) {
|
|
54
|
-
// image-snapshots and options were renamed
|
|
55
|
-
map('imageSnapshots.files', 'upload.files');
|
|
56
|
-
map('imageSnapshots.ignore', 'upload.ignore');
|
|
57
|
-
del('imageSnapshots');
|
|
58
|
-
}
|
|
59
|
-
}
|
package/dist/index.js
DELETED
package/dist/resources.js
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.createImageResources = createImageResources;
|
|
7
|
-
exports.default = void 0;
|
|
8
|
-
|
|
9
|
-
var _path = _interopRequireDefault(require("path"));
|
|
10
|
-
|
|
11
|
-
var _utils = require("@percy/client/dist/utils");
|
|
12
|
-
|
|
13
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
|
-
|
|
15
|
-
// Returns a root resource object with a sha and mimetype.
|
|
16
|
-
function createRootResource(url, content) {
|
|
17
|
-
return {
|
|
18
|
-
url,
|
|
19
|
-
content,
|
|
20
|
-
sha: (0, _utils.sha256hash)(content),
|
|
21
|
-
mimetype: 'text/html',
|
|
22
|
-
root: true
|
|
23
|
-
};
|
|
24
|
-
} // Returns an image resource object with a sha.
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
function createImageResource(url, content, mimetype) {
|
|
28
|
-
return {
|
|
29
|
-
url,
|
|
30
|
-
content,
|
|
31
|
-
sha: (0, _utils.sha256hash)(content),
|
|
32
|
-
mimetype
|
|
33
|
-
};
|
|
34
|
-
} // Returns root resource and image resource objects based on an image's
|
|
35
|
-
// filename, contents, and dimensions. The root resource is a generated DOM
|
|
36
|
-
// designed to display an image at it's native size without margins or padding.
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
function createImageResources(filename, content, size) {
|
|
40
|
-
let {
|
|
41
|
-
dir,
|
|
42
|
-
name,
|
|
43
|
-
ext
|
|
44
|
-
} = _path.default.parse(filename);
|
|
45
|
-
|
|
46
|
-
let rootUrl = `/${encodeURIComponent(_path.default.join(dir, name))}`;
|
|
47
|
-
let imageUrl = `/${encodeURIComponent(filename)}`;
|
|
48
|
-
let mimetype = ext === '.png' ? 'image/png' : 'image/jpeg';
|
|
49
|
-
return [createRootResource(rootUrl, `
|
|
50
|
-
<!doctype html>
|
|
51
|
-
<html lang="en">
|
|
52
|
-
<head>
|
|
53
|
-
<meta charset="utf-8">
|
|
54
|
-
<title>${filename}</title>
|
|
55
|
-
<style>
|
|
56
|
-
*, *::before, *::after { margin: 0; padding: 0; font-size: 0; }
|
|
57
|
-
html, body { width: 100%; }
|
|
58
|
-
img { max-width: 100%; }
|
|
59
|
-
</style>
|
|
60
|
-
</head>
|
|
61
|
-
<body>
|
|
62
|
-
<img src="${imageUrl}" width="${size.width}px" height="${size.height}px"/>
|
|
63
|
-
</body>
|
|
64
|
-
</html>
|
|
65
|
-
`), createImageResource(imageUrl, content, mimetype)];
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
var _default = createImageResources;
|
|
69
|
-
exports.default = _default;
|
package/dist/upload.js
DELETED
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.upload = exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _fs = _interopRequireDefault(require("fs"));
|
|
9
|
-
|
|
10
|
-
var _path = _interopRequireDefault(require("path"));
|
|
11
|
-
|
|
12
|
-
var _cliCommand = _interopRequireDefault(require("@percy/cli-command"));
|
|
13
|
-
|
|
14
|
-
var UploadConfig = _interopRequireWildcard(require("./config"));
|
|
15
|
-
|
|
16
|
-
var _package = _interopRequireDefault(require("../package.json"));
|
|
17
|
-
|
|
18
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
|
-
|
|
20
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
21
|
-
|
|
22
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
23
|
-
|
|
24
|
-
const ALLOWED_FILE_TYPES = /\.(png|jpg|jpeg)$/i;
|
|
25
|
-
const upload = (0, _cliCommand.default)('upload', {
|
|
26
|
-
description: 'Upload a directory of images to Percy',
|
|
27
|
-
args: [{
|
|
28
|
-
name: 'dirname',
|
|
29
|
-
description: 'Directory of images to upload',
|
|
30
|
-
required: true,
|
|
31
|
-
validate: dir => {
|
|
32
|
-
if (!_fs.default.existsSync(dir)) {
|
|
33
|
-
throw new Error(`Not found: ${dir}`);
|
|
34
|
-
} else if (!_fs.default.lstatSync(dir).isDirectory()) {
|
|
35
|
-
throw new Error(`Not a directory: ${dir}`);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}],
|
|
39
|
-
flags: [{
|
|
40
|
-
name: 'files',
|
|
41
|
-
description: 'One or more globs matching image file paths to upload',
|
|
42
|
-
default: UploadConfig.schema.upload.properties.files.default,
|
|
43
|
-
percyrc: 'upload.files',
|
|
44
|
-
type: 'pattern',
|
|
45
|
-
multiple: true,
|
|
46
|
-
short: 'f'
|
|
47
|
-
}, {
|
|
48
|
-
name: 'ignore',
|
|
49
|
-
description: 'One or more globs matching image file paths to ignore',
|
|
50
|
-
percyrc: 'upload.ignore',
|
|
51
|
-
type: 'pattern',
|
|
52
|
-
multiple: true,
|
|
53
|
-
short: 'i'
|
|
54
|
-
}, {
|
|
55
|
-
name: 'strip-extensions',
|
|
56
|
-
description: 'Strips file extensions from snapshot names',
|
|
57
|
-
percyrc: 'upload.stripExtensions',
|
|
58
|
-
short: 'e'
|
|
59
|
-
}],
|
|
60
|
-
examples: ['$0 ./images'],
|
|
61
|
-
percy: {
|
|
62
|
-
clientInfo: `${_package.default.name}/${_package.default.version}`,
|
|
63
|
-
environmentInfo: `node/${process.version}`,
|
|
64
|
-
discoveryFlags: false,
|
|
65
|
-
deferUploads: true
|
|
66
|
-
},
|
|
67
|
-
config: {
|
|
68
|
-
schemas: [UploadConfig.schema],
|
|
69
|
-
migrations: [UploadConfig.migration]
|
|
70
|
-
}
|
|
71
|
-
}, async function* ({
|
|
72
|
-
flags,
|
|
73
|
-
args,
|
|
74
|
-
percy,
|
|
75
|
-
log,
|
|
76
|
-
exit
|
|
77
|
-
}) {
|
|
78
|
-
if (!percy) exit(0, 'Percy is disabled');
|
|
79
|
-
let config = percy.config.upload;
|
|
80
|
-
let {
|
|
81
|
-
default: globby
|
|
82
|
-
} = await Promise.resolve().then(() => _interopRequireWildcard(require('globby')));
|
|
83
|
-
let pathnames = yield globby(config.files, {
|
|
84
|
-
ignore: [].concat(config.ignore || []),
|
|
85
|
-
cwd: args.dirname
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
if (!pathnames.length) {
|
|
89
|
-
exit(1, `No matching files found in '${args.dirname}'`);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
let {
|
|
93
|
-
default: imageSize
|
|
94
|
-
} = await Promise.resolve().then(() => _interopRequireWildcard(require('image-size')));
|
|
95
|
-
let {
|
|
96
|
-
createImageResources
|
|
97
|
-
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./resources'))); // the internal upload queue shares a concurrency with the snapshot queue
|
|
98
|
-
|
|
99
|
-
percy.setConfig({
|
|
100
|
-
discovery: {
|
|
101
|
-
concurrency: config.concurrency
|
|
102
|
-
}
|
|
103
|
-
}); // do not launch a browser when starting
|
|
104
|
-
|
|
105
|
-
yield percy.start({
|
|
106
|
-
browser: false
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
for (let filename of pathnames) {
|
|
110
|
-
let file = _path.default.parse(filename);
|
|
111
|
-
|
|
112
|
-
let name = config.stripExtensions ? _path.default.join(file.dir, file.name) : filename;
|
|
113
|
-
|
|
114
|
-
if (!ALLOWED_FILE_TYPES.test(filename)) {
|
|
115
|
-
log.info(`Skipping unsupported file type: ${filename}`);
|
|
116
|
-
} else {
|
|
117
|
-
if (percy.dryRun) log.info(`Snapshot found: ${name}`);
|
|
118
|
-
|
|
119
|
-
percy._scheduleUpload(filename, async () => {
|
|
120
|
-
let filepath = _path.default.resolve(args.dirname, filename);
|
|
121
|
-
|
|
122
|
-
let buffer = _fs.default.readFileSync(filepath); // width and height is clamped to API min and max
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
let size = imageSize(filepath);
|
|
126
|
-
let widths = [Math.max(10, Math.min(size.width, 2000))];
|
|
127
|
-
let minHeight = Math.max(10, Math.min(size.height, 2000));
|
|
128
|
-
let resources = createImageResources(filename, buffer, size);
|
|
129
|
-
return {
|
|
130
|
-
name,
|
|
131
|
-
widths,
|
|
132
|
-
minHeight,
|
|
133
|
-
resources
|
|
134
|
-
};
|
|
135
|
-
}).then(() => {
|
|
136
|
-
log.info(`Snapshot uploaded: ${name}`);
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
try {
|
|
142
|
-
yield* percy.stop();
|
|
143
|
-
} catch (error) {
|
|
144
|
-
await percy.stop(true);
|
|
145
|
-
throw error;
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
exports.upload = upload;
|
|
149
|
-
var _default = upload;
|
|
150
|
-
exports.default = _default;
|