-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
72 lines (63 loc) · 1.67 KB
/
index.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
#!/usr/bin/env node
import { existsSync } from 'fs';
import {
dirname,
extname,
resolve,
} from 'path';
import { fileURLToPath } from 'url';
import signale from 'signale';
import dotenv from 'dotenv'; // https://github.com/motdotla/dotenv
import { program } from 'commander'; // https://github.com/tj/commander.js
// eslint-disable-next-line import/no-named-as-default, import/no-named-as-default-member
import Cahe from './src/Cahe.js';
const filePath = process.argv[2];
const scriptPath = dirname(fileURLToPath(import.meta.url));
dotenv.config({ path: resolve(scriptPath, '.env') });
program
.option('-w, --web-version')
.option('-e, --extract-zip-file');
program.parse();
const options = program.opts();
if (
filePath
&& existsSync(filePath)
&& extname(filePath.toLowerCase()) === '.html'
) {
try {
const cahe = new Cahe(
filePath,
process.env.NETLIFY_KEY,
process.env.PROXY,
options.webVersion,
options.extractZipFile,
);
await cahe.archiveContent();
} catch (error) {
signale.fatal(error);
}
} else if (
filePath
&& existsSync(filePath)
&& extname(filePath.toLowerCase()) === '.zip'
) {
if (options.webVersion) {
try {
const webletter = await Cahe.createWebletter(
filePath,
dirname(filePath),
process.env.NETLIFY_KEY,
process.env.PROXY,
);
signale.info(`Webletter: ${webletter.webletterUrl}`);
} catch (error) {
signale.fatal(error);
}
} else {
Cahe.extractArchive(filePath);
}
} else {
signale.fatal(
'The path to the HTML or ZIP file is either incorrect or missing. Please verify the path and ensure it is correctly specified.',
);
}