@percy/cli-snapshot 1.0.0-beta.9 → 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/README.md +243 -111
- package/package.json +27 -33
- package/dist/commands/snapshot.js +0 -194
- package/dist/config.js +0 -41
- package/dist/hooks/init.js +0 -16
- package/dist/index.js +0 -8
- package/oclif.manifest.json +0 -1
package/README.md
CHANGED
|
@@ -4,160 +4,145 @@ Snapshot a list or static directory of web pages.
|
|
|
4
4
|
|
|
5
5
|
## Commands
|
|
6
6
|
<!-- commands -->
|
|
7
|
-
* [`percy snapshot
|
|
7
|
+
* [`percy snapshot`](#percy-snapshot)
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
### `percy snapshot`
|
|
10
10
|
|
|
11
|
-
Snapshot a
|
|
11
|
+
Snapshot a static directory, snapshots file, or sitemap URL
|
|
12
12
|
|
|
13
13
|
```
|
|
14
|
-
|
|
15
|
-
$ percy snapshot
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
-b, --base-url
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
-
|
|
31
|
-
|
|
32
|
-
-
|
|
33
|
-
|
|
34
|
-
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
--silent
|
|
41
|
-
|
|
42
|
-
|
|
14
|
+
Usage:
|
|
15
|
+
$ percy snapshot [options] <dir|file|sitemap>
|
|
16
|
+
|
|
17
|
+
Arguments:
|
|
18
|
+
dir|file|sitemap Static directory, snapshots file, or sitemap url
|
|
19
|
+
|
|
20
|
+
Options:
|
|
21
|
+
-b, --base-url <string> The base url pages are hosted at when snapshotting
|
|
22
|
+
--include <pattern> One or more globs/patterns matching snapshots to include
|
|
23
|
+
--exclude <pattern> One or more globs/patterns matching snapshots to exclude
|
|
24
|
+
|
|
25
|
+
Static options:
|
|
26
|
+
--clean-urls Rewrite static index and filepath URLs to be clean
|
|
27
|
+
|
|
28
|
+
Percy options:
|
|
29
|
+
-c, --config <file> Config file path
|
|
30
|
+
-d, --dry-run Print snapshot names only
|
|
31
|
+
-h, --allowed-hostname <hostname> Allowed hostnames to capture in asset discovery
|
|
32
|
+
--disallowed-hostname <hostname> Disallowed hostnames to abort in asset discovery
|
|
33
|
+
-t, --network-idle-timeout <ms> Asset discovery network idle timeout
|
|
34
|
+
--disable-cache Disable asset discovery caches
|
|
35
|
+
--debug Debug asset discovery and do not upload snapshots
|
|
36
|
+
|
|
37
|
+
Global options:
|
|
38
|
+
-v, --verbose Log everything
|
|
39
|
+
-q, --quiet Log errors only
|
|
40
|
+
-s, --silent Log nothing
|
|
41
|
+
--help Display command help
|
|
42
|
+
|
|
43
|
+
Examples:
|
|
43
44
|
$ percy snapshot ./public
|
|
44
|
-
$ percy snapshot
|
|
45
|
+
$ percy snapshot snapshots.yml
|
|
46
|
+
$ percy snapshot https://percy.io/sitemap.xml
|
|
45
47
|
```
|
|
46
48
|
<!-- commandsstop -->
|
|
47
49
|
|
|
48
50
|
## Usage
|
|
49
51
|
|
|
50
|
-
###
|
|
51
|
-
|
|
52
|
-
When snapshotting a static directory, the directory will be served locally and each matching page
|
|
53
|
-
will be navigated to and snapshotted.
|
|
54
|
-
|
|
55
|
-
```sh-session
|
|
56
|
-
$ percy snapshot ./public
|
|
57
|
-
[percy] Percy has started!
|
|
58
|
-
[percy] Created build #1: https://percy.io/org/project/123
|
|
59
|
-
[percy] Snapshot taken: /index.html
|
|
60
|
-
[percy] Snapshot taken: /about.html
|
|
61
|
-
[percy] Snapshot taken: /contact.html
|
|
62
|
-
[percy] Stopping percy...
|
|
63
|
-
[percy] Finalized build #1: https://percy.io/org/project/123
|
|
64
|
-
[percy] Done!
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
### Page Listing
|
|
68
|
-
|
|
69
|
-
When snapshotting a file containing a list of pages to snapshot, the page URLs must all be
|
|
70
|
-
accessible by a browser. The file must be YAML, JSON, or a JS file exporting a list of pages. Each
|
|
71
|
-
page must contain a snapshot `name` and `url`, with an optional `waitFor` option to wait for a selector
|
|
72
|
-
or timeout before snapshotting the page.
|
|
52
|
+
### Snapshot Lists
|
|
73
53
|
|
|
74
|
-
|
|
54
|
+
When providing a file containing a list of snapshots, the file must be YAML, JSON, or a JS file
|
|
55
|
+
exporting a list of pages. Each snapshot must contain at least a `url` that can be navigated to
|
|
56
|
+
using a browser.
|
|
75
57
|
|
|
76
|
-
`
|
|
58
|
+
`snapshots.yml`:
|
|
77
59
|
|
|
78
60
|
```yaml
|
|
79
|
-
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
- name: Snapshot two
|
|
83
|
-
url: http://localhost:8080/two
|
|
84
|
-
# wait for an element or timeout before snapshotting
|
|
85
|
-
waitFor: .some-element
|
|
61
|
+
- http://localhost:8080
|
|
62
|
+
- http://localhost:8080/two
|
|
86
63
|
```
|
|
87
64
|
|
|
88
|
-
Snapshotting `
|
|
65
|
+
Snapshotting `snapshots.yml`:
|
|
89
66
|
|
|
90
67
|
```sh-session
|
|
91
|
-
$ percy snapshot
|
|
68
|
+
$ percy snapshot snapshots.yml
|
|
92
69
|
[percy] Percy has started!
|
|
93
|
-
[percy]
|
|
94
|
-
[percy] Snapshot taken:
|
|
95
|
-
[percy] Snapshot taken: Snapshot two
|
|
96
|
-
[percy] Stopping percy...
|
|
70
|
+
[percy] Snapshot taken: /
|
|
71
|
+
[percy] Snapshot taken: /two
|
|
97
72
|
[percy] Finalized build #1: https://percy.io/org/project/123
|
|
98
|
-
[percy] Done!
|
|
99
73
|
```
|
|
100
74
|
|
|
101
|
-
####
|
|
75
|
+
#### Snapshot Options
|
|
76
|
+
|
|
77
|
+
A `name` can be provided which will override the default snapshot name generated from the url
|
|
78
|
+
path. The options `waitForTimeout` and `waitForSelector` can also be provided to wait for a timeout
|
|
79
|
+
or selector respectively before taking the snapshot.
|
|
102
80
|
|
|
103
|
-
`
|
|
81
|
+
`snapshots.json`:
|
|
104
82
|
|
|
105
83
|
```json
|
|
106
84
|
[{
|
|
107
85
|
"name": "Snapshot one",
|
|
108
|
-
"url": "http://localhost:8080"
|
|
86
|
+
"url": "http://localhost:8080",
|
|
87
|
+
"waitForTimeout": 1000
|
|
109
88
|
}, {
|
|
110
89
|
"name": "Snapshot two",
|
|
111
90
|
"url": "http://localhost:8080/two",
|
|
112
|
-
"
|
|
91
|
+
"waitForSelector": ".some-element"
|
|
113
92
|
}]
|
|
114
93
|
```
|
|
115
94
|
|
|
116
|
-
Snapshotting `
|
|
95
|
+
Snapshotting `snapshots.json`:
|
|
117
96
|
|
|
118
97
|
```sh-session
|
|
119
|
-
$ percy snapshot
|
|
98
|
+
$ percy snapshot snapshots.json
|
|
120
99
|
[percy] Percy has started!
|
|
121
|
-
[percy] Created build #1: https://percy.io/org/project/123
|
|
122
100
|
[percy] Snapshot taken: Snapshot one
|
|
123
101
|
[percy] Snapshot taken: Snapshot two
|
|
124
|
-
[percy] Stopping percy...
|
|
125
102
|
[percy] Finalized build #1: https://percy.io/org/project/123
|
|
126
|
-
[percy] Done!
|
|
127
103
|
```
|
|
128
104
|
|
|
129
|
-
|
|
105
|
+
For more advanced use cases, an `execute` function and `additionalSnapshots` may be specified for
|
|
106
|
+
each snapshot to execute JavaScript within the page execution context before subsequent snapshots
|
|
107
|
+
are taken.
|
|
130
108
|
|
|
131
|
-
|
|
132
|
-
|
|
109
|
+
> Note: All options are also accepted by other file formats. For `execute` however, a string
|
|
110
|
+
> containing a function body can be provided when the file format prevents normal functions.
|
|
133
111
|
|
|
134
|
-
`
|
|
112
|
+
`snapshots.js`:
|
|
135
113
|
|
|
136
114
|
```js
|
|
137
115
|
module.exports = [{
|
|
138
|
-
name: '
|
|
139
|
-
url: 'http://localhost:8080',
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
async execute(page) {
|
|
150
|
-
await page.click('.button')
|
|
116
|
+
name: 'My form',
|
|
117
|
+
url: 'http://localhost:8080/form',
|
|
118
|
+
waitForSelector: '.form-loaded',
|
|
119
|
+
execute() {
|
|
120
|
+
document.querySelector('.name').value = 'Name Namerson';
|
|
121
|
+
document.querySelector('.email').value = 'email@domain.com';
|
|
122
|
+
},
|
|
123
|
+
additionalSnapshots: [{
|
|
124
|
+
suffix: ' - submitting',
|
|
125
|
+
execute() {
|
|
126
|
+
document.querySelector('.submit').click();
|
|
151
127
|
}
|
|
152
128
|
}, {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
await page.click('.button', { clickCount: 2 })
|
|
156
|
-
}
|
|
129
|
+
suffix: ' - after submit',
|
|
130
|
+
waitForSelector: '.form-submitted'
|
|
157
131
|
}]
|
|
158
132
|
}]
|
|
159
133
|
```
|
|
160
134
|
|
|
135
|
+
Snapshotting `snapshots.js`:
|
|
136
|
+
|
|
137
|
+
```sh-session
|
|
138
|
+
$ percy snapshot snapshots.js
|
|
139
|
+
[percy] Percy has started!
|
|
140
|
+
[percy] Snapshot taken: My form
|
|
141
|
+
[percy] Snapshot taken: My form - submitting
|
|
142
|
+
[percy] Snapshot taken: My form - after submit
|
|
143
|
+
[percy] Finalized build #1: https://percy.io/org/project/123
|
|
144
|
+
```
|
|
145
|
+
|
|
161
146
|
JavaScript files may also export sync or async functions that return a list of pages to snapshot.
|
|
162
147
|
|
|
163
148
|
``` js
|
|
@@ -167,17 +152,164 @@ module.exports = async () => {
|
|
|
167
152
|
}
|
|
168
153
|
```
|
|
169
154
|
|
|
170
|
-
|
|
155
|
+
#### Advanced List Options
|
|
156
|
+
|
|
157
|
+
Instead of an array of snapshots, list files can also contain an object that defines additional
|
|
158
|
+
top-level options along with a `snapshots` option containing the array of snapshots. This allows
|
|
159
|
+
dynamically filtering lists with `include`/`exclude` options, and enables utilizing features such as
|
|
160
|
+
YAML anchors and references.
|
|
161
|
+
|
|
162
|
+
<details>
|
|
163
|
+
<summary>Example <code>snapshots.yml</code></summary><br>
|
|
164
|
+
|
|
165
|
+
``` yaml
|
|
166
|
+
base-url: https://example.com
|
|
167
|
+
exclude:
|
|
168
|
+
- /page/(\d+)
|
|
169
|
+
|
|
170
|
+
references:
|
|
171
|
+
dismiss-cookie-banner: &dismiss-cookie-banner |
|
|
172
|
+
document.querySelector('.cookie-banner .dismiss').click();
|
|
173
|
+
|
|
174
|
+
snapshots:
|
|
175
|
+
- url: /foo
|
|
176
|
+
execute: *dismiss-cookie-banner
|
|
177
|
+
- url: /foo
|
|
178
|
+
name: "/foo - with cookie banner"
|
|
179
|
+
- url: /bar
|
|
180
|
+
execute: *dismiss-cookie-banner
|
|
181
|
+
```
|
|
182
|
+
</details>
|
|
183
|
+
|
|
184
|
+
### Static Directory
|
|
185
|
+
|
|
186
|
+
When providing a static directory, it will be served locally and pages matching the `files` argument
|
|
187
|
+
(and excluding the `ignore` argument) will be navigated to and snapshotted.
|
|
171
188
|
|
|
172
189
|
```sh-session
|
|
173
|
-
$ percy snapshot
|
|
190
|
+
$ percy snapshot ./public
|
|
174
191
|
[percy] Percy has started!
|
|
175
|
-
[percy]
|
|
176
|
-
[percy] Snapshot taken:
|
|
177
|
-
[percy] Snapshot taken:
|
|
178
|
-
[percy] Snapshot taken: Snapshot two - after click
|
|
179
|
-
[percy] Snapshot taken: Snapshot two - after double click
|
|
180
|
-
[percy] Stopping percy...
|
|
192
|
+
[percy] Snapshot taken: /index.html
|
|
193
|
+
[percy] Snapshot taken: /about.html
|
|
194
|
+
[percy] Snapshot taken: /contact.html
|
|
181
195
|
[percy] Finalized build #1: https://percy.io/org/project/123
|
|
182
|
-
[percy] Done!
|
|
183
196
|
```
|
|
197
|
+
|
|
198
|
+
#### Static Options
|
|
199
|
+
|
|
200
|
+
For snapshotting static directories, the following Percy config file options are also accepted:
|
|
201
|
+
|
|
202
|
+
``` yaml
|
|
203
|
+
# .percy.yml
|
|
204
|
+
version: 2
|
|
205
|
+
static:
|
|
206
|
+
base-url: /
|
|
207
|
+
clean-urls: false
|
|
208
|
+
include: **/*.html
|
|
209
|
+
exclude: []
|
|
210
|
+
rewrites: {}
|
|
211
|
+
overrides: []
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
- **base-url** - The base URL path the static site should be served under.
|
|
215
|
+
- **clean-urls** - When true, rewrite index and filepath URLs to be clean.
|
|
216
|
+
|
|
217
|
+
<span/>
|
|
218
|
+
|
|
219
|
+
- **include/exclude** - A predicate or an array of predicates matching snapshots to include/exclude.
|
|
220
|
+
|
|
221
|
+
A predicate can be a string glob or pattern, a regular expression, or a function that accepts a
|
|
222
|
+
snapshot object and returns `true` or `false` if the snapshot is considered matching or not.
|
|
223
|
+
|
|
224
|
+
``` javascript
|
|
225
|
+
// .percy.js
|
|
226
|
+
module.exports = {
|
|
227
|
+
version: 2,
|
|
228
|
+
static: {
|
|
229
|
+
include: [
|
|
230
|
+
'blog/**/*.html', // glob
|
|
231
|
+
'pages/page-(?!10).html$', // pattern
|
|
232
|
+
/about-(.+)\.html/i // regexp
|
|
233
|
+
],
|
|
234
|
+
exclude: [
|
|
235
|
+
// function that returns true when matching
|
|
236
|
+
({ name }) => DISALLOWED.includes(name)
|
|
237
|
+
]
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
- **rewrites** - An object containing source-destination pairs for rewriting URLs.
|
|
243
|
+
|
|
244
|
+
Paths for resources can sometimes be expected to be in a certain format that may not be covered by
|
|
245
|
+
the `clean-urls` option. For such paths, rewrites can map a short, clean, or pretty path to a
|
|
246
|
+
specific resource. Paths are matched using [path-to-regexp](https://github.com/pillarjs/path-to-regexp).
|
|
247
|
+
|
|
248
|
+
``` yaml
|
|
249
|
+
# .percy.yml
|
|
250
|
+
version: 2
|
|
251
|
+
static:
|
|
252
|
+
base-url: /blog
|
|
253
|
+
rewrites:
|
|
254
|
+
/:year/:month/:title: /posts/:year-:month--:title.html
|
|
255
|
+
/:year/:month: /posts/index-:year-:month.html
|
|
256
|
+
/:year: /posts/index-:year.html
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
- **overrides** - An array of per-snapshot option overrides.
|
|
260
|
+
|
|
261
|
+
Just like [page listing options](#page-options), static snapshots may also contain
|
|
262
|
+
per-snapshot configuration options. However, since pages are matched against the `files`
|
|
263
|
+
option, so are per-snapshot configuration options via an array of `overrides`. If multiple
|
|
264
|
+
overrides match a snapshot, they will be merged with previously matched overrides.
|
|
265
|
+
|
|
266
|
+
``` yaml
|
|
267
|
+
# .percy.yml
|
|
268
|
+
version: 2
|
|
269
|
+
static:
|
|
270
|
+
overrides:
|
|
271
|
+
- files: /foo-bar.html
|
|
272
|
+
waitForSelector: .is-ready
|
|
273
|
+
execute: |
|
|
274
|
+
document.querySelector('.button').click()
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
### Sitemap URL
|
|
278
|
+
|
|
279
|
+
When providing a sitemap URL, the document must be an XML document. For sitemap URLs the `--include` and
|
|
280
|
+
`--exclude` flags can be used to filter snapshots. With a Percy config file, the `overrides` option
|
|
281
|
+
is also accepted.
|
|
282
|
+
|
|
283
|
+
> Tip: Sitemaps can contain **a lot** of URLs, so its best to always start with the `--dry-run` flag
|
|
284
|
+
> while fine tuning the `include` and `exclude` options.
|
|
285
|
+
|
|
286
|
+
``` sh-session
|
|
287
|
+
$ percy snapshot https://percy.io/sitemap.xml --dry-run
|
|
288
|
+
[percy] Found 10 snapshots
|
|
289
|
+
[percy] Snapshot found: /
|
|
290
|
+
[percy] Snapshot found: /changelog
|
|
291
|
+
[percy] Snapshot found: /customers
|
|
292
|
+
[percy] Snapshot found: /enterprise
|
|
293
|
+
[percy] Snapshot found: /features
|
|
294
|
+
[percy] Snapshot found: /how-it-works
|
|
295
|
+
[percy] Snapshot found: /integrations
|
|
296
|
+
[percy] Snapshot found: /pricing
|
|
297
|
+
[percy] Snapshot found: /security
|
|
298
|
+
[percy] Snapshot found: /visual-testing
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
#### Sitemap Options
|
|
302
|
+
|
|
303
|
+
For snapshotting sitemaps, the following Percy config file options are accepted:
|
|
304
|
+
|
|
305
|
+
``` yaml
|
|
306
|
+
# .percy.yml
|
|
307
|
+
version: 2
|
|
308
|
+
static:
|
|
309
|
+
include: **/*.html
|
|
310
|
+
exclude: []
|
|
311
|
+
overrides: []
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
See [the corresponding static options](#static-options) for details on `includes`, `excludes`, and
|
|
315
|
+
`overrides` options.
|
package/package.json
CHANGED
|
@@ -1,45 +1,39 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@percy/cli-snapshot",
|
|
3
|
-
"version": "1.0.0
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"
|
|
6
|
-
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
],
|
|
10
|
-
"scripts": {
|
|
11
|
-
"build": "babel --root-mode upward src --out-dir dist",
|
|
12
|
-
"lint": "eslint --ignore-path ../../.gitignore .",
|
|
13
|
-
"postbuild": "oclif-dev manifest",
|
|
14
|
-
"readme": "oclif-dev readme",
|
|
15
|
-
"pretest": "node ../../scripts/install-browser",
|
|
16
|
-
"test": "cross-env NODE_ENV=test mocha",
|
|
17
|
-
"test:coverage": "nyc yarn test"
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/percy/cli",
|
|
8
|
+
"directory": "packages/cli-snapshot"
|
|
18
9
|
},
|
|
19
10
|
"publishConfig": {
|
|
20
11
|
"access": "public"
|
|
21
12
|
},
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
|
|
13
|
+
"engines": {
|
|
14
|
+
"node": ">=14"
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"./dist"
|
|
18
|
+
],
|
|
19
|
+
"main": "./dist/index.js",
|
|
20
|
+
"type": "module",
|
|
21
|
+
"exports": "./dist/index.js",
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "node ../../scripts/build",
|
|
24
|
+
"lint": "eslint --ignore-path ../../.gitignore .",
|
|
25
|
+
"readme": "percy-cli-readme",
|
|
26
|
+
"test": "node ../../scripts/test",
|
|
27
|
+
"test:coverage": "yarn test --coverage"
|
|
25
28
|
},
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
"init": "./dist/hooks/init"
|
|
31
|
-
}
|
|
29
|
+
"@percy/cli": {
|
|
30
|
+
"commands": [
|
|
31
|
+
"./dist/snapshot.js"
|
|
32
|
+
]
|
|
32
33
|
},
|
|
33
34
|
"dependencies": {
|
|
34
|
-
"@percy/cli-command": "
|
|
35
|
-
"
|
|
36
|
-
"@percy/core": "^1.0.0-beta.9",
|
|
37
|
-
"@percy/dom": "^1.0.0-beta.9",
|
|
38
|
-
"@percy/logger": "^1.0.0-beta.9",
|
|
39
|
-
"cors": "^2.8.5",
|
|
40
|
-
"express": "^4.17.1",
|
|
41
|
-
"globby": "^11.0.0",
|
|
42
|
-
"yaml": "^1.8.0"
|
|
35
|
+
"@percy/cli-command": "1.0.0",
|
|
36
|
+
"yaml": "^1.10.0"
|
|
43
37
|
},
|
|
44
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "6df509421a60144e4f9f5d59dc57a5675372a0b2"
|
|
45
39
|
}
|
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.Snapshot = 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 _core = _interopRequireDefault(require("@percy/core"));
|
|
15
|
-
|
|
16
|
-
var _logger = _interopRequireDefault(require("@percy/logger"));
|
|
17
|
-
|
|
18
|
-
var _globby = _interopRequireDefault(require("globby"));
|
|
19
|
-
|
|
20
|
-
var _yaml = _interopRequireDefault(require("yaml"));
|
|
21
|
-
|
|
22
|
-
var _config = require("../config");
|
|
23
|
-
|
|
24
|
-
var _package = _interopRequireDefault(require("../../package.json"));
|
|
25
|
-
|
|
26
|
-
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
|
27
|
-
|
|
28
|
-
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; }
|
|
29
|
-
|
|
30
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
31
|
-
|
|
32
|
-
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; }
|
|
33
|
-
|
|
34
|
-
class Snapshot extends _cliCommand.default {
|
|
35
|
-
async run() {
|
|
36
|
-
if (!this.isPercyEnabled()) {
|
|
37
|
-
_logger.default.info('Percy is disabled. Skipping snapshots');
|
|
38
|
-
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
let config = this.percyrc();
|
|
43
|
-
let {
|
|
44
|
-
pathname
|
|
45
|
-
} = this.args;
|
|
46
|
-
|
|
47
|
-
if (!_fs.default.existsSync(pathname)) {
|
|
48
|
-
return this.error(`Not found: ${pathname}`);
|
|
49
|
-
} else if (config.static.baseUrl[0] !== '/') {
|
|
50
|
-
return this.error('The base-url flag must begin with a forward slash (/)');
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
let pages = _fs.default.lstatSync(pathname).isDirectory() ? await this.loadStaticPages(pathname, config.static) : await this.loadPagesFile(pathname);
|
|
54
|
-
|
|
55
|
-
if (!pages.length) {
|
|
56
|
-
return this.error('No snapshots found');
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (this.flags['dry-run']) {
|
|
60
|
-
let l = pages.length;
|
|
61
|
-
|
|
62
|
-
_logger.default.info(`Found ${l} snapshot${l === 1 ? '' : 's'}:`);
|
|
63
|
-
|
|
64
|
-
return pages.forEach(({
|
|
65
|
-
name,
|
|
66
|
-
snapshots = []
|
|
67
|
-
}) => {
|
|
68
|
-
(name ? [{
|
|
69
|
-
name
|
|
70
|
-
}].concat(snapshots) : snapshots).forEach(({
|
|
71
|
-
name
|
|
72
|
-
}) => console.log(name));
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
this.percy = await _core.default.start({
|
|
77
|
-
clientInfo: `${_package.default.name}/${_package.default.version}`,
|
|
78
|
-
server: false,
|
|
79
|
-
config: false,
|
|
80
|
-
...config
|
|
81
|
-
});
|
|
82
|
-
await Promise.all(pages.map(page => this.percy.capture(page)));
|
|
83
|
-
} // Called on error, interupt, or after running
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
async finally() {
|
|
87
|
-
var _this$percy, _this$server;
|
|
88
|
-
|
|
89
|
-
await ((_this$percy = this.percy) === null || _this$percy === void 0 ? void 0 : _this$percy.stop());
|
|
90
|
-
(_this$server = this.server) === null || _this$server === void 0 ? void 0 : _this$server.close();
|
|
91
|
-
} // Serves a static directory at a base-url and resolves when listening.
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
async serve(staticDir, baseUrl) {
|
|
95
|
-
let express = require('express');
|
|
96
|
-
|
|
97
|
-
let app = express();
|
|
98
|
-
app.use(require('cors')());
|
|
99
|
-
app.use(baseUrl, express.static(staticDir));
|
|
100
|
-
return new Promise(resolve => {
|
|
101
|
-
this.server = app.listen(() => {
|
|
102
|
-
let {
|
|
103
|
-
port
|
|
104
|
-
} = this.server.address();
|
|
105
|
-
resolve(`http://localhost:${port}`);
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
} // Starts a static server and returns a list of pages to snapshot.
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
async loadStaticPages(pathname, {
|
|
112
|
-
baseUrl,
|
|
113
|
-
files,
|
|
114
|
-
ignore
|
|
115
|
-
}) {
|
|
116
|
-
ignore = [].concat(ignore).filter(Boolean);
|
|
117
|
-
let paths = await (0, _globby.default)(files, {
|
|
118
|
-
cwd: pathname,
|
|
119
|
-
ignore
|
|
120
|
-
});
|
|
121
|
-
let addr = '';
|
|
122
|
-
|
|
123
|
-
if (!this.flags['dry-run']) {
|
|
124
|
-
addr = await this.serve(pathname, baseUrl);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
return paths.sort().map(path => ({
|
|
128
|
-
url: `${addr}${baseUrl}${path}`,
|
|
129
|
-
name: `${baseUrl}${path}`
|
|
130
|
-
}));
|
|
131
|
-
} // Loads pages to snapshot from a js, json, or yaml file.
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
async loadPagesFile(pathname) {
|
|
135
|
-
let ext = _path.default.extname(pathname);
|
|
136
|
-
|
|
137
|
-
if (ext === '.js') {
|
|
138
|
-
let pages = require(_path.default.resolve(pathname));
|
|
139
|
-
|
|
140
|
-
return typeof pages === 'function' ? await pages() : pages;
|
|
141
|
-
} else if (ext === '.json') {
|
|
142
|
-
return JSON.parse(_fs.default.readFileSync(pathname, {
|
|
143
|
-
encoding: 'utf-8'
|
|
144
|
-
}));
|
|
145
|
-
} else if (ext.match(/\.ya?ml$/)) {
|
|
146
|
-
return _yaml.default.parse(_fs.default.readFileSync(pathname, {
|
|
147
|
-
encoding: 'utf-8'
|
|
148
|
-
}));
|
|
149
|
-
} else {
|
|
150
|
-
return this.error(`Unsupported filetype: ${pathname}`);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
exports.Snapshot = Snapshot;
|
|
157
|
-
|
|
158
|
-
_defineProperty(Snapshot, "description", 'Snapshot a list of pages from a file or directory');
|
|
159
|
-
|
|
160
|
-
_defineProperty(Snapshot, "args", [{
|
|
161
|
-
name: 'pathname',
|
|
162
|
-
description: 'path to a directory or file containing a list of pages',
|
|
163
|
-
required: true
|
|
164
|
-
}]);
|
|
165
|
-
|
|
166
|
-
_defineProperty(Snapshot, "flags", { ..._cliCommand.flags.logging,
|
|
167
|
-
..._cliCommand.flags.discovery,
|
|
168
|
-
..._cliCommand.flags.config,
|
|
169
|
-
'base-url': _cliCommand.flags.string({
|
|
170
|
-
char: 'b',
|
|
171
|
-
description: 'the url path to serve the static directory from',
|
|
172
|
-
default: _config.schema.static.properties.baseUrl.default,
|
|
173
|
-
percyrc: 'static.baseUrl'
|
|
174
|
-
}),
|
|
175
|
-
files: _cliCommand.flags.string({
|
|
176
|
-
char: 'f',
|
|
177
|
-
multiple: true,
|
|
178
|
-
description: 'one or more globs matching static file paths to snapshot',
|
|
179
|
-
default: _config.schema.static.properties.files.default,
|
|
180
|
-
percyrc: 'static.files'
|
|
181
|
-
}),
|
|
182
|
-
ignore: _cliCommand.flags.string({
|
|
183
|
-
char: 'i',
|
|
184
|
-
multiple: true,
|
|
185
|
-
description: 'one or more globs matching static file paths to ignore',
|
|
186
|
-
percyrc: 'static.ignore'
|
|
187
|
-
}),
|
|
188
|
-
'dry-run': _cliCommand.flags.boolean({
|
|
189
|
-
char: 'd',
|
|
190
|
-
description: 'prints a list of pages to snapshot without snapshotting'
|
|
191
|
-
})
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
_defineProperty(Snapshot, "examples", ['$ percy snapshot ./public', '$ percy snapshot pages.yml']);
|
package/dist/config.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.schema = void 0;
|
|
7
|
-
const schema = {
|
|
8
|
-
static: {
|
|
9
|
-
type: 'object',
|
|
10
|
-
additionalProperties: false,
|
|
11
|
-
properties: {
|
|
12
|
-
baseUrl: {
|
|
13
|
-
type: 'string',
|
|
14
|
-
default: '/'
|
|
15
|
-
},
|
|
16
|
-
files: {
|
|
17
|
-
anyOf: [{
|
|
18
|
-
type: 'string'
|
|
19
|
-
}, {
|
|
20
|
-
type: 'array',
|
|
21
|
-
items: {
|
|
22
|
-
type: 'string'
|
|
23
|
-
}
|
|
24
|
-
}],
|
|
25
|
-
default: '**/*.{html,htm}'
|
|
26
|
-
},
|
|
27
|
-
ignore: {
|
|
28
|
-
anyOf: [{
|
|
29
|
-
type: 'string'
|
|
30
|
-
}, {
|
|
31
|
-
type: 'array',
|
|
32
|
-
items: {
|
|
33
|
-
type: 'string'
|
|
34
|
-
}
|
|
35
|
-
}],
|
|
36
|
-
default: ''
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
exports.schema = schema;
|
package/dist/hooks/init.js
DELETED
|
@@ -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
|
-
}
|
package/dist/index.js
DELETED
package/oclif.manifest.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":"1.0.0-beta.9","commands":{"snapshot":{"id":"snapshot","description":"Snapshot a list of pages from a file or directory","pluginName":"@percy/cli-snapshot","pluginType":"core","aliases":[],"examples":["$ percy snapshot ./public","$ percy snapshot pages.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"},"network-idle-timeout":{"name":"network-idle-timeout","type":"option","char":"t","description":"asset discovery idle timeout"},"disable-asset-cache":{"name":"disable-asset-cache","type":"boolean","description":"disable asset discovery caches","allowNo":false},"config":{"name":"config","type":"option","char":"c","description":"configuration file path"},"base-url":{"name":"base-url","type":"option","char":"b","description":"the url path to serve the static directory from","default":"/"},"files":{"name":"files","type":"option","char":"f","description":"one or more globs matching static file paths to snapshot","default":"**/*.{html,htm}"},"ignore":{"name":"ignore","type":"option","char":"i","description":"one or more globs matching static file paths to ignore"},"dry-run":{"name":"dry-run","type":"boolean","char":"d","description":"prints a list of pages to snapshot without snapshotting","allowNo":false}},"args":[{"name":"pathname","description":"path to a directory or file containing a list of pages","required":true}]}}}
|