This repository has been archived by the owner on Jul 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
87 lines (73 loc) · 2.14 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
85
var async = require('async');
var getPackageVersion = function(packageName, callback) {
var versionJob = {
"id": "get package version",
"working_dir": "/tmp/KHAgent",
"options": {
"timeoutms": 40000,
"noEcho": true
},
"files": [],
"script": {
"env": {
"PATH": '/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin',
"PACKAGE_NAME": packageName
},
"commands": [
{
"command": "npm show ${PACKAGE_NAME} version"
}
]
}
}
var KnowhowShell = require('../knowhow-shell');
var knowhowShell = new KnowhowShell();
knowhowShell.executeJobAsSubProcess(versionJob, function(err, jobRuntime) {
if(err) {
console.error("unable to get version for packaage: "+packageName+" "+err.message);
callback(err);
} else {
console.log(jobRuntime);
callback(undefined, jobRuntime.scriptRuntime.completedCommands[0].output);
}
});
};
var getInstalledVersions = function() {
var knowhow = require('./package.json');
var knowhowShell = require('knowhow-shell/package.json');
var knowhowApi = require('knowhow-api/package.json');
var knowhowServer = require('knowhow-server/package.json');
var knowhowAgent = require('knowhow-agent/package.json');
var versions = {
'knowhow': knowhow.version,
'knowhow-shell': knowhowShell.version,
'knowhow-api': knowhowApi.version,
'knowhow-server': knowhowServer.version,
'knowhow-agent': knowhowAgent.version
};
return versions;
}
var getNewestVersions = function(callback) {
var packages = ['knowhow', 'knowhow-shell', 'knowhow-api', 'knowhow-server', 'knowhow-agent'];
var versions = {};
async.each(packages, function(package, cb) {
getPackageVersion(package, function(err, version) {
if (err) {
cb(err);
} else {
versions[package] = version;
cb();
}
});
}, function(err) {
callback(versions);
});
}
exports.getNewestVersions = getNewestVersions;
exports.installedVersions = getInstalledVersions();
/*
getNewestVersions(function(newestVersions) {
exports.newestVersions = newestVersions;
console.log(exports.newestVersions);
console.log(exports.installedVersions);
});*/