1 | import R from "ramda";
|
2 | import Promise from "bluebird";
|
3 | import semver from "semver";
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | export default (id, gettinglocalPackage, gettingRemotePackage) => {
|
15 | return new Promise((resolve, reject) => {
|
16 | const isUpdateRequired = (localVersion, remoteVersion) => {
|
17 | return R.isNil(remoteVersion)
|
18 | ? false
|
19 | : localVersion === null ? true : semver.gt(remoteVersion, localVersion);
|
20 | };
|
21 |
|
22 | const isDependenciesChanged = (localJson, remoteJson) => {
|
23 | if (R.isNil(localJson)) { return false; }
|
24 | if (R.isNil(remoteJson)) { return false; }
|
25 | const local = localJson.dependencies || {};
|
26 | const remote = remoteJson.dependencies || {};
|
27 | const localKeys = Object.keys(local);
|
28 | const remoteKeys = Object.keys(remote);
|
29 | if (localKeys.length !== remoteKeys.length) { return true; }
|
30 | const index = 0;
|
31 | const isChanged = (key) => {
|
32 | if (localKeys[index] !== remoteKeys[index]) { return false; }
|
33 | return local[key] !== remote[key];
|
34 | };
|
35 | return R.any(isChanged)(Object.keys(local));
|
36 | };
|
37 |
|
38 | Promise.coroutine(function*() {
|
39 |
|
40 | const localPackage = yield gettinglocalPackage.catch(err => reject(err));
|
41 | const remotePackage = yield gettingRemotePackage.catch(err => reject(err));
|
42 |
|
43 |
|
44 | const localVersion = localPackage.exists ? localPackage.json.version : null;
|
45 | const remoteVersion = remotePackage.exists ? remotePackage.json.version : null;
|
46 | const result = {
|
47 | id,
|
48 | local: localVersion,
|
49 | remote: remoteVersion,
|
50 | isUpdateRequired: isUpdateRequired(localVersion, remoteVersion),
|
51 | isDependenciesChanged: isDependenciesChanged(localPackage.json, remotePackage.json)
|
52 | };
|
53 |
|
54 |
|
55 | resolve(result);
|
56 | })();
|
57 | });
|
58 | };
|