Skip to content

Commit

Permalink
refactor(Core): Adds code rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
unigazer committed Oct 24, 2021
1 parent d73d7bf commit 94c19d1
Show file tree
Hide file tree
Showing 7 changed files with 612 additions and 3,512 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": 2018,
"ecmaVersion": 2020,
"sourceType": "module"
},
"rules": {
Expand Down
13 changes: 7 additions & 6 deletions components/notify.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const WindowsToaster = require('node-notifier').WindowsToaster;
const open = require('open');
import { WindowsToaster } from 'node-notifier';
import open from 'open';

// Create notification
/**
Expand All @@ -8,17 +8,18 @@ const open = require('open');
* This only shows the notification if there is a version greater than
* the one that is installed on your machine.
*/
const notify = (latest) => {
const notify = (latest, lts = '') => {
let notifier = new WindowsToaster({
withFallback: true
});

notifier.notify({
title: 'New Node.js version is available',
title: `New Node.js ${lts} version is available`,
message: `Version tag: ${latest}\nClick on the notification to download`,
icon: './icons/app.png',
wait: true,
}, (error, res) => {
appID: 'gimme-new-node',
}, (error) => {
if (error) {
throw new Error(error);
}
Expand All @@ -29,4 +30,4 @@ const notify = (latest) => {
});
};

module.exports = notify;
export default notify;
30 changes: 18 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
// Imports
const got = require('got');
const notify = require('./components/notify');
import got from 'got';
import notify from './components/notify.js';

// Get the latest version
(async () => {
try {
// Get the data
const res = await got('https://gimme-new-node-api.vercel.app/api/query').json();
const localVersion = process.version.split('.').join('').substring(1);

// Get the latest version by tag
const [{ tag }] = res.filter(({ tag }) => tag.name.includes(process.version.slice(1,3)));

// Current Node.js version on the machine
const current_ver = process.version;

// Show the notificaion
if (current_ver < tag.name ) {
notify(tag.name);
// If the local version is LTS
if (process.release?.lts) {
const versions = res.filter(({ tagName, name }) => {
return name.includes('LTS') && Number(tagName.split('.').join('').substring(1)) > Number(localVersion);
});
if (versions?.[0]?.tagName) {
notify(versions[0].tagName, 'LTS');
}
} else {
const versions = res.filter(({ isLatest, tagName }) => {
return isLatest && Number(tagName.split('.').join('').substring(1)) > Number(localVersion);
});
if (versions?.[0]?.tagName) {
notify(versions[0].tagName);
}
}

} catch (error) {
throw new Error(error);
}
Expand Down
Loading

0 comments on commit 94c19d1

Please sign in to comment.