-
Notifications
You must be signed in to change notification settings - Fork 0
/
events.js
109 lines (94 loc) · 2.9 KB
/
events.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
var chalk = require('chalk');
function subscriber(emitter, options) {
var count = 0;
emitter.on('abandoned', function (data) {
if (options.verbose || (options['max-delay'] < 5 && !options['info-only']) ) {
console.log(chalk.red('Package '+ data[0] +' abandoned, use https://packagist.org/packages/'+ data[1] +' instead'));
}
if (options['info-only']) {
return;
}
if (options['max-delay'] < 5) {
count++;
if (count === options['max-count']) {
process.exit(1);
}
}
});
emitter.on('unstable', function (data) {
if (options.verbose || (options['max-delay'] < 4 && !options['info-only']) ) {
console.log(chalk.red('Your using '+ data[0] +' with version '+ data[1] +' which is unstable'));
}
if (options['info-only']) {
return;
}
if (options['max-delay'] < 4) {
count++;
if (count === options['max-count']) {
process.exit(1);
}
}
});
emitter.on('major', function (data) {
if (options.verbose || (options['max-delay'] < 3 && !options['info-only']) ) {
console.log(chalk.red('Your version of '+ data[0] + ' is ' + data[1] + ' major late'));
}
if (options['info-only']) {
return;
}
if (options['max-delay'] < 3) {
count++;
if (count === options['max-count']) {
process.exit(1);
}
}
});
emitter.on('minor', function (data) {
if (options.verbose || (options['max-delay'] < 2 && !options['info-only']) ) {
console.log(chalk.yellow('Your version of '+ data[0] + ' is ' + data[1] + ' minor late'));
}
if (options['info-only']) {
return;
}
if (options['max-delay'] < 2) {
count++;
if (count === options['max-count']) {
process.exit(1);
}
}
});
emitter.on('patch', function (data) {
if (options.verbose || (options['max-delay'] < 1 && !options['info-only']) ) {
console.log(chalk.green('Your version of '+ data[0] + ' is ' + data[1] + ' patches late'));
}
if (options['info-only']) {
return;
}
if (options['max-delay'] < 1) {
count++;
if (count === options['max-count']) {
process.exit(1);
}
}
});
}
function delayValue(delay) {
switch (delay) {
case 'abandoned':
return 4;
case 'unstable':
return 3;
case 'major':
return 2;
case 'minor':
return 1;
case 'patch':
return 0;
default:
return 4;
}
}
module.exports = {
subscriber: subscriber,
delayValue: delayValue
};