Skip to content

Commit

Permalink
Fix ||=
Browse files Browse the repository at this point in the history
  • Loading branch information
extempl committed Dec 6, 2021
1 parent 4cf4a2c commit f95875c
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 11 deletions.
18 changes: 14 additions & 4 deletions core.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ let _fs;
let _octokitUrl;
let _octokit;


// TODO skip merge commits, but take newest version of files as a previous contents
module.exports = async (context, { LokaliseApi, fs }) => {
_context = context;
_lokalise = new LokaliseApi({ apiKey: context.apiKey });
Expand Down Expand Up @@ -132,7 +134,9 @@ async function composeDiffSequence(compareResult) {
if (Object.keys(jsonDifferenceResult.new).length ||
Object.keys(jsonDifferenceResult.removed).length ||
jsonDifferenceResult.edited.length) {
diffSequence[language] ||= [];
if (!diffSequence[language]) {
diffSequence[language] = [];
}
diffSequence[language].push(jsonDifferenceResult);
}

Expand Down Expand Up @@ -161,9 +165,13 @@ function composeActionsFromDiffSequence (diffSequence, keysToCreate, keysToUpdat
fileDiffSequence.forEach(change => {
Object.keys(change.new).forEach(key => {
const normalizedKey = normalizeKey(key);
keysToCreate[normalizedKey] ||= {};
if (!keysToCreate[normalizedKey]) {
keysToCreate[normalizedKey] = {};
}
keysToCreate[normalizedKey][language] = change.new[key];
keysToUpdate[normalizedKey] ||= {};
if (!keysToUpdate[normalizedKey]) {
keysToUpdate[normalizedKey] = {};
}
keysToUpdate[normalizedKey][language] = change.new[key];
});
change.edited.forEach(edited => {
Expand All @@ -172,7 +180,9 @@ function composeActionsFromDiffSequence (diffSequence, keysToCreate, keysToUpdat
if (keysToCreate[normalizedKey]?.[language]) {
keysToCreate[normalizedKey][language] = edited[key].newvalue;
} else {
keysToUpdate[normalizedKey] ||= {};
if (!keysToUpdate[normalizedKey]) {
keysToUpdate[normalizedKey] = {};
}
keysToUpdate[normalizedKey][language] = edited[key].newvalue;
}
});
Expand Down
18 changes: 14 additions & 4 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ let _fs;
let _octokitUrl;
let _octokit;


// TODO skip merge commits, but take newest version of files as a previous contents
module.exports = async (context, { LokaliseApi, fs }) => {
_context = context;
_lokalise = new LokaliseApi({ apiKey: context.apiKey });
Expand Down Expand Up @@ -146,7 +148,9 @@ async function composeDiffSequence(compareResult) {
if (Object.keys(jsonDifferenceResult.new).length ||
Object.keys(jsonDifferenceResult.removed).length ||
jsonDifferenceResult.edited.length) {
diffSequence[language] ||= [];
if (!diffSequence[language]) {
diffSequence[language] = [];
}
diffSequence[language].push(jsonDifferenceResult);
}

Expand Down Expand Up @@ -175,9 +179,13 @@ function composeActionsFromDiffSequence (diffSequence, keysToCreate, keysToUpdat
fileDiffSequence.forEach(change => {
Object.keys(change.new).forEach(key => {
const normalizedKey = normalizeKey(key);
keysToCreate[normalizedKey] ||= {};
if (!keysToCreate[normalizedKey]) {
keysToCreate[normalizedKey] = {};
}
keysToCreate[normalizedKey][language] = change.new[key];
keysToUpdate[normalizedKey] ||= {};
if (!keysToUpdate[normalizedKey]) {
keysToUpdate[normalizedKey] = {};
}
keysToUpdate[normalizedKey][language] = change.new[key];
});
change.edited.forEach(edited => {
Expand All @@ -186,7 +194,9 @@ function composeActionsFromDiffSequence (diffSequence, keysToCreate, keysToUpdat
if (keysToCreate[normalizedKey]?.[language]) {
keysToCreate[normalizedKey][language] = edited[key].newvalue;
} else {
keysToUpdate[normalizedKey] ||= {};
if (!keysToUpdate[normalizedKey]) {
keysToUpdate[normalizedKey] = {};
}
keysToUpdate[normalizedKey][language] = edited[key].newvalue;
}
});
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "push-lokalise-keys",
"version": "4.0.2",
"version": "4.0.3",
"description": "",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit f95875c

Please sign in to comment.