-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
60 lines (53 loc) · 2.17 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
const dayjs = require('dayjs');
const customParseFormat = require('dayjs/plugin/customParseFormat');
const chalk = require('chalk');
const warning = chalk.bold.yellow;
const warningItalic = chalk.bold.yellow.italic;
const warningHeader = chalk.bold.bgYellowBright.black;
dayjs.extend(customParseFormat);
class DependencyHint {
static defaultOptions = {
lastUpdate: '',
daysTillWarning: 90,
inputFormat: 'DD.MM.YYYY',
outputFormat: 'DD.MM.YYYY',
warningText: 'Please consider your project manager to arrange a dependency update.',
compilerHook: 'afterEnvironment'
};
// Any options should be passed in the constructor of your plugin,
// (this is a public API of your plugin).
constructor(options = {}) {
// Applying user-specified options over the default options
// and making merged options further available to the plugin methods.
// You should probably validate all the options here as well.
this.options = { ...DependencyHint.defaultOptions, ...options };
}
apply(compiler) {
compiler.hooks[this.options.compilerHook].tap(
'Dependency Update hint plugin',
(
stats /* stats is passed as an argument when done hook is tapped. */
) => {
const {
daysTillWarning,
lastUpdate,
inputFormat,
outputFormat,
warningText,
} = this.options || {};
const lastUpdateDate = dayjs(lastUpdate, inputFormat);
const timeSinceLastUpdate = lastUpdateDate.diff(dayjs(), 'day') * -1
const isExpired = timeSinceLastUpdate >= daysTillWarning;
if (lastUpdate && lastUpdateDate.isValid() && isExpired) {
console.log('\n\n');
console.log(warningHeader(`${String.fromCodePoint(0x1F6A8)} Dependency Check:`));
console.log(' ' + warning(`The last dependency update is already ${chalk.underline(`${timeSinceLastUpdate} days`)} old.`));
console.log(' ' + warning(warningText));
console.log(' ' + warningItalic(`Last check: ${lastUpdateDate.format(outputFormat)}`));
console.log('\n\n');
}
}
);
}
}
module.exports = DependencyHint;