iwgt 2.4.9 → 2.4.11
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.
- package/dist/data/insales-permanent-links.json +68 -0
- package/dist/data/references/commonjs-reference.json +1 -1
- package/dist/data/references/icons-registry.json +39 -24
- package/dist/data/references/javascript-guide.json +436 -0
- package/dist/data/references/liquid-filters.json +1 -1
- package/dist/data/references/liquid-variables.json +1 -1
- package/dist/data/widget-wrapper-and-context.md +647 -0
- package/dist/generators/index.d.ts +23 -0
- package/dist/generators/index.js +91 -1
- package/dist/server-http.js +1 -1
- package/dist/server.js +79 -2
- package/dist/tools/index.d.ts +15 -9
- package/dist/tools/index.js +286 -512
- package/package.json +1 -1
package/dist/generators/index.js
CHANGED
|
@@ -1038,7 +1038,30 @@ export function generateWidgetFiles(config) {
|
|
|
1038
1038
|
files['settings_form.json'] = settingsForm.form;
|
|
1039
1039
|
files['settings_form'] = { settingsCount: settingsForm.count }; // метаинформация
|
|
1040
1040
|
// snippet.liquid
|
|
1041
|
-
|
|
1041
|
+
const liquidCode = generateSnippetLiquid(config);
|
|
1042
|
+
// Валидируем Liquid код на несуществующие фильтры
|
|
1043
|
+
const validation = validateLiquidFilters(liquidCode);
|
|
1044
|
+
if (!validation.isValid) {
|
|
1045
|
+
console.warn('⚠️ Обнаружены несуществующие фильтры в Liquid коде:');
|
|
1046
|
+
validation.errors.forEach(error => {
|
|
1047
|
+
console.warn(` - Строка ${error.line}: фильтр '${error.filter}' - ${error.suggestion}`);
|
|
1048
|
+
});
|
|
1049
|
+
// Автоматически исправляем несуществующие фильтры
|
|
1050
|
+
const fixed = fixInvalidFilters(liquidCode);
|
|
1051
|
+
if (fixed.fixes.length > 0) {
|
|
1052
|
+
console.log('✅ Автоматически исправлены несуществующие фильтры:');
|
|
1053
|
+
fixed.fixes.forEach(fix => {
|
|
1054
|
+
console.log(` - Строка ${fix.line}: ${fix.suggestion}`);
|
|
1055
|
+
});
|
|
1056
|
+
files['snippet.liquid'] = fixed.fixedCode;
|
|
1057
|
+
}
|
|
1058
|
+
else {
|
|
1059
|
+
files['snippet.liquid'] = liquidCode;
|
|
1060
|
+
}
|
|
1061
|
+
}
|
|
1062
|
+
else {
|
|
1063
|
+
files['snippet.liquid'] = liquidCode;
|
|
1064
|
+
}
|
|
1042
1065
|
// snippet.scss
|
|
1043
1066
|
files['snippet.scss'] = generateSnippetScss(config);
|
|
1044
1067
|
// snippet.js
|
|
@@ -1049,4 +1072,71 @@ export function generateWidgetFiles(config) {
|
|
|
1049
1072
|
}
|
|
1050
1073
|
return files;
|
|
1051
1074
|
}
|
|
1075
|
+
/**
|
|
1076
|
+
* Валидирует Liquid код на наличие несуществующих фильтров
|
|
1077
|
+
*/
|
|
1078
|
+
export function validateLiquidFilters(liquidCode) {
|
|
1079
|
+
const invalidFiltersList = [
|
|
1080
|
+
{ name: 't', suggestion: 'Используйте messages или widget_messages для переводов' },
|
|
1081
|
+
{ name: 'translate', suggestion: 'Используйте messages для переводов' },
|
|
1082
|
+
{ name: 'i18n', suggestion: 'Используйте messages для переводов' },
|
|
1083
|
+
{ name: 'l', suggestion: 'Используйте messages для переводов' },
|
|
1084
|
+
{ name: 'localize', suggestion: 'Используйте messages для переводов' },
|
|
1085
|
+
{ name: 'tr', suggestion: 'Используйте messages для переводов' }
|
|
1086
|
+
];
|
|
1087
|
+
const errors = [];
|
|
1088
|
+
const lines = liquidCode.split('\n');
|
|
1089
|
+
lines.forEach((line, lineIndex) => {
|
|
1090
|
+
invalidFiltersList.forEach(invalidFilter => {
|
|
1091
|
+
// Ищем паттерн | filter_name
|
|
1092
|
+
const regex = new RegExp(`\\|\\s*${invalidFilter.name}\\b`, 'g');
|
|
1093
|
+
let match;
|
|
1094
|
+
while ((match = regex.exec(line)) !== null) {
|
|
1095
|
+
errors.push({
|
|
1096
|
+
filter: invalidFilter.name,
|
|
1097
|
+
line: lineIndex + 1,
|
|
1098
|
+
column: match.index + 1,
|
|
1099
|
+
suggestion: invalidFilter.suggestion
|
|
1100
|
+
});
|
|
1101
|
+
}
|
|
1102
|
+
});
|
|
1103
|
+
});
|
|
1104
|
+
return {
|
|
1105
|
+
isValid: errors.length === 0,
|
|
1106
|
+
errors
|
|
1107
|
+
};
|
|
1108
|
+
}
|
|
1109
|
+
/**
|
|
1110
|
+
* Проверяет и исправляет несуществующие фильтры в Liquid коде
|
|
1111
|
+
*/
|
|
1112
|
+
export function fixInvalidFilters(liquidCode) {
|
|
1113
|
+
const fixes = [];
|
|
1114
|
+
let fixedCode = liquidCode;
|
|
1115
|
+
// Исправляем фильтр 't' на messages
|
|
1116
|
+
const tRegex = /\|\s*t\b/g;
|
|
1117
|
+
let match;
|
|
1118
|
+
while ((match = tRegex.exec(fixedCode)) !== null) {
|
|
1119
|
+
const beforeMatch = fixedCode.substring(0, match.index);
|
|
1120
|
+
const afterMatch = fixedCode.substring(match.index + match[0].length);
|
|
1121
|
+
// Определяем, что это за контекст
|
|
1122
|
+
const contextBefore = beforeMatch.substring(Math.max(0, beforeMatch.length - 50));
|
|
1123
|
+
if (contextBefore.includes('widget_messages')) {
|
|
1124
|
+
// Если это в контексте widget_messages, оставляем как есть
|
|
1125
|
+
continue;
|
|
1126
|
+
}
|
|
1127
|
+
else {
|
|
1128
|
+
// Заменяем на messages
|
|
1129
|
+
fixedCode = beforeMatch + '| messages' + afterMatch;
|
|
1130
|
+
fixes.push({
|
|
1131
|
+
filter: 't',
|
|
1132
|
+
line: fixedCode.substring(0, match.index).split('\n').length,
|
|
1133
|
+
suggestion: 'Заменен на messages'
|
|
1134
|
+
});
|
|
1135
|
+
}
|
|
1136
|
+
}
|
|
1137
|
+
return {
|
|
1138
|
+
fixedCode,
|
|
1139
|
+
fixes
|
|
1140
|
+
};
|
|
1141
|
+
}
|
|
1052
1142
|
//# sourceMappingURL=index.js.map
|
package/dist/server-http.js
CHANGED
package/dist/server.js
CHANGED
|
@@ -17,6 +17,7 @@ import liquidFilters from './data/references/liquid-filters.json' with { type: '
|
|
|
17
17
|
import commonjsReference from './data/references/commonjs-reference.json' with { type: 'json' };
|
|
18
18
|
import collectionsMenuPatterns from './data/references/collections-menu-patterns.json' with { type: 'json' };
|
|
19
19
|
import librariesApiReference from './data/references/libraries-api-reference.json' with { type: 'json' };
|
|
20
|
+
import javascriptGuide from './data/references/javascript-guide.json' with { type: 'json' };
|
|
20
21
|
// Импорт модулей
|
|
21
22
|
import { generateWidgetFiles } from './generators/index.js';
|
|
22
23
|
import * as tools from './tools/index.js';
|
|
@@ -26,7 +27,7 @@ export class WidgetServer {
|
|
|
26
27
|
constructor() {
|
|
27
28
|
this.server = new Server({
|
|
28
29
|
name: 'insales-widgets',
|
|
29
|
-
version: '2.4.
|
|
30
|
+
version: '2.4.11',
|
|
30
31
|
}, {
|
|
31
32
|
capabilities: {
|
|
32
33
|
tools: {},
|
|
@@ -238,6 +239,48 @@ export class WidgetServer {
|
|
|
238
239
|
},
|
|
239
240
|
},
|
|
240
241
|
},
|
|
242
|
+
{
|
|
243
|
+
name: 'get_insales_permanent_links',
|
|
244
|
+
description: 'Получить постоянные ссылки InSales для основных разделов сайта (корзина, избранное, сравнение, личный кабинет). Используйте эти ссылки вместо выдуманных типа pages.favorite.url',
|
|
245
|
+
inputSchema: {
|
|
246
|
+
type: 'object',
|
|
247
|
+
properties: {
|
|
248
|
+
search: {
|
|
249
|
+
type: 'string',
|
|
250
|
+
description: 'Поиск ссылок по названию или описанию',
|
|
251
|
+
},
|
|
252
|
+
},
|
|
253
|
+
},
|
|
254
|
+
},
|
|
255
|
+
{
|
|
256
|
+
name: 'get_javascript_guide',
|
|
257
|
+
description: 'Получить руководство по написанию JavaScript для виджетов InSales. Включает принципы, API, паттерны, частые ошибки, отладку и best practices.',
|
|
258
|
+
inputSchema: {
|
|
259
|
+
type: 'object',
|
|
260
|
+
properties: {
|
|
261
|
+
section: {
|
|
262
|
+
type: 'string',
|
|
263
|
+
description: 'Конкретный раздел руководства (principles, global_apis, data_attributes, patterns, common_errors, debugging, linting, checklist, golden_rule)',
|
|
264
|
+
},
|
|
265
|
+
search: {
|
|
266
|
+
type: 'string',
|
|
267
|
+
description: 'Поиск по всему руководству по ключевым словам',
|
|
268
|
+
},
|
|
269
|
+
pattern: {
|
|
270
|
+
type: 'string',
|
|
271
|
+
description: 'ID конкретного паттерна (widget_isolation, declarative_cart, counters, mobile_menu, scroll_animation, products_work, cart_events)',
|
|
272
|
+
},
|
|
273
|
+
error: {
|
|
274
|
+
type: 'string',
|
|
275
|
+
description: 'ID конкретной ошибки (no_widget_isolation, global_selectors, reinventing_wheel, using_imports, return_outside_function, forgot_mobile)',
|
|
276
|
+
},
|
|
277
|
+
api_module: {
|
|
278
|
+
type: 'string',
|
|
279
|
+
description: 'Название модуля API (Cart, Products, EventBus, Shop, ajaxAPI, Template, AjaxSearch)',
|
|
280
|
+
},
|
|
281
|
+
},
|
|
282
|
+
},
|
|
283
|
+
},
|
|
241
284
|
],
|
|
242
285
|
}));
|
|
243
286
|
// Список ресурсов
|
|
@@ -309,6 +352,12 @@ export class WidgetServer {
|
|
|
309
352
|
mimeType: 'application/json',
|
|
310
353
|
description: 'Подробная API документация библиотек: InsalesCutList и другие',
|
|
311
354
|
},
|
|
355
|
+
{
|
|
356
|
+
uri: 'insales://javascript-guide',
|
|
357
|
+
name: 'JavaScript руководство',
|
|
358
|
+
mimeType: 'application/json',
|
|
359
|
+
description: 'Полное руководство по написанию JavaScript для виджетов InSales: принципы, API, паттерны, ошибки, отладка',
|
|
360
|
+
},
|
|
312
361
|
],
|
|
313
362
|
}));
|
|
314
363
|
// Чтение ресурсов
|
|
@@ -407,7 +456,7 @@ export class WidgetServer {
|
|
|
407
456
|
};
|
|
408
457
|
case 'insales://widget-architecture': {
|
|
409
458
|
// Читаем markdown файл с документацией об архитектуре
|
|
410
|
-
const docPath = join(__dirname, '
|
|
459
|
+
const docPath = join(__dirname, 'data/widget-wrapper-and-context.md');
|
|
411
460
|
const content = readFileSync(docPath, 'utf-8');
|
|
412
461
|
return {
|
|
413
462
|
contents: [
|
|
@@ -429,6 +478,16 @@ export class WidgetServer {
|
|
|
429
478
|
},
|
|
430
479
|
],
|
|
431
480
|
};
|
|
481
|
+
case 'insales://javascript-guide':
|
|
482
|
+
return {
|
|
483
|
+
contents: [
|
|
484
|
+
{
|
|
485
|
+
uri,
|
|
486
|
+
mimeType: 'application/json',
|
|
487
|
+
text: JSON.stringify(javascriptGuide, null, 2),
|
|
488
|
+
},
|
|
489
|
+
],
|
|
490
|
+
};
|
|
432
491
|
default:
|
|
433
492
|
throw new Error(`Unknown resource: ${uri}`);
|
|
434
493
|
}
|
|
@@ -521,6 +580,24 @@ export class WidgetServer {
|
|
|
521
580
|
},
|
|
522
581
|
],
|
|
523
582
|
};
|
|
583
|
+
case 'get_insales_permanent_links':
|
|
584
|
+
return {
|
|
585
|
+
content: [
|
|
586
|
+
{
|
|
587
|
+
type: 'text',
|
|
588
|
+
text: JSON.stringify(tools.getInsalesPermanentLinks(args || {}), null, 2),
|
|
589
|
+
},
|
|
590
|
+
],
|
|
591
|
+
};
|
|
592
|
+
case 'get_javascript_guide':
|
|
593
|
+
return {
|
|
594
|
+
content: [
|
|
595
|
+
{
|
|
596
|
+
type: 'text',
|
|
597
|
+
text: JSON.stringify(tools.getJavaScriptGuide(args || {}), null, 2),
|
|
598
|
+
},
|
|
599
|
+
],
|
|
600
|
+
};
|
|
524
601
|
default:
|
|
525
602
|
throw new Error(`Unknown tool: ${name}`);
|
|
526
603
|
}
|
package/dist/tools/index.d.ts
CHANGED
|
@@ -14,22 +14,17 @@ export declare function getAvailableIcons(args?: any): any;
|
|
|
14
14
|
/**
|
|
15
15
|
* Получить информацию о категории виджетов
|
|
16
16
|
*/
|
|
17
|
-
export declare function getCategoryInfo(args
|
|
17
|
+
export declare function getCategoryInfo(args?: any): any;
|
|
18
18
|
/**
|
|
19
19
|
* Получить информацию о библиотеках
|
|
20
20
|
*/
|
|
21
21
|
export declare function getLibrariesInfo(args?: any): any;
|
|
22
|
-
/**
|
|
23
|
-
* Получить справочник Liquid переменных
|
|
24
|
-
*/
|
|
25
|
-
export declare function getLiquidVariables(args?: any): any;
|
|
26
22
|
/**
|
|
27
23
|
* Получить справочник Liquid фильтров
|
|
28
24
|
*/
|
|
29
25
|
export declare function getLiquidFilters(args?: any): any;
|
|
30
26
|
/**
|
|
31
|
-
* Получить справочник CommonJS API
|
|
32
|
-
* ОБНОВЛЕНО: использует commonjs-api-complete.json с акцентом на глобальные переменные
|
|
27
|
+
* Получить справочник CommonJS API
|
|
33
28
|
*/
|
|
34
29
|
export declare function getCommonJSAPI(args?: any): any;
|
|
35
30
|
/**
|
|
@@ -37,8 +32,19 @@ export declare function getCommonJSAPI(args?: any): any;
|
|
|
37
32
|
*/
|
|
38
33
|
export declare function getCollectionsMenuPatterns(args?: any): any;
|
|
39
34
|
/**
|
|
40
|
-
* Получить
|
|
41
|
-
* Объединяет информацию из libraries-registry и libraries-api-reference
|
|
35
|
+
* Получить API библиотек
|
|
42
36
|
*/
|
|
43
37
|
export declare function getLibrariesAPI(args?: any): any;
|
|
38
|
+
/**
|
|
39
|
+
* Получить справочник Liquid переменных
|
|
40
|
+
*/
|
|
41
|
+
export declare function getLiquidVariables(args?: any): any;
|
|
42
|
+
/**
|
|
43
|
+
* Получить постоянные ссылки InSales
|
|
44
|
+
*/
|
|
45
|
+
export declare function getInsalesPermanentLinks(args?: any): any;
|
|
46
|
+
/**
|
|
47
|
+
* Получить руководство по JavaScript для виджетов
|
|
48
|
+
*/
|
|
49
|
+
export declare function getJavaScriptGuide(args?: any): any;
|
|
44
50
|
//# sourceMappingURL=index.d.ts.map
|