MCPcopy
hub / github.com/ZToolsCenter/ZTools / migrateDevPluginNames

Function migrateDevPluginNames

src/main/core/startupDataMigrations.ts:140–179  ·  view source on GitHub ↗

* 将历史记录和固定列表中旧式开发版插件记录迁移为新格式。 * * 旧格式:{ pluginName: 'demo', pluginSource: 'development' } * 新格式:{ pluginName: 'demo__dev' } (移除 pluginSource 字段) * * 迁移策略: * - 若 pluginSource === 'development',将 pluginName 加上 __dev 后缀 * - 否则保持不变,仅移除 pluginSource 字段

()

Source from the content-addressed store, hash-verified

138 * - 否则保持不变,仅移除 pluginSource 字段
139 */
140function migrateDevPluginNames(): void {
141 const targetKeys = ['command-history', 'pinned-commands', 'super-panel-pinned']
142
143 for (const key of targetKeys) {
144 try {
145 const data: any[] = databaseAPI.dbGet(key) || []
146 if (!Array.isArray(data)) continue
147
148 let changed = false
149 for (const item of data) {
150 if (item?.type !== 'plugin') continue
151
152 // 将旧式 { pluginName, pluginSource: 'development' } 迁移为 __dev 后缀
153 // 内置插件(setting、system)在开发模式下以 isDevelopment: true 存储但不加后缀,迁移时跳过
154 // 仅当 pluginName 尚未含 __dev 后缀时才追加,避免新格式数据被重复迁移
155 if (item.pluginSource === 'development' && typeof item.pluginName === 'string') {
156 if (
157 !isBundledInternalPlugin(item.pluginName) &&
158 !isDevelopmentPluginName(item.pluginName)
159 ) {
160 item.pluginName = toDevPluginName(item.pluginName)
161 }
162 changed = true
163 }
164 // 移除 pluginSource 字段(已不再需要)
165 if ('pluginSource' in item) {
166 delete item.pluginSource
167 changed = true
168 }
169 }
170
171 if (changed) {
172 databaseAPI.dbPut(key, data)
173 console.log(`[StartupMigration] 已迁移开发版插件名称: ${key}`)
174 }
175 } catch (error) {
176 console.error(`[StartupMigration] 开发版插件名称迁移失败: ${key}`, error)
177 }
178 }
179}
180
181/**
182 * 将 autoStartPlugin / outKillPlugin / autoDetachPlugin 中旧式对象格式迁移为新式字符串格式。

Callers 1

runStartupDataMigrationsFunction · 0.85

Calls 5

isBundledInternalPluginFunction · 0.85
isDevelopmentPluginNameFunction · 0.85
toDevPluginNameFunction · 0.85
dbGetMethod · 0.45
dbPutMethod · 0.45

Tested by

no test coverage detected