Skip to content

Commit 840a2c2

Browse files
committed
feat(compiler): save stub files for target locales during the build
1 parent 1f61009 commit 840a2c2

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

packages/compiler/src/index.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ const unplugin = createUnplugin<ReplexicaConfig>((options) => ({
1515
transform(code, absoluteFilePath) {
1616
try {
1717
const relativeFilePath = path.relative(process.cwd(), absoluteFilePath);
18-
19-
const relativeFileDir = path.relative(process.cwd(), path.dirname(absoluteFilePath));
2018

2119
const compiler = ReplexicaCompiler
2220
.fromCode(code, relativeFilePath)
@@ -28,9 +26,10 @@ const unplugin = createUnplugin<ReplexicaConfig>((options) => ({
2826
const result = compiler.generate();
2927

3028
const outputProcessor = ReplexicaOutputProcessor.create(relativeFilePath, options);
31-
outputProcessor.saveData(compiler.data);
29+
outputProcessor.saveBuildData(compiler.data);
3230
outputProcessor.saveFullSourceLocaleData(compiler.data);
3331
outputProcessor.saveClientSourceLocaleData(compiler.data);
32+
outputProcessor.saveStubLocaleData();
3433

3534
if (options.debug) {
3635
outputProcessor.saveAst(compiler.ast);

packages/compiler/src/output.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export class ReplexicaOutputProcessor {
1717
private _outDir = path.join(process.cwd(), `node_modules/@replexica/translations`);
1818
private _debugDir = path.join(process.cwd(), '.debug/replexica');
1919

20-
public saveData(data: ReplexicaCompilerData) {
20+
public saveBuildData(data: ReplexicaCompilerData) {
2121
const filePath = path.join(this._outDir, '.replexica.json');
2222
const existingData: ReplexicaData = this._loadObject<ReplexicaData>(filePath) || this._createEmptyData();
2323
const newData: ReplexicaData = {
@@ -50,6 +50,16 @@ export class ReplexicaOutputProcessor {
5050
);
5151
}
5252

53+
public saveStubLocaleData() {
54+
for (const targetLocale of this.options.locale.targets) {
55+
const fullLocaleDataFilePath = path.join(this._outDir, `${targetLocale}.json`);
56+
fs.writeFileSync(fullLocaleDataFilePath, '{}', 'utf-8');
57+
58+
const clientLocaleDataFilePath = path.join(this._outDir, `${targetLocale}.client.json`);
59+
fs.writeFileSync(clientLocaleDataFilePath, '{}', 'utf-8');
60+
}
61+
}
62+
5363
private _saveSourceLocaleData(
5464
data: ReplexicaCompilerData,
5565
fileName: string,

0 commit comments

Comments
 (0)