-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
52 lines (37 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
49
50
51
52
import chalk from "chalk";
import { input, select } from "@inquirer/prompts";
import getFillers from "./helper/getFillers.js";
import getAnimeList from "./helper/getAnimeList.js";
import checkMatch from "./helper/checkMatch.js";
import logFillers from "./helper/logFillers.js";
const log = console.log;
// get user input
let query = await input({ message: "Enter anime title to hunt its fillers: " });
// get anime list
const animeList = await getAnimeList();
let matches = animeList.filter((anime) => checkMatch(anime.title, query));
while (matches.length === 0) {
log(chalk.redBright("\nNo anime found, please try again.\n"));
query = await input({ message: "Enter anime title to hunt its fillers: " });
matches = animeList.filter((anime) => checkMatch(anime.title, query));
}
if (matches.length === 1) {
const anime = matches[0];
const fillers = await getFillers(anime.path);
logFillers(fillers, anime.title);
process.exit();
}
log(chalk.cyanBright("\nHere are the matches found: \n"));
const choices = matches.map((anime) => ({
name: anime.title,
value: {
title: anime.title,
path: anime.path,
},
}));
const chosenAnime = await select({
message: "Select an anime",
choices,
});
const fillers = await getFillers(chosenAnime.path);
logFillers(fillers, chosenAnime.title);