iwgt 2.4.10 → 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/references/commonjs-reference.json +1 -1
- 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/server-http.js +1 -1
- package/dist/server.js +57 -2
- package/dist/tools/index.d.ts +4 -0
- package/dist/tools/index.js +122 -0
- package/package.json +1 -1
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: {},
|
|
@@ -251,6 +252,35 @@ export class WidgetServer {
|
|
|
251
252
|
},
|
|
252
253
|
},
|
|
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
|
+
},
|
|
254
284
|
],
|
|
255
285
|
}));
|
|
256
286
|
// Список ресурсов
|
|
@@ -322,6 +352,12 @@ export class WidgetServer {
|
|
|
322
352
|
mimeType: 'application/json',
|
|
323
353
|
description: 'Подробная API документация библиотек: InsalesCutList и другие',
|
|
324
354
|
},
|
|
355
|
+
{
|
|
356
|
+
uri: 'insales://javascript-guide',
|
|
357
|
+
name: 'JavaScript руководство',
|
|
358
|
+
mimeType: 'application/json',
|
|
359
|
+
description: 'Полное руководство по написанию JavaScript для виджетов InSales: принципы, API, паттерны, ошибки, отладка',
|
|
360
|
+
},
|
|
325
361
|
],
|
|
326
362
|
}));
|
|
327
363
|
// Чтение ресурсов
|
|
@@ -420,7 +456,7 @@ export class WidgetServer {
|
|
|
420
456
|
};
|
|
421
457
|
case 'insales://widget-architecture': {
|
|
422
458
|
// Читаем markdown файл с документацией об архитектуре
|
|
423
|
-
const docPath = join(__dirname, '
|
|
459
|
+
const docPath = join(__dirname, 'data/widget-wrapper-and-context.md');
|
|
424
460
|
const content = readFileSync(docPath, 'utf-8');
|
|
425
461
|
return {
|
|
426
462
|
contents: [
|
|
@@ -442,6 +478,16 @@ export class WidgetServer {
|
|
|
442
478
|
},
|
|
443
479
|
],
|
|
444
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
|
+
};
|
|
445
491
|
default:
|
|
446
492
|
throw new Error(`Unknown resource: ${uri}`);
|
|
447
493
|
}
|
|
@@ -543,6 +589,15 @@ export class WidgetServer {
|
|
|
543
589
|
},
|
|
544
590
|
],
|
|
545
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
|
+
};
|
|
546
601
|
default:
|
|
547
602
|
throw new Error(`Unknown tool: ${name}`);
|
|
548
603
|
}
|
package/dist/tools/index.d.ts
CHANGED
|
@@ -43,4 +43,8 @@ export declare function getLiquidVariables(args?: any): any;
|
|
|
43
43
|
* Получить постоянные ссылки InSales
|
|
44
44
|
*/
|
|
45
45
|
export declare function getInsalesPermanentLinks(args?: any): any;
|
|
46
|
+
/**
|
|
47
|
+
* Получить руководство по JavaScript для виджетов
|
|
48
|
+
*/
|
|
49
|
+
export declare function getJavaScriptGuide(args?: any): any;
|
|
46
50
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/tools/index.js
CHANGED
|
@@ -13,6 +13,7 @@ import commonjsApiComplete from '../data/references/commonjs-api-complete.json'
|
|
|
13
13
|
import collectionsMenuPatterns from '../data/references/collections-menu-patterns.json' with { type: 'json' };
|
|
14
14
|
import librariesApiReference from '../data/references/libraries-api-reference.json' with { type: 'json' };
|
|
15
15
|
import insalesPermanentLinks from '../data/insales-permanent-links.json' with { type: 'json' };
|
|
16
|
+
import javascriptGuide from '../data/references/javascript-guide.json' with { type: 'json' };
|
|
16
17
|
/**
|
|
17
18
|
* Получить список блок-темплейтов с фильтрацией
|
|
18
19
|
*/
|
|
@@ -306,4 +307,125 @@ export function getInsalesPermanentLinks(args = {}) {
|
|
|
306
307
|
notes: data.notes
|
|
307
308
|
};
|
|
308
309
|
}
|
|
310
|
+
/**
|
|
311
|
+
* Получить руководство по JavaScript для виджетов
|
|
312
|
+
*/
|
|
313
|
+
export function getJavaScriptGuide(args = {}) {
|
|
314
|
+
const { section, search, pattern, error, api_module } = args;
|
|
315
|
+
const data = javascriptGuide;
|
|
316
|
+
if (section) {
|
|
317
|
+
const sectionData = data.sections?.[section];
|
|
318
|
+
if (sectionData) {
|
|
319
|
+
return {
|
|
320
|
+
section,
|
|
321
|
+
...sectionData
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
return { error: `Раздел '${section}' не найден` };
|
|
325
|
+
}
|
|
326
|
+
if (pattern) {
|
|
327
|
+
const patterns = data.sections?.patterns?.patterns || [];
|
|
328
|
+
const foundPattern = patterns.find((p) => p.id === pattern);
|
|
329
|
+
if (foundPattern) {
|
|
330
|
+
return {
|
|
331
|
+
pattern: foundPattern
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
return { error: `Паттерн '${pattern}' не найден` };
|
|
335
|
+
}
|
|
336
|
+
if (error) {
|
|
337
|
+
const errors = data.sections?.common_errors?.errors || [];
|
|
338
|
+
const foundError = errors.find((e) => e.id === error);
|
|
339
|
+
if (foundError) {
|
|
340
|
+
return {
|
|
341
|
+
error: foundError
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
return { error: `Ошибка '${error}' не найдена` };
|
|
345
|
+
}
|
|
346
|
+
if (api_module) {
|
|
347
|
+
const modules = data.sections?.global_apis?.modules || [];
|
|
348
|
+
const foundModule = modules.find((m) => m.name === api_module);
|
|
349
|
+
if (foundModule) {
|
|
350
|
+
return {
|
|
351
|
+
module: foundModule
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
return { error: `Модуль API '${api_module}' не найден` };
|
|
355
|
+
}
|
|
356
|
+
if (search) {
|
|
357
|
+
const searchLower = search.toLowerCase();
|
|
358
|
+
const results = {
|
|
359
|
+
sections: {},
|
|
360
|
+
patterns: [],
|
|
361
|
+
errors: [],
|
|
362
|
+
modules: [],
|
|
363
|
+
attributes: []
|
|
364
|
+
};
|
|
365
|
+
// Поиск по разделам
|
|
366
|
+
Object.keys(data.sections || {}).forEach(sectionKey => {
|
|
367
|
+
const section = data.sections[sectionKey];
|
|
368
|
+
if (section.title?.toLowerCase().includes(searchLower) ||
|
|
369
|
+
section.description?.toLowerCase().includes(searchLower)) {
|
|
370
|
+
results.sections[sectionKey] = section;
|
|
371
|
+
}
|
|
372
|
+
});
|
|
373
|
+
// Поиск по паттернам
|
|
374
|
+
const patterns = data.sections?.patterns?.patterns || [];
|
|
375
|
+
patterns.forEach((pattern) => {
|
|
376
|
+
if (pattern.title?.toLowerCase().includes(searchLower) ||
|
|
377
|
+
pattern.description?.toLowerCase().includes(searchLower) ||
|
|
378
|
+
pattern.code?.toLowerCase().includes(searchLower)) {
|
|
379
|
+
results.patterns.push(pattern);
|
|
380
|
+
}
|
|
381
|
+
});
|
|
382
|
+
// Поиск по ошибкам
|
|
383
|
+
const errors = data.sections?.common_errors?.errors || [];
|
|
384
|
+
errors.forEach((error) => {
|
|
385
|
+
if (error.title?.toLowerCase().includes(searchLower) ||
|
|
386
|
+
error.description?.toLowerCase().includes(searchLower)) {
|
|
387
|
+
results.errors.push(error);
|
|
388
|
+
}
|
|
389
|
+
});
|
|
390
|
+
// Поиск по модулям API
|
|
391
|
+
const modules = data.sections?.global_apis?.modules || [];
|
|
392
|
+
modules.forEach((module) => {
|
|
393
|
+
if (module.name?.toLowerCase().includes(searchLower) ||
|
|
394
|
+
module.description?.toLowerCase().includes(searchLower)) {
|
|
395
|
+
results.modules.push(module);
|
|
396
|
+
}
|
|
397
|
+
});
|
|
398
|
+
// Поиск по data-атрибутам
|
|
399
|
+
const attributes = data.sections?.data_attributes?.attributes || [];
|
|
400
|
+
attributes.forEach((attr) => {
|
|
401
|
+
if (attr.name?.toLowerCase().includes(searchLower) ||
|
|
402
|
+
attr.description?.toLowerCase().includes(searchLower)) {
|
|
403
|
+
results.attributes.push(attr);
|
|
404
|
+
}
|
|
405
|
+
});
|
|
406
|
+
return {
|
|
407
|
+
search,
|
|
408
|
+
total: Object.keys(results.sections).length + results.patterns.length +
|
|
409
|
+
results.errors.length + results.modules.length + results.attributes.length,
|
|
410
|
+
results
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
return {
|
|
414
|
+
title: data.title,
|
|
415
|
+
description: data.description,
|
|
416
|
+
version: data.version,
|
|
417
|
+
sections: Object.keys(data.sections || {}),
|
|
418
|
+
available_sections: {
|
|
419
|
+
principles: "Основные принципы написания JavaScript",
|
|
420
|
+
global_apis: "Глобальные API (Cart, Products, EventBus, etc.)",
|
|
421
|
+
data_attributes: "Data-атрибуты CommonJS",
|
|
422
|
+
patterns: "Паттерны и примеры кода",
|
|
423
|
+
common_errors: "Частые ошибки и их исправление",
|
|
424
|
+
debugging: "Способы отладки",
|
|
425
|
+
linting: "Линтер и проверка кода",
|
|
426
|
+
checklist: "Чеклист перед завершением",
|
|
427
|
+
golden_rule: "Золотое правило"
|
|
428
|
+
}
|
|
429
|
+
};
|
|
430
|
+
}
|
|
309
431
|
//# sourceMappingURL=index.js.map
|