@percy/cli-snapshot 1.0.0-beta.68 → 1.0.0-beta.69
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 +1 -1
- package/dist/commands/snapshot.js +14 -34
- package/dist/config.js +2 -1
- package/dist/utils.js +25 -13
- package/oclif.manifest.json +1 -1
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -20,7 +20,7 @@ ARGUMENTS
|
|
|
20
20
|
OPTIONS
|
|
21
21
|
-b, --base-url=base-url the base url pages are hosted at when snapshotting
|
|
22
22
|
-c, --config=config configuration file path
|
|
23
|
-
-d, --dry-run
|
|
23
|
+
-d, --dry-run print logs only, do not run asset discovery or upload snapshots
|
|
24
24
|
-h, --allowed-hostname=allowed-hostname allowed hostnames to capture in asset discovery
|
|
25
25
|
-q, --quiet log errors only
|
|
26
26
|
-t, --network-idle-timeout=network-idle-timeout asset discovery network idle timeout
|
|
@@ -70,26 +70,14 @@ class Snapshot extends _cliCommand.default {
|
|
|
70
70
|
}); // gather snapshots
|
|
71
71
|
|
|
72
72
|
let snapshots = isSitemap && (await this.loadSitemapSnapshots(arg)) || isStatic && (await this.loadStaticSnapshots(arg)) || (await this.loadSnapshotsFile(arg));
|
|
73
|
-
|
|
74
|
-
if (!
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
this.log.info(`Snapshot found: ${snap.name}`);
|
|
82
|
-
this.log.debug(`-> url: ${snap.url}`);
|
|
83
|
-
|
|
84
|
-
for (let s of snap.additionalSnapshots || []) {
|
|
85
|
-
let name = s.name || `${s.prefix || ''}${snap.name}${s.suffix || ''}`;
|
|
86
|
-
this.log.info(`Snapshot found: ${name}`);
|
|
87
|
-
this.log.debug(`-> url: ${snap.url}`);
|
|
88
|
-
}
|
|
89
|
-
} else {
|
|
90
|
-
this.percy.snapshot(snap);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
73
|
+
|
|
74
|
+
if (!snapshots.length) {
|
|
75
|
+
this.error('No snapshots found');
|
|
76
|
+
} // start processing snapshots
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
await this.percy.start();
|
|
80
|
+
this.percy.snapshot(snapshots);
|
|
93
81
|
} // Called on error, interupt, or after running
|
|
94
82
|
|
|
95
83
|
|
|
@@ -128,7 +116,7 @@ class Snapshot extends _cliCommand.default {
|
|
|
128
116
|
async loadStaticSnapshots(dir) {
|
|
129
117
|
let config = this.percy.config.static;
|
|
130
118
|
let baseUrl = this.flags['base-url'] || config.baseUrl;
|
|
131
|
-
let
|
|
119
|
+
let dryRun = this.flags['dry-run']; // validate any provided base-url
|
|
132
120
|
|
|
133
121
|
if (baseUrl && !baseUrl.startsWith('/')) {
|
|
134
122
|
this.error('The base-url must begin with a forward slash (/) ' + 'when snapshotting static directories');
|
|
@@ -137,12 +125,8 @@ class Snapshot extends _cliCommand.default {
|
|
|
137
125
|
|
|
138
126
|
this.server = await (0, _utils.serve)(dir, { ...config,
|
|
139
127
|
baseUrl,
|
|
140
|
-
|
|
141
|
-
});
|
|
142
|
-
let {
|
|
143
|
-
host,
|
|
144
|
-
rewrites
|
|
145
|
-
} = this.server; // gather paths and map snapshots
|
|
128
|
+
dryRun
|
|
129
|
+
}); // gather paths
|
|
146
130
|
|
|
147
131
|
let isStr = s => typeof s === 'string';
|
|
148
132
|
|
|
@@ -153,10 +137,10 @@ class Snapshot extends _cliCommand.default {
|
|
|
153
137
|
let paths = await (0, _globby.default)(files, {
|
|
154
138
|
cwd: dir,
|
|
155
139
|
ignore
|
|
156
|
-
});
|
|
140
|
+
}); // map snapshots from paths and config
|
|
141
|
+
|
|
157
142
|
return (0, _utils.mapStaticSnapshots)(paths, { ...config,
|
|
158
|
-
|
|
159
|
-
rewrites
|
|
143
|
+
server: this.server
|
|
160
144
|
});
|
|
161
145
|
} // Loads snapshots from a js, json, or yaml file.
|
|
162
146
|
|
|
@@ -238,10 +222,6 @@ _defineProperty(Snapshot, "flags", { ..._cliCommand.flags.logging,
|
|
|
238
222
|
description: 'one or more globs/patterns matching snapshots to exclude',
|
|
239
223
|
multiple: true
|
|
240
224
|
}),
|
|
241
|
-
'dry-run': _cliCommand.flags.boolean({
|
|
242
|
-
description: 'prints a list of snapshots without processing them',
|
|
243
|
-
char: 'd'
|
|
244
|
-
}),
|
|
245
225
|
// static only flags
|
|
246
226
|
'clean-urls': _cliCommand.flags.boolean({
|
|
247
227
|
description: 'rewrite static index and filepath URLs to be clean',
|
package/dist/config.js
CHANGED
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.configSchema = exports.cliSchema = void 0;
|
|
6
7
|
exports.migration = migration;
|
|
7
|
-
exports.
|
|
8
|
+
exports.snapshotListSchema = exports.schemas = void 0;
|
|
8
9
|
|
|
9
10
|
var _config = require("@percy/core/dist/config");
|
|
10
11
|
|
package/dist/utils.js
CHANGED
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.mapStaticSnapshots = mapStaticSnapshots;
|
|
7
7
|
exports.serve = serve;
|
|
8
8
|
exports.snapshotMatches = snapshotMatches;
|
|
9
|
-
exports.
|
|
9
|
+
exports.withDefaults = withDefaults;
|
|
10
10
|
|
|
11
11
|
var _path = _interopRequireDefault(require("path"));
|
|
12
12
|
|
|
@@ -48,28 +48,34 @@ function withDefaults(options, {
|
|
|
48
48
|
|
|
49
49
|
options.url = url.href;
|
|
50
50
|
return options;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function mapRewrites(map, arr) {
|
|
54
|
+
return Object.entries(map).reduce((r, [source, destination]) => {
|
|
55
|
+
return (r || []).concat({
|
|
56
|
+
source,
|
|
57
|
+
destination
|
|
58
|
+
});
|
|
59
|
+
}, arr);
|
|
51
60
|
} // Serves a static directory with the provided options and returns an object containing adjusted
|
|
52
61
|
// rewrites (combined with any baseUrl), the server host, a close method, and the server
|
|
53
|
-
// instance. The `
|
|
62
|
+
// instance. The `dryRun` option will prevent the server from actually starting.
|
|
54
63
|
|
|
55
64
|
|
|
56
65
|
async function serve(dir, {
|
|
57
|
-
|
|
66
|
+
dryRun,
|
|
58
67
|
baseUrl,
|
|
59
68
|
cleanUrls,
|
|
60
69
|
rewrites = {}
|
|
61
70
|
}) {
|
|
62
|
-
let host = 'http://localhost'; //
|
|
71
|
+
let host = 'http://localhost'; // map rewrite options with any base-url
|
|
63
72
|
|
|
64
|
-
rewrites =
|
|
65
|
-
source,
|
|
66
|
-
destination
|
|
67
|
-
}), baseUrl ? [{
|
|
73
|
+
rewrites = mapRewrites(rewrites, baseUrl && [{
|
|
68
74
|
source: _path.default.posix.join(baseUrl, '/:path*'),
|
|
69
75
|
destination: '/:path*'
|
|
70
|
-
}]
|
|
76
|
+
}]); // start the server
|
|
71
77
|
|
|
72
|
-
let server = !
|
|
78
|
+
let server = !dryRun && (await new Promise(resolve => {
|
|
73
79
|
let server = require('http').createServer((req, res) => {
|
|
74
80
|
require('serve-handler')(req, res, {
|
|
75
81
|
public: dir,
|
|
@@ -147,9 +153,15 @@ function mapStaticSnapshots(snapshots, {
|
|
|
147
153
|
exclude,
|
|
148
154
|
cleanUrls,
|
|
149
155
|
rewrites = [],
|
|
150
|
-
overrides = []
|
|
156
|
+
overrides = [],
|
|
157
|
+
server
|
|
151
158
|
} = {}) {
|
|
152
|
-
|
|
159
|
+
var _server$host, _server$rewrites;
|
|
160
|
+
|
|
161
|
+
// prioritize server properties
|
|
162
|
+
host = (_server$host = server === null || server === void 0 ? void 0 : server.host) !== null && _server$host !== void 0 ? _server$host : host;
|
|
163
|
+
rewrites = (_server$rewrites = server === null || server === void 0 ? void 0 : server.rewrites) !== null && _server$rewrites !== void 0 ? _server$rewrites : mapRewrites(rewrites, []); // reduce rewrites into a single function
|
|
164
|
+
|
|
153
165
|
let applyRewrites = [{
|
|
154
166
|
test: url => !/^(https?:\/)?\//.test(url) && url,
|
|
155
167
|
rewrite: url => _path.default.posix.normalize(_path.default.posix.join('/', url))
|
package/oclif.manifest.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"1.0.0-beta.
|
|
1
|
+
{"version":"1.0.0-beta.69","commands":{"snapshot":{"id":"snapshot","description":"Take snapshots from a static directory, snapshots file, or sitemap url","pluginName":"@percy/cli-snapshot","pluginType":"core","aliases":[],"examples":["$ percy snapshot ./public","$ percy snapshot snapshots.yml"],"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},"allowed-hostname":{"name":"allowed-hostname","type":"option","char":"h","description":"allowed hostnames to capture in asset discovery"},"network-idle-timeout":{"name":"network-idle-timeout","type":"option","char":"t","description":"asset discovery network idle timeout"},"disable-cache":{"name":"disable-cache","type":"boolean","description":"disable asset discovery caches","allowNo":false},"dry-run":{"name":"dry-run","type":"boolean","char":"d","description":"print logs only, do not run asset discovery or upload snapshots","allowNo":false},"debug":{"name":"debug","type":"boolean","description":"debug asset discovery and do not upload snapshots","allowNo":false},"config":{"name":"config","type":"option","char":"c","description":"configuration file path"},"base-url":{"name":"base-url","type":"option","char":"b","description":"the base url pages are hosted at when snapshotting"},"include":{"name":"include","type":"option","description":"one or more globs/patterns matching snapshots to include"},"exclude":{"name":"exclude","type":"option","description":"one or more globs/patterns matching snapshots to exclude"},"clean-urls":{"name":"clean-urls","type":"boolean","description":"rewrite static index and filepath URLs to be clean","allowNo":false},"files":{"name":"files","type":"option","hidden":true},"ignore":{"name":"ignore","type":"option","hidden":true}},"args":[{"name":"dir|file|sitemap","description":"static directory, snapshots file, or sitemap url","required":true}]}}}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@percy/cli-snapshot",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.69",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"files": [
|
|
@@ -29,11 +29,11 @@
|
|
|
29
29
|
}
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@percy/cli-command": "1.0.0-beta.
|
|
33
|
-
"@percy/config": "1.0.0-beta.
|
|
34
|
-
"@percy/core": "1.0.0-beta.
|
|
35
|
-
"@percy/dom": "1.0.0-beta.
|
|
36
|
-
"@percy/logger": "1.0.0-beta.
|
|
32
|
+
"@percy/cli-command": "1.0.0-beta.69",
|
|
33
|
+
"@percy/config": "1.0.0-beta.69",
|
|
34
|
+
"@percy/core": "1.0.0-beta.69",
|
|
35
|
+
"@percy/dom": "1.0.0-beta.69",
|
|
36
|
+
"@percy/logger": "1.0.0-beta.69",
|
|
37
37
|
"globby": "^11.0.4",
|
|
38
38
|
"path-to-regexp": "^6.2.0",
|
|
39
39
|
"picomatch": "^2.3.0",
|
|
@@ -45,5 +45,5 @@
|
|
|
45
45
|
"url": "https://github.com/percy/cli",
|
|
46
46
|
"directory": "packages/cli-snapshot"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "99b0617016a07c9d7d4ca37c1442011c904cf860"
|
|
49
49
|
}
|