migrateSettings.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import * as vscode from "vscode"
  2. import * as path from "path"
  3. import * as fs from "fs/promises"
  4. import { fileExistsAtPath } from "./fs"
  5. import { GlobalFileNames } from "../shared/globalFileNames"
  6. /**
  7. * Migrates old settings files to new file names
  8. *
  9. * TODO: Remove this migration code in September 2025 (6 months after implementation)
  10. */
  11. export async function migrateSettings(
  12. context: vscode.ExtensionContext,
  13. outputChannel: vscode.OutputChannel,
  14. ): Promise<void> {
  15. // Legacy file names that need to be migrated to the new names in GlobalFileNames
  16. const fileMigrations = [
  17. { oldName: "cline_custom_modes.json", newName: GlobalFileNames.customModes },
  18. { oldName: "cline_mcp_settings.json", newName: GlobalFileNames.mcpSettings },
  19. ]
  20. try {
  21. const settingsDir = path.join(context.globalStorageUri.fsPath, "settings")
  22. // Check if settings directory exists first
  23. if (!(await fileExistsAtPath(settingsDir))) {
  24. outputChannel.appendLine("No settings directory found, no migrations necessary")
  25. return
  26. }
  27. // Process each file migration
  28. for (const migration of fileMigrations) {
  29. const oldPath = path.join(settingsDir, migration.oldName)
  30. const newPath = path.join(settingsDir, migration.newName)
  31. // Only migrate if old file exists and new file doesn't exist yet
  32. // This ensures we don't overwrite any existing new files
  33. const oldFileExists = await fileExistsAtPath(oldPath)
  34. const newFileExists = await fileExistsAtPath(newPath)
  35. if (oldFileExists && !newFileExists) {
  36. await fs.rename(oldPath, newPath)
  37. outputChannel.appendLine(`Renamed ${migration.oldName} to ${migration.newName}`)
  38. } else {
  39. outputChannel.appendLine(
  40. `Skipping migration of ${migration.oldName} to ${migration.newName}: ${oldFileExists ? "new file already exists" : "old file not found"}`,
  41. )
  42. }
  43. }
  44. } catch (error) {
  45. outputChannel.appendLine(`Error migrating settings files: ${error}`)
  46. }
  47. }