-
Notifications
You must be signed in to change notification settings - Fork 1
/
fileList.js
34 lines (30 loc) · 828 Bytes
/
fileList.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
import fs from 'fs';
import path from 'path';
import readline from 'readline';
const readFilesSync = (dir) => {
const files = [];
let i = 0;
fs.readdirSync(dir).forEach(filename => {
files.push({ index: i, name: path.parse(filename).base});
i++;
});
return files;
}
const getFileName = () => {
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
const testFiles = readFilesSync('./testsFiles/');
return new Promise(resolve =>
rl.question(`Test files are: ${testFiles.map(file => `\n Index: ${file.index} | TestFile: ${file.name}`)} \n\nChoose one index!\n`,
(answer) => {
const fileName = testFiles[answer].name;
rl.close();
resolve(fileName);
console.clear();
}
)
);
}
export default getFileName;