-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
47 lines (41 loc) · 1.2 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
'use strict';
const commandGenerate = require(`./src/commands/generate`);
const processCommands = require(`./src/commands`);
const {askQuestion} = require(`./src/interface-frontend`);
const {checkFileExist} = require(`./src/interface-backend`);
if (process.argv.length === 2) {
const questions = [
`Сколько сущностей создаем? `,
`Какой будет путь до файла? `
];
let count = 0;
let dataFilePath = ``;
askQuestion(questions[0])
.then((answer) => {
count = answer;
return askQuestion(questions[1]);
})
.then((answer) => {
dataFilePath = answer;
return checkFileExist(dataFilePath);
})
.then((fileExist) => {
if (fileExist) {
askQuestion(`Перезаписать? (y)`)
.then((answer) => {
if (answer === `y`) {
return commandGenerate.execute(count, dataFilePath);
} else {
console.log(`Файл с данными не был создан!`);
}
return true;
});
}
})
.catch((error) => {
console.error(error);
process.exit(1);
});
} else {
processCommands(process.argv.slice(2));
}