helium-npm 1.0.5
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.
Potentially problematic release.
This version of helium-npm might be problematic. Click here for more details.
- package/index.js +11 -0
- package/lib/createHeliumPkgFile.js +57 -0
- package/lib/fetchHeliumPkgInfo.js +88 -0
- package/lib/getBasicMavenArtifactInfo.js +275 -0
- package/lib/getMavenArtifactInfo.js +293 -0
- package/package.json +30 -0
package/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import {Command} from "commander";
|
|
2
|
+
import {create} from "./lib/createHeliumPkgFile.js";
|
|
3
|
+
|
|
4
|
+
const command = new Command();
|
|
5
|
+
command
|
|
6
|
+
.name('create')
|
|
7
|
+
.description('CLI to create helium json')
|
|
8
|
+
.action((str, options) => {
|
|
9
|
+
create();
|
|
10
|
+
});
|
|
11
|
+
command.parse();
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import fetch from "node-fetch";
|
|
2
|
+
import Promise from "bluebird";
|
|
3
|
+
import stringify from 'json-stringify-pretty-compact';
|
|
4
|
+
import {getMavenHandler} from "./getMavenArtifactInfo.js";
|
|
5
|
+
import {fetchHelium} from "./fetchHeliumPkgInfo.js";
|
|
6
|
+
import * as fs from "fs";
|
|
7
|
+
import {getBasicMavenHandler} from "./getBasicMavenArtifactInfo.js";
|
|
8
|
+
|
|
9
|
+
const pushPkgInfoToTmp = async function() {
|
|
10
|
+
const response = await fetch('https://zeppelin.apache.org/helium.json')
|
|
11
|
+
const data = await response.json();
|
|
12
|
+
return data[0];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const delay = (timeToDelay) => new Promise((resolve) => setTimeout(resolve, timeToDelay))
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
export function create() {
|
|
19
|
+
pushPkgInfoToTmp()
|
|
20
|
+
.then(async (response) => {
|
|
21
|
+
const result = await getBasicMavenHandler(() => {});
|
|
22
|
+
for (const body of result) {
|
|
23
|
+
for (const key of Object.keys(body)) {
|
|
24
|
+
response[key] = body[key];
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return response;
|
|
28
|
+
})
|
|
29
|
+
.then(async (response) => {
|
|
30
|
+
const result = await getMavenHandler(() => {});
|
|
31
|
+
for (const body of result) {
|
|
32
|
+
for (const key of Object.keys(body)) {
|
|
33
|
+
response[key] = body[key];
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return response;
|
|
37
|
+
})
|
|
38
|
+
.then(async (response) => {
|
|
39
|
+
const result = await fetchHelium();
|
|
40
|
+
for (const body of result) {
|
|
41
|
+
for (const key of Object.keys(body)) {
|
|
42
|
+
response[key] = body[key];
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return response;
|
|
46
|
+
})
|
|
47
|
+
.then(async (response) => {
|
|
48
|
+
await delay(8000)
|
|
49
|
+
const result = [response];
|
|
50
|
+
fs.writeFileSync('./helium.json', stringify(result), (err) => {
|
|
51
|
+
console.log("error!!!");
|
|
52
|
+
})
|
|
53
|
+
})
|
|
54
|
+
// .then(async (response) => {
|
|
55
|
+
// await fetchHelium();
|
|
56
|
+
// })
|
|
57
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import Promise from "bluebird";
|
|
2
|
+
import stringify from "json-stringify-pretty-compact";
|
|
3
|
+
import RegistryClient from 'npm-registry-client';
|
|
4
|
+
import dependants from 'npm-dependants'
|
|
5
|
+
|
|
6
|
+
const depList = [
|
|
7
|
+
"zeppelin-vis",
|
|
8
|
+
"zeppelin-spell",
|
|
9
|
+
]
|
|
10
|
+
|
|
11
|
+
const removeExtraSquareBracket = function(jsonArray) {
|
|
12
|
+
jsonArray = jsonArray.map(function(e){
|
|
13
|
+
return stringify(e)
|
|
14
|
+
})
|
|
15
|
+
return jsonArray.join(",")
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const setEachVersionInfo = function(dependency, data) {
|
|
19
|
+
const eachVerInfo = {}
|
|
20
|
+
const versions = data.versions
|
|
21
|
+
const defaultIcon = '<i class="fa fa-question-circle"></i>'
|
|
22
|
+
const type = (dependency == "zeppelin-vis") ? "VISUALIZATION" : "SPELL"
|
|
23
|
+
|
|
24
|
+
for (let ver in versions) {
|
|
25
|
+
const key = versions[ver]
|
|
26
|
+
// to keep "latest" version tag, use artifact's one
|
|
27
|
+
const verTag = key._id.split('@')[1]
|
|
28
|
+
|
|
29
|
+
if (ver == data["dist-tags"].latest) {
|
|
30
|
+
ver = "latest"
|
|
31
|
+
}
|
|
32
|
+
eachVerInfo[ver] = {
|
|
33
|
+
type: type,
|
|
34
|
+
name: key.name,
|
|
35
|
+
version: verTag,
|
|
36
|
+
published: data.time[verTag],
|
|
37
|
+
artifact: key._id,
|
|
38
|
+
author:
|
|
39
|
+
(key.author?.name == undefined) && (key.maintainers[0].name == undefined)
|
|
40
|
+
?
|
|
41
|
+
'unknown'
|
|
42
|
+
:
|
|
43
|
+
key.author?.name || key.maintainers[0].name,
|
|
44
|
+
description:
|
|
45
|
+
(key.description == undefined) ? 'unknown' : key.description,
|
|
46
|
+
license:
|
|
47
|
+
(key.license == undefined) ? 'unknown' : key.license,
|
|
48
|
+
icon:
|
|
49
|
+
(key.helium)
|
|
50
|
+
?
|
|
51
|
+
(key.helium.icon == undefined) ? defaultIcon : key.helium.icon
|
|
52
|
+
:
|
|
53
|
+
(key.icon == undefined) ? defaultIcon : key.icon,
|
|
54
|
+
config:
|
|
55
|
+
(key.helium) ? key.helium.config : undefined,
|
|
56
|
+
spell:
|
|
57
|
+
(key.helium) ? key.helium.spell : undefined
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return eachVerInfo
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const finalResult = []
|
|
64
|
+
const client = new RegistryClient();
|
|
65
|
+
async function getDependencies(packageName) {
|
|
66
|
+
await client.get(`https://registry.npmjs.org/${packageName}`, { timeout: 1000 }, (error, data) => {
|
|
67
|
+
if (error) {
|
|
68
|
+
console.error(error.message);
|
|
69
|
+
return reject(error)
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const pkgInfo = {}
|
|
73
|
+
pkgInfo[data.name] = setEachVersionInfo(packageName, data)
|
|
74
|
+
finalResult.push(pkgInfo)
|
|
75
|
+
// var result = removeExtraSquareBracket(finalResult).replace(/]|[[]/g, '').trim()
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const delay = (timeToDelay) => new Promise((resolve) => setTimeout(resolve, timeToDelay))
|
|
80
|
+
export async function fetchHelium() {
|
|
81
|
+
depList.map(async function(dependency) {
|
|
82
|
+
for await (const dependant of dependants(dependency)) {
|
|
83
|
+
await getDependencies(dependant);
|
|
84
|
+
}
|
|
85
|
+
})
|
|
86
|
+
await delay(10000);
|
|
87
|
+
return finalResult;
|
|
88
|
+
}
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
import _ from 'underscore';
|
|
2
|
+
import moment from "moment";
|
|
3
|
+
import Promise from 'bluebird';
|
|
4
|
+
import fetch from "node-fetch";
|
|
5
|
+
import xml2jsImport from 'xml2js';
|
|
6
|
+
|
|
7
|
+
const xml2js = Promise.promisifyAll(xml2jsImport)
|
|
8
|
+
|
|
9
|
+
const zeppelinList = []
|
|
10
|
+
const pomUriList = []
|
|
11
|
+
const responseList = []
|
|
12
|
+
const bodyList = []
|
|
13
|
+
const finalArtifactList = []
|
|
14
|
+
|
|
15
|
+
function filterLessThanOneYear(standard) {
|
|
16
|
+
const duration = moment.duration({'year': 1})
|
|
17
|
+
const oneYearAgo = moment().subtract(duration).format()
|
|
18
|
+
|
|
19
|
+
// filter only artifacts created within 1 year from now
|
|
20
|
+
return moment(standard).isAfter(oneYearAgo)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async function searchOnlyZeppelinRelatedArtifact(uri) {
|
|
24
|
+
const options = {
|
|
25
|
+
uri: uri,
|
|
26
|
+
json: true
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return fetch(uri)
|
|
30
|
+
.then(async (result) => {
|
|
31
|
+
const response = (await result.json()).response
|
|
32
|
+
const body = response.docs;
|
|
33
|
+
|
|
34
|
+
for (const artifact in body) {
|
|
35
|
+
const artifactId = body[artifact].a
|
|
36
|
+
const groupId = body[artifact].g
|
|
37
|
+
let published = body[artifact].timestamp
|
|
38
|
+
published = moment(published).format()
|
|
39
|
+
|
|
40
|
+
if (filterLessThanOneYear(published)) {
|
|
41
|
+
zeppelinList.push({
|
|
42
|
+
groupId,
|
|
43
|
+
artifactId
|
|
44
|
+
})
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return zeppelinList
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function createSlashedGroupId(groupId) {
|
|
52
|
+
let slashedGroupId = ""
|
|
53
|
+
|
|
54
|
+
for (const id in groupId) {
|
|
55
|
+
const text = groupId[id] + '/'
|
|
56
|
+
slashedGroupId = slashedGroupId.concat(text)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return slashedGroupId
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function createPomUrl(groupId, artifactId, version) {
|
|
63
|
+
const baseUri = 'http://repo1.maven.org/maven2/'
|
|
64
|
+
const slashedGroupId = createSlashedGroupId(groupId)
|
|
65
|
+
|
|
66
|
+
if (slashedGroupId) {
|
|
67
|
+
const uri = baseUri + slashedGroupId + artifactId + '/' + version + '/'
|
|
68
|
+
return uri + artifactId + '-' + version + '.pom';
|
|
69
|
+
}
|
|
70
|
+
return undefined;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
async function getAllVersionInfo(zeppelinList) {
|
|
74
|
+
// get all version of an artifact
|
|
75
|
+
return _.map(zeppelinList, function (resources) {
|
|
76
|
+
const baseUri =
|
|
77
|
+
'http://search.maven.org/solrsearch/select?q=g:%22'
|
|
78
|
+
+ resources.groupId + '%22+AND+a:%22' + resources.artifactId + '%22&core=gav&rows=20'
|
|
79
|
+
const options = {
|
|
80
|
+
uri: baseUri,
|
|
81
|
+
json: true
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return fetch(baseUri)
|
|
85
|
+
.then(async (result) => {
|
|
86
|
+
const response = (await result.json()).response
|
|
87
|
+
const body = response.docs;
|
|
88
|
+
const pomUriListEachVer = {}
|
|
89
|
+
|
|
90
|
+
for (const ver in body) {
|
|
91
|
+
|
|
92
|
+
const artifactId = body[ver].a
|
|
93
|
+
const groupId = body[ver].g.split('.')
|
|
94
|
+
const version = body[ver].v
|
|
95
|
+
let published = body[ver].timestamp
|
|
96
|
+
published = moment(published).format()
|
|
97
|
+
|
|
98
|
+
if (filterLessThanOneYear(published) && createSlashedGroupId(groupId)) {
|
|
99
|
+
const pomUri = createPomUrl(groupId, artifactId, version)
|
|
100
|
+
|
|
101
|
+
pomUriListEachVer[version] = {
|
|
102
|
+
artifactId,
|
|
103
|
+
version,
|
|
104
|
+
published,
|
|
105
|
+
pomUri
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
pomUriList.push(pomUriListEachVer)
|
|
110
|
+
return pomUriList
|
|
111
|
+
});
|
|
112
|
+
})
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function getEachPomFileContent(pomUriList) {
|
|
116
|
+
return _.map(pomUriList, function (result) {
|
|
117
|
+
|
|
118
|
+
return Promise.all(_.map(result, function (ver) {
|
|
119
|
+
const options = {
|
|
120
|
+
uri: ver.pomUri
|
|
121
|
+
}
|
|
122
|
+
const artifactId = ver.artifactId
|
|
123
|
+
const published = ver.published
|
|
124
|
+
const version = ver.version
|
|
125
|
+
|
|
126
|
+
const pomUri = ver.pomUri.replace('http', 'https')
|
|
127
|
+
return fetch(pomUri)
|
|
128
|
+
.then(async (result) => {
|
|
129
|
+
const response = (await result.text())
|
|
130
|
+
|
|
131
|
+
const eachVersionResponse = {
|
|
132
|
+
version: version,
|
|
133
|
+
artifactId: artifactId,
|
|
134
|
+
published: published,
|
|
135
|
+
response: response,
|
|
136
|
+
};
|
|
137
|
+
return eachVersionResponse;
|
|
138
|
+
});
|
|
139
|
+
})).then(function (result) {
|
|
140
|
+
responseList.push(result);
|
|
141
|
+
})
|
|
142
|
+
})
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function parseXmlToJson(responseList) {
|
|
146
|
+
return _.map(responseList, function (response) {
|
|
147
|
+
|
|
148
|
+
return Promise.all(_.map(response, function (ver) {
|
|
149
|
+
// parse each pom.xml to JSON format
|
|
150
|
+
return xml2js.parseStringAsync(ver.response, {explicitArray: false})
|
|
151
|
+
.then(function (result) {
|
|
152
|
+
const projectDeps = result.project.dependencies
|
|
153
|
+
const projectDepManages = result.project.dependencyManagement
|
|
154
|
+
const name = result.project.artifactId
|
|
155
|
+
const groupId = result.project.groupId ? result.project.groupId : result.project.parent.groupId
|
|
156
|
+
const artifactId = result.project.artifactId
|
|
157
|
+
const version = result.project.version ? result.project.version : result.project.parent.version
|
|
158
|
+
const description = result.project.description ? result.project.description : result.project.name
|
|
159
|
+
const published = ver.published
|
|
160
|
+
|
|
161
|
+
let dependencies;
|
|
162
|
+
if (projectDeps) {
|
|
163
|
+
dependencies = projectDeps.dependency;
|
|
164
|
+
} else if (projectDepManages) {
|
|
165
|
+
dependencies = projectDepManages.dependencies.dependency;
|
|
166
|
+
} else {
|
|
167
|
+
dependencies = undefined;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const eachVerBodyList = {
|
|
171
|
+
name: name,
|
|
172
|
+
groupId: groupId,
|
|
173
|
+
artifactId: artifactId,
|
|
174
|
+
version: version,
|
|
175
|
+
description: description,
|
|
176
|
+
published: published,
|
|
177
|
+
dependencies: dependencies,
|
|
178
|
+
};
|
|
179
|
+
return eachVerBodyList;
|
|
180
|
+
})
|
|
181
|
+
}))
|
|
182
|
+
.then(function (result) {
|
|
183
|
+
bodyList.push(result);
|
|
184
|
+
})
|
|
185
|
+
})
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function filterWithGivenArtifact(bodyList) {
|
|
189
|
+
return _.map(bodyList, function (version) {
|
|
190
|
+
|
|
191
|
+
return Promise.all(_.map(version, function (dep, index) {
|
|
192
|
+
const type = 'INTERPRETER'
|
|
193
|
+
const license = 'Apache-2.0'
|
|
194
|
+
const icon = '<i class=\"fa fa-rocket\"></i>'
|
|
195
|
+
const dependency = dep.dependencies
|
|
196
|
+
const name = dep.name
|
|
197
|
+
const groupId = dep.groupId
|
|
198
|
+
const artifactId = dep.artifactId
|
|
199
|
+
const version = (index == 0) ? 'latest' : dep.version
|
|
200
|
+
const artifact = artifactId + '@' + dep.version
|
|
201
|
+
const description = dep.description ? dep.description : name
|
|
202
|
+
const published = dep.published
|
|
203
|
+
|
|
204
|
+
const interpreters = [
|
|
205
|
+
'spark-interpreter', 'zeppelin-jupyter-interpreter', 'zeppelin-display', 'zeppelin-flink',
|
|
206
|
+
'spark-scala-2.11', 'sap', 'spark1-shims', 'spark2-shims', 'spark-scala-parent',
|
|
207
|
+
'spark-scala-2.10', 'spark-shims', 'zeppelin-beam', 'zeppelin-ignite_2.11', 'zeppelin-kylin',
|
|
208
|
+
'zeppelin-ignite_2.10', 'zeppelin-cassandra_2.11', 'zeppelin-flink_2.11', 'zeppelin-lens',
|
|
209
|
+
'zeppelin-cassandra_2.10', 'zeppelin-solr', 'zeppelin-viyadb'
|
|
210
|
+
];
|
|
211
|
+
const result = dependency ?
|
|
212
|
+
(
|
|
213
|
+
_.findWhere(dependency, {artifactId: 'zeppelin-interpreter'})
|
|
214
|
+
|| interpreters.includes(dep.name)
|
|
215
|
+
)
|
|
216
|
+
: undefined
|
|
217
|
+
|
|
218
|
+
return result
|
|
219
|
+
?
|
|
220
|
+
{
|
|
221
|
+
type: type,
|
|
222
|
+
name: name,
|
|
223
|
+
version: version,
|
|
224
|
+
published: published,
|
|
225
|
+
artifact: artifact,
|
|
226
|
+
description: description,
|
|
227
|
+
license: license,
|
|
228
|
+
icon: icon,
|
|
229
|
+
groupId: groupId,
|
|
230
|
+
artifactId: artifactId
|
|
231
|
+
}
|
|
232
|
+
:
|
|
233
|
+
undefined;
|
|
234
|
+
}))
|
|
235
|
+
.then(function (result) {
|
|
236
|
+
const resultByVersion = _.indexBy(_.omit(result, _.isUndefined), 'version')
|
|
237
|
+
for (const key in resultByVersion) {
|
|
238
|
+
const obj = resultByVersion[key]
|
|
239
|
+
if (obj.version == 'latest') {
|
|
240
|
+
obj.version = obj.artifact.split('@')[1]
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
finalArtifactList.push(resultByVersion)
|
|
245
|
+
})
|
|
246
|
+
})
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
const delay = (timeToDelay) => new Promise((resolve) => setTimeout(resolve, timeToDelay))
|
|
250
|
+
const result = [];
|
|
251
|
+
|
|
252
|
+
export async function getBasicMavenHandler(callback) {
|
|
253
|
+
const uri = 'http://search.maven.org/solrsearch/select?q=zeppelin&rows=200';
|
|
254
|
+
await searchOnlyZeppelinRelatedArtifact(uri);
|
|
255
|
+
await delay(5000);
|
|
256
|
+
await getAllVersionInfo(zeppelinList);
|
|
257
|
+
await delay(3000);
|
|
258
|
+
await getEachPomFileContent(pomUriList);
|
|
259
|
+
await delay(3000);
|
|
260
|
+
await parseXmlToJson(responseList);
|
|
261
|
+
await delay(3000);
|
|
262
|
+
await filterWithGivenArtifact(bodyList);
|
|
263
|
+
await delay(3000);
|
|
264
|
+
_.map(finalArtifactList, function (artifact) {
|
|
265
|
+
if (!_.isEmpty(artifact)) {
|
|
266
|
+
for (const key in artifact) {
|
|
267
|
+
const artifactId = artifact[key].artifactId
|
|
268
|
+
const body = {}
|
|
269
|
+
body[artifactId] = artifact
|
|
270
|
+
result.push(body);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
});
|
|
274
|
+
return result;
|
|
275
|
+
}
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
import _ from 'underscore';
|
|
2
|
+
import moment from "moment";
|
|
3
|
+
import Promise from 'bluebird';
|
|
4
|
+
import fetch from "node-fetch";
|
|
5
|
+
import xml2jsImport from 'xml2js';
|
|
6
|
+
|
|
7
|
+
const xml2js = Promise.promisifyAll(xml2jsImport)
|
|
8
|
+
|
|
9
|
+
const zeppelinList = []
|
|
10
|
+
const pomUriList = []
|
|
11
|
+
const responseList = []
|
|
12
|
+
const bodyList = []
|
|
13
|
+
const finalArtifactList = []
|
|
14
|
+
|
|
15
|
+
function filterLessThanOneYear(standard) {
|
|
16
|
+
const duration = moment.duration({'year': 1})
|
|
17
|
+
const oneYearAgo = moment().subtract(duration).format()
|
|
18
|
+
|
|
19
|
+
// filter only artifacts created within 1 year from now
|
|
20
|
+
return moment(standard).isAfter(oneYearAgo)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async function searchOnlyZeppelinRelatedArtifact(uri) {
|
|
24
|
+
const options = {
|
|
25
|
+
uri: uri,
|
|
26
|
+
json: true
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return fetch(uri)
|
|
30
|
+
.then(async (result) => {
|
|
31
|
+
const response = (await result.json()).response
|
|
32
|
+
const body = response.docs;
|
|
33
|
+
|
|
34
|
+
for (const artifact in body) {
|
|
35
|
+
const artifactId = body[artifact].a
|
|
36
|
+
const groupId = body[artifact].g
|
|
37
|
+
let published = body[artifact].timestamp
|
|
38
|
+
published = moment(published).format()
|
|
39
|
+
|
|
40
|
+
if (filterLessThanOneYear(published)) {
|
|
41
|
+
zeppelinList.push({
|
|
42
|
+
groupId,
|
|
43
|
+
artifactId
|
|
44
|
+
})
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return zeppelinList
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function createSlashedGroupId(groupId) {
|
|
52
|
+
let slashedGroupId = ""
|
|
53
|
+
|
|
54
|
+
for (const id in groupId) {
|
|
55
|
+
const text = groupId[id] + '/'
|
|
56
|
+
slashedGroupId = slashedGroupId.concat(text)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return slashedGroupId
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function createPomUrl(groupId, artifactId, version) {
|
|
63
|
+
const baseUri = 'http://repo1.maven.org/maven2/'
|
|
64
|
+
const slashedGroupId = createSlashedGroupId(groupId)
|
|
65
|
+
|
|
66
|
+
if (slashedGroupId) {
|
|
67
|
+
const uri = baseUri + slashedGroupId + artifactId + '/' + version + '/'
|
|
68
|
+
return uri + artifactId + '-' + version + '.pom';
|
|
69
|
+
}
|
|
70
|
+
return undefined;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
async function getAllVersionInfo(zeppelinList) {
|
|
74
|
+
// get all version of an artifact
|
|
75
|
+
return _.map(zeppelinList, function (resources) {
|
|
76
|
+
const baseUri =
|
|
77
|
+
'http://search.maven.org/solrsearch/select?q=g:%22'
|
|
78
|
+
+ resources.groupId + '%22+AND+a:%22' + resources.artifactId + '%22&core=gav&rows=20'
|
|
79
|
+
const options = {
|
|
80
|
+
uri: baseUri,
|
|
81
|
+
json: true
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return fetch(baseUri)
|
|
85
|
+
.then(async (result) => {
|
|
86
|
+
const response = (await result.json()).response
|
|
87
|
+
const body = response.docs;
|
|
88
|
+
const pomUriListEachVer = {}
|
|
89
|
+
|
|
90
|
+
for (const ver in body) {
|
|
91
|
+
|
|
92
|
+
const artifactId = body[ver].a
|
|
93
|
+
const groupId = body[ver].g.split('.')
|
|
94
|
+
const version = body[ver].v
|
|
95
|
+
let published = body[ver].timestamp
|
|
96
|
+
published = moment(published).format()
|
|
97
|
+
|
|
98
|
+
if (filterLessThanOneYear(published) && createSlashedGroupId(groupId)) {
|
|
99
|
+
const pomUri = createPomUrl(groupId, artifactId, version)
|
|
100
|
+
|
|
101
|
+
pomUriListEachVer[version] = {
|
|
102
|
+
artifactId,
|
|
103
|
+
version,
|
|
104
|
+
published,
|
|
105
|
+
pomUri
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
pomUriList.push(pomUriListEachVer)
|
|
110
|
+
return pomUriList
|
|
111
|
+
});
|
|
112
|
+
})
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function getEachPomFileContent(pomUriList) {
|
|
116
|
+
return _.map(pomUriList, function (result) {
|
|
117
|
+
|
|
118
|
+
return Promise.all(_.map(result, function (ver) {
|
|
119
|
+
const options = {
|
|
120
|
+
uri: ver.pomUri
|
|
121
|
+
}
|
|
122
|
+
const artifactId = ver.artifactId
|
|
123
|
+
const published = ver.published
|
|
124
|
+
const version = ver.version
|
|
125
|
+
|
|
126
|
+
const pomUri = ver.pomUri.replace('http', 'https')
|
|
127
|
+
return fetch(pomUri)
|
|
128
|
+
.then(async (result) => {
|
|
129
|
+
const response = (await result.text())
|
|
130
|
+
|
|
131
|
+
const eachVersionResponse = {
|
|
132
|
+
version: version,
|
|
133
|
+
artifactId: artifactId,
|
|
134
|
+
published: published,
|
|
135
|
+
response: response,
|
|
136
|
+
};
|
|
137
|
+
return eachVersionResponse;
|
|
138
|
+
});
|
|
139
|
+
})).then(function (result) {
|
|
140
|
+
responseList.push(result);
|
|
141
|
+
})
|
|
142
|
+
})
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function parseXmlToJson(responseList) {
|
|
146
|
+
return _.map(responseList, function (response) {
|
|
147
|
+
|
|
148
|
+
return Promise.all(_.map(response, function (ver) {
|
|
149
|
+
// parse each pom.xml to JSON format
|
|
150
|
+
return xml2js.parseStringAsync(ver.response, {explicitArray: false})
|
|
151
|
+
.then(function (result) {
|
|
152
|
+
const projectDeps = result.project.dependencies
|
|
153
|
+
const projectDepManages = result.project.dependencyManagement
|
|
154
|
+
const name = result.project.artifactId
|
|
155
|
+
const groupId = result.project.groupId ? result.project.groupId : result.project.parent.groupId
|
|
156
|
+
const artifactId = result.project.artifactId
|
|
157
|
+
const version = result.project.version ? result.project.version : result.project.parent.version
|
|
158
|
+
const description = result.project.description ? result.project.description : result.project.name
|
|
159
|
+
const published = ver.published
|
|
160
|
+
|
|
161
|
+
let dependencies;
|
|
162
|
+
if (projectDeps) {
|
|
163
|
+
dependencies = projectDeps.dependency;
|
|
164
|
+
} else if (projectDepManages) {
|
|
165
|
+
dependencies = projectDepManages.dependencies.dependency;
|
|
166
|
+
} else {
|
|
167
|
+
dependencies = undefined;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const eachVerBodyList = {
|
|
171
|
+
name: name,
|
|
172
|
+
groupId: groupId,
|
|
173
|
+
artifactId: artifactId,
|
|
174
|
+
version: version,
|
|
175
|
+
description: description,
|
|
176
|
+
published: published,
|
|
177
|
+
dependencies: dependencies,
|
|
178
|
+
};
|
|
179
|
+
return eachVerBodyList;
|
|
180
|
+
})
|
|
181
|
+
}))
|
|
182
|
+
.then(function (result) {
|
|
183
|
+
bodyList.push(result);
|
|
184
|
+
})
|
|
185
|
+
})
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function filterWithGivenArtifact(bodyList) {
|
|
189
|
+
return _.map(bodyList, function (version) {
|
|
190
|
+
|
|
191
|
+
return Promise.all(_.map(version, function (dep, index) {
|
|
192
|
+
const type = 'INTERPRETER'
|
|
193
|
+
const license = 'Apache-2.0'
|
|
194
|
+
const icon = '<i class=\"fa fa-rocket\"></i>'
|
|
195
|
+
const dependency = dep.dependencies
|
|
196
|
+
const name = dep.name
|
|
197
|
+
const groupId = dep.groupId
|
|
198
|
+
const artifactId = dep.artifactId
|
|
199
|
+
const version = (index == 0) ? 'latest' : dep.version
|
|
200
|
+
const artifact = artifactId + '@' + dep.version
|
|
201
|
+
const description = dep.description ? dep.description : name
|
|
202
|
+
const published = dep.published
|
|
203
|
+
|
|
204
|
+
// const result = dependency ? _.findWhere(dependency, {artifactId: 'zeppelin-interpreter'}) : undefined
|
|
205
|
+
|
|
206
|
+
return result
|
|
207
|
+
?
|
|
208
|
+
{
|
|
209
|
+
type: type,
|
|
210
|
+
name: name,
|
|
211
|
+
version: version,
|
|
212
|
+
published: published,
|
|
213
|
+
artifact: artifact,
|
|
214
|
+
description: description,
|
|
215
|
+
license: license,
|
|
216
|
+
icon: icon,
|
|
217
|
+
groupId: groupId,
|
|
218
|
+
artifactId: artifactId
|
|
219
|
+
}
|
|
220
|
+
:
|
|
221
|
+
undefined;
|
|
222
|
+
}))
|
|
223
|
+
.then(function (result) {
|
|
224
|
+
const resultByVersion = _.indexBy(_.omit(result, _.isUndefined), 'version')
|
|
225
|
+
for (const key in resultByVersion) {
|
|
226
|
+
const obj = resultByVersion[key]
|
|
227
|
+
if (obj.version == 'latest') {
|
|
228
|
+
obj.version = obj.artifact.split('@')[1]
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
finalArtifactList.push(resultByVersion)
|
|
233
|
+
})
|
|
234
|
+
})
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
function getMavenUris() {
|
|
238
|
+
const dependencies = [
|
|
239
|
+
'zeppelin-alluxio',
|
|
240
|
+
'zeppelin-angular',
|
|
241
|
+
'zeppelin-bigquery',
|
|
242
|
+
'zeppelin-cassandra',
|
|
243
|
+
'zeppelin-elasticsearch',
|
|
244
|
+
'zeppelin-file',
|
|
245
|
+
'zeppelin-flink',
|
|
246
|
+
'zeppelin-groovy',
|
|
247
|
+
'zeppelin-hbase',
|
|
248
|
+
'zeppelin-java',
|
|
249
|
+
'zeppelin-jdbc',
|
|
250
|
+
'zeppelin-livy',
|
|
251
|
+
'zeppelin-markdown',
|
|
252
|
+
'zeppelin-neo4j',
|
|
253
|
+
'zeppelin-python',
|
|
254
|
+
'zeppelin-shell',
|
|
255
|
+
'zeppelin-sparql',
|
|
256
|
+
];
|
|
257
|
+
const uris = [];
|
|
258
|
+
for (const dependency of dependencies) {
|
|
259
|
+
const uri = `http://search.maven.org/solrsearch/select?q=${dependency}&rows=100`;
|
|
260
|
+
uris.push(uri);
|
|
261
|
+
}
|
|
262
|
+
return uris;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
const delay = (timeToDelay) => new Promise((resolve) => setTimeout(resolve, timeToDelay))
|
|
266
|
+
const result = [];
|
|
267
|
+
|
|
268
|
+
export async function getMavenHandler(callback) {
|
|
269
|
+
let mavenUris = getMavenUris();
|
|
270
|
+
for (const uri of mavenUris) {
|
|
271
|
+
await searchOnlyZeppelinRelatedArtifact(uri);
|
|
272
|
+
}
|
|
273
|
+
await delay(5000);
|
|
274
|
+
await getAllVersionInfo(zeppelinList);
|
|
275
|
+
await delay(3000);
|
|
276
|
+
await getEachPomFileContent(pomUriList);
|
|
277
|
+
await delay(3000);
|
|
278
|
+
await parseXmlToJson(responseList);
|
|
279
|
+
await delay(3000);
|
|
280
|
+
await filterWithGivenArtifact(bodyList);
|
|
281
|
+
await delay(3000);
|
|
282
|
+
_.map(finalArtifactList, function (artifact) {
|
|
283
|
+
if (!_.isEmpty(artifact)) {
|
|
284
|
+
for (const key in artifact) {
|
|
285
|
+
const artifactId = artifact[key].artifactId
|
|
286
|
+
const body = {}
|
|
287
|
+
body[artifactId] = artifact
|
|
288
|
+
result.push(body);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
return result;
|
|
293
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "helium-npm",
|
|
3
|
+
"version": "1.0.5",
|
|
4
|
+
"description": "create helium json",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"helium-cli": "./index.js"
|
|
8
|
+
},
|
|
9
|
+
"type": "module",
|
|
10
|
+
"scripts": {
|
|
11
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
12
|
+
},
|
|
13
|
+
"author": "pythonstrup",
|
|
14
|
+
"license": "ISC",
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"bluebird": "^3.7.2",
|
|
17
|
+
"commander": "^12.1.0",
|
|
18
|
+
"console-ui": "^3.1.2",
|
|
19
|
+
"json-stringify-pretty-compact": "^4.0.0",
|
|
20
|
+
"moment": "^2.30.1",
|
|
21
|
+
"node-fetch": "^3.3.2",
|
|
22
|
+
"npm-dependants": "^2.1.2",
|
|
23
|
+
"npm-registry-client": "^8.6.0",
|
|
24
|
+
"prttty": "^0.9.1",
|
|
25
|
+
"silent-npm-registry-client": "^3.0.1",
|
|
26
|
+
"stream": "^0.0.3",
|
|
27
|
+
"underscore": "^1.13.6",
|
|
28
|
+
"xml2js": "^0.6.2"
|
|
29
|
+
}
|
|
30
|
+
}
|