Hi! so I wanted to use netlify cms for one of my projects and I am a netlify newbie. so my collections export in JSON format extension: JSON , format: JSON
and obviously netlify cms create a file, and each entry to the file is stored as independent JSON files so I wanted to combine all this json files into one json file on the build . Now the problem I am facing is on build in the local server there is no problem the code combines all JSON files into a new JSON file but when building on netlify the file is not created in the git repo ad no error is also thrown.
folder structure:-
main.js:-
var fs = require("fs");
var path = require("path");
let jsonfile = [];
const dirPath = path.join(__dirname, "../products")
fs.readdir(dirPath, (err, fileNames) => {
fileNames.forEach(filename => {
const filePath = path.join(dirPath,"/",filename)
let jsonData = require(filePath);
jsonfile.push(jsonData);
});
fs.writeFile("./src/Shared/products/products.json", JSON.stringify(jsonfile), err => {
// Checking for errors
if (err) throw err;
console.log("Done writing"); // Success
});
});
package.json
"build": "node ./public/main.js && react-scripts build",
Well, this works perfectly in the local server but on build in netlify there are no errors thrown yet the file is not created.
well I am also open any ideas where I can get a combined JSON file directly from the CMS (I have aleady tried list but it looks a bit messsy .)