-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
85 lines (81 loc) · 1.99 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
'use strict';
const alfy = require('alfy');
// 搜索模式
// <artifactId>
// <artifactId> <version>
// <groupId> <artifactId> <version>
// 任意一个都可以被*代替
let query = {groupId: '', artifactId: '', version: '', repoId: 'central'};
let field3 = ['groupId', 'artifactId', 'version'];
let field2 = ['artifactId', 'version'];
let field1 = ['artifactId'];
let keywords = alfy.input.split(' ');
if (keywords.length === 3) {
keywords.forEach((v, i) => {
if (v !== '*') {
query[field3[i]] = v;
}
});
}
if (keywords.length === 2) {
keywords.forEach((v, i) => {
if (v !== '*') {
query[field2[i]] = v;
}
});
}
if (keywords.length === 3) {
keywords.forEach((v, i) => {
if (v !== '*') {
query[field3[i]] = v;
}
});
}
if (keywords.length === 1) {
keywords.forEach((v, i) => {
if (v !== '*') {
query[field1[i]] = v;
}
});
}
alfy.fetch('http://maven.aliyun.com/artifact/aliyunMaven/searchArtifactByGav', {
query: query
}).then(data => {
let result = data.object.filter(m => {
// 过滤非jar
return m.packaging === 'jar';
}).slice(0, 20).map(m => {
// 整理成alfred
const mvn = `<dependency>\n <groupId>${m.groupId}</groupId>\n <artifactId>${m.artifactId}</artifactId>\n <version>${m.version}</version>\n</dependency>`;
const gradle = `compile '${m.groupId}:${m.artifactId}:${m.version}'`;
const url = `https://mvnrepository.com/artifact/${m.groupId}/${m.artifactId}/${m.version}`;
return {
title: m.artifactId,
subtitle: m.groupId + ':' + m.artifactId + ':' + m.version,
autocomplete: m.artifactId,
arg: mvn,
mods: {
cmd: {
arg: gradle,
subtitle: `Copy as gradle format`,
variables: {
action: 'copy',
text: 'Gradle format was copied to your clipboard'
}
},
alt: {
arg: url,
subtitle: `Open in mvnrepository.com`,
variables: {
action: 'browser'
}
}
},
variables: {
action: 'copy',
text: 'Maven format was copied to your clipboard'
}
};
});
alfy.output(result);
});