@@ -10,6 +10,7 @@ import { ComplexTab, SelectItem } from "@halcyontech/vscode-ibmi-types/api/Custo
10
10
import { IProject } from "../../iproject" ;
11
11
import * as path from "path" ;
12
12
import * as tar from "tar" ;
13
+ import * as fs from 'fs' ;
13
14
14
15
/**
15
16
* Represents the configuration for a migration.
@@ -158,6 +159,11 @@ export async function migrateSource(iProject: IProject, library: string): Promis
158
159
if ( migrationConfig . automaticRename ) {
159
160
progress . report ( { message : l10n . t ( 'Renaming file extensions to be more precise...' ) , increment : increment } ) ;
160
161
await commands . executeCommand ( 'vscode-sourceorbit.autoFix' , workspaceFolder , 'renames' ) ;
162
+
163
+ // Fix file extensions with the format FILE.pgm.CLLE to FILE.PGM.CLLE
164
+ if ( ! migrationConfig . lower ) {
165
+ fixExtensions ( migrationConfig . workspaceFolderUri ! . fsPath ) ;
166
+ }
161
167
}
162
168
163
169
if ( migrationConfig . fixIncludes ) {
@@ -187,6 +193,36 @@ export async function migrateSource(iProject: IProject, library: string): Promis
187
193
}
188
194
}
189
195
196
+ function fixExtensions ( workspaceFolder : string ) : void {
197
+ const filesAndDirs = fs . readdirSync ( workspaceFolder ) ;
198
+
199
+ filesAndDirs . forEach ( ( fileDir : string ) => {
200
+ const path = `${ workspaceFolder } /${ fileDir } ` ;
201
+ const stats = fs . statSync ( path ) ;
202
+
203
+ if ( stats . isDirectory ( ) ) {
204
+ fixExtensions ( path ) ;
205
+ } else {
206
+ const fileSplit = fileDir . split ( '.' ) ;
207
+ const extension = fileSplit . at ( - 1 ) ;
208
+
209
+ if ( fileSplit . length === 3 && extension ?. toUpperCase ( ) === extension ) {
210
+ fileSplit [ 1 ] = fileSplit [ 1 ] . toUpperCase ( ) ;
211
+
212
+ const newFileName = fileSplit . join ( '.' ) ;
213
+
214
+ fs . rename ( path , workspaceFolder + "/" + newFileName , ( error ) => {
215
+ if ( error ) {
216
+ console . error ( `Error fixing extension's case for file: ${ fileDir } ` ) ;
217
+ } else {
218
+ console . log ( `File ${ fileDir } renamed successfully to ${ newFileName } ` ) ;
219
+ }
220
+ } ) ;
221
+ }
222
+ }
223
+ } ) ;
224
+ }
225
+
190
226
/**
191
227
* Get the migration configuration by retrieving the source physical files
192
228
* in a library and prompting for the configuration parameters.
0 commit comments