m8-mcp-server 1.0.6 → 1.0.8

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.
Files changed (75) hide show
  1. package/dist/cli.d.ts +1 -1
  2. package/dist/cli.js +1 -13
  3. package/dist/docs/apis.d.ts +1 -1
  4. package/dist/docs/apis.js +9 -326
  5. package/dist/docs/components.d.ts +1 -1
  6. package/dist/docs/components.js +2 -186
  7. package/dist/docs/index.d.ts +1 -1
  8. package/dist/docs/index.js +18 -177
  9. package/dist/docs/loader.d.ts +1 -1
  10. package/dist/docs/loader.js +1 -165
  11. package/dist/docs/search.d.ts +1 -1
  12. package/dist/docs/search.js +2 -196
  13. package/dist/docs/standards.d.ts +1 -1
  14. package/dist/docs/standards.js +3 -134
  15. package/dist/docs/utils.d.ts +1 -1
  16. package/dist/docs/utils.js +3 -129
  17. package/dist/generator/card-component.d.ts +55 -0
  18. package/dist/generator/card-component.d.ts.map +1 -0
  19. package/dist/generator/card-component.js +262 -0
  20. package/dist/generator/header.d.ts +1 -1
  21. package/dist/generator/header.js +3 -83
  22. package/dist/generator/index.d.ts +1 -1
  23. package/dist/generator/index.js +283 -648
  24. package/dist/generator/vue-template.d.ts +1 -1
  25. package/dist/generator/vue-template.js +336 -1016
  26. package/dist/index.d.ts +1 -1
  27. package/dist/index.js +1 -73
  28. package/dist/recommend/index.d.ts +1 -1
  29. package/dist/recommend/index.js +2 -412
  30. package/dist/tools/generate-card-component.d.ts +16 -0
  31. package/dist/tools/generate-card-component.d.ts.map +1 -0
  32. package/dist/tools/generate-card-component.js +4 -0
  33. package/dist/tools/generate-code.d.ts +1 -1
  34. package/dist/tools/generate-code.js +39 -211
  35. package/dist/tools/get-api-info.d.ts +1 -1
  36. package/dist/tools/get-api-info.js +1 -65
  37. package/dist/tools/get-coding-standard.d.ts +1 -1
  38. package/dist/tools/get-coding-standard.js +1 -66
  39. package/dist/tools/get-component-info.d.ts +1 -1
  40. package/dist/tools/get-component-info.js +1 -60
  41. package/dist/tools/get-util-info.d.ts +1 -1
  42. package/dist/tools/get-util-info.js +1 -65
  43. package/dist/tools/index.d.ts +2 -1
  44. package/dist/tools/index.d.ts.map +1 -1
  45. package/dist/tools/index.js +3 -101
  46. package/dist/tools/recommend-solution.d.ts +1 -1
  47. package/dist/tools/recommend-solution.js +1 -67
  48. package/dist/tools/search-docs.d.ts +1 -1
  49. package/dist/tools/search-docs.js +1 -71
  50. package/dist/types/index.d.ts +74 -1
  51. package/dist/types/index.d.ts.map +1 -1
  52. package/dist/types/index.js +0 -8
  53. package/package.json +4 -2
  54. package/dist/cli.js.map +0 -1
  55. package/dist/docs/apis.js.map +0 -1
  56. package/dist/docs/components.js.map +0 -1
  57. package/dist/docs/index.js.map +0 -1
  58. package/dist/docs/loader.js.map +0 -1
  59. package/dist/docs/search.js.map +0 -1
  60. package/dist/docs/standards.js.map +0 -1
  61. package/dist/docs/utils.js.map +0 -1
  62. package/dist/generator/header.js.map +0 -1
  63. package/dist/generator/index.js.map +0 -1
  64. package/dist/generator/vue-template.js.map +0 -1
  65. package/dist/index.js.map +0 -1
  66. package/dist/recommend/index.js.map +0 -1
  67. package/dist/tools/generate-code.js.map +0 -1
  68. package/dist/tools/get-api-info.js.map +0 -1
  69. package/dist/tools/get-coding-standard.js.map +0 -1
  70. package/dist/tools/get-component-info.js.map +0 -1
  71. package/dist/tools/get-util-info.js.map +0 -1
  72. package/dist/tools/index.js.map +0 -1
  73. package/dist/tools/recommend-solution.js.map +0 -1
  74. package/dist/tools/search-docs.js.map +0 -1
  75. package/dist/types/index.js.map +0 -1
@@ -1,177 +1,18 @@
1
- /**
2
- * Document Manager 主入口
3
- * @作者 li peng
4
- * @创建时间 2024-12-29
5
- * @描述 文档管理器,提供文档加载、搜索和查询功能
6
- */
7
- import { loadAllDocuments } from './loader.js';
8
- import { searchDocs, formatSearchResults } from './search.js';
9
- import { getComponentInfo, formatComponentInfo, findSimilarComponents, getAllComponents } from './components.js';
10
- import { getApiInfo, formatApiInfo, loadEjsApis, getAvailableModules } from './apis.js';
11
- import { getUtilInfo, formatUtilInfo, getAvailableCategories } from './utils.js';
12
- import { getCodingStandard, formatCodingStandard, getAvailableStandardTypes } from './standards.js';
13
- /**
14
- * 文档管理器类
15
- */
16
- export class DocumentManager {
17
- index;
18
- initialized = false;
19
- constructor() {
20
- this.index = {
21
- components: new Map(),
22
- apis: new Map(),
23
- utils: new Map(),
24
- standards: new Map(),
25
- cases: []
26
- };
27
- }
28
- /**
29
- * 初始化文档管理器,加载所有文档
30
- */
31
- async initialize() {
32
- if (this.initialized)
33
- return;
34
- try {
35
- // 加载文档资源
36
- this.index = loadAllDocuments();
37
- // 加载内置的 EJS API
38
- this.index.apis = loadEjsApis();
39
- this.initialized = true;
40
- // MCP 协议不允许输出非 JSON 内容,移除 console.log
41
- }
42
- catch {
43
- // 初始化失败,静默抛出错误
44
- throw new Error('Document manager initialization failed');
45
- }
46
- }
47
- /**
48
- * 搜索文档
49
- */
50
- searchDocs(query, options) {
51
- return searchDocs(this.index, query, options);
52
- }
53
- /**
54
- * 搜索文档并格式化结果
55
- */
56
- searchDocsFormatted(query, options) {
57
- const results = this.searchDocs(query, options);
58
- return formatSearchResults(results);
59
- }
60
- /**
61
- * 获取组件信息
62
- */
63
- getComponentInfo(name) {
64
- return getComponentInfo(this.index.components, name);
65
- }
66
- /**
67
- * 获取组件信息并格式化
68
- */
69
- getComponentInfoFormatted(name) {
70
- const doc = this.getComponentInfo(name);
71
- if (!doc) {
72
- const similar = findSimilarComponents(this.index.components, name);
73
- if (similar.length > 0) {
74
- return `组件 "${name}" 不存在。\n\n您是否在找:\n${similar.map(s => `- ${s}`).join('\n')}`;
75
- }
76
- return `组件 "${name}" 不存在。请检查组件名称是否正确。`;
77
- }
78
- return formatComponentInfo(doc);
79
- }
80
- /**
81
- * 获取所有组件列表
82
- */
83
- getAllComponents() {
84
- return getAllComponents(this.index.components);
85
- }
86
- /**
87
- * 获取 API 信息
88
- */
89
- getApiInfo(moduleName, methodName) {
90
- return getApiInfo(moduleName);
91
- }
92
- /**
93
- * 获取 API 信息并格式化
94
- */
95
- getApiInfoFormatted(moduleName, methodName) {
96
- const api = getApiInfo(moduleName);
97
- if (!api) {
98
- const available = getAvailableModules();
99
- return `API 模块 "${moduleName}" 不存在。\n\n可用模块:\n${available.map(m => `- ejs.${m}`).join('\n')}`;
100
- }
101
- return formatApiInfo(api, methodName);
102
- }
103
- /**
104
- * 获取可用的 API 模块
105
- */
106
- getAvailableApiModules() {
107
- return getAvailableModules();
108
- }
109
- /**
110
- * 获取 Util 信息
111
- */
112
- getUtilInfo(category, methodName) {
113
- return getUtilInfo(this.index.utils, category);
114
- }
115
- /**
116
- * 获取 Util 信息并格式化
117
- */
118
- getUtilInfoFormatted(category, methodName) {
119
- const doc = getUtilInfo(this.index.utils, category);
120
- if (!doc) {
121
- const available = getAvailableCategories(this.index.utils);
122
- return `Util 分类 "${category}" 不存在。\n\n可用分类:\n${available.map(c => `- ${c}`).join('\n')}`;
123
- }
124
- return formatUtilInfo(doc, methodName);
125
- }
126
- /**
127
- * 获取可用的 Util 分类
128
- */
129
- getAvailableUtilCategories() {
130
- return getAvailableCategories(this.index.utils);
131
- }
132
- /**
133
- * 获取编码规范
134
- */
135
- getCodingStandard(type, keyword) {
136
- return getCodingStandard(this.index.standards, type);
137
- }
138
- /**
139
- * 获取编码规范并格式化
140
- */
141
- getCodingStandardFormatted(type, keyword) {
142
- const doc = getCodingStandard(this.index.standards, type);
143
- if (!doc) {
144
- const available = getAvailableStandardTypes(this.index.standards);
145
- return `编码规范类型 "${type}" 不存在。\n\n可用类型:\n${available.map(t => `- ${t}`).join('\n')}\n- all (获取所有规范)`;
146
- }
147
- return formatCodingStandard(doc, keyword);
148
- }
149
- /**
150
- * 获取可用的规范类型
151
- */
152
- getAvailableStandardTypes() {
153
- return getAvailableStandardTypes(this.index.standards);
154
- }
155
- /**
156
- * 获取文档索引(用于测试)
157
- */
158
- getIndex() {
159
- return this.index;
160
- }
161
- /**
162
- * 检查是否已初始化
163
- */
164
- isInitialized() {
165
- return this.initialized;
166
- }
167
- }
168
- // 导出单例实例
169
- export const documentManager = new DocumentManager();
170
- // 导出子模块
171
- export * from './loader.js';
172
- export * from './search.js';
173
- export * from './components.js';
174
- export * from './apis.js';
175
- export * from './utils.js';
176
- export * from './standards.js';
177
- //# sourceMappingURL=index.js.map
1
+ import{loadAllDocuments as p}from"./loader.js";import{searchDocs as m,formatSearchResults as c}from"./search.js";import{getComponentInfo as u,formatComponentInfo as f,findSimilarComponents as h,getAllComponents as x}from"./components.js";import{getApiInfo as o,formatApiInfo as I,loadEjsApis as A,getAvailableModules as s}from"./apis.js";import{getUtilInfo as a,formatUtilInfo as C,getAvailableCategories as d}from"./utils.js";import{getCodingStandard as l,formatCodingStandard as D,getAvailableStandardTypes as g}from"./standards.js";export*from"./loader.js";export*from"./search.js";export*from"./components.js";export*from"./apis.js";export*from"./utils.js";export*from"./standards.js";class S{index;initialized=!1;constructor(){this.index={components:new Map,apis:new Map,utils:new Map,standards:new Map,cases:[]}}async initialize(){if(!this.initialized)try{this.index=p(),this.index.apis=A(),this.initialized=!0}catch{throw new Error("Document manager initialization failed")}}searchDocs(t,n){return m(this.index,t,n)}searchDocsFormatted(t,n){const i=this.searchDocs(t,n);return c(i)}getComponentInfo(t){return u(this.index.components,t)}getComponentInfoFormatted(t){const n=this.getComponentInfo(t);if(!n){const i=h(this.index.components,t);return i.length>0?`\u7EC4\u4EF6 "${t}" \u4E0D\u5B58\u5728\u3002
2
+
3
+ \u60A8\u662F\u5426\u5728\u627E:
4
+ ${i.map(e=>`- ${e}`).join(`
5
+ `)}`:`\u7EC4\u4EF6 "${t}" \u4E0D\u5B58\u5728\u3002\u8BF7\u68C0\u67E5\u7EC4\u4EF6\u540D\u79F0\u662F\u5426\u6B63\u786E\u3002`}return f(n)}getAllComponents(){return x(this.index.components)}getApiInfo(t,n){return o(t)}getApiInfoFormatted(t,n){const i=o(t);if(!i){const e=s();return`API \u6A21\u5757 "${t}" \u4E0D\u5B58\u5728\u3002
6
+
7
+ \u53EF\u7528\u6A21\u5757:
8
+ ${e.map(r=>`- ejs.${r}`).join(`
9
+ `)}`}return I(i,n)}getAvailableApiModules(){return s()}getUtilInfo(t,n){return a(this.index.utils,t)}getUtilInfoFormatted(t,n){const i=a(this.index.utils,t);if(!i){const e=d(this.index.utils);return`Util \u5206\u7C7B "${t}" \u4E0D\u5B58\u5728\u3002
10
+
11
+ \u53EF\u7528\u5206\u7C7B:
12
+ ${e.map(r=>`- ${r}`).join(`
13
+ `)}`}return C(i,n)}getAvailableUtilCategories(){return d(this.index.utils)}getCodingStandard(t,n){return l(this.index.standards,t)}getCodingStandardFormatted(t,n){const i=l(this.index.standards,t);if(!i){const e=g(this.index.standards);return`\u7F16\u7801\u89C4\u8303\u7C7B\u578B "${t}" \u4E0D\u5B58\u5728\u3002
14
+
15
+ \u53EF\u7528\u7C7B\u578B:
16
+ ${e.map(r=>`- ${r}`).join(`
17
+ `)}
18
+ - all (\u83B7\u53D6\u6240\u6709\u89C4\u8303)`}return D(i,n)}getAvailableStandardTypes(){return g(this.index.standards)}getIndex(){return this.index}isInitialized(){return this.initialized}}const F=new S;export{S as DocumentManager,F as documentManager};
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * 文档加载器
3
3
  * @作者 li peng
4
- * @创建时间 2024-12-29
4
+ * @创建时间 2025-12-20
5
5
  * @描述 负责加载编码规范、组件文档、工具文档和典型案例
6
6
  */
7
7
  import type { CodingStandardDoc, UIComponentDoc, UtilDoc, CaseDoc, DocumentIndex } from '../types/index.js';
@@ -1,165 +1 @@
1
- /**
2
- * 文档加载器
3
- * @作者 li peng
4
- * @创建时间 2024-12-29
5
- * @描述 负责加载编码规范、组件文档、工具文档和典型案例
6
- */
7
- import { readFileSync, existsSync, readdirSync } from 'fs';
8
- import { join, dirname } from 'path';
9
- import { fileURLToPath } from 'url';
10
- // 获取当前模块的目录路径
11
- const __filename = fileURLToPath(import.meta.url);
12
- const __dirname = dirname(__filename);
13
- // 资源目录路径
14
- const RESOURCES_DIR = join(__dirname, '../../resources');
15
- /**
16
- * 读取 JSON 文件
17
- * @param filePath 文件路径
18
- * @returns 解析后的 JSON 对象
19
- */
20
- function readJsonFile(filePath) {
21
- try {
22
- if (!existsSync(filePath)) {
23
- // 文件不存在,静默返回 null
24
- return null;
25
- }
26
- const content = readFileSync(filePath, 'utf-8');
27
- return JSON.parse(content);
28
- }
29
- catch {
30
- // 读取失败,静默返回 null(MCP 协议不允许输出非 JSON 内容)
31
- return null;
32
- }
33
- }
34
- /**
35
- * 加载编码规范文档
36
- * @returns 编码规范文档映射
37
- */
38
- export function loadStandards() {
39
- const standards = new Map();
40
- const standardsDir = join(RESOURCES_DIR, 'standards');
41
- if (!existsSync(standardsDir)) {
42
- // 目录不存在,静默返回空 Map
43
- return standards;
44
- }
45
- const files = readdirSync(standardsDir).filter(f => f.endsWith('.json') && f !== 'index.json');
46
- for (const file of files) {
47
- const filePath = join(standardsDir, file);
48
- const doc = readJsonFile(filePath);
49
- if (doc) {
50
- standards.set(doc.category, doc);
51
- }
52
- }
53
- return standards;
54
- }
55
- /**
56
- * 加载 UI 组件文档
57
- * @returns 组件文档映射
58
- */
59
- export function loadComponents() {
60
- const components = new Map();
61
- const componentsDir = join(RESOURCES_DIR, 'components');
62
- if (!existsSync(componentsDir)) {
63
- // 目录不存在,静默返回空 Map
64
- return components;
65
- }
66
- const files = readdirSync(componentsDir).filter(f => f.endsWith('.json') && f !== 'index.json');
67
- for (const file of files) {
68
- const filePath = join(componentsDir, file);
69
- const doc = readJsonFile(filePath);
70
- if (doc) {
71
- // 同时用 id 和 name 作为键,方便查找
72
- components.set(doc.id, doc);
73
- components.set(doc.name, doc);
74
- // 不带 em- 前缀的名称也作为键
75
- if (doc.name.startsWith('em-')) {
76
- components.set(doc.name.replace('em-', ''), doc);
77
- }
78
- }
79
- }
80
- return components;
81
- }
82
- /**
83
- * 加载 Util 工具文档
84
- * @returns 工具文档映射
85
- */
86
- export function loadUtils() {
87
- const utils = new Map();
88
- const utilsDir = join(RESOURCES_DIR, 'utils');
89
- if (!existsSync(utilsDir)) {
90
- // 目录不存在,静默返回空 Map
91
- return utils;
92
- }
93
- const files = readdirSync(utilsDir).filter(f => f.endsWith('.json') && f !== 'index.json');
94
- for (const file of files) {
95
- const filePath = join(utilsDir, file);
96
- const doc = readJsonFile(filePath);
97
- if (doc) {
98
- utils.set(doc.category, doc);
99
- }
100
- }
101
- return utils;
102
- }
103
- /**
104
- * 加载典型案例文档
105
- * @returns 案例文档数组
106
- */
107
- export function loadCases() {
108
- const cases = [];
109
- const casesDir = join(RESOURCES_DIR, 'cases');
110
- if (!existsSync(casesDir)) {
111
- // 目录不存在,静默返回空数组
112
- return cases;
113
- }
114
- const files = readdirSync(casesDir).filter(f => f.endsWith('.json') && f !== 'index.json');
115
- for (const file of files) {
116
- const filePath = join(casesDir, file);
117
- const doc = readJsonFile(filePath);
118
- if (doc) {
119
- cases.push(doc);
120
- }
121
- }
122
- return cases;
123
- }
124
- /**
125
- * 加载所有文档并构建索引
126
- * @returns 文档索引
127
- */
128
- export function loadAllDocuments() {
129
- return {
130
- standards: loadStandards(),
131
- components: loadComponents(),
132
- utils: loadUtils(),
133
- apis: new Map(), // API 文档暂时为空,后续可扩展
134
- cases: loadCases()
135
- };
136
- }
137
- /**
138
- * 获取所有已加载的编码规范类型
139
- * @param standards 编码规范映射
140
- * @returns 规范类型数组
141
- */
142
- export function getStandardTypes(standards) {
143
- return Array.from(standards.keys());
144
- }
145
- /**
146
- * 获取所有已加载的组件名称
147
- * @param components 组件映射
148
- * @returns 组件名称数组(去重)
149
- */
150
- export function getComponentNames(components) {
151
- const names = new Set();
152
- for (const doc of components.values()) {
153
- names.add(doc.name);
154
- }
155
- return Array.from(names);
156
- }
157
- /**
158
- * 获取所有已加载的 Util 分类
159
- * @param utils 工具映射
160
- * @returns 分类数组
161
- */
162
- export function getUtilCategories(utils) {
163
- return Array.from(utils.keys());
164
- }
165
- //# sourceMappingURL=loader.js.map
1
+ import{readFileSync as l,existsSync as c,readdirSync as a}from"fs";import{join as r,dirname as p}from"path";import{fileURLToPath as u}from"url";const m=u(import.meta.url),D=p(m),d=r(D,"../../resources");function f(n){try{if(!c(n))return null;const t=l(n,"utf-8");return JSON.parse(t)}catch{return null}}function g(){const n=new Map,t=r(d,"standards");if(!c(t))return n;const s=a(t).filter(o=>o.endsWith(".json")&&o!=="index.json");for(const o of s){const i=r(t,o),e=f(i);e&&n.set(e.category,e)}return n}function C(){const n=new Map,t=r(d,"components");if(!c(t))return n;const s=a(t).filter(o=>o.endsWith(".json")&&o!=="index.json");for(const o of s){const i=r(t,o),e=f(i);e&&(n.set(e.id,e),n.set(e.name,e),e.name.startsWith("em-")&&n.set(e.name.replace("em-",""),e))}return n}function x(){const n=new Map,t=r(d,"utils");if(!c(t))return n;const s=a(t).filter(o=>o.endsWith(".json")&&o!=="index.json");for(const o of s){const i=r(t,o),e=f(i);e&&n.set(e.category,e)}return n}function y(){const n=[],t=r(d,"cases");if(!c(t))return n;const s=a(t).filter(o=>o.endsWith(".json")&&o!=="index.json");for(const o of s){const i=r(t,o),e=f(i);e&&n.push(e)}return n}function j(){return{standards:g(),components:C(),utils:x(),apis:new Map,cases:y()}}function M(n){return Array.from(n.keys())}function I(n){const t=new Set;for(const s of n.values())t.add(s.name);return Array.from(t)}function w(n){return Array.from(n.keys())}export{I as getComponentNames,M as getStandardTypes,w as getUtilCategories,j as loadAllDocuments,y as loadCases,C as loadComponents,g as loadStandards,x as loadUtils};
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * 文档搜索功能
3
3
  * @作者 li peng
4
- * @创建时间 2024-12-29
4
+ * @创建时间 2025-12-20
5
5
  * @描述 实现文档的关键词搜索和分类过滤
6
6
  */
7
7
  import type { SearchOptions, SearchResult, DocumentIndex } from '../types/index.js';
@@ -1,196 +1,2 @@
1
- /**
2
- * 文档搜索功能
3
- * @作者 li peng
4
- * @创建时间 2024-12-29
5
- * @描述 实现文档的关键词搜索和分类过滤
6
- */
7
- /**
8
- * 检查文本是否包含关键词(不区分大小写)
9
- * @param text 要检查的文本
10
- * @param keyword 关键词
11
- * @returns 是否包含
12
- */
13
- function containsKeyword(text, keyword) {
14
- if (!text)
15
- return false;
16
- return text.toLowerCase().includes(keyword.toLowerCase());
17
- }
18
- /**
19
- * 搜索文档
20
- * @param index 文档索引
21
- * @param query 搜索关键词
22
- * @param options 搜索选项
23
- * @returns 搜索结果数组
24
- */
25
- export function searchDocs(index, query, options) {
26
- const results = [];
27
- const category = options?.category;
28
- const limit = options?.limit ?? 10;
29
- // 搜索编码规范
30
- if (!category || category === 'standard') {
31
- for (const [, doc] of index.standards) {
32
- // 搜索规范标题
33
- if (containsKeyword(doc.title, query) || containsKeyword(doc.description, query)) {
34
- results.push({
35
- title: doc.title,
36
- category: 'standard',
37
- description: doc.description || '',
38
- content: `包含 ${doc.rules.length} 条规则`
39
- });
40
- }
41
- // 搜索具体规则
42
- for (const rule of doc.rules) {
43
- if (containsKeyword(rule.title, query) || containsKeyword(rule.description, query)) {
44
- results.push({
45
- title: `${doc.title} - ${rule.title}`,
46
- category: 'standard',
47
- description: rule.description,
48
- content: rule.correctExample || ''
49
- });
50
- }
51
- }
52
- }
53
- }
54
- // 搜索 UI 组件
55
- if (!category || category === 'ui-component') {
56
- const seenComponents = new Set();
57
- for (const [, doc] of index.components) {
58
- // 避免重复(因为同一个组件可能有多个键)
59
- if (seenComponents.has(doc.id))
60
- continue;
61
- seenComponents.add(doc.id);
62
- if (containsKeyword(doc.name, query) ||
63
- containsKeyword(doc.title, query) ||
64
- containsKeyword(doc.description, query)) {
65
- results.push({
66
- title: `${doc.name} (${doc.title})`,
67
- category: 'ui-component',
68
- description: doc.description,
69
- content: `Props: ${doc.props.length}, Events: ${doc.events.length}`
70
- });
71
- }
72
- }
73
- }
74
- // 搜索 Util 工具
75
- if (!category || category === 'util-tool') {
76
- for (const [, doc] of index.utils) {
77
- // 搜索分类
78
- if (containsKeyword(doc.title, query) || containsKeyword(doc.description, query)) {
79
- results.push({
80
- title: `Util.${doc.category}`,
81
- category: 'util-tool',
82
- description: doc.description || doc.title,
83
- content: `包含 ${doc.methods.length} 个方法`
84
- });
85
- }
86
- // 搜索具体方法
87
- for (const method of doc.methods) {
88
- if (containsKeyword(method.name, query) || containsKeyword(method.description, query)) {
89
- results.push({
90
- title: `Util.${doc.category === 'common' ? '' : doc.category + '.'}${method.name}`,
91
- category: 'util-tool',
92
- description: method.description,
93
- content: method.examples?.[0]?.code || ''
94
- });
95
- }
96
- }
97
- }
98
- }
99
- // 搜索典型案例
100
- if (!category || category === 'typical-case') {
101
- for (const doc of index.cases) {
102
- if (containsKeyword(doc.title, query) || containsKeyword(doc.description, query)) {
103
- results.push({
104
- title: doc.title,
105
- category: 'typical-case',
106
- description: doc.description,
107
- content: `Vue${doc.vueVersion} 版本`
108
- });
109
- }
110
- }
111
- }
112
- // 搜索 EJS API(如果有)
113
- if (!category || category === 'ejs-api') {
114
- for (const [, doc] of index.apis) {
115
- if (containsKeyword(doc.module, query) || containsKeyword(doc.description, query)) {
116
- results.push({
117
- title: `ejs.${doc.module}`,
118
- category: 'ejs-api',
119
- description: doc.description,
120
- content: `包含 ${doc.methods.length} 个方法`
121
- });
122
- }
123
- // 搜索具体方法
124
- for (const method of doc.methods) {
125
- if (containsKeyword(method.name, query) || containsKeyword(method.description, query)) {
126
- results.push({
127
- title: `ejs.${doc.module}.${method.name}`,
128
- category: 'ejs-api',
129
- description: method.description,
130
- content: method.examples?.[0]?.code || ''
131
- });
132
- }
133
- }
134
- }
135
- }
136
- // 限制结果数量
137
- return results.slice(0, limit);
138
- }
139
- /**
140
- * 获取搜索结果的摘要信息
141
- * @param results 搜索结果
142
- * @returns 摘要字符串
143
- */
144
- export function getSearchSummary(results) {
145
- if (results.length === 0) {
146
- return '未找到匹配的文档。请尝试其他关键词或检查拼写。';
147
- }
148
- const categoryCounts = {};
149
- for (const result of results) {
150
- categoryCounts[result.category] = (categoryCounts[result.category] || 0) + 1;
151
- }
152
- const parts = [];
153
- for (const [category, count] of Object.entries(categoryCounts)) {
154
- const categoryName = getCategoryDisplayName(category);
155
- parts.push(`${categoryName}: ${count}`);
156
- }
157
- return `找到 ${results.length} 条结果 (${parts.join(', ')})`;
158
- }
159
- /**
160
- * 获取分类的显示名称
161
- * @param category 分类标识
162
- * @returns 显示名称
163
- */
164
- function getCategoryDisplayName(category) {
165
- const names = {
166
- 'ejs-api': 'EJS API',
167
- 'ui-component': 'UI 组件',
168
- 'util-tool': 'Util 工具',
169
- 'typical-case': '典型案例',
170
- 'standard': '编码规范'
171
- };
172
- return names[category] || category;
173
- }
174
- /**
175
- * 格式化搜索结果为文本
176
- * @param results 搜索结果
177
- * @returns 格式化的文本
178
- */
179
- export function formatSearchResults(results) {
180
- if (results.length === 0) {
181
- return '未找到匹配的文档。请尝试其他关键词或检查拼写。';
182
- }
183
- const lines = [getSearchSummary(results), ''];
184
- for (let i = 0; i < results.length; i++) {
185
- const result = results[i];
186
- lines.push(`${i + 1}. **${result.title}**`);
187
- lines.push(` 分类: ${getCategoryDisplayName(result.category)}`);
188
- lines.push(` 描述: ${result.description}`);
189
- if (result.content) {
190
- lines.push(` ${result.content}`);
191
- }
192
- lines.push('');
193
- }
194
- return lines.join('\n');
195
- }
196
- //# sourceMappingURL=search.js.map
1
+ function s(n,e){return n?n.toLowerCase().includes(e.toLowerCase()):!1}function d(n,e,r){const i=[],c=r?.category,a=r?.limit??10;if(!c||c==="standard")for(const[,t]of n.standards){(s(t.title,e)||s(t.description,e))&&i.push({title:t.title,category:"standard",description:t.description||"",content:`\u5305\u542B ${t.rules.length} \u6761\u89C4\u5219`});for(const o of t.rules)(s(o.title,e)||s(o.description,e))&&i.push({title:`${t.title} - ${o.title}`,category:"standard",description:o.description,content:o.correctExample||""})}if(!c||c==="ui-component"){const t=new Set;for(const[,o]of n.components)t.has(o.id)||(t.add(o.id),(s(o.name,e)||s(o.title,e)||s(o.description,e))&&i.push({title:`${o.name} (${o.title})`,category:"ui-component",description:o.description,content:`Props: ${o.props.length}, Events: ${o.events.length}`}))}if(!c||c==="util-tool")for(const[,t]of n.utils){(s(t.title,e)||s(t.description,e))&&i.push({title:`Util.${t.category}`,category:"util-tool",description:t.description||t.title,content:`\u5305\u542B ${t.methods.length} \u4E2A\u65B9\u6CD5`});for(const o of t.methods)(s(o.name,e)||s(o.description,e))&&i.push({title:`Util.${t.category==="common"?"":t.category+"."}${o.name}`,category:"util-tool",description:o.description,content:o.examples?.[0]?.code||""})}if(!c||c==="typical-case")for(const t of n.cases)(s(t.title,e)||s(t.description,e))&&i.push({title:t.title,category:"typical-case",description:t.description,content:`Vue${t.vueVersion} \u7248\u672C`});if(!c||c==="ejs-api")for(const[,t]of n.apis){(s(t.module,e)||s(t.description,e))&&i.push({title:`ejs.${t.module}`,category:"ejs-api",description:t.description,content:`\u5305\u542B ${t.methods.length} \u4E2A\u65B9\u6CD5`});for(const o of t.methods)(s(o.name,e)||s(o.description,e))&&i.push({title:`ejs.${t.module}.${o.name}`,category:"ejs-api",description:o.description,content:o.examples?.[0]?.code||""})}return i.slice(0,a)}function l(n){if(n.length===0)return"\u672A\u627E\u5230\u5339\u914D\u7684\u6587\u6863\u3002\u8BF7\u5C1D\u8BD5\u5176\u4ED6\u5173\u952E\u8BCD\u6216\u68C0\u67E5\u62FC\u5199\u3002";const e={};for(const i of n)e[i.category]=(e[i.category]||0)+1;const r=[];for(const[i,c]of Object.entries(e)){const a=p(i);r.push(`${a}: ${c}`)}return`\u627E\u5230 ${n.length} \u6761\u7ED3\u679C (${r.join(", ")})`}function p(n){return{"ejs-api":"EJS API","ui-component":"UI \u7EC4\u4EF6","util-tool":"Util \u5DE5\u5177","typical-case":"\u5178\u578B\u6848\u4F8B",standard:"\u7F16\u7801\u89C4\u8303"}[n]||n}function f(n){if(n.length===0)return"\u672A\u627E\u5230\u5339\u914D\u7684\u6587\u6863\u3002\u8BF7\u5C1D\u8BD5\u5176\u4ED6\u5173\u952E\u8BCD\u6216\u68C0\u67E5\u62FC\u5199\u3002";const e=[l(n),""];for(let r=0;r<n.length;r++){const i=n[r];e.push(`${r+1}. **${i.title}**`),e.push(` \u5206\u7C7B: ${p(i.category)}`),e.push(` \u63CF\u8FF0: ${i.description}`),i.content&&e.push(` ${i.content}`),e.push("")}return e.join(`
2
+ `)}export{f as formatSearchResults,l as getSearchSummary,d as searchDocs};
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * 编码规范查询
3
3
  * @作者 li peng
4
- * @创建时间 2024-12-29
4
+ * @创建时间 2025-12-20
5
5
  * @描述 实现编码规范信息的查询功能
6
6
  */
7
7
  import type { CodingStandardDoc, CodingRule, StandardType } from '../types/index.js';