Skip to content

Commit 34c70db

Browse files
Irfan SharifIrfan Sharif
Irfan Sharif
authored and
Irfan Sharif
committed
Fix file extension during file source orbit rename
Signed-off-by: Irfan Sharif <[email protected]>
1 parent a41ffc4 commit 34c70db

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

src/views/projectExplorer/migrateSource.ts

+36
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { ComplexTab, SelectItem } from "@halcyontech/vscode-ibmi-types/api/Custo
1010
import { IProject } from "../../iproject";
1111
import * as path from "path";
1212
import * as tar from "tar";
13+
import * as fs from 'fs';
1314

1415
/**
1516
* Represents the configuration for a migration.
@@ -158,6 +159,11 @@ export async function migrateSource(iProject: IProject, library: string): Promis
158159
if (migrationConfig.automaticRename) {
159160
progress.report({ message: l10n.t('Renaming file extensions to be more precise...'), increment: increment });
160161
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+
}
161167
}
162168

163169
if (migrationConfig.fixIncludes) {
@@ -187,6 +193,36 @@ export async function migrateSource(iProject: IProject, library: string): Promis
187193
}
188194
}
189195

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+
190226
/**
191227
* Get the migration configuration by retrieving the source physical files
192228
* in a library and prompting for the configuration parameters.

0 commit comments

Comments
 (0)