-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
cli.js
97 lines (91 loc) · 3.16 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/env node
/**
* gsap-video-export
* github: workeffortwaste
* twitter: @defaced
*
* Source: https://github.com/workeffortwaste/gsap-video-export/
*/
import { videoExport } from './index.js'
import yargs from 'yargs'
import { hideBin } from 'yargs/helpers'
import fs from 'fs'
/* Colors */
const colors = {
dim: '\x1b[2m',
reset: '\x1b[0m',
underscore: '\x1b[4m',
magenta: '\x1b[35m',
blue: '\x1b[34m',
green: '\x1b[32m',
red: '\x1b[31m',
yellow: '\x1b[33m'
}
/* CLI welcome message */
const { version } = JSON.parse(fs.readFileSync(new URL('./package.json', import.meta.url)))
console.log(`gsap-video-export ${version} / ${colors.blue}@defaced${colors.reset}`)
/* Support */
if (!process.env.WORKEFFORTWASTE_SUPPORTER) {
console.log(`${colors.magenta}
┃
┃ ${colors.underscore}Support this project! ${colors.reset}${colors.magenta}
┃
┃ Help support the work that goes into creating and maintaining my projects
┃ and consider donating via on GitHub Sponsors.
┃
┃ GitHub Sponsors: https://github.com/sponsors/workeffortwaste/
┃${colors.reset}
`)
}
const _yargs = yargs(hideBin(process.argv))
/* CLI arguments config */
const options = _yargs
.wrap(Math.min(110, _yargs.terminalWidth()))
.default({ C: 'mp4', r: 'gsap', p: 'auto', c: 'libx264', o: 'video.mp4', t: 'gsap', f: 60, S: 'document', z: 1, V: '1920x1080', v: 'auto', E: '"-pix_fmt yuv420p -crf 18"', q: true, h: true, chrome: false })
.usage('$0 <url>', 'Export GreenSock (GSAP) animation to video')
.describe('s', '[browser] Custom script')
.describe('S', '[browser] DOM selector')
.describe('t', '[browser] GSAP timeline object')
.describe('z', '[browser] Scale factor')
.describe('V', '[browser] Viewport size')
.describe('i', '[browser] Info only')
.describe('frame-start', '[browser] Start frame')
.describe('frame-end', '[browser] End frame')
.describe('chrome', '[browser] Use the system installed Chrome')
.describe('cookies', '[browser] Cookie JSON file')
.describe('a', '[browser] Frame advance method')
.describe('h', '[browser] Headless mode')
.describe('p', '[video] Auto padding color')
.describe('c', '[video] Codec')
.describe('C', '[video] Format')
.describe('e', '[video] FFmpeg input options')
.describe('E', '[video] FFmpeg output options')
.describe('o', '[video] Filename')
.describe('f', '[video] Framerate')
.describe('v', '[video] Output resolution')
.describe('q', '[tool] Verbose output')
.alias('i', 'info')
.alias('o', 'output')
.alias('t', 'timeline')
.alias('f', 'fps')
.alias('c', 'codec')
.alias('C', 'format')
.alias('S', 'selector')
.alias('s', 'script')
.alias('z', 'scale')
.alias('e', 'input-options')
.alias('E', 'output-options')
.alias('p', 'color')
.alias('V', 'viewport')
.alias('v', 'resolution')
.alias('a', 'advance')
.alias('q', 'verbose')
.alias('h', 'headless')
.number(['f', 'z'])
.boolean(['i', 'q', 'h', 'chrome'])
.string(['C', 'e', 'E', 'S', 's', 'o', 't', 'v', 'V', 'c', 'p', 'cookies', 'advance'])
.epilogue('For more information visit documentation at: \nhttp://github.com/workeffortwaste/gsap-video-export')
.argv
/* Add CLI flag */
options['cli'] = true
videoExport(options)