Roo-Code/src/utils/migrateSettings.ts
Steven T. Cramer 8ad4fff0d2
Removed hardcoded filenames to GlobalFileNames constants. (#1904)
* Replace hardcoded custom modes filename with GlobalFileNames constant

* Remove 'cline' prefix from mcpSettings filename

* Use GlobalFileNames.customModes in modes.ts

* replace two more `cline_mcp_settings` with `mcp_settings` in tests.

* feat: add settings file migration for new file naming convention

- Implement migrateSettings function to rename legacy settings files to new format
- Migrate cline_custom_modes.json to new custom modes filename
- Migrate cline_mcp_settings.json to new MCP settings filename
- Add TODO to remove migration code in September 2025 (6 months after implementation)
- Make activate function async to support migration on startup

* Add associated changeset

* removed unused import

* refactor: move migrateSettings to dedicated utility file

- Extract migrateSettings function from extension.ts to src/utils/migrateSettings.ts
- Update extension.ts to import and use the extracted function
- Update tests to use the real implementation
- Improve dependency injection by passing outputChannel as parameter
- Enhance maintainability by isolating temporary migration code (to be removed Sept 2025)

* Update src/extension.ts

---------

Co-authored-by: Matt Rubens <mrubens@users.noreply.github.com>
2025-03-24 13:32:44 -04:00

53 lines
1.9 KiB
TypeScript

import * as vscode from "vscode"
import * as path from "path"
import * as fs from "fs/promises"
import { fileExistsAtPath } from "./fs"
import { GlobalFileNames } from "../shared/globalFileNames"
/**
* Migrates old settings files to new file names
*
* TODO: Remove this migration code in September 2025 (6 months after implementation)
*/
export async function migrateSettings(
context: vscode.ExtensionContext,
outputChannel: vscode.OutputChannel,
): Promise<void> {
// Legacy file names that need to be migrated to the new names in GlobalFileNames
const fileMigrations = [
{ oldName: "cline_custom_modes.json", newName: GlobalFileNames.customModes },
{ oldName: "cline_mcp_settings.json", newName: GlobalFileNames.mcpSettings },
]
try {
const settingsDir = path.join(context.globalStorageUri.fsPath, "settings")
// Check if settings directory exists first
if (!(await fileExistsAtPath(settingsDir))) {
outputChannel.appendLine("No settings directory found, no migrations necessary")
return
}
// Process each file migration
for (const migration of fileMigrations) {
const oldPath = path.join(settingsDir, migration.oldName)
const newPath = path.join(settingsDir, migration.newName)
// Only migrate if old file exists and new file doesn't exist yet
// This ensures we don't overwrite any existing new files
const oldFileExists = await fileExistsAtPath(oldPath)
const newFileExists = await fileExistsAtPath(newPath)
if (oldFileExists && !newFileExists) {
await fs.rename(oldPath, newPath)
outputChannel.appendLine(`Renamed ${migration.oldName} to ${migration.newName}`)
} else {
outputChannel.appendLine(
`Skipping migration of ${migration.oldName} to ${migration.newName}: ${oldFileExists ? "new file already exists" : "old file not found"}`,
)
}
}
} catch (error) {
outputChannel.appendLine(`Error migrating settings files: ${error}`)
}
}