const fs = require('fs'); // get all language files const files = fs.readdirSync('./src/locales/'); files.forEach((f) => { // read file as object const unordered = JSON.parse(fs.readFileSync(`src/locales/${f}`)); // order object by keys alpabetically A-Z const ordered = Object.keys(unordered).sort().reduce((obj, key) => { obj[key] = unordered[key]; return obj; }, {}); // format output as json for commit diff compatibility const out = JSON.stringify(ordered, 0, 4); // write output file fs.writeFileSync(`src/locales/${f}`, out); });