Repository URL to install this package:
|
Version:
4.2.0 ▾
|
const fs = require('fs');
const { promisify } = require('util');
const writeFileAsync = promisify(fs.writeFile);
const readFileAsync = promisify(fs.readFile);
/**
* File utilities
*
* @module @doodle/i18n/onesky/dist/utils
*/
/**
* Write a JSON object to a file
*
* @param {String} file
* @param {object} messages
* @returns {Promise}
* @async
*/
const writeJsonFile = async (file, messages) => {
const content = JSON.stringify(messages);
return writeFileAsync(file, content);
};
/**
* Read a JSON file and parse the contents
*
* @param {string} file
* @returns {Promise<object>}
* @async
*/
const readJsonFile = async file => {
const content = await readFileAsync(file);
return JSON.parse(content);
};
/**
* Read OneSky resource configuration file, `.oneskyrc`
*
* @param {string} file
* @returns {Promise<object>}
* @async
*/
const getResourceConfiguration = async (file = `${process.cwd()}/.oneskyrc`) => readJsonFile(file);
module.exports = {
readJsonFile,
writeJsonFile,
getResourceConfiguration,
};