-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.js
44 lines (39 loc) · 1.08 KB
/
util.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
import * as readline from 'readline';
import * as fs from 'fs';
import chalk from 'chalk';
export const errorLog = (error) => {
const eLog = chalk.red(chalk.bold('ERROR: ' + error));
console.log(eLog);
};
export const successLog = (successString) => {
const sLog = chalk.greenBright.bold(successString);
console.log(sLog);
};
//prompts the user to enter an input from the terminal
export const prompt = (question) => {
const readLine = readline.createInterface({
input: process.stdin,
output: process.stdout,
terminal: false,
});
return new Promise((resolve, reject) => {
readLine.question(question, (answer) => {
readLine.close();
resolve(answer);
});
});
};
//reads data from JSON files
export const jsonReader = (filePath) => {
let data;
try {
data = fs.readFileSync(filePath);
} catch (err) {
return;
}
return JSON.parse(data);
};
//writes data to JSON files
export const jsonWriter = (filePath, data) => {
fs.writeFileSync(filePath, JSON.stringify(data));
};