From 34c70db2334a099596e2d2f7759220fa3409ac76 Mon Sep 17 00:00:00 2001 From: Irfan Sharif Date: Tue, 23 Jan 2024 10:10:48 -0500 Subject: [PATCH 1/2] Fix file extension during file source orbit rename Signed-off-by: Irfan Sharif --- src/views/projectExplorer/migrateSource.ts | 36 ++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/views/projectExplorer/migrateSource.ts b/src/views/projectExplorer/migrateSource.ts index 3e5c4dc7..f86734c9 100644 --- a/src/views/projectExplorer/migrateSource.ts +++ b/src/views/projectExplorer/migrateSource.ts @@ -10,6 +10,7 @@ import { ComplexTab, SelectItem } from "@halcyontech/vscode-ibmi-types/api/Custo import { IProject } from "../../iproject"; import * as path from "path"; import * as tar from "tar"; +import * as fs from 'fs'; /** * Represents the configuration for a migration. @@ -158,6 +159,11 @@ export async function migrateSource(iProject: IProject, library: string): Promis if (migrationConfig.automaticRename) { progress.report({ message: l10n.t('Renaming file extensions to be more precise...'), increment: increment }); await commands.executeCommand('vscode-sourceorbit.autoFix', workspaceFolder, 'renames'); + + // Fix file extensions with the format FILE.pgm.CLLE to FILE.PGM.CLLE + if (!migrationConfig.lower) { + fixExtensions(migrationConfig.workspaceFolderUri!.fsPath); + } } if (migrationConfig.fixIncludes) { @@ -187,6 +193,36 @@ export async function migrateSource(iProject: IProject, library: string): Promis } } +function fixExtensions(workspaceFolder: string): void { + const filesAndDirs = fs.readdirSync(workspaceFolder); + + filesAndDirs.forEach((fileDir: string) => { + const path = `${workspaceFolder}/${fileDir}`; + const stats = fs.statSync(path); + + if (stats.isDirectory()) { + fixExtensions(path); + } else { + const fileSplit = fileDir.split('.'); + const extension = fileSplit.at(-1); + + if (fileSplit.length === 3 && extension?.toUpperCase() === extension) { + fileSplit[1] = fileSplit[1].toUpperCase(); + + const newFileName = fileSplit.join('.'); + + fs.rename(path, workspaceFolder + "/" + newFileName, (error) => { + if (error) { + console.error(`Error fixing extension's case for file: ${fileDir}`); + } else { + console.log(`File ${fileDir} renamed successfully to ${newFileName}`); + } + }); + } + } + }); +} + /** * Get the migration configuration by retrieving the source physical files * in a library and prompting for the configuration parameters. From 1e47a9fb4a35996581aec5caceb40c71360948e2 Mon Sep 17 00:00:00 2001 From: Irfan Sharif Date: Wed, 24 Jan 2024 10:26:39 -0500 Subject: [PATCH 2/2] Remove error logs Signed-off-by: Irfan Sharif --- src/views/projectExplorer/migrateSource.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/views/projectExplorer/migrateSource.ts b/src/views/projectExplorer/migrateSource.ts index f86734c9..8ebadb1a 100644 --- a/src/views/projectExplorer/migrateSource.ts +++ b/src/views/projectExplorer/migrateSource.ts @@ -211,12 +211,7 @@ function fixExtensions(workspaceFolder: string): void { const newFileName = fileSplit.join('.'); - fs.rename(path, workspaceFolder + "/" + newFileName, (error) => { - if (error) { - console.error(`Error fixing extension's case for file: ${fileDir}`); - } else { - console.log(`File ${fileDir} renamed successfully to ${newFileName}`); - } + fs.rename(path, workspaceFolder + "/" + newFileName, () => { }); } }