-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.js
executable file
·69 lines (51 loc) · 1.86 KB
/
cli.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
#!/usr/bin/env node
/*!
has-news-alert
If any items in the RSS feeds are less than `alertOnLessThan` old, exit with a non-zero value.
© Nick Freear, 19-June-2019.
License: MIT
*/
const hasNewsAlert = require('./index');
const notifier = require('node-notifier');
const PKG = require('./package.json');
const OPT = PKG[ 'x-hasNewsAlertConfig' ];
const URLS = OPT.feedUrls;
// https://github.com/datejs/Datejs#syntax-overview
const DATE_COMPARE = Date.parse('-' + OPT.alertOnLessThan);
// https://www.npmjs.com/package/rss-parser#nodejs
// https://es6console.com/jilim58f/
// let Parser = require('rss-parser');
console.warn('has-news-alert URLs:', URLS);
console.warn('Date compare:', DATE_COMPARE, ',', OPT.alertOnLessThan);
console.warn('HTTPS proxy:', process.env.https_proxy);
console.warn('Travis event type:', process.env.TRAVIS_EVENT_TYPE);
var newsAlerts = [];
var promises = hasNewsAlert(OPT, URLS, function (err, feed) {
if (err) {
console.error('Error:', err);
process.exit(254);
}
console.warn('Feed:', feed.title, ',', feed.url, ',', feed.statusCode);
}, function (err, alert) {
if (err) {
console.error('Error:', err);
process.exit(255);
}
newsAlerts.push(alert);
// https://en.wikibooks.org/wiki/Unicode/List_of_useful_symbols#Geometry
console.warn(' ∟ Alert:', alert.title, ',', alert.timeAgo, ',', alert.url);
if (!process.env.TRAVIS) {
notifier.notify({ title: alert.title, message: alert.timeAgo, url: alert.url, date: alert.date, icon: null, sound: true, wait: true });
}
});
notifier.on('click', function (obj, options) {
console.warn('Notify:', options);
});
Promise.all(promises).then(function () {
console.warn('Alert count:', newsAlerts.length);
console.warn('Exit code:', newsAlerts.length);
setTimeout(function () {
process.exit(newsAlerts.length);
}, process.env.TRAVIS ? 0 : 3000);
});
// End.