MCPcopy Create free account
hub / github.com/babel/babel / assignJSONFile

Function assignJSONFile

scripts/generate-babel-7-tests.mjs:47–66  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

45 * @param {object} inputProperties - The properties to assign.
46 */
47function 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.

Callers 2

updateBabel8BreakingTrueFunction · 0.85
createBabel7TestsFunction · 0.85

Calls 1

parseMethod · 0.45

Tested by

no test coverage detected