-
Notifications
You must be signed in to change notification settings - Fork 0
/
startup.js
100 lines (86 loc) · 2.74 KB
/
startup.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
import inquirer from 'inquirer';
import fs from 'fs'
import config from './config.js'
import helpers from './helpers.js'
function createOutputDirectory() {
try {
if (!fs.existsSync('./' + config.outputDir)) {
fs.mkdirSync('./' + config.outputDir);
}
} catch (err) {
console.error(err);
}
}
function getAnswers() {
const filesInsideOutputDir = helpers.getFilesInsideOutputDir()
const questions = [
{
type: 'list',
name: 'category',
message: 'What category do you choose?',
choices: [{
key: 'rsTh',
name: 'Theater',
value: 'reservation-theatre',
},
{
key: 'rsHm',
name: 'Humor',
value: 'reservation-humour',
},
{
key: 'rsMuDa',
name: 'Music & dance',
value: 'reservation-musique-danse',
},
{
key: 'rsSpEn',
name: 'Shows for children',
value: 'reservation-spectacles-pour-enfants',
},
{
key: 'rsSpCa',
name: 'Big cabaret show',
value: 'reservation-grand-spectacle-show-cabaret',
},
{
key: 'rsMuEx',
name: 'Museum exhibition',
value: 'reservation-musee-exposition-visite-guidee',
},
{
key: 'rsLoSp',
name: 'Sports & leisures',
value: 'reservation-loisir-sport',
},
],
}, {
type: 'confirm',
name: 'outfutFile',
message: 'Output file ?',
default: false,
}, {
type: 'input',
name: 'fileName',
message: 'Enter a valid csv file name',
when: (answers) => answers.outfutFile === true,
validate: function(input) {
const pass = input.match(
/^\w+.(csv)$/igm
);
if (pass) {
if (!filesInsideOutputDir.includes(input)) {
return true;
} else {
return 'Please enter another file : ' + input + ' is already created'
}
}
return 'Please enter a csv file name';
}
}
]
return inquirer.prompt(questions).then((answers) => {
return answers
})
}
export default { getAnswers, createOutputDirectory }