-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
cli.js
executable file
·57 lines (51 loc) · 1.29 KB
/
cli.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env node
import fs from 'node:fs';
import path from 'node:path';
import meow from 'meow';
import {getWallpaper, setWallpaper, setSolidColorWallpaper} from 'wallpaper';
import isUrl from 'is-url-superb';
import got from 'got';
import tempfile from 'tempfile';
import isRGBHex from './utilities/is-rgb-hex.js';
const cli = meow(`
Usage
$ wallpaper [file|url|color]
Options
--scale Scaling method: auto fill fit stretch center [Default: auto]
Only available on macOS
Examples
$ wallpaper unicorn.jpg
$ wallpaper https://octodex.github.com/images/dojocat.jpg
$ wallpaper '#ff69b4'
$ wallpaper
/Users/sindresorhus/unicorn.jpg
$ wallpaper codercat.jpg --scale=fit
`, {
importMeta: import.meta,
flags: {
// TODO: Use the `choices` option in `meow` when it supports that.
scale: {
type: 'string',
},
},
});
const input = cli.input[0];
(async () => {
if (input) {
if (isUrl(input)) {
const file = tempfile(path.extname(input));
got
.stream(input)
.pipe(fs.createWriteStream(file))
.on('finish', async () => {
await setWallpaper(file, cli.flags);
});
} else if (isRGBHex(input)) {
await setSolidColorWallpaper(input);
} else {
await setWallpaper(input, cli.flags);
}
} else {
console.log(await getWallpaper());
}
})();