-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
45 lines (42 loc) · 1.22 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
const yargs = require("yargs");
const { colours } = require("./utils/colours");
const helloFresh = require("./services/hello-fresh");
// Parse command-line configurations
const argv = yargs
.strict(true)
.usage("Usage: $0 <command> [options]")
.command("HelloFresh", "Perform crawling on HelloFresh", {
locale: {
alias: "l",
describe: "Locale to perform crawling on.",
choices: ["US", "GB", "DE", "FR"],
default: "US",
nargs: 1,
},
recipeCardSaveDirectory: {
alias: "s",
describe: "Directory where to save PDF recipe cards.",
default: "./recipe-card-pdfs",
nargs: 1,
},
})
.demandCommand(1, 1, "Please specify which service should be used")
.example(
"$0 HelloFresh -l GB -s ./downloads",
"Crawl on HelloFresh and use the GB locale"
).argv;
console.log(
colours.fg.green,
`Performing crawl on ${argv._} using ${argv.locale} locale`,
colours.reset
);
if (argv._[0] === "HelloFresh") {
helloFresh
.crawl(argv)
.catch(console.error)
.finally(() => {
console.log("The crawling process has completed. Press enter to exit...");
process.stdin.resume();
process.stdin.on("data", process.exit.bind(process, 0));
});
}