@ruck-plugins/maven-search 1.0.0

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/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # MavenSearch
2
+
3
+ ## 介绍
4
+
5
+ > 基于:https://mvn.coderead.cn/ 开发
6
+
7
+ 最快捷的Maven搜索
8
+ - 不依赖于国外网络,每周自动去Maven仓库同步索引到国内。
9
+ - 自研搜索算法,无论单词多长,输入你记得的前几个字母即可。
10
+ - 热度排序,使用的人数越多,结果越智能。
11
+
12
+ ## 使用
13
+
14
+ 输入依赖关键词
15
+
16
+ ![搜索依赖](https://picx.zhimg.com/v2-4f3287153c9f8fa9cfa2c017c8cec562.png)
17
+
18
+ 点击对应版本号
19
+
20
+ ![选择版本点击](https://pic1.zhimg.com/v2-659b8cb904e3a49368cef6271084a3cb.png)
21
+
22
+ 自动复制依赖信息到剪切板
23
+
24
+ ```xml
25
+ <dependency>
26
+ <groupId>org.springframework.boot</groupId>
27
+ <artifactId>spring-boot</artifactId>
28
+ <version>4.0.0-M3</version>
29
+ </dependency>
30
+ ```
31
+
package/api.js ADDED
@@ -0,0 +1,57 @@
1
+ async function searchList(searchWord) {
2
+ return await fetch(`https://mvn.coderead.cn/search?keyword=${searchWord}`)
3
+ .then((res) => res.json())
4
+ .then((res) => {
5
+ // console.log(res);
6
+ if (!res.success) {
7
+ return [];
8
+ }
9
+ return res.results.map((item) => {
10
+ debugger;
11
+ /'text'>(.*?)<\/span>.*description'>(.*?)<\/span>.*description'>(.*?)<\/span>/gm.test(
12
+ item.name.replace(/\s+/g, "")
13
+ );
14
+ let title = RegExp.$1;
15
+ let time = RegExp.$2;
16
+ let description = RegExp.$3;
17
+ title = title.replace(/<.?em>/g, "").trim();
18
+ time = time.replace(/<.?em>/g, "").trim();
19
+ description = description.replace(/<.?em>/g, "").trim() + "——" + time;
20
+ // console.log(RegExp.$1);
21
+ return {
22
+ title,
23
+ description,
24
+ value: item.value,
25
+ };
26
+ });
27
+ });
28
+ }
29
+
30
+ async function searchVersionList(groupId, artifactId) {
31
+ return await fetch(
32
+ `https://mvn.coderead.cn/version?groupId=${groupId}&artifactId=${artifactId}`
33
+ )
34
+ .then((res) => res.text())
35
+ .then((res) => {
36
+ const domParser = new DOMParser();
37
+ const html = domParser.parseFromString(res, "text/html");
38
+ const vHtmls = html.querySelectorAll('tr[onclick="doFold($(this))"]');
39
+ const items = [];
40
+ vHtmls.forEach((vHtml) => {
41
+ const version = vHtml.querySelector("td:nth-child(1)").textContent;
42
+ const downloadCount =
43
+ vHtml.querySelector("td:nth-child(3)").textContent;
44
+ const time = vHtml.querySelector("td:nth-child(4)").textContent;
45
+ items.push({
46
+ title: version,
47
+ description: `下载量:${downloadCount}——发布时间${time}`,
48
+ });
49
+ });
50
+ return {
51
+ items,
52
+ html,
53
+ };
54
+ });
55
+ }
56
+
57
+ module.exports = { searchList, searchVersionList };
package/logo.png ADDED
Binary file
package/package.json ADDED
@@ -0,0 +1,84 @@
1
+ {
2
+ "name": "@ruck-plugins/maven-search",
3
+ "version": "1.0.0",
4
+ "description": "最快捷的 Maven/Gradle 依赖搜索工具",
5
+ "ruckPlugin": {
6
+ "name": "@ruck-plugins/maven-search",
7
+ "version": "1.0.0",
8
+ "displayName": "Maven 搜索",
9
+ "description": "实时搜索 Maven 仓库,一键复制依赖配置。",
10
+ "author": "JIAHE",
11
+ "logo": "logo.png",
12
+ "pluginType": "ui",
13
+ "preload": "preload.js",
14
+ "permissions": [
15
+ "clipboard_write",
16
+ "notification",
17
+ "network"
18
+ ],
19
+ "keywords": [
20
+ "maven",
21
+ "mvn",
22
+ "gradle",
23
+ "kotlin",
24
+ "dependency",
25
+ "依赖",
26
+ "pinyinmaven"
27
+ ],
28
+ "features": [
29
+ {
30
+ "code": "maven",
31
+ "explain": "输入内容查询依赖,复制格式为maven格式",
32
+ "cmds": [
33
+ "maven",
34
+ "mvn",
35
+ {
36
+ "type": "over",
37
+ "label": "maven"
38
+ }
39
+ ]
40
+ },
41
+ {
42
+ "code": "gradle",
43
+ "explain": "输入内容查询依赖,复制格式为gradle格式",
44
+ "cmds": [
45
+ "gradle",
46
+ {
47
+ "type": "over",
48
+ "label": "gradle"
49
+ }
50
+ ]
51
+ },
52
+ {
53
+ "code": "kotlin",
54
+ "explain": "输入内容查询依赖,复制格式为gradle(kotlin)格式",
55
+ "cmds": [
56
+ "kotlin",
57
+ {
58
+ "type": "over",
59
+ "label": "kotlin"
60
+ }
61
+ ]
62
+ }
63
+ ]
64
+ },
65
+ "keywords": [
66
+ "maven",
67
+ "search",
68
+ "dependency"
69
+ ],
70
+ "author": "JIAHE",
71
+ "license": "MIT",
72
+ "main": "preload.js",
73
+ "scripts": {
74
+ "test": "echo \"Error: no test specified\" && exit 1"
75
+ },
76
+ "repository": {
77
+ "type": "git",
78
+ "url": "git+https://github.com/iamxiaojianzheng/ruck-plugins.git#main"
79
+ },
80
+ "bugs": {
81
+ "url": "https://github.com/iamxiaojianzheng/ruck-plugins/issues"
82
+ },
83
+ "homepage": "https://github.com/iamxiaojianzheng/ruck-plugins/tree/main#readme"
84
+ }
package/preload.js ADDED
@@ -0,0 +1,146 @@
1
+ /**
2
+ * Maven Search Plugin (List Mode)
3
+ */
4
+
5
+ // API: Search Artifacts
6
+ async function searchList(searchWord) {
7
+ try {
8
+ const res = await fetch(`https://mvn.coderead.cn/search?keyword=${searchWord}`);
9
+ const data = await res.json();
10
+ if (!data.success) return [];
11
+
12
+ return data.results.map((item) => {
13
+ const [groupId, artifactId] = (item.value || '').split(':');
14
+ const dateMatch = item.name.match(/\d{4}-\d{2}-\d{2}/);
15
+ const date = dateMatch ? dateMatch[0] : '';
16
+
17
+ return {
18
+ title: artifactId || item.value,
19
+ description: `${groupId}${date ? ` · ${date}` : ''}`,
20
+ icon: 'logo.png', // Assuming logo is available
21
+ // Custom data for next step
22
+ data: {
23
+ type: 'artifact',
24
+ groupId,
25
+ artifactId,
26
+ value: item.value,
27
+ },
28
+ };
29
+ });
30
+ } catch (error) {
31
+ console.error('Search API Error:', error);
32
+ return [];
33
+ }
34
+ }
35
+
36
+ // API: Search Versions
37
+ async function searchVersionList(groupId, artifactId) {
38
+ try {
39
+ console.log(`[MavenSearch] searching versions for ${groupId}:${artifactId}`);
40
+ const res = await fetch(`https://mvn.coderead.cn/version?groupId=${groupId}&artifactId=${artifactId}`);
41
+ const htmlText = await res.text();
42
+ console.log(`[MavenSearch] version response length: ${htmlText.length}`);
43
+
44
+ const domParser = new DOMParser();
45
+ const html = domParser.parseFromString(htmlText, 'text/html');
46
+ const vRows = html.querySelectorAll('tr[onclick="doFold($(this))"]');
47
+ console.log(`[MavenSearch] found ${vRows.length} version rows`);
48
+
49
+ const items = [];
50
+ vRows.forEach((row) => {
51
+ const version = row.querySelector('td:nth-child(1)').textContent.trim();
52
+ // Get Maven config from hidden textarea in next row if possible, or construct it
53
+ // Ideally we parse it here, but the original code did it on select.
54
+ // Let's try to extract basic info here.
55
+
56
+ const downloadCount = row.querySelector('td:nth-child(3)').textContent.trim();
57
+ const time = row.querySelector('td:nth-child(4)').textContent.trim();
58
+
59
+ // Try to find the config
60
+ let mavenConfig = '';
61
+ const nextRow = row.nextElementSibling;
62
+ if (nextRow) {
63
+ const textarea = nextRow.querySelector('textarea');
64
+ if (textarea) mavenConfig = textarea.textContent.trim();
65
+ }
66
+
67
+ items.push({
68
+ title: version,
69
+ description: `下载: ${downloadCount} · 发布: ${time}`,
70
+ icon: 'logo.png',
71
+ data: {
72
+ type: 'version',
73
+ groupId,
74
+ artifactId,
75
+ version,
76
+ mavenConfig, // Store raw config if available
77
+ },
78
+ });
79
+ });
80
+
81
+ console.log(`[MavenSearch] returning ${items.length} version items`);
82
+ return items;
83
+ } catch (error) {
84
+ console.error('Version API Error:', error);
85
+ return [];
86
+ }
87
+ }
88
+
89
+ // Helper: Format dependency string
90
+ function formatDependency(type, groupId, artifactId, version, mavenConfig) {
91
+ if (type === 'maven') {
92
+ if (mavenConfig) {
93
+ // Format Maven config
94
+ const lines = mavenConfig.replace(/\n/g, '&&&').trim().replace(/\s+/g, '').split('&&&');
95
+ return lines
96
+ .map((line, index) => {
97
+ if (index !== 0 && index !== lines.length - 1) {
98
+ return ' ' + line;
99
+ }
100
+ return line;
101
+ })
102
+ .join('\n');
103
+ }
104
+ return `<dependency>\n <groupId>${groupId}</groupId>\n <artifactId>${artifactId}</artifactId>\n <version>${version}</version>\n</dependency>`;
105
+ } else if (type === 'gradle') {
106
+ return `implementation '${groupId}:${artifactId}:${version}'`;
107
+ } else if (type === 'kotlin') {
108
+ return `implementation("${groupId}:${artifactId}:${version}")`;
109
+ }
110
+ return `${groupId}:${artifactId}:${version}`;
111
+ }
112
+
113
+ const commonListHandler = (modeType) => ({
114
+ mode: 'list',
115
+ args: {
116
+ placeholder: '输入包名搜索...',
117
+ enter: (action, callbackSetList) => {},
118
+ search: async (action, searchWord, callbackSetList) => {
119
+ if (!searchWord) return;
120
+ const items = await searchList(searchWord);
121
+ callbackSetList(items);
122
+ },
123
+ select: async (action, itemData, callbackSetList) => {
124
+ console.log('[MavenSearch] select called with:', itemData);
125
+ const { data } = itemData;
126
+ if (!data) return;
127
+
128
+ if (data.type === 'artifact') {
129
+ const versions = await searchVersionList(data.groupId, data.artifactId);
130
+ callbackSetList(versions);
131
+ } else if (data.type === 'version') {
132
+ const text = formatDependency(modeType, data.groupId, data.artifactId, data.version, data.mavenConfig);
133
+ window.ruck.clipboard.writeText(text);
134
+ window.ruck.notification.success(`已复制 ${modeType} 依赖`);
135
+ }
136
+ },
137
+ },
138
+ });
139
+
140
+ window.exports = {
141
+ maven: commonListHandler('maven'),
142
+ gradle: commonListHandler('gradle'),
143
+ kotlin: commonListHandler('kotlin'),
144
+ };
145
+
146
+ console.log('Maven Search Plugin Loaded (List Mode)');