Skip to content

Commit eca4595

Browse files
fix: write stub locale data files only when no files exist (#17)
* fix: write stub locale data files only when no files exist * chore: add changeset * fix: node deprecation issue --------- Co-authored-by: maxprilutskiy <[email protected]>
1 parent 561802a commit eca4595

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

.changeset/angry-elephants-cheat.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@replexica/compiler": patch
3+
---
4+
5+
write stub locale data files only when no files exist

packages/compiler/src/output.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ export class ReplexicaOutputProcessor {
1212
private constructor(
1313
private readonly relativeFilePath: string,
1414
private readonly options: ReplexicaConfig,
15-
) {}
15+
) { }
1616

1717
private _outDir = path.join(process.cwd(), `node_modules/@replexica/translations`);
1818
private _debugDir = path.join(process.cwd(), '.debug/replexica');
19-
19+
2020
public saveBuildData(data: ReplexicaCompilerData) {
2121
const filePath = path.join(this._outDir, '.replexica.json');
2222
const existingData: ReplexicaData = this._loadObject<ReplexicaData>(filePath) || this._createEmptyData();
@@ -44,19 +44,23 @@ export class ReplexicaOutputProcessor {
4444
public saveClientSourceLocaleData(data: ReplexicaCompilerData) {
4545
const fileName = `${this.options.locale.source}.client.json`;
4646
this._saveSourceLocaleData(
47-
data,
48-
fileName,
47+
data,
48+
fileName,
4949
(fileData) => fileData.context.isClient,
5050
);
5151
}
5252

5353
public saveStubLocaleData() {
5454
for (const targetLocale of this.options.locale.targets) {
5555
const fullLocaleDataFilePath = path.join(this._outDir, `${targetLocale}.json`);
56-
fs.writeFileSync(fullLocaleDataFilePath, '{}', 'utf-8');
56+
if (!fs.existsSync(fullLocaleDataFilePath)) {
57+
fs.writeFileSync(fullLocaleDataFilePath, '{}', 'utf-8');
58+
}
5759

5860
const clientLocaleDataFilePath = path.join(this._outDir, `${targetLocale}.client.json`);
59-
fs.writeFileSync(clientLocaleDataFilePath, '{}', 'utf-8');
61+
if (!fs.existsSync(clientLocaleDataFilePath)) {
62+
fs.writeFileSync(clientLocaleDataFilePath, '{}', 'utf-8');
63+
}
6064
}
6165
}
6266

0 commit comments

Comments
 (0)