* Assign properties from input to a JSON file, creating or updating it. * @param {string} jsonFile - The path to the JSON file. * @param {object} inputProperties - The properties to assign.
(jsonFile, inputProperties)
| 45 | * @param {object} inputProperties - The properties to assign. |
| 46 | */ |
| 47 | function assignJSONFile(jsonFile, inputProperties) { |
| 48 | let options = inputProperties; |
| 49 | const jsonFileExists = existsSync(jsonFile); |
| 50 | if (jsonFileExists) { |
| 51 | try { |
| 52 | options = { |
| 53 | ...JSON.parse(readFileSync(jsonFile, "utf-8")), |
| 54 | ...inputProperties, |
| 55 | }; |
| 56 | } catch (error) { |
| 57 | console.error(`Error reading ${jsonFile}:`, error.message); |
| 58 | } |
| 59 | } |
| 60 | try { |
| 61 | writeFileSync(jsonFile, JSON.stringify(options, null, 2) + "\n", "utf-8"); |
| 62 | console.log(`${jsonFileExists ? "Updated" : "Created"} ${jsonFile}`); |
| 63 | } catch (error) { |
| 64 | console.error(`Error writing ${jsonFile}:`, error.message); |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Update the options.json files for Babel 8 breaking changes. |
no test coverage detected