-
Notifications
You must be signed in to change notification settings - Fork 0
/
composer.js
95 lines (79 loc) · 3.41 KB
/
composer.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
86
87
88
89
90
91
92
93
94
95
var chalk = require('chalk');
var clear = require('clear');
var CLI = require('clui');
var figlet = require('figlet');
var parseArgs = require('minimist');
var Spinner = CLI.Spinner;
var path = require('path');
var axios = require('axios');
var file = require('./file.js');
var packagist = require('./packagist.js');
var delay = require('./delay.js');
var EventEmitter = require('events');
var events = require('./events.js');
var composer = require('./composer.js');
function testComposer(eventEmitter, options){
console.log(chalk.yellow('Reading composer.lock'));
var composerLock = file.readJsonFile('composer.lock');
var composer = file.readJsonFile('composer.json');
var packages = [];
var infos = [];
var infosSpinner = new Spinner('Getting Packages Info', ['⣾','⣽','⣻','⢿','⡿','⣟','⣯','⣷']);
infosSpinner.start();
for (let dependency of composerLock.packages) {
infos.push(axios.get(packagist.getPackageInfosUri(dependency.name)));
}
let projectDelay = {'major':0, 'minor':0, 'patch':0, 'abandoned':0, 'unstable':0};
axios.all(infos).then(function (results) {
for (let result of results) {
var packageInfos = result.data;
packages[packageInfos.package.name] = packageInfos.package;
}
}).then(function(){
infosSpinner.stop();
for (let dependency of composerLock.packages) {
var name = dependency.name;
var range = null;
if (options['respect-require']) {
range = composer.require[name];
}
var lastDependencyVersion = delay.getMaxVersion(Object.keys(packages[name].versions), range);
if (dependency.abandoned) {
projectDelay.abandoned++;
eventEmitter.emit('abandoned', [name, dependency.abandoned]);
}
if (!delay.isStable(dependency.version)) {
projectDelay.unstable++;
eventEmitter.emit('unstable', [name, dependency.version]);
}
if (delay.isStable(dependency.version)) {
var versionCompare = delay.compareVersions(lastDependencyVersion, dependency.version);
switch (versionCompare) {
case null:
eventEmitter.emit('nodelay', name);
break;
default:
if (versionCompare.major) {
eventEmitter.emit('major', [name, versionCompare.major]);
projectDelay.major++;
break;
}
if (versionCompare.minor) {
eventEmitter.emit('minor', [name, versionCompare.minor]);
projectDelay.minor++;
break;
}
if (versionCompare.patch) {
eventEmitter.emit('patch', [name, versionCompare.patch]);
projectDelay.patch++;
break;
}
}
}
}
delay.projectDelay(projectDelay, 'Composer');
});
}
module.exports = {
testComposer: testComposer
};