Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix file extension during file source orbit rename #325

Merged
merged 2 commits into from
Jan 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/views/projectExplorer/migrateSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -187,6 +193,31 @@ 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, () => {
});
}
}
});
}

/**
* Get the migration configuration by retrieving the source physical files
* in a library and prompting for the configuration parameters.
Expand Down
Loading