mirror of https://github.com/Lissy93/dashy.git
🔀 Merge pull request #102 from Lissy93/BUILD/adds-update-check
[BUILD] - Adds update check in build process, and refactors
This commit is contained in:
commit
3836b58908
|
@ -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
|
||||
|
||||
|
|
|
@ -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": {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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');
|
||||
}
|
|
@ -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');
|
||||
});
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue