mirror of
https://github.com/strapi/strapi.git
synced 2025-12-27 15:13:21 +00:00
Fix PR feedback
Signed-off-by: soupette <cyril.lpz@gmail.com>
This commit is contained in:
parent
cd55915642
commit
9347083625
@ -1,6 +1,6 @@
|
||||
import { flatten } from 'lodash';
|
||||
import { flatMap } from 'lodash';
|
||||
|
||||
const generateArrayOfLinks = array => flatten(array.map(({ links }) => links));
|
||||
const generateArrayOfLinks = array => flatMap(array, 'links');
|
||||
|
||||
const findFirstAllowedEndpoint = menuArray => {
|
||||
const arrayOfLinks = generateArrayOfLinks(menuArray);
|
||||
|
||||
@ -5,8 +5,8 @@ const glob = promisify(require('glob').glob);
|
||||
|
||||
async function orderTrads({ mainTranslationFile, translationFiles }) {
|
||||
const data = await fs.readJSON(mainTranslationFile);
|
||||
const orderedData = Object.keys(data)
|
||||
|
||||
const orderedData = Object.keys(data)
|
||||
.sort()
|
||||
.reduce((acc, current) => {
|
||||
acc[current] = data[current];
|
||||
@ -16,25 +16,31 @@ async function orderTrads({ mainTranslationFile, translationFiles }) {
|
||||
|
||||
await fs.writeJSON(mainTranslationFile, orderedData, { spaces: 2 });
|
||||
|
||||
await Promise.all(
|
||||
translationFiles.map(async trad => {
|
||||
const cleanedFile = Object.keys(orderedData).reduce((acc, current) => {
|
||||
const currentTrad = fs.readJsonSync(trad);
|
||||
|
||||
if (currentTrad[current]) {
|
||||
acc[current] = currentTrad[current];
|
||||
}
|
||||
|
||||
return acc;
|
||||
}, {});
|
||||
const cleanFile = async trad => {
|
||||
const cleanedFile = {};
|
||||
const orderedDataKeys = Object.keys(orderedData);
|
||||
|
||||
for (let i in orderedDataKeys) {
|
||||
try {
|
||||
await fs.writeJSON(trad, cleanedFile, { spaces: 2 });
|
||||
const currentTrad = await fs.readJson(trad);
|
||||
const currentKey = orderedDataKeys[i];
|
||||
|
||||
if (currentTrad[currentKey]) {
|
||||
cleanedFile[currentKey] = currentTrad[currentKey];
|
||||
}
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
console.error(err);
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
await fs.writeJSON(trad, cleanedFile, { spaces: 2 });
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
};
|
||||
|
||||
await Promise.all(translationFiles.map(trad => cleanFile(trad)));
|
||||
}
|
||||
|
||||
async function run() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user