Skip to content

Commit

Permalink
feat(@formatjs/cli): modify output JSON schema
Browse files Browse the repository at this point in the history
BREAKING CHANGE: The old output JSON messages used to be a
`MessageDescriptor[]`. This format isn't friendly to translation vendors
so we've changed it to `Record<string, Omit<MessageDescriptor, 'id'>>`.
For example:
```json
{
  "fjk13": {
    "defaultMessage": "a message",
    "description": "a description",
    "start": 0,
    "end": 20
  }
}
```
  • Loading branch information
longlho committed Jul 25, 2020
1 parent 0b0c810 commit 457d30b
Show file tree
Hide file tree
Showing 4 changed files with 150 additions and 198 deletions.
7 changes: 6 additions & 1 deletion packages/cli/src/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,12 @@ ${JSON.stringify(message, undefined, 2)}`
extractedMessages.set(id, message);
}
}
const results = Array.from(extractedMessages.values());
const results: Record<string, Omit<MessageDescriptor, 'id'>> = {};
const messages = Array.from(extractedMessages.values());
for (const {id, ...msg} of messages) {
results[id] = msg;
}

if (outFile) {
outputJSONSync(outFile, results, {
spaces: 2,
Expand Down
4 changes: 4 additions & 0 deletions packages/cli/tests/extract/__snapshots__/unit.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Array [
Object {
"compilerOptions": Object {
"allowJs": true,
"noEmit": true,
"target": 99,
},
"fileName": "file1.js",
"transformers": Object {
Expand All @@ -21,6 +23,8 @@ Array [
Object {
"compilerOptions": Object {
"allowJs": true,
"noEmit": true,
"target": 99,
},
"fileName": "file2.tsx",
"transformers": Object {
Expand Down
Loading

0 comments on commit 457d30b

Please sign in to comment.