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 diff --git a/package.json b/package.json index 2dc77a18..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": { @@ -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/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; 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'); } 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'); +}); 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