sloth-d2c-mcp 1.0.4-beta75 → 1.0.4-beta76

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,142 +0,0 @@
1
- /**
2
- * 映射数据存储
3
- */
4
- import { promises as fs } from 'fs';
5
- import * as path from 'path';
6
- /**
7
- * 基于JSON文件的本地存储实现
8
- */
9
- export class LocalMappingStorage {
10
- storageDir;
11
- mappingsFile;
12
- mappings = new Map();
13
- initialized = false;
14
- constructor(baseDir = '.') {
15
- this.storageDir = path.join(baseDir, '.mcp', 'component-mappings');
16
- this.mappingsFile = path.join(this.storageDir, 'mappings.json');
17
- }
18
- /**
19
- * 初始化存储
20
- */
21
- async initialize() {
22
- if (this.initialized)
23
- return;
24
- try {
25
- // 确保目录存在
26
- await fs.mkdir(this.storageDir, { recursive: true });
27
- // 加载现有映射
28
- try {
29
- const data = await fs.readFile(this.mappingsFile, 'utf-8');
30
- const mappingsArray = JSON.parse(data);
31
- for (const mapping of mappingsArray) {
32
- // 转换日期字符串为Date对象
33
- mapping.createdAt = new Date(mapping.createdAt);
34
- mapping.updatedAt = new Date(mapping.updatedAt);
35
- this.mappings.set(mapping.id, mapping);
36
- }
37
- }
38
- catch (error) {
39
- if (error.code !== 'ENOENT') {
40
- console.warn('加载映射文件失败:', error);
41
- }
42
- // 文件不存在是正常的,创建新的
43
- }
44
- this.initialized = true;
45
- }
46
- catch (error) {
47
- console.error('初始化存储失败:', error);
48
- throw error;
49
- }
50
- }
51
- /**
52
- * 持久化映射到文件
53
- */
54
- async persist() {
55
- const mappingsArray = Array.from(this.mappings.values());
56
- await fs.writeFile(this.mappingsFile, JSON.stringify(mappingsArray, null, 2), 'utf-8');
57
- }
58
- async saveMapping(mapping) {
59
- await this.initialize();
60
- this.mappings.set(mapping.id, mapping);
61
- await this.persist();
62
- }
63
- async getMapping(id) {
64
- await this.initialize();
65
- return this.mappings.get(id) || null;
66
- }
67
- async findMappingByFigmaNode(figmaNodeId) {
68
- await this.initialize();
69
- for (const mapping of this.mappings.values()) {
70
- if (mapping.figmaNodeId === figmaNodeId) {
71
- return mapping;
72
- }
73
- }
74
- return null;
75
- }
76
- async listMappings(filter) {
77
- await this.initialize();
78
- let mappings = Array.from(this.mappings.values());
79
- if (filter) {
80
- if (filter.platform) {
81
- mappings = mappings.filter((m) => m.platform === filter.platform);
82
- }
83
- if (filter.figmaFileId) {
84
- mappings = mappings.filter((m) => m.figmaNodeId.startsWith(filter.figmaFileId));
85
- }
86
- if (filter.componentId) {
87
- mappings = mappings.filter((m) => m.componentId === filter.componentId);
88
- }
89
- if (filter.minConfidence !== undefined) {
90
- mappings = mappings.filter((m) => m.confidence >= filter.minConfidence);
91
- }
92
- }
93
- return mappings;
94
- }
95
- async deleteMapping(id) {
96
- await this.initialize();
97
- this.mappings.delete(id);
98
- await this.persist();
99
- }
100
- async updateMapping(id, updates) {
101
- await this.initialize();
102
- const existing = this.mappings.get(id);
103
- if (!existing) {
104
- throw new Error(`映射不存在: ${id}`);
105
- }
106
- const updated = {
107
- ...existing,
108
- ...updates,
109
- updatedAt: new Date(),
110
- };
111
- this.mappings.set(id, updated);
112
- await this.persist();
113
- }
114
- /**
115
- * 清空所有映射
116
- */
117
- async clear() {
118
- await this.initialize();
119
- this.mappings.clear();
120
- await this.persist();
121
- }
122
- /**
123
- * 导出映射数据
124
- */
125
- async export() {
126
- await this.initialize();
127
- return Array.from(this.mappings.values());
128
- }
129
- /**
130
- * 导入映射数据
131
- */
132
- async import(mappings) {
133
- await this.initialize();
134
- for (const mapping of mappings) {
135
- // 确保日期对象正确
136
- mapping.createdAt = new Date(mapping.createdAt);
137
- mapping.updatedAt = new Date(mapping.updatedAt);
138
- this.mappings.set(mapping.id, mapping);
139
- }
140
- await this.persist();
141
- }
142
- }
@@ -1,4 +0,0 @@
1
- /**
2
- * 组件映射系统 - 类型定义
3
- */
4
- export {};