@@ -7,6 +7,7 @@ const { OpenAI } = require('openai');
7
7
const yargs = require ( 'yargs/yargs' ) ;
8
8
const { hideBin } = require ( 'yargs/helpers' ) ;
9
9
const glob = require ( 'glob' ) ;
10
+
10
11
// Initialize OpenAI client
11
12
const openai = new OpenAI ( {
12
13
apiKey : process . env . OPENAI_API_KEY ,
@@ -68,21 +69,6 @@ async function processFile(filePath) {
68
69
const lintedContent = await lintFileContent ( fileContent ) ;
69
70
fs . writeFileSync ( filePath , lintedContent , 'utf8' ) ;
70
71
console . log ( `File has been linted and updated successfully: ${ filePath } ` ) ;
71
- const tsConfigPath = findTsConfig ( filePath ) ;
72
- try {
73
- const tscOutput = execFileSync (
74
- 'tsc' ,
75
- [ '--noEmit' , '--project' , tsConfigPath ] ,
76
- {
77
- stdio : 'pipe' ,
78
- } ,
79
- ) . toString ( ) ;
80
- console . log ( `TypeScript check passed for ${ filePath } :\n${ tscOutput } ` ) ;
81
- } catch ( error ) {
82
- console . error (
83
- `TypeScript check failed for ${ filePath } :\n${ error . stdout . toString ( ) } ` ,
84
- ) ;
85
- }
86
72
} catch ( error ) {
87
73
console . error ( `Error performing linting on ${ filePath } :` , error . message ) ;
88
74
process . exit ( 1 ) ;
@@ -101,17 +87,32 @@ function findTsConfig(filePath) {
101
87
throw new Error ( 'tsconfig.json not found' ) ;
102
88
}
103
89
90
+ async function processFilesWithConcurrencyLimit ( files , limit ) {
91
+ const results = [ ] ;
92
+ const executing = [ ] ;
93
+
94
+ for ( const file of files ) {
95
+ const p = processFile ( file ) . then ( ( ) => {
96
+ executing . splice ( executing . indexOf ( p ) , 1 ) ;
97
+ } ) ;
98
+ results . push ( p ) ;
99
+ executing . push ( p ) ;
100
+ if ( executing . length >= limit ) {
101
+ await Promise . race ( executing ) ;
102
+ }
103
+ }
104
+
105
+ return Promise . all ( results ) ;
106
+ }
107
+
104
108
async function main ( ) {
105
109
if ( argv . path ) {
106
110
await processFile ( argv . path ) ;
107
111
} else if ( argv . pattern ) {
108
112
console . log ( 'pattern' , argv . pattern ) ;
109
113
try {
110
114
const files = await glob . glob ( argv . pattern ) ;
111
-
112
- for ( const filePath of files ) {
113
- await processFile ( filePath ) ;
114
- }
115
+ await processFilesWithConcurrencyLimit ( files , 3 ) ; // Process files with concurrency limit of 3
115
116
} catch ( err ) {
116
117
console . error ( 'Error finding files:' , err . message ) ;
117
118
process . exit ( 1 ) ;
0 commit comments