Skip to content

Commit

Permalink
ESLint Refactorings
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Litzenburger committed Sep 22, 2021
1 parent 901decd commit 0249716
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 11,305 deletions.
15 changes: 13 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
{
"root": true,
"extends": ["airbnb-typescript-prettier"],
"ignorePatterns": ["*.js"]
}
"ignorePatterns": ["*.js"],
"rules": {
"newline-before-return": "warn",
"no-restricted-syntax": "off",
"import/no-unresolved": "off",
"no-await-in-loop": "warn",
"lines-between-class-members": "off",
"class-methods-use-this": "warn",
"@typescript-eslint/no-empty-function": "warn",
"no-param-reassign": "warn"
}
}
4 changes: 2 additions & 2 deletions MMM-NINA.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*! *****************************************************************************
mmm-nina
Version 1.0.0
Version 1.1.1
Simple Client Implementierung für die NINA Warn App für die MagicMirror² Plattform.
Please submit bugs at https://github.com/jalibu/MMM-NINA/issues
Expand All @@ -11,4 +11,4 @@
This file is auto-generated. Do not edit.
***************************************************************************** */

!function(){"use strict";Module.register("MMM-NINA",{defaults:{ags:"110000000000",maxAgeInHours:6,maxWidth:null,showIcon:!0,showNoWarning:!1,updateIntervalInSeconds:120},getStyles:()=>["font-awesome.css","MMM-NINA.css"],getScripts:function(){return["moment.js"]},getTranslations:()=>({en:"translations/en.json",de:"translations/de.json"}),getTemplate:()=>"templates/MMM-NINA.njk",getTemplateData(){return{config:this.config,alerts:this.alerts}},start(){this.loadData(),this.scheduleUpdate(),this.updateDom()},scheduleUpdate(){const t=this;setInterval((()=>{t.loadData()}),1e3*this.config.updateIntervalInSeconds)},loadData(){this.sendSocketNotification("GET_NINA_ALERTS",this.config)},socketNotificationReceived(t,e){"NINA_ALERTS_RESPONSE"===t&&(this.alerts=e.map((t=>(t.date=moment(new Date(t.sent)).format("DD.MM.YYYY - HH:mm"),t))),this.updateDom(),console.debug("Alerts",this.alerts))}})}();
!function(){"use strict";Module.register("MMM-NINA",{defaults:{ags:"110000000000",maxAgeInHours:6,maxWidth:null,showIcon:!0,showNoWarning:!1,updateIntervalInSeconds:120},getStyles:()=>["font-awesome.css","MMM-NINA.css"],getScripts:()=>["moment.js"],getTranslations:()=>({en:"translations/en.json",de:"translations/de.json"}),getTemplate:()=>"templates/MMM-NINA.njk",getTemplateData(){return{config:this.config,alerts:this.alerts}},start(){this.loadData(),this.scheduleUpdate(),this.updateDom()},scheduleUpdate(){setInterval((()=>{this.loadData()}),1e3*this.config.updateIntervalInSeconds)},loadData(){this.sendSocketNotification("GET_NINA_ALERTS",this.config)},socketNotificationReceived(t,e){"NINA_ALERTS_RESPONSE"===t&&(this.alerts=e.map((t=>(t.date=moment(new Date(t.sent)).format("DD.MM.YYYY - HH:mm"),t))),this.updateDom(),console.debug("Alerts",this.alerts))}})}();
4 changes: 2 additions & 2 deletions node_helper.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*! *****************************************************************************
mmm-nina
Version 1.0.0
Version 1.1.1
Simple Client Implementierung für die NINA Warn App für die MagicMirror² Plattform.
Please submit bugs at https://github.com/jalibu/MMM-NINA/issues
Expand All @@ -26,4 +26,4 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
function a(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{c(r.next(e))}catch(e){i(e)}}function s(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}c((r=r.apply(e,t||[])).next())}))}module.exports=o.create({start(){console.log(`${this.name} helper method started...`)},transformNinaAlerts(e,t){const n=(new Date).getTime();return e.filter((e=>(n-Date.parse(e.sent))/36e5<=t.maxAgeInHours))},harmonizeAgs:e=>e.substring(0,e.length-7)+"0000000",socketNotificationReceived(e,t){return a(this,void 0,void 0,(function*(){if("GET_NINA_ALERTS"===e){const e=yield i.default(`https://warnung.bund.de/api31/dashboard/${this.harmonizeAgs(t.ags)}.json`);if(e.ok)try{const n=yield e.json();this.sendSocketNotification("NINA_ALERTS_RESPONSE",this.transformNinaAlerts(n,t))}catch(e){console.warn("There was a problem requesting the NINA API",e)}else console.warn(`There was a problem ${e.status} requesting the NINA API:`,e.statusText)}else console.warn(`${e} is invalid notification`)}))}});
function a(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{c(r.next(e))}catch(e){i(e)}}function s(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}c((r=r.apply(e,t||[])).next())}))}module.exports=o.create({start(){console.log(`${this.name} helper method started...`)},transformNinaAlerts(e,t){const n=(new Date).getTime();return e.filter((e=>(n-Date.parse(e.sent))/36e5<=t.maxAgeInHours))},harmonizeAgs:e=>`${e.substring(0,e.length-7)}0000000`,socketNotificationReceived(e,t){return a(this,void 0,void 0,(function*(){if("GET_NINA_ALERTS"===e){const e=yield i.default(`https://warnung.bund.de/api31/dashboard/${this.harmonizeAgs(t.ags)}.json`);if(e.ok)try{const n=yield e.json();this.sendSocketNotification("NINA_ALERTS_RESPONSE",this.transformNinaAlerts(n,t))}catch(e){console.warn("There was a problem requesting the NINA API",e)}else console.warn(`There was a problem ${e.status} requesting the NINA API:`,e.statusText)}else console.warn(`${e} is invalid notification`)}))}});
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mmm-nina",
"version": "1.1.0",
"version": "1.1.1",
"description": "Simple Client Implementierung für die NINA Warn App für die MagicMirror² Plattform.",
"main": "MMM-NINA.js",
"repository": {
Expand Down
4 changes: 2 additions & 2 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ const bannerText = `/*! ********************************************************
`
export default [
{
input: './src/client/Client.ts',
input: './src/frontend/Frontend.ts',
plugins: [typescript({ module: 'ESNext' }), nodeResolve(), commonjs(), terser(), banner2(() => bannerText)],
output: {
file: './' + pkg.main,
format: 'iife'
}
},
{
input: './src/server/Server.ts',
input: './src/backend/Backend.ts',
external: ['node_helper', 'node-fetch'],
plugins: [typescript({ module: 'ESNext' }), terser(), banner2(() => bannerText)],
output: {
Expand Down
3 changes: 2 additions & 1 deletion src/server/Server.ts → src/backend/Backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ module.exports = NodeHelper.create({
const now = new Date().getTime()

const filtered = alerts.filter((alert) => (now - Date.parse(alert.sent)) / (1000 * 60 * 60) <= config.maxAgeInHours)

return filtered
},

harmonizeAgs(ags: string): string {
return ags.substring(0, ags.length - 7) + '0000000'
return `${ags.substring(0, ags.length - 7)}0000000`
},

async socketNotificationReceived(notification, payload) {
Expand Down
8 changes: 4 additions & 4 deletions src/client/Client.ts → src/frontend/Frontend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Module.register<Config>('MMM-NINA', {
return ['font-awesome.css', 'MMM-NINA.css']
},

getScripts: function () {
getScripts: () => {
return ['moment.js']
},

Expand Down Expand Up @@ -46,9 +46,8 @@ Module.register<Config>('MMM-NINA', {
},

scheduleUpdate() {
const self = this
setInterval(() => {
self.loadData()
this.loadData()
}, this.config.updateIntervalInSeconds * 1000)
},

Expand All @@ -60,10 +59,11 @@ Module.register<Config>('MMM-NINA', {
if (notificationIdentifier === 'NINA_ALERTS_RESPONSE') {
this.alerts = payload.map((alert) => {
alert.date = moment(new Date(alert.sent)).format('DD.MM.YYYY - HH:mm')

return alert
})
this.updateDom()

console.debug('Alerts', this.alerts)
}
}
Expand Down
Loading

0 comments on commit 0249716

Please sign in to comment.