Skip to content

Commit f5b17a7

Browse files
committed
feat: updated config structure
1 parent d99d3fa commit f5b17a7

File tree

3 files changed

+29
-17
lines changed

3 files changed

+29
-17
lines changed

demo/next/next.config.mjs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ const nextConfig = {};
55

66
/** @type {import('@replexica/compiler').ReplexicaConfig} */
77
const replexicaConfig = {
8-
sourceLocale: 'en',
8+
locale: {
9+
source: 'en',
10+
targets: ['es'],
11+
},
912
debug: true,
1013
};
1114

1215
export default compiler.next(
1316
replexicaConfig,
1417
nextConfig,
1518
);
16-

packages/compiler/src/compiler/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export type ReplexicaCompilerPayload = {
22
settings: {
3-
locale: { source: string; };
3+
locale: { source: string; targets: string[]; };
44
};
55
data: ReplexicaCompilerData;
66
};

packages/compiler/src/output.ts

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { File } from "@babel/types";
22
import fs from 'fs';
33
import path from 'path';
44
import { ReplexicaCompilerData, ReplexicaCompilerPayload } from "./compiler";
5-
import { ReplexicaLocaleData, ReplexicaConfig } from "./types";
5+
import { ReplexicaLocaleData, ReplexicaConfig, ReplexicaData } from "./types";
66

77
export class ReplexicaOutputProcessor {
88
public static create(relativeFilePath: string, options: ReplexicaConfig) {
@@ -19,24 +19,30 @@ export class ReplexicaOutputProcessor {
1919

2020
public saveData(data: ReplexicaCompilerData) {
2121
const filePath = path.join(this._outDir, '.replexica.json');
22-
const existingData: ReplexicaCompilerPayload = this._loadObject<ReplexicaCompilerPayload>(filePath) || this._createEmptyCompilerPayload();
23-
const newData = {
22+
const existingData: ReplexicaData = this._loadObject<ReplexicaData>(filePath) || this._createEmptyData();
23+
const newData: ReplexicaData = {
2424
...existingData,
25-
data: {
26-
...existingData.data,
27-
...data,
28-
},
2925
};
26+
for (const [fileId, fileData] of Object.entries(data)) {
27+
newData.meta.files[fileId] = {
28+
isClient: fileData.context.isClient,
29+
};
30+
for (const [scopeId, scopeData] of Object.entries(fileData.data)) {
31+
newData.meta.scopes[scopeId] = {
32+
hints: scopeData.hints,
33+
};
34+
}
35+
}
3036
this._saveObject(filePath, newData);
3137
}
3238

3339
public saveFullSourceLocaleData(data: ReplexicaCompilerData) {
34-
const fileName = `${this.options.sourceLocale}.json`;
40+
const fileName = `${this.options.locale.source}.json`;
3541
this._saveSourceLocaleData(data, fileName);
3642
}
3743

3844
public saveClientSourceLocaleData(data: ReplexicaCompilerData) {
39-
const fileName = `${this.options.sourceLocale}.client.json`;
45+
const fileName = `${this.options.locale.source}.client.json`;
4046
this._saveSourceLocaleData(
4147
data,
4248
fileName,
@@ -80,25 +86,29 @@ export class ReplexicaOutputProcessor {
8086
}
8187

8288
public saveAst(ast: File) {
83-
const filePath = path.join(process.cwd(), this._debugDir, this.relativeFilePath + '.json');
89+
const filePath = path.join(this._debugDir, this.relativeFilePath + '.json');
8490
this._saveObject(filePath, ast);
8591
}
8692

8793
public saveOutput(output: string) {
88-
const filePath = path.join(process.cwd(), this._debugDir, this.relativeFilePath + '.txt');
94+
const filePath = path.join(this._debugDir, this.relativeFilePath + '.txt');
8995
this._saveText(filePath, output);
9096
}
9197

9298
// Private
9399

94-
private _createEmptyCompilerPayload(): ReplexicaCompilerPayload {
100+
private _createEmptyData(): ReplexicaData {
95101
return {
96102
settings: {
97103
locale: {
98-
source: this.options.sourceLocale,
104+
source: this.options.locale.source,
105+
targets: this.options.locale.targets,
99106
},
100107
},
101-
data: {},
108+
meta: {
109+
files: {},
110+
scopes: {},
111+
},
102112
};
103113
}
104114

0 commit comments

Comments
 (0)