From d60ea923a83bf55a603cc2d8cb6578ac98efe6f4 Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Sun, 25 Jul 2021 17:40:10 +0100 Subject: [PATCH 1/6] :sparkles: Wrote quick script to check for updates --- services/update-checker.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 services/update-checker.js diff --git a/services/update-checker.js b/services/update-checker.js new file mode 100644 index 00000000..c55492fd --- /dev/null +++ b/services/update-checker.js @@ -0,0 +1,28 @@ +const axios = require('axios').default; + +const currentVersion = require('../package.json').version; + +const packageUrl = 'https://raw.githubusercontent.com/Lissy93/dashy/master/package.json'; + +const makeMsg = (latestVersion) => { + const parse = (version) => parseInt(version.replaceAll('.', ''), 10); + const difference = parse(latestVersion) - parse(currentVersion); + let msg = ''; + if (difference <= 0) { + msg = '\x1b[1m\x1b[32m✅ Dashy is Up-to-Date\x1b[0m\n'; + } else { + msg = `\x1b[103m\x1b[34m${new Array(27).fill('━').join('')}\x1b[0m\n` + + `\x1b[103m\x1b[34m⚠️ Update Available: ${latestVersion} \x1b[0m\n` + + `\x1b[103m\x1b[34m${new Array(27).fill('━').join('')}\x1b[0m\n`; + } + return msg; +}; + +axios.get(packageUrl).then((response) => { + if (response && response.data && response.data.version) { + console.log(`\nUsing Dashy V-${currentVersion}. Update Check Complete`); + console.log(makeMsg(response.data.version)); + } +}).catch(() => { + console.log('Unable to check for updates'); +}); From 7db441b493e0ad3a9734b1def1ce3d2855b7d7f9 Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Sun, 25 Jul 2021 17:42:01 +0100 Subject: [PATCH 2/6] :recycle: Moved config validator into services --- package.json | 2 +- .../ConfigValidator.js => services/config-validator.js | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) rename src/utils/ConfigValidator.js => services/config-validator.js (89%) diff --git a/package.json b/package.json index 2dc77a18..97567266 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "pm2-start": "npx pm2 start server.js", "build-watch": "vue-cli-service build --watch --mode production", "build-and-start": "npm-run-all --parallel build-watch start", - "validate-config": "node src/utils/ConfigValidator", + "validate-config": "node services/config-validator", "health-check": "node services/healthcheck" }, "dependencies": { diff --git a/src/utils/ConfigValidator.js b/services/config-validator.js similarity index 89% rename from src/utils/ConfigValidator.js rename to services/config-validator.js index 5f9bfdb6..bc6545e3 100644 --- a/src/utils/ConfigValidator.js +++ b/services/config-validator.js @@ -4,14 +4,16 @@ const Ajv = require('ajv'); const yaml = require('js-yaml'); const fs = require('fs'); -const schema = require('./ConfigSchema.json'); +const schema = require('../src/utils/ConfigSchema.json'); +/* Tell AJV to use strict mode, and report all errors */ const validatorOptions = { strict: true, allowUnionTypes: true, allErrors: true, }; +/* Initiate AJV validator */ const ajv = new Ajv(validatorOptions); /* Message printed when validation was successful */ @@ -58,13 +60,13 @@ const validate = (config) => { try { const config = yaml.load(fs.readFileSync('./public/conf.yml', 'utf8')); validate(config); -} catch (e) { +} catch (e) { // Something went very wrong... setIsValidVariable(false); console.log(bigError()); console.log('Please ensure that your config file is present, ' + 'has the correct access rights and is parsable. ' + 'If this warning persists, it may be an issue with the ' + 'validator function. Please raise an issue, and include the following stack trace:\n'); - console.warn('\x1b[33mStack Trace for ConfigValidators.js:\x1b[0m\n', e); + console.warn('\x1b[33mStack Trace for config-validator.js:\x1b[0m\n', e); console.log('\n\n'); } From 5a4c23ccc5ea48f35aae2b3f47520a71d25d8c72 Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Sun, 25 Jul 2021 17:42:49 +0100 Subject: [PATCH 3/6] :card_file_box: Adds appConfig.disableUpdateChecks to schema --- src/utils/ConfigSchema.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/utils/ConfigSchema.json b/src/utils/ConfigSchema.json index bb7a04d1..c07d1e95 100644 --- a/src/utils/ConfigSchema.json +++ b/src/utils/ConfigSchema.json @@ -244,6 +244,11 @@ "type": "boolean", "default": false, "description": "If set to true, custom right-click context menu will be disabled" + }, + "disableUpdateChecks": { + "type": "boolean", + "default": false, + "description": "Prevents Dashy from checking for updates" } }, "additionalProperties": false From bd1723237a37c74d916254c73c7d4585c5f07f42 Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Sun, 25 Jul 2021 17:43:47 +0100 Subject: [PATCH 4/6] :truck: Updates validator path, adds version checker script --- server.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/server.js b/server.js index 102cbb25..ee74ea37 100644 --- a/server.js +++ b/server.js @@ -13,12 +13,15 @@ const dns = require('dns'); const os = require('os'); const bodyParser = require('body-parser'); +/* Kick of some basic checks */ +require('./services/update-checker'); // Checks if there are any updates available, prints message +require('./services/config-validator'); // Include and kicks off the config file validation script + /* Include helper functions and route handlers */ const pingUrl = require('./services/ping'); // Used by the status check feature, to ping services const saveConfig = require('./services/save-config'); // Saves users new conf.yml to file-system const printMessage = require('./services/print-message'); // Function to print welcome msg on start const rebuild = require('./services/rebuild-app'); // A script to programmatically trigger a build -require('./src/utils/ConfigValidator'); // Include and kicks off the config file validation script /* Checks if app is running within a container, from env var */ const isDocker = !!process.env.IS_DOCKER; From ae0277efda57659748791e5b36d60bab6fefb9f6 Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Sun, 25 Jul 2021 17:44:29 +0100 Subject: [PATCH 5/6] :bookmark: Bumps to V-1.4.4 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 97567266..a7c219ed 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "Dashy", - "version": "1.4.3", + "version": "1.4.4", "license": "MIT", "main": "server", "scripts": { From 5806e8f97a6c6b8f520c4f3b88b224ae6e317ba2 Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Sun, 25 Jul 2021 17:48:08 +0100 Subject: [PATCH 6/6] :octocat: Adds checklist item in PR template, to remember version bump --- .github/pull_request_template.md | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 6041f6e0..f4a641b3 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -20,4 +20,5 @@ - [ ] There are no (new) build warnings or errors - [ ] _(If a new config option is added)_ Attribute is outlined in the schema and documented - [ ] _(If a new dependency is added)_ Package is essential, and has been checked out for security or performance +- [ ] Bumps version, if new feature added