-
Notifications
You must be signed in to change notification settings - Fork 3
/
config.js
32 lines (25 loc) · 886 Bytes
/
config.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
"use strict";
const fs = require("fs");
const inquirer = require("inquirer");
const Parameters = require("./parameters").get();
const { promisify } = require("util");
const writeFileAsync = promisify(fs.writeFile);
const fileExists = promisify(fs.exists);
module.exports.checkConfig = async () => {
const exists = await fileExists(Parameters.configFileName);
if (exists) {
return;
}
const config = await inquirer.prompt(Parameters.configQuestions);
await writeFileAsync("./snapshot.config.json", JSON.stringify(config, null, 2));
console.info("Configuration file was successfully created. Please run the program again.");
process.exit();
};
module.exports.getConfig = () => {
try {
const contents = fs.readFileSync(Parameters.configFileName);
return JSON.parse(contents);
} catch (e) {
console.error("Configuration file was not found.");
}
};