Codacy update for localize.js

This commit is contained in:
Angelos Chalaris
2018-09-15 13:32:28 +03:00
parent 3b75e60b60
commit 6e6d390abd

View File

@ -26,12 +26,12 @@ locales.forEach(locale => {
if (locData.hasOwnProperty(snippetName)) {
if (locData[snippetName].hash !== snippetHash) {
existingData =
existingData.indexOf(' => ' + snippetHash) !== -1
existingData.indexOf(` => ${snippetHash}`) !== -1
? existingData
: existingData.replace(
locData[snippetName].hash,
locData[snippetName].hash + ' => ' + snippetHash
);
locData[snippetName].hash,
`${locData[snippetName].hash} => ${snippetHash}`
);
hashChanges.push({
snippetName,
oldHash: locData[snippetName].hash.split(' => ')[0],
@ -44,39 +44,20 @@ locales.forEach(locale => {
'comments': [${(snippets[snippet].match(COMMENT_REGEX) || []).map(
v => '`' + v.replace(/`/g, '\\`') + '`'
)}],
'hash': '${snippetHash}'
}`);
'hash': '${snippetHash}'\n}`);
}
});
if (!fs.existsSync(path.join(LOCALE_PATH, locale + '.js')) || !existingData.length)
existingData = `module.exports = {
'locale': {
'locale': '${locale}'
}};`;
'locale': '${locale}'\n}};`;
fs.writeFileSync(
path.join(LOCALE_PATH, locale + '.js'),
newData.length ? `${existingData.trim().slice(0, -2)},${newData.join(',')}};` : existingData
);
fs.writeFileSync(
path.join(LOCALE_PATH, locale + '_log'),
`${new Date()}
Hash changes: ${hashChanges.length}
${
hashChanges.length
? hashChanges
.map(
v =>
'Snippet name:' +
v.snippetName +
'\n Old hash: ' +
v.oldHash +
'\n New hash: ' +
v.newHash +
'\n'
)
.join('\n')
: ''
}`
`${new Date()}\nHash changes: ${hashChanges.length}\n${
hashChanges.length ? hashChanges.map(v => `Snippet name: ${v.snippetName}\n Old hash: ${v.oldHash}\n New hash: ${v.newHash}\n`).join('\n'): ''}`
);
});