Skip to content

Commit

Permalink
Switch to ES6 exports/imports (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
reconman authored Sep 24, 2022
1 parent 7f31832 commit 3524829
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 44 deletions.
3 changes: 2 additions & 1 deletion etc/config.example.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
let config = {
interval: 60000, // Feed check interval, in miliseconds
userAgent: 'Mozilla/5.0 (Linux x86_64; rv:76.0) Gecko/20100101 Firefox/76.0', // Experimental: User agent string to bypass possible fetching limits on GitHub
/**
Expand Down Expand Up @@ -84,3 +84,4 @@ module.exports = {
// direct rss links from other sources if you want to watch with this tool
],
};
export { config }
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "2.1.1",
"description": "A tool to send notifications when an update to a repository is released",
"main": "./src/index.js",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"init": "cp ./etc/config.example.js ./etc/config.js",
Expand Down
19 changes: 10 additions & 9 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
/* eslint no-console: ["error", { allow: ["warn", "error", "log"] }] */

// First, let's require the libraries
const RssFeedEmitter = require('rss-feed-emitter');
const http = require('http');

const config = require('../etc/config');
const alertHubUtils = require('./utils/alertHub');
const pushBulletUtils = require('./utils/pushBullet');
const pushOverUtils = require('./utils/pushOver');
const emailUtils = require('./utils/email');
const rssUtils = require('./utils/rss');
import RssFeedEmitter from 'rss-feed-emitter'
import http from 'http'

import * as alertHubUtils from './utils/alertHub.js';
import pushBulletUtils from './utils/pushBullet.js';
import pushOverUtils from './utils/pushOver.js';
import emailUtils from './utils/email.js';
import rssUtils from './utils/rss.js';

import { config } from '../etc/config.js';

// RSS Feed emitter to watch and parse feed
const feeder = new RssFeedEmitter({ userAgent: config.userAgent || 'Mozilla/5.0 (Linux x86_64; rv:76.0) Gecko/20100101 Firefox/76.0' });
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/rss-braider/addReleaseNameToTitle.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
}]
*/
// We need a plug-in to add release name to the title.
const utils = require('../../utils/alertHub');
import * as utils from '../../utils/alertHub.js'

module.exports = (_item, itemOptions, /* source */) => {
export default (_item, itemOptions, /* source */) => {
if (
utils.isFeedFromGitHub(itemOptions) === true
|| utils.isFeedFromGitLab(itemOptions) === true
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/rss-braider/fixGitLabDateColumn.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"props": true, "ignorePropertyModificationsFor": ["itemOptions"]
}]
*/
module.exports = (item, itemOptions /* , source */) => {
export default (item, itemOptions /* , source */) => {
if (
itemOptions.date === null
&& item.meta !== undefined
Expand Down
7 changes: 4 additions & 3 deletions src/utils/alertHub.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const URL = require('url');
const querystring = require('querystring');
import URL from 'url';
import querystring from 'querystring';

// Because there are also feeds,
// we need this method to check whether the feed is from GitHub or not
function isFeedFromGitHub(item) {
Expand Down Expand Up @@ -66,7 +67,7 @@ function generateURLForTheFeed(options, config) {
return '';
}

module.exports = {
export {
parseFeedData,
generateURLForTheFeed,
// These bottom methods are for rss braider plugin to prepend release name to feed title
Expand Down
10 changes: 3 additions & 7 deletions src/utils/email.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const mail = require('nodemailer');
const striptags = require('striptags');
import mail from 'nodemailer';
import striptags from 'striptags';

// Sends and e-mail notification to provided user
async function sendEmailNotification(config, feedData) {
export default async function sendEmailNotification(config, feedData) {
const transporter = mail.createTransport(config.notifications.email.config);

/* await smtp.verify((error, success) => {
Expand Down Expand Up @@ -31,7 +31,3 @@ async function sendEmailNotification(config, feedData) {
return info;
});
}

module.exports = {
sendEmailNotification,
};
10 changes: 3 additions & 7 deletions src/utils/pushBullet.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const PushBullet = require('pushbullet');
import PushBullet from 'pushbullet';

// Strip tags is to remove HTML before sending to Pushbullet.
const striptags = require('striptags');
import striptags from 'striptags';

// Send the push notification.
// Todo: why bother with async / await at all ?
async function sendPushBulletNotification(config, feedData) {
export default async function sendPushBulletNotification(config, feedData) {
const pusher = new PushBullet(config.notifications.pushbullet.accessToken);
await pusher.link(
{},
Expand All @@ -21,7 +21,3 @@ async function sendPushBulletNotification(config, feedData) {
}
);
}

module.exports = {
sendPushBulletNotification,
};
10 changes: 3 additions & 7 deletions src/utils/pushOver.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const PushOver = require('pushover-notifications');
const striptags = require('striptags');
import PushOver from 'pushover-notifications';
import striptags from 'striptags';

// Send the push notification.
// Todo: why bother with async / await at all ?
async function sendPushOverNotification(config, feedData) {
export default async function sendPushOverNotification(config, feedData) {
return new Promise((resolve, reject) => {
const pusher = new PushOver({
user: config.notifications.pushover.config.user,
Expand All @@ -24,7 +24,3 @@ async function sendPushOverNotification(config, feedData) {
});
});
}

module.exports = {
sendPushOverNotification,
};
11 changes: 4 additions & 7 deletions src/utils/rss.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const rssBraider = require('rss-braider');
const path = require('path');
const alertHubUtils = require('./alertHub');
import rssBraider from 'rss-braider';
import path from 'path';
import * as alertHubUtils from './alertHub.js';

// Creates a RSS feed from the configuration provided
function createRSSFeed(config) {
export default function createRSSFeed(config) {
if (config.rss.enabled === true) {
const AlertHubFeeds = {
alertHub: {
Expand Down Expand Up @@ -138,6 +138,3 @@ function createRSSFeed(config) {
return Promise.resolve('');
}

module.exports = {
createRSSFeed,
};

0 comments on commit 3524829

Please sign in to comment.