@@ -2,28 +2,15 @@ import { execSync } from 'node:child_process'
22import * as fs from 'node:fs'
33import type { EnJson , EnMetaJson } from './types.d.ts'
44
5- export function git ( command : string ) {
6- try {
7- return execSync ( `git ${ command } ` , { encoding : 'utf-8' } ) . trim ( )
8- } catch {
9- console . error ( `🚨 Git command failed: git ${ command } ` )
10- return null
11- }
12- }
13-
14- function readJson < T > ( filePath : string ) : T {
15- return JSON . parse ( fs . readFileSync ( filePath , 'utf-8' ) ) as T
16- }
17-
185export function getCurrentCommitHash ( ) {
196 return git ( 'rev-parse HEAD' )
207}
218
229export function getNewEnJson ( enJsonPath : string ) : EnJson {
2310 if ( fs . existsSync ( enJsonPath ) ) {
24- return readJson < EnMetaJson > ( enJsonPath )
11+ return readJson < EnJson > ( enJsonPath )
2512 }
26- return { } as EnMetaJson
13+ return { } as EnJson
2714}
2815
2916export function getOldEnMetaJson ( enMetaJsonPath : string ) : EnMetaJson {
@@ -33,11 +20,6 @@ export function getOldEnMetaJson(enMetaJsonPath: string): EnMetaJson {
3320 return { } as EnMetaJson
3421}
3522
36- function omitMeta < T extends object > ( obj : T ) : Omit < T , '$meta' > {
37- const { $meta : _ , ...rest } = obj as T & { $meta ?: unknown }
38- return rest
39- }
40-
4123export function checkTranslationChanges ( oldMeta : EnMetaJson , newMeta : EnMetaJson ) : boolean {
4224 const oldObj = omitMeta ( oldMeta )
4325 const newObj = omitMeta ( newMeta )
@@ -53,6 +35,24 @@ export function createUpdatedEnMetaJson(
5335 last_updated_commit : commitHash ,
5436 updated_at : new Date ( ) . toISOString ( ) ,
5537 } ,
56- ...content ,
38+ ...omitMeta ( content ) ,
5739 } as EnMetaJson
5840}
41+
42+ function git ( command : string ) {
43+ try {
44+ return execSync ( `git ${ command } ` , { encoding : 'utf-8' } ) . trim ( )
45+ } catch {
46+ console . error ( `🚨 Git command failed: git ${ command } ` )
47+ return null
48+ }
49+ }
50+
51+ function readJson < T > ( filePath : string ) : T {
52+ return JSON . parse ( fs . readFileSync ( filePath , 'utf-8' ) ) as T
53+ }
54+
55+ function omitMeta < T extends object > ( obj : T ) : Omit < T , '$meta' > {
56+ const { $meta : _ , ...rest } = obj as T & { $meta ?: unknown }
57+ return rest
58+ }
0 commit comments