Skip to content

Commit

Permalink
refactor: return early if unchanged
Browse files Browse the repository at this point in the history
  • Loading branch information
ST-DDT committed Apr 16, 2024
1 parent fab137e commit 4b7acf1
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions scripts/generate-locales.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,11 +363,18 @@ async function normalizeLocaleFile(filePath: string, definitionKey: string) {

const fileContentPreData = fileContent.substring(0, compareIndex);
const fileImport = await import(`file:${filePath}`);
const localeData = normalizeDataRecursive(fileImport.default);
const oldData = fileImport.default;
const localeData = normalizeDataRecursive(oldData);

// We reattach the content before the actual data implementation to keep stuff like comments.
// In the long term we should probably define a whether we want those in the files at all.
const newContent = fileContentPreData + JSON.stringify(localeData);
const newDataJson = JSON.stringify(localeData);
const newContent = fileContentPreData + newDataJson;

// Exit early if unchanged for performance reasons
if (JSON.stringify(oldData) === newDataJson) {
return;
}

return writeFile(filePath, await formatTypescript(newContent));
}
Expand Down

0 comments on commit 4b7acf1

Please sign in to comment.