UNPKG

1.35 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.updateClusterConfigConfigurationFile = updateClusterConfigConfigurationFile;
7
8var _fs = _interopRequireDefault(require("fs"));
9
10var _util = require("util");
11
12function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
14const readFileAsync = (0, _util.promisify)(_fs.default.readFile);
15const writeFileAsync = (0, _util.promisify)(_fs.default.writeFile);
16
17async function updateClusterConfigConfigurationFile(pathToFile, optionsToUpdate) {
18 const fileContent = await readFileAsync(pathToFile, "utf8");
19 const lines = fileContent.split("\n");
20 const patchedLines = [];
21 const appliedOptionNames = [];
22
23 for (const line of lines) {
24 const [name] = line.split("=", 2).map(x => x.trim());
25
26 if (Object.keys(optionsToUpdate).includes(name)) {
27 appliedOptionNames.push(name);
28 patchedLines.push(`${name} = ${optionsToUpdate[name]}`);
29 } else {
30 patchedLines.push(line);
31 }
32 }
33
34 for (const optionName of Object.keys(optionsToUpdate)) {
35 if (!appliedOptionNames.includes(optionName)) {
36 patchedLines.push(`${optionName} = ${optionsToUpdate[optionName]}`);
37 }
38 }
39
40 await writeFileAsync(pathToFile, patchedLines.join("\n"), "utf8");
41}
42//# sourceMappingURL=clusterConfigSettingsUtils.js.map
\No newline at end of file