Repository URL to install this package:
|
Version:
5.0.0-rc.11 ▾
|
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js');
var path = _interopDefault(require('path'));
var fs = _interopDefault(require('fs'));
var util = require('util');
var util__default = _interopDefault(util);
var writeFileAsync = util.promisify(fs.writeFile);
var readFileAsync = util.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
*/
var writeJsonFile = /*#__PURE__*/function () {
var _ref = _rollupPluginBabelHelpers.asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(file, messages) {
var content;
return regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
content = JSON.stringify(messages);
try {
path.dirname(file).split('/').reduce(function (currentPath, directory) {
if (!fs.existsSync(currentPath)) {
fs.mkdirSync(currentPath);
}
return "".concat(currentPath, "/").concat(directory);
});
} catch (e) {// ignore
}
return _context.abrupt("return", writeFileAsync(file, content));
case 3:
case "end":
return _context.stop();
}
}
}, _callee);
}));
return function writeJsonFile(_x, _x2) {
return _ref.apply(this, arguments);
};
}();
/**
* Read a JSON file and parse the contents
*
* @param {string} file
* @returns {Promise<object>}
* @async
*/
var readJsonFile = /*#__PURE__*/function () {
var _ref2 = _rollupPluginBabelHelpers.asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(file) {
var content;
return regeneratorRuntime.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
_context2.next = 2;
return readFileAsync(file);
case 2:
content = _context2.sent;
return _context2.abrupt("return", JSON.parse(content));
case 4:
case "end":
return _context2.stop();
}
}
}, _callee2);
}));
return function readJsonFile(_x3) {
return _ref2.apply(this, arguments);
};
}();
/**
* Read OneSky resource configuration file, `.oneskyrc`
*
* @param {string} file
* @returns {Promise<object>}
* @async
*/
var getResourceConfiguration = /*#__PURE__*/function () {
var _ref3 = _rollupPluginBabelHelpers.asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3() {
var file,
_args3 = arguments;
return regeneratorRuntime.wrap(function _callee3$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
file = _args3.length > 0 && _args3[0] !== undefined ? _args3[0] : "".concat(process.cwd(), "/.oneskyrc");
return _context3.abrupt("return", readJsonFile(file));
case 2:
case "end":
return _context3.stop();
}
}
}, _callee3);
}));
return function getResourceConfiguration() {
return _ref3.apply(this, arguments);
};
}();
exports.getResourceConfiguration = getResourceConfiguration;
exports.readJsonFile = readJsonFile;
exports.writeJsonFile = writeJsonFile;
//# sourceMappingURL=utils.js.map