-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
100 lines (92 loc) · 2.4 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
require("dotenv").config();
var inquirer = require("inquirer");
var generator = require("./lib/generator");
var helpers = require("./lib/helpers");
let playlists;
const choices = {
createAdd: "Create/Add songs to JSON",
analyze: "Analyze existing JSON",
other: "Other (create a new one)"
};
async function askName() {
const { jsonName } = await inquirer.prompt([
{
type: "input",
name: "jsonName",
message: "Enter the name of the JSON to output (e.g.: alt-rock)"
}
]);
return jsonName;
}
async function askPlaylistId() {
const { playlistId } = await inquirer.prompt([
{
type: "input",
name: "playlistId",
message: "Enter the playlistId to copy the songs from"
}
]);
return playlistId;
}
async function addSongsToPlaylist() {
let jsonName;
if (playlists.length) {
let answers = await inquirer.prompt([
{
type: "list",
name: "jsonName",
message: "Choose an existing JSON name or create a new one",
choices: [...playlists, choices.other]
}
]);
if (answers.jsonName === choices.other) {
jsonName = await askName();
} else {
jsonName = answers.jsonName;
}
} else {
jsonName = await askName();
}
const playlistId = await askPlaylistId();
const tracks = await generator.getSongsFromPlaylist(playlistId);
await helpers.saveObjectToFile(tracks, `./dist/${jsonName}.json`);
console.log("Finished!");
}
async function countLettersInPlaylist() {
if (playlists.length === 0) {
console.log(
"There is no playlists available to analyze, create one first."
);
return;
}
let { jsonName } = await inquirer.prompt([
{
type: "list",
name: "jsonName",
message: "Choose one of the existing JSON to analyze",
choices: playlists
}
]);
const letterCount = helpers.getLetterCount(`./dist/${jsonName}.json`);
}
async function init() {
playlists = await helpers.getExistingPlaylists("./dist");
if (playlists.length === 0) {
addSongsToPlaylist();
} else {
let { whatToDo } = await inquirer.prompt([
{
type: "list",
name: "whatToDo",
message: "What do you want to do?",
choices: [choices.createAdd, choices.analyze]
}
]);
if (whatToDo === choices.createAdd) {
addSongsToPlaylist();
} else if (whatToDo === choices.analyze) {
countLettersInPlaylist();
}
}
}
init();