1
1
import PathGenerator from "./controllers/path.ts" ;
2
2
import translate , { getFileErrors } from "./controllers/recurTranslate.ts" ;
3
- import fs from "fs" ;
3
+ import fs , { Dirent } from "fs" ;
4
4
import util from "util" ;
5
5
import path from "path" ;
6
6
import { fileURLToPath } from "url" ;
7
7
import { dirname } from "path" ;
8
8
import OpenAI from "openai" ;
9
+ import { max_trans_num , translationSummaryPrefix } from "./config.ts" ;
9
10
10
11
// Get the directory name of the current module
11
12
const __filename = fileURLToPath ( import . meta. url ) ;
12
13
const __dirname = dirname ( __filename ) ;
13
14
14
15
const readdir = util . promisify ( fs . readdir ) ;
15
- const getDirectories = async source =>
16
+ const getDirectories = async ( source : fs . PathLike ) =>
16
17
( await readdir ( source , { withFileTypes : true } ) )
17
18
. filter ( dirent => dirent . isDirectory ( ) )
18
19
. map ( dirent => dirent . name ) ;
@@ -26,8 +27,6 @@ let failureCount = 0;
26
27
let processedCount = 0 ;
27
28
let failures : { file : string ; error : any } [ ] = [ ] ;
28
29
29
- const max_trans_num = Number ( process . env . MAX_TRANSLATION_NO ) || 5 ;
30
-
31
30
// Function to save summary log - can be called from signal handlers
32
31
async function saveSummaryLog ( ) {
33
32
try {
@@ -115,7 +114,7 @@ Success rate: ${filesToTranslate.length > 0 ? ((successCount / filesToTranslate.
115
114
fs . mkdirSync ( logDir , { recursive : true } ) ;
116
115
}
117
116
118
- const logPath = path . join ( logDir , `translation-summary -${ timestamp } .log` ) ;
117
+ const logPath = path . join ( logDir , `${ translationSummaryPrefix } -${ timestamp } .log` ) ;
119
118
fs . writeFileSync ( logPath , summaryLog ) ;
120
119
console . log (
121
120
`Summary log saved to logs/translation-summary-${ timestamp } .log`
@@ -190,7 +189,7 @@ async function needsTranslation(
190
189
const enStats = await fs . promises . stat ( enFilePath ) ;
191
190
return enStats . mtime > cnStats . mtime ;
192
191
} catch ( error ) {
193
- return true ;
192
+ throw error ;
194
193
}
195
194
}
196
195
@@ -313,7 +312,6 @@ export default async function fancyName(path: string, language: string) {
313
312
if ( result . value . success ) {
314
313
successCount ++ ;
315
314
} else {
316
- failureCount ++ ;
317
315
failures . push ( {
318
316
file : result . value . file ,
319
317
error : result . value . error
@@ -324,7 +322,6 @@ export default async function fancyName(path: string, language: string) {
324
322
}
325
323
} else {
326
324
// This is for Promise rejections (should be rare with our error handling)
327
- failureCount ++ ;
328
325
failures . push ( {
329
326
file : "Unknown file in batch" ,
330
327
error : result . reason
0 commit comments