1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.updateClusterConfigConfigurationFile = updateClusterConfigConfigurationFile;
|
7 |
|
8 | var _fs = _interopRequireDefault(require("fs"));
|
9 |
|
10 | var _util = require("util");
|
11 |
|
12 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
13 |
|
14 | const readFileAsync = (0, _util.promisify)(_fs.default.readFile);
|
15 | const writeFileAsync = (0, _util.promisify)(_fs.default.writeFile);
|
16 |
|
17 | async 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 |
|
\ | No newline at end of file |