Commits

Tim Donohue authored and GitHub committed 02e089a51b3 Merge
Merge pull request #1666 from atmire/w2p-91400_Fix-for-missing-comma-in-json-files

Fix for missing comma in json files
No tags
gidlmaster

scripts/sync-i18n-files.ts

Modified
1 -import { projectRoot} from '../webpack/helpers';
1 +import { projectRoot } from '../webpack/helpers';
2 +
2 3 const commander = require('commander');
3 4 const fs = require('fs');
4 5 const JSON5 = require('json5');
5 6 const _cliProgress = require('cli-progress');
6 7 const _ = require('lodash');
7 8
8 9 const program = new commander.Command();
9 10 program.version('1.0.0', '-v, --version');
10 11
11 12 const NEW_MESSAGE_TODO = '// TODO New key - Add a translation';
112 113
113 114 const file = fs.createWriteStream(pathToOutputFile);
114 115 file.on('error', function (err) {
115 116 console.error('Something went wrong writing to output file at: ' + pathToOutputFile + err)
116 117 });
117 118 file.on('open', function() {
118 119 file.write("{\n");
119 120 outputChunks.forEach(function (chunk) {
120 121 progressBar.increment();
121 122 chunk.split("\n").forEach(function (line) {
122 - file.write(" " + line + "\n");
123 + file.write((line === '' ? '' : ` ${line}`) + "\n");
123 124 });
124 125 });
125 126 file.write("\n}");
126 127 file.end();
127 128 });
128 129 file.on('finish', function() {
129 130 const osName = process.platform;
130 131 if (osName.startsWith("win")) {
131 132 replaceLineEndingsToCRLF(pathToOutputFile);
132 133 }
185 186 * - If the key-value in the target comments is not the same as the source key-value (because it changes since last time) => Add message changed message
186 187 * - Add the old todos if they haven't been added already
187 188 * - End with the original target key-value
188 189 */
189 190 function createNewChunkComparingSourceAndTarget(correspondingTargetChunk, sourceChunk, commentSource, keyValueSource, newChunk) {
190 191 let commentsOfSourceHaveChanged = false;
191 192 let messageOfSourceHasChanged = false;
192 193
193 194 const targetList = correspondingTargetChunk.split("\n");
194 195 const oldKeyValueInTargetComments = getSubStringWithRegex(correspondingTargetChunk, "\\s*\\/\\/\\s*\".*");
195 - const keyValueTarget = targetList[targetList.length - 1];
196 + let keyValueTarget = targetList[targetList.length - 1];
197 + if (!keyValueTarget.endsWith(",")) {
198 + keyValueTarget = keyValueTarget + ",";
199 + }
196 200
197 201 if (oldKeyValueInTargetComments != null) {
198 202 const oldKeyValueUncommented = getSubStringWithRegex(oldKeyValueInTargetComments[0], "\".*")[0];
199 203
200 204 if (!(_.isEmpty(correspondingTargetChunk) && _.isEmpty(commentSource)) && !removeWhiteLines(correspondingTargetChunk).includes(removeWhiteLines(commentSource.trim()))) {
201 205 commentsOfSourceHaveChanged = true;
202 206 newChunk.push(COMMENTS_CHANGED_TODO);
203 207 }
204 208 const parsedOldKey = JSON5.stringify("{" + oldKeyValueUncommented + "}");
205 209 const parsedSourceKey = JSON5.stringify("{" + keyValueSource + "}");

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut