@percy/cli-upload 1.0.0-beta.7 → 1.0.0-beta.73

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/README.md CHANGED
@@ -4,29 +4,36 @@ Percy CLI command to uploade a directory of static images to Percy for diffing.
4
4
 
5
5
  ## Commands
6
6
  <!-- commands -->
7
- * [`percy upload DIRNAME`](#percy-upload-dirname)
7
+ * [`percy upload`](#percy-upload)
8
8
 
9
- ## `percy upload DIRNAME`
9
+ ### `percy upload`
10
10
 
11
11
  Upload a directory of images to Percy
12
12
 
13
13
  ```
14
- USAGE
15
- $ percy upload DIRNAME
16
-
17
- ARGUMENTS
18
- DIRNAME directory of images to upload
19
-
20
- OPTIONS
21
- -c, --config=config configuration file path
22
- -d, --dry-run prints a list of matching images to upload without uploading
23
- -f, --files=files [default: **/*.{png,jpg,jpeg}] one or more globs matching image file paths to upload
24
- -i, --ignore=ignore one or more globs matching image file paths to ignore
25
- -q, --quiet log errors only
26
- -v, --verbose log everything
27
- --silent log nothing
28
-
29
- EXAMPLE
14
+ Usage:
15
+ $ percy upload [options] <dirname>
16
+
17
+ Arguments:
18
+ dirname Directory of images to upload
19
+
20
+ Options:
21
+ -f, --files [pattern] One or more globs matching image file paths to upload (default:
22
+ "**/*.{png,jpg,jpeg}")
23
+ -i, --ignore <pattern> One or more globs matching image file paths to ignore
24
+ -e, --strip-extensions Strips file extensions from snapshot names
25
+
26
+ Percy options:
27
+ -c, --config <file> Config file path
28
+ -d, --dry-run Print snapshot names only
29
+
30
+ Global options:
31
+ -v, --verbose Log everything
32
+ -q, --quiet Log errors only
33
+ -s, --silent Log nothing
34
+ -h, --help Display command help
35
+
36
+ Examples:
30
37
  $ percy upload ./images
31
38
  ```
32
39
  <!-- commandsstop -->
@@ -39,6 +46,11 @@ This CLI plugin adds the following Percy configuration options (defaults shown).
39
46
  # defaults
40
47
  version: 2
41
48
  upload:
49
+ strip-extensions: false
42
50
  files: '**/*.{png,jpg,jpeg}'
43
51
  ignore: ''
44
52
  ```
53
+
54
+ - **strip-extensions** - Strips file extensions from snapshot names
55
+ - **files** - A glob or array of globs matching file paths to upload
56
+ - **ignore** - A glob or array of globs matching file paths to ignore
package/dist/config.js CHANGED
@@ -3,6 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.migration = migration;
6
7
  exports.schema = void 0;
7
8
  const schema = {
8
9
  upload: {
@@ -30,8 +31,29 @@ const schema = {
30
31
  }
31
32
  }],
32
33
  default: ''
34
+ },
35
+ stripExtensions: {
36
+ type: 'boolean',
37
+ default: false
38
+ },
39
+ concurrency: {
40
+ type: 'number',
41
+ minimum: 1
33
42
  }
34
43
  }
35
44
  }
36
45
  };
37
- exports.schema = schema;
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 CHANGED
@@ -1,8 +1,3 @@
1
1
  "use strict";
2
2
 
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var _default = {};
8
- exports.default = _default;
3
+ module.exports = require('./commands/upload').Upload;
package/dist/resources.js CHANGED
@@ -3,7 +3,8 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = createImageResources;
6
+ exports.createImageResources = createImageResources;
7
+ exports.default = void 0;
7
8
 
8
9
  var _path = _interopRequireDefault(require("path"));
9
10
 
@@ -35,15 +36,17 @@ function createImageResource(url, content, mimetype) {
35
36
  // designed to display an image at it's native size without margins or padding.
36
37
 
37
38
 
38
- function createImageResources(filename, content, width, height) {
39
+ function createImageResources(filename, content, size) {
39
40
  let {
41
+ dir,
40
42
  name,
41
43
  ext
42
44
  } = _path.default.parse(filename);
43
45
 
44
- let url = `/${encodeURIComponent(filename)}`;
46
+ let rootUrl = `/${encodeURIComponent(_path.default.join(dir, name))}`;
47
+ let imageUrl = `/${encodeURIComponent(filename)}`;
45
48
  let mimetype = ext === '.png' ? 'image/png' : 'image/jpeg';
46
- return [createRootResource(encodeURIComponent(name), `
49
+ return [createRootResource(rootUrl, `
47
50
  <!doctype html>
48
51
  <html lang="en">
49
52
  <head>
@@ -56,8 +59,11 @@ function createImageResources(filename, content, width, height) {
56
59
  </style>
57
60
  </head>
58
61
  <body>
59
- <img src="${url}" width="${width}px" height="${height}px"/>
62
+ <img src="${imageUrl}" width="${size.width}px" height="${size.height}px"/>
60
63
  </body>
61
64
  </html>
62
- `), createImageResource(url, content, mimetype)];
63
- }
65
+ `), createImageResource(imageUrl, content, mimetype)];
66
+ }
67
+
68
+ var _default = createImageResources;
69
+ exports.default = _default;
package/dist/upload.js ADDED
@@ -0,0 +1,150 @@
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;
package/package.json CHANGED
@@ -1,40 +1,40 @@
1
1
  {
2
2
  "name": "@percy/cli-upload",
3
- "version": "1.0.0-beta.7",
3
+ "version": "1.0.0-beta.73",
4
4
  "license": "MIT",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/percy/cli",
8
+ "directory": "packages/cli-upload"
9
+ },
10
+ "publishConfig": {
11
+ "access": "public"
12
+ },
5
13
  "main": "dist/index.js",
6
14
  "files": [
7
- "dist",
8
- "oclif.manifest.json"
15
+ "dist"
9
16
  ],
17
+ "engines": {
18
+ "node": ">=12"
19
+ },
10
20
  "scripts": {
11
- "build": "babel --root-mode upward src --out-dir dist",
21
+ "build": "node ../../scripts/build",
12
22
  "lint": "eslint --ignore-path ../../.gitignore .",
13
- "postbuild": "oclif-dev manifest",
14
- "readme": "oclif-dev readme",
15
- "test": "cross-env NODE_ENV=test mocha",
16
- "test:coverage": "nyc yarn test"
17
- },
18
- "publishConfig": {
19
- "access": "public"
20
- },
21
- "mocha": {
22
- "require": "../../scripts/babel-register"
23
+ "readme": "percy-cli-readme",
24
+ "test": "node ../../scripts/test",
25
+ "test:coverage": "yarn test --coverage"
23
26
  },
24
- "oclif": {
25
- "bin": "percy",
26
- "commands": "./dist/commands",
27
- "hooks": {
28
- "init": "./dist/hooks/init"
29
- }
27
+ "@percy/cli": {
28
+ "commands": [
29
+ "./dist/upload.js"
30
+ ]
30
31
  },
31
32
  "dependencies": {
32
- "@percy/cli-command": "^1.0.0-beta.7",
33
- "@percy/client": "^1.0.0-beta.7",
34
- "@percy/config": "^1.0.0-beta.7",
35
- "@percy/logger": "^1.0.0-beta.7",
36
- "globby": "^11.0.0",
37
- "image-size": "^0.8.3"
33
+ "@percy/cli-command": "1.0.0-beta.73",
34
+ "@percy/client": "1.0.0-beta.73",
35
+ "@percy/logger": "1.0.0-beta.73",
36
+ "globby": "^11.0.4",
37
+ "image-size": "^1.0.0"
38
38
  },
39
- "gitHead": "5be796ec8f17958e93ada0b634899b945c9b0d60"
39
+ "gitHead": "aa8160e02bea3e04ab1d3605762f89fbe79605d4"
40
40
  }
@@ -1,169 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.Upload = void 0;
7
-
8
- var _fs = _interopRequireDefault(require("fs"));
9
-
10
- var _path = _interopRequireDefault(require("path"));
11
-
12
- var _cliCommand = _interopRequireWildcard(require("@percy/cli-command"));
13
-
14
- var _logger = _interopRequireDefault(require("@percy/logger"));
15
-
16
- var _globby = _interopRequireDefault(require("globby"));
17
-
18
- var _imageSize = _interopRequireDefault(require("image-size"));
19
-
20
- var _client = _interopRequireDefault(require("@percy/client"));
21
-
22
- var _resources = _interopRequireDefault(require("../resources"));
23
-
24
- var _config = require("../config");
25
-
26
- var _package = _interopRequireDefault(require("../../package.json"));
27
-
28
- function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
29
-
30
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (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; }
31
-
32
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
33
-
34
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
35
-
36
- const ALLOWED_IMAGE_TYPES = /\.(png|jpg|jpeg)$/i;
37
-
38
- class Upload extends _cliCommand.default {
39
- async run() {
40
- if (!this.isPercyEnabled()) {
41
- _logger.default.info('Percy is disabled. Skipping upload');
42
-
43
- return;
44
- }
45
-
46
- let {
47
- dirname
48
- } = this.args;
49
-
50
- if (!_fs.default.existsSync(dirname)) {
51
- return this.error(`Not found: ${dirname}`);
52
- } else if (!_fs.default.lstatSync(dirname).isDirectory()) {
53
- return this.error(`Not a directory: ${dirname}`);
54
- }
55
-
56
- let {
57
- upload: {
58
- files,
59
- ignore
60
- }
61
- } = this.percyrc();
62
- ignore = [].concat(ignore).filter(Boolean);
63
- let paths = await (0, _globby.default)(files, {
64
- cwd: dirname,
65
- ignore
66
- });
67
- paths.sort();
68
-
69
- if (!paths.length) {
70
- return this.error(`No matching files found in '${dirname}'`);
71
- } else if (this.flags['dry-run']) {
72
- _logger.default.info('Matching files:');
73
-
74
- return paths.forEach(p => console.log(p));
75
- } // we already have assets so we don't need asset discovery from @percy/core,
76
- // we can use @percy/client directly to send snapshots
77
-
78
-
79
- this.client = new _client.default({
80
- clientInfo: `${_package.default.name}/${_package.default.version}`
81
- });
82
- await this.client.createBuild();
83
- let {
84
- build
85
- } = this.client;
86
-
87
- _logger.default.info('Percy has started!');
88
-
89
- _logger.default.info(`Created build #${build.number}: ${build.url}`);
90
-
91
- for (let name of paths) {
92
- _logger.default.debug(`Uploading snapshot: ${name}`); // only snapshot supported images
93
-
94
-
95
- if (!name.match(ALLOWED_IMAGE_TYPES)) {
96
- _logger.default.info(`Skipping unsupported image type: ${name}`);
97
-
98
- continue;
99
- }
100
-
101
- let filepath = _path.default.resolve(dirname, name);
102
-
103
- let buffer = _fs.default.readFileSync(filepath);
104
-
105
- let {
106
- width,
107
- height
108
- } = (0, _imageSize.default)(filepath);
109
- await this.client.sendSnapshot({
110
- // width and height is clamped to API min and max
111
- widths: [Math.max(10, Math.min(width, 2000))],
112
- minimumHeight: Math.max(10, Math.min(height, 2000)),
113
- resources: (0, _resources.default)(name, buffer, width, height),
114
- name
115
- });
116
-
117
- _logger.default.info(`Snapshot uploaded: ${name}`);
118
- }
119
- } // Finalize the build when finished
120
-
121
-
122
- async finally() {
123
- var _this$client;
124
-
125
- let build = (_this$client = this.client) === null || _this$client === void 0 ? void 0 : _this$client.build;
126
-
127
- if (build === null || build === void 0 ? void 0 : build.id) {
128
- var _this$client2;
129
-
130
- await ((_this$client2 = this.client) === null || _this$client2 === void 0 ? void 0 : _this$client2.finalizeBuild());
131
-
132
- _logger.default.info(`Finalized build #${build.number}: ${build.url}`);
133
- }
134
- }
135
-
136
- }
137
-
138
- exports.Upload = Upload;
139
-
140
- _defineProperty(Upload, "description", 'Upload a directory of images to Percy');
141
-
142
- _defineProperty(Upload, "args", [{
143
- name: 'dirname',
144
- description: 'directory of images to upload',
145
- required: true
146
- }]);
147
-
148
- _defineProperty(Upload, "flags", { ..._cliCommand.flags.logging,
149
- ..._cliCommand.flags.config,
150
- files: _cliCommand.flags.string({
151
- char: 'f',
152
- multiple: true,
153
- description: 'one or more globs matching image file paths to upload',
154
- default: _config.schema.upload.properties.files.default,
155
- percyrc: 'upload.files'
156
- }),
157
- ignore: _cliCommand.flags.string({
158
- char: 'i',
159
- multiple: true,
160
- description: 'one or more globs matching image file paths to ignore',
161
- percyrc: 'upload.ignore'
162
- }),
163
- 'dry-run': _cliCommand.flags.boolean({
164
- char: 'd',
165
- description: 'prints a list of matching images to upload without uploading'
166
- })
167
- });
168
-
169
- _defineProperty(Upload, "examples", ['$ percy upload ./images']);
@@ -1,16 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = _default;
7
-
8
- var _config = _interopRequireDefault(require("@percy/config"));
9
-
10
- var _config2 = require("../config");
11
-
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
14
- function _default() {
15
- _config.default.addSchema(_config2.schema);
16
- }
@@ -1 +0,0 @@
1
- {"version":"1.0.0-beta.7","commands":{"upload":{"id":"upload","description":"Upload a directory of images to Percy","pluginName":"@percy/cli-upload","pluginType":"core","aliases":[],"examples":["$ percy upload ./images"],"flags":{"verbose":{"name":"verbose","type":"boolean","char":"v","description":"log everything","allowNo":false},"quiet":{"name":"quiet","type":"boolean","char":"q","description":"log errors only","allowNo":false},"silent":{"name":"silent","type":"boolean","description":"log nothing","allowNo":false},"config":{"name":"config","type":"option","char":"c","description":"configuration file path"},"files":{"name":"files","type":"option","char":"f","description":"one or more globs matching image file paths to upload","default":"**/*.{png,jpg,jpeg}"},"ignore":{"name":"ignore","type":"option","char":"i","description":"one or more globs matching image file paths to ignore"},"dry-run":{"name":"dry-run","type":"boolean","char":"d","description":"prints a list of matching images to upload without uploading","allowNo":false}},"args":[{"name":"dirname","description":"directory of images to upload","required":true}]}}}