-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
48 lines (38 loc) · 1.29 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
const commandLineArgs = require("command-line-args");
const commandLineUsage = require("command-line-usage");
const { optionDefinitions, sections } = require("./command");
const { parseHTMLPage } = require("./html");
const { convertTextToAudio } = require("./convert");
async function run() {
const usage = commandLineUsage(sections);
try {
const options = commandLineArgs(optionDefinitions);
const requiredArgs = optionDefinitions
.map((it) => it.name)
.filter((it) => it !== "help");
const argKeys = Object.keys(options).filter((it) => it !== "help");
if (options.help || argKeys.length === 0) {
console.log(usage);
process.exit(0);
}
const missingArgs = [];
for (const param of requiredArgs) {
if (!argKeys.includes(param)) missingArgs.push(param);
}
if (missingArgs.length > 0) {
console.log(`missing required arguments: ${missingArgs.join(", ")}`);
console.log(usage);
process.exit(1);
}
const text = await parseHTMLPage(options["url"]);
const value = await convertTextToAudio(text, options["output"]);
if (value) {
console.log("blog post conversion completed successfully");
}
} catch (error) {
console.log(error.message);
console.log(usage);
process.exit(1);
}
}
run();