-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
cli.js
75 lines (67 loc) · 1.79 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
import yargs from 'yargs';
import { hideBin } from 'yargs/helpers';
import Prevvy from './src/index.js';
const MAX_RETRIES = 3;
const generateTimestamp = () => {
// Generate a timestamp as a string
const now = new Date();
return now.toISOString().replace(/[:.]/g, '-');
};
const runGenerateCommand = async (argv, retryCount = 0) => {
const timestamp = generateTimestamp(); // Get the timestamp
console.info(argv);
console.log('hello generation');
try {
console.log('beginning Prevvy');
// Prefix the timestamp to temporary file names
const opts = {
input: argv.input,
output: argv.output,
throttleTimeout: 2000,
width: 128,
cols: 5,
rows: 5,
};
const thumb = new Prevvy(opts);
await thumb.generate();
} catch (error) {
console.error(`Error during generation: ${error.message}`);
if (retryCount < MAX_RETRIES) {
console.log(`Retrying (attempt ${retryCount + 1})...`);
await runGenerateCommand(argv, retryCount + 1);
} else {
console.error('Max retries reached. Exiting.');
process.exit(1);
}
}
};
yargs(hideBin(process.argv))
.command({
command: 'generate',
alias: 'g',
desc: 'Generate a storyboard image',
builder: (yargs) => {
return yargs
.option('input', {
alias: 'i',
describe: 'input file or html or whatever',
required: true,
})
.option('output', {
alias: 'o',
describe: 'output file',
required: true,
})
.option('max-retries', {
describe: 'Maximum number of retries',
default: MAX_RETRIES,
type: 'number',
});
},
handler: async (argv) => {
await runGenerateCommand(argv);
},
})
.demandCommand(1)
.help()
.parse();