Skip to content

Commit 7ce664d

Browse files
committed
refactor: swap makeEnMetaJson() args order
1 parent 8f1acd7 commit 7ce664d

2 files changed

Lines changed: 24 additions & 25 deletions

File tree

scripts/i18n-meta/update-en-meta-json.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export function updateEnMetaJson() {
2222

2323
const currentCommitHash = getCurrentCommitHash()
2424
const enMetaJson = currentCommitHash
25-
? makeEnMetaJson(newEnJson, oldEnMetaJson, currentCommitHash)
25+
? makeEnMetaJson(oldEnMetaJson, newEnJson, currentCommitHash)
2626
: ({} as EnMetaJson)
2727

2828
const hasChanges = checkTranslationChanges(oldEnMetaJson, enMetaJson)
@@ -38,8 +38,8 @@ export function updateEnMetaJson() {
3838
}
3939

4040
export function makeEnMetaJson(
41-
newEnJson: EnJson,
4241
oldMetaEnJson: EnMetaJson,
42+
newEnJson: EnJson,
4343
latestCommitHash: string,
4444
): EnMetaJson {
4545
const newFlat = dot.dot(newEnJson) as Record<string, string>

test/unit/scripts/generate-en-meta-json.spec.ts

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@ import { makeEnMetaJson } from '#scripts/i18n-meta/update-en-meta-json'
33

44
describe('Create en.meta.json', () => {
55
it('should handle an empty en.json file', () => {
6-
const newEnJson = {}
76
const oldEnMetaJson = {}
7+
const newEnJson = {}
88

9-
const enMetaJson = makeEnMetaJson(newEnJson, oldEnMetaJson, 'sha-new-12345')
9+
const enMetaJson = makeEnMetaJson(oldEnMetaJson, newEnJson, 'sha-new-12345')
1010
expect(enMetaJson).toEqual({})
1111
})
1212

1313
it('should generate en.meta.json correctly for an initial en.json', () => {
14+
const oldEnMetaJson = {}
1415
const newEnJson = {
1516
tagline: 'npmx - a fast, modern browser for the npm registry',
1617
}
17-
const oldEnMetaJson = {}
1818

19-
const enMetaJson = makeEnMetaJson(newEnJson, oldEnMetaJson, 'sha-new-12345')
19+
const enMetaJson = makeEnMetaJson(oldEnMetaJson, newEnJson, 'sha-new-12345')
2020
expect(enMetaJson).toEqual({
2121
tagline: {
2222
text: 'npmx - a fast, modern browser for the npm registry',
@@ -26,11 +26,6 @@ describe('Create en.meta.json', () => {
2626
})
2727

2828
it('should update existing keys and add new keys with the latest commit hash', () => {
29-
const newEnJson = {
30-
name: 'npmx',
31-
tagline: 'npmx - a fast, modern browser for the npm registry',
32-
description: 'Search, browse, and explore packages with a modern interface.',
33-
}
3429
const oldEnMetaJson = {
3530
name: {
3631
text: 'npmx',
@@ -41,8 +36,13 @@ describe('Create en.meta.json', () => {
4136
commit: 'sha-old-12345',
4237
},
4338
}
39+
const newEnJson = {
40+
name: 'npmx',
41+
tagline: 'npmx - a fast, modern browser for the npm registry',
42+
description: 'Search, browse, and explore packages with a modern interface.',
43+
}
4444

45-
const enMetaJson = makeEnMetaJson(newEnJson, oldEnMetaJson, 'sha-new-12345')
45+
const enMetaJson = makeEnMetaJson(oldEnMetaJson, newEnJson, 'sha-new-12345')
4646
expect(enMetaJson).toEqual({
4747
name: {
4848
text: 'npmx',
@@ -60,18 +60,18 @@ describe('Create en.meta.json', () => {
6060
})
6161

6262
it('should remove keys that are no longer in en.json', () => {
63-
const newEnJson = {
64-
tagline: 'npmx - a fast, modern browser for the npm registry',
65-
}
6663
const oldEnMetaJson = {
6764
tagline: {
6865
text: 'npmx - a fast, modern browser for the npm registry',
6966
commit: 'sha-old-12345',
7067
},
7168
toBeRemoved: { text: 'This will be gone', commit: 'sha-old-12345' },
7269
}
70+
const newEnJson = {
71+
tagline: 'npmx - a fast, modern browser for the npm registry',
72+
}
7373

74-
const enMetaJson = makeEnMetaJson(newEnJson, oldEnMetaJson, 'sha-new-12345')
74+
const enMetaJson = makeEnMetaJson(oldEnMetaJson, newEnJson, 'sha-new-12345')
7575
expect(enMetaJson).toEqual({
7676
tagline: {
7777
text: 'npmx - a fast, modern browser for the npm registry',
@@ -81,14 +81,6 @@ describe('Create en.meta.json', () => {
8181
})
8282

8383
it('should handle complex nested structures', () => {
84-
const newEnJson = {
85-
a: {
86-
b: 'updated-value',
87-
},
88-
c: 'value-c',
89-
d: 'added-value',
90-
}
91-
9284
const oldEnMetaJson = {
9385
a: {
9486
b: {
@@ -105,8 +97,15 @@ describe('Create en.meta.json', () => {
10597
commit: 'sha-new-12345',
10698
},
10799
}
100+
const newEnJson = {
101+
a: {
102+
b: 'updated-value',
103+
},
104+
c: 'value-c',
105+
d: 'added-value',
106+
}
108107

109-
const enMetaJson = makeEnMetaJson(newEnJson, oldEnMetaJson, 'sha-new-12345')
108+
const enMetaJson = makeEnMetaJson(oldEnMetaJson, newEnJson, 'sha-new-12345')
110109
expect(enMetaJson).toEqual({
111110
a: {
112111
b: { text: 'updated-value', commit: 'sha-new-12345' },

0 commit comments

Comments
 (0)