Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUILD] - Adds update check in build process, and refactors #102

Merged
merged 6 commits into from
Jul 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Dashy",
"version": "1.4.3",
"version": "1.4.4",
"license": "MIT",
"main": "server",
"scripts": {
Expand All @@ -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": {
Expand Down
5 changes: 4 additions & 1 deletion server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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');
}
28 changes: 28 additions & 0 deletions services/update-checker.js
Original file line number Diff line number Diff line change
@@ -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');
});
5 changes: 5 additions & 0 deletions src/utils/ConfigSchema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down