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