-
Notifications
You must be signed in to change notification settings - Fork 152
/
util-file.js
executable file
·43 lines (36 loc) · 1.12 KB
/
util-file.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
const util = require('util')
const fs = require('fs')
const path = require('path')
const { convertToString, generateSessionExirationDate } = require('./util-common.js')
const readConfigurationFromFile = () => {
const readFile = util.promisify(fs.readFile)
return readFile(path.join(process.cwd(), './configuration.json'))
}
const writeConfigurationToFile = (configuration) => {
const configurationAsString = JSON.stringify(configuration, null, 4)
const writeFile = util.promisify(fs.writeFile)
return writeFile(path.join(process.cwd(), './configuration.json'), configurationAsString)
}
const getConfiguration = (callback) => {
readConfigurationFromFile().then((data) => {
callback(null, JSON.parse(data.toString()))
}).catch((error) => {
console.log(error)
return callback(error)
})
}
const setConfiguration = (configuration, callback) => {
writeConfigurationToFile(configuration).then(() => {
callback(null)
}).catch((error) => {
return callback(error)
})
}
module.exports = {
convertToString,
generateSessionExirationDate,
readConfigurationFromFile,
writeConfigurationToFile,
getConfiguration,
setConfiguration
}