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

Function assignJSONFile

scripts/generate-babel-7-tests.ts:46–65  ·  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: string, inputProperties: object)

Source from the content-addressed store, hash-verified

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

Callers 2

updateBabel8BreakingTrueFunction · 0.85
createBabel7TestsFunction · 0.85

Calls 1

parseMethod · 0.45

Tested by

no test coverage detected