Skip to content

Commit 9cdb399

Browse files
committed
Add support for WebP image type
1 parent 1773572 commit 9cdb399

File tree

4 files changed

+50
-48
lines changed

4 files changed

+50
-48
lines changed

cli.js

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env node
2+
import process from 'node:process';
23
import meow from 'meow';
34
import captureWebsite from 'capture-website';
45
import arrify from 'arrify';
@@ -14,8 +15,8 @@ const cli = meow(`
1415
--output Image file path (writes it to stdout if omitted)
1516
--width Page width [default: 1280]
1617
--height Page height [default: 800]
17-
--type Image type: png|jpeg [default: png]
18-
--quality Image quality: 0...1 (Only for JPEG) [default: 1]
18+
--type Image type: png|jpeg|webp [default: png]
19+
--quality Image quality: 0...1 (Only for JPEG and WebP) [default: 1]
1920
--scale-factor Scale the webpage \`n\` times [default: 2]
2021
--list-devices Output a list of supported devices to emulate
2122
--emulate-device Capture as if it were captured on the given device
@@ -83,109 +84,109 @@ const cli = meow(`
8384
importMeta: import.meta,
8485
flags: {
8586
output: {
86-
type: 'string'
87+
type: 'string',
8788
},
8889
width: {
89-
type: 'number'
90+
type: 'number',
9091
},
9192
height: {
92-
type: 'number'
93+
type: 'number',
9394
},
9495
type: {
95-
type: 'string'
96+
type: 'string',
9697
},
9798
quality: {
98-
type: 'number'
99+
type: 'number',
99100
},
100101
scaleFactor: {
101-
type: 'number'
102+
type: 'number',
102103
},
103104
listDevices: {
104-
type: 'boolean'
105+
type: 'boolean',
105106
},
106107
emulateDevice: {
107-
type: 'string'
108+
type: 'string',
108109
},
109110
fullPage: {
110-
type: 'boolean'
111+
type: 'boolean',
111112
},
112113
defaultBackground: {
113-
type: 'boolean'
114+
type: 'boolean',
114115
},
115116
timeout: {
116-
type: 'number'
117+
type: 'number',
117118
},
118119
delay: {
119-
type: 'number'
120+
type: 'number',
120121
},
121122
waitForElement: {
122-
type: 'string'
123+
type: 'string',
123124
},
124125
element: {
125-
type: 'string'
126+
type: 'string',
126127
},
127128
hideElements: {
128129
type: 'string',
129-
isMultiple: true
130+
isMultiple: true,
130131
},
131132
removeElements: {
132133
type: 'string',
133-
isMultiple: true
134+
isMultiple: true,
134135
},
135136
clickElement: {
136-
type: 'string'
137+
type: 'string',
137138
},
138139
scrollToElement: {
139-
type: 'string'
140+
type: 'string',
140141
},
141142
disableAnimations: {
142-
type: 'boolean'
143+
type: 'boolean',
143144
},
144145
javascript: {
145146
type: 'boolean',
146-
default: true
147+
default: true,
147148
},
148149
module: {
149150
type: 'string',
150-
isMultiple: true
151+
isMultiple: true,
151152
},
152153
script: {
153154
type: 'string',
154-
isMultiple: true
155+
isMultiple: true,
155156
},
156157
style: {
157158
type: 'string',
158-
isMultiple: true
159+
isMultiple: true,
159160
},
160161
header: {
161-
type: 'string'
162+
type: 'string',
162163
},
163164
userAgent: {
164-
type: 'string'
165+
type: 'string',
165166
},
166167
cookie: {
167168
type: 'string',
168-
isMultiple: true
169+
isMultiple: true,
169170
},
170171
authentication: {
171-
type: 'string'
172+
type: 'string',
172173
},
173174
debug: {
174-
type: 'boolean'
175+
type: 'boolean',
175176
},
176177
darkMode: {
177-
type: 'boolean'
178+
type: 'boolean',
178179
},
179180
launchOptions: {
180-
type: 'string'
181+
type: 'string',
181182
},
182183
overwrite: {
183-
type: 'boolean'
184+
type: 'boolean',
184185
},
185186
inset: {
186-
type: 'string'
187-
}
188-
}
187+
type: 'string',
188+
},
189+
},
189190
});
190191

191192
let [input] = cli.input;
@@ -244,7 +245,7 @@ options.isJavaScriptEnabled = options.javascript;
244245
const {
245246
internalPrintFlags,
246247
listDevices,
247-
output
248+
output,
248249
} = options;
249250

250251
if (internalPrintFlags) {

package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,17 @@
4242
],
4343
"dependencies": {
4444
"arrify": "^3.0.0",
45-
"capture-website": "^2.0.0",
45+
"capture-website": "^2.1.0",
4646
"get-stdin": "^9.0.0",
47-
"meow": "^10.0.0",
47+
"meow": "^10.1.1",
4848
"split-on-first": "^3.0.0"
4949
},
5050
"devDependencies": {
5151
"ava": "^3.15.0",
5252
"create-test-server": "^3.0.1",
53-
"execa": "^5.0.0",
54-
"file-type": "^12.4.0",
55-
"xo": "^0.39.1"
53+
"execa": "^5.1.1",
54+
"file-type": "^16.5.3",
55+
"typescript": "^4.4.3",
56+
"xo": "^0.45.0"
5657
}
5758
}

readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ $ capture-website --help
2525
--output Image file path (writes it to stdout if omitted)
2626
--width Page width [default: 1280]
2727
--height Page height [default: 800]
28-
--type Image type: png|jpeg [default: png]
29-
--quality Image quality: 0...1 (Only for JPEG) [default: 1]
28+
--type Image type: png|jpeg|webp [default: png]
29+
--quality Image quality: 0...1 (Only for JPEG and WebP) [default: 1]
3030
--scale-factor Scale the webpage `n` times [default: 2]
3131
--list-devices Output a list of supported devices to emulate
3232
--emulate-device Capture as if it were captured on the given device

test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import test from 'ava';
22
import execa from 'execa';
33
import createTestServer from 'create-test-server';
4-
import fileType from 'file-type';
4+
import FileType from 'file-type';
55

66
test('main', async t => {
77
const server = await createTestServer();
@@ -12,17 +12,17 @@ test('main', async t => {
1212

1313
const {stdout} = await execa('./cli.js', [server.url], {encoding: 'buffer'});
1414

15-
t.is(fileType(stdout).mime, 'image/png');
15+
t.is((await FileType.fromBuffer(stdout)).mime, 'image/png');
1616

1717
await server.close();
1818
});
1919

2020
test('support HTML input', async t => {
2121
const {stdout} = await execa('./cli.js', [], {
2222
input: '<h1>Unicorn</h1>',
23-
encoding: 'buffer'
23+
encoding: 'buffer',
2424
});
25-
t.is(fileType(stdout).mime, 'image/png');
25+
t.is((await FileType.fromBuffer(stdout)).mime, 'image/png');
2626
});
2727

2828
test('check flags', async t => {

0 commit comments

Comments
 (0)