From 980b8a2924d99261c884328af8a35d6f89e13c71 Mon Sep 17 00:00:00 2001 From: Olexandr Savchuk Date: Wed, 14 Dec 2016 18:54:44 +0100 Subject: [PATCH 1/4] Added console warning for deprecated config options --- CHANGELOG.md | 1 + config/.gitignore | 1 + config/deprecated.js | 12 ++++++++++++ js/app.js | 16 ++++++++++++++++ 4 files changed, 30 insertions(+) create mode 100644 config/deprecated.js diff --git a/CHANGELOG.md b/CHANGELOG.md index fb41a8de..8e92ebf6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). - Added option `roundTemp` for currentweather and weatherforecast modules to display temperatures rounded to nearest integer. - Added abilty set the classes option to compliments module for style and text size of compliments. - Added ability to configure electronOptions +- Added console warning on startup when deprecated config options are used ### Updated - Modified translations for Frysk. diff --git a/config/.gitignore b/config/.gitignore index d85e3bd4..daeb6336 100644 --- a/config/.gitignore +++ b/config/.gitignore @@ -1,2 +1,3 @@ * !config.js.sample +!deprecated.js diff --git a/config/deprecated.js b/config/deprecated.js new file mode 100644 index 00000000..cf305582 --- /dev/null +++ b/config/deprecated.js @@ -0,0 +1,12 @@ +/* Magic Mirror Deprecated Config Options List + * + * By Michael Teeuw http://michaelteeuw.nl + * MIT Licensed. + */ + +var deprecated = [ + 'kioskmode' +]; + +/*************** DO NOT EDIT THE LINE BELOW ***************/ +if (typeof module !== 'undefined') {module.exports = deprecated;} diff --git a/js/app.js b/js/app.js index 29036f69..e5ea72fb 100644 --- a/js/app.js +++ b/js/app.js @@ -42,6 +42,7 @@ var App = function() { try { fs.accessSync(configFilename, fs.F_OK); var c = require(configFilename); + checkDeprecatedOptions(c); var config = Object.assign(defaults, c); callback(config); } catch (e) { @@ -58,6 +59,21 @@ var App = function() { } }; + var checkDeprecatedOptions = function(userConfig) { + var deprecatedOptions = require(__dirname + "/../config/deprecated.js"); + var usedDeprecated = []; + + deprecatedOptions.forEach(function(option) { + if (userConfig.hasOwnProperty(option)) { + usedDeprecated.push(option); + } + }); + + if (usedDeprecated.length > 0) { + console.error("WARNING! Your config is using deprecated options: " + usedDeprecated.join(", ") + ". Check README and CHANGELOG for more up-to-date ways of getting the same functionality."); + } + } + /* loadModule(module) * Loads a specific module. * From 90616c82b67af98fe4769fec14b1c0a282f96f41 Mon Sep 17 00:00:00 2001 From: Olexandr Savchuk Date: Wed, 14 Dec 2016 18:54:44 +0100 Subject: [PATCH 2/4] Added console warning for deprecated config options --- CHANGELOG.md | 1 + config/.gitignore | 1 + config/deprecated.js | 12 ++++++++++++ js/app.js | 16 ++++++++++++++++ 4 files changed, 30 insertions(+) create mode 100644 config/deprecated.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 706299cd..237315d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -70,6 +70,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). - Added ability to configure electronOptions - Calendar module: option to hide private events - Add root_path for global vars +- Added console warning on startup when deprecated config options are used ### Updated - Modified translations for Frysk. diff --git a/config/.gitignore b/config/.gitignore index d85e3bd4..daeb6336 100644 --- a/config/.gitignore +++ b/config/.gitignore @@ -1,2 +1,3 @@ * !config.js.sample +!deprecated.js diff --git a/config/deprecated.js b/config/deprecated.js new file mode 100644 index 00000000..cf305582 --- /dev/null +++ b/config/deprecated.js @@ -0,0 +1,12 @@ +/* Magic Mirror Deprecated Config Options List + * + * By Michael Teeuw http://michaelteeuw.nl + * MIT Licensed. + */ + +var deprecated = [ + 'kioskmode' +]; + +/*************** DO NOT EDIT THE LINE BELOW ***************/ +if (typeof module !== 'undefined') {module.exports = deprecated;} diff --git a/js/app.js b/js/app.js index 9f992b29..56216238 100644 --- a/js/app.js +++ b/js/app.js @@ -56,6 +56,7 @@ var App = function() { try { fs.accessSync(configFilename, fs.F_OK); var c = require(configFilename); + checkDeprecatedOptions(c); var config = Object.assign(defaults, c); callback(config); } catch (e) { @@ -72,6 +73,21 @@ var App = function() { } }; + var checkDeprecatedOptions = function(userConfig) { + var deprecatedOptions = require(__dirname + "/../config/deprecated.js"); + var usedDeprecated = []; + + deprecatedOptions.forEach(function(option) { + if (userConfig.hasOwnProperty(option)) { + usedDeprecated.push(option); + } + }); + + if (usedDeprecated.length > 0) { + console.error("WARNING! Your config is using deprecated options: " + usedDeprecated.join(", ") + ". Check README and CHANGELOG for more up-to-date ways of getting the same functionality."); + } + } + /* loadModule(module) * Loads a specific module. * From db0b663a3dbad2d4bcb1fa8a5e0a9eca0b277341 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodrigo=20Ram=C3=ADrez=20Norambuena?= Date: Tue, 21 Feb 2017 19:28:53 -0300 Subject: [PATCH 3/4] Put file deprecated into js directory Request in Pull Request #569 Initial work by @olexs --- CHANGELOG.md | 2 +- config/.gitignore | 1 - js/app.js | 8 ++++++-- {config => js}/deprecated.js | 10 ++++++---- 4 files changed, 13 insertions(+), 8 deletions(-) rename {config => js}/deprecated.js (52%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 56bd5fc1..1138da27 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -47,6 +47,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). - Estonian Translation. - Add test for compliments module for parts of day - Korean Translation. +- Added console warning on startup when deprecated config options are used ### Fixed @@ -92,7 +93,6 @@ This project adheres to [Semantic Versioning](http://semver.org/). - Added ability to configure electronOptions - Calendar module: option to hide private events - Add root_path for global vars -- Added console warning on startup when deprecated config options are used ### Updated - Modified translations for Frysk. diff --git a/config/.gitignore b/config/.gitignore index daeb6336..d85e3bd4 100644 --- a/config/.gitignore +++ b/config/.gitignore @@ -1,3 +1,2 @@ * !config.js.sample -!deprecated.js diff --git a/js/app.js b/js/app.js index 792b9047..5582df58 100644 --- a/js/app.js +++ b/js/app.js @@ -79,7 +79,7 @@ var App = function() { }; var checkDeprecatedOptions = function(userConfig) { - var deprecatedOptions = require(__dirname + "/../config/deprecated.js"); + var deprecatedOptions = require(global.root_path + "/js/deprecated.js").configs; var usedDeprecated = []; deprecatedOptions.forEach(function(option) { @@ -89,7 +89,11 @@ var App = function() { }); if (usedDeprecated.length > 0) { - console.error("WARNING! Your config is using deprecated options: " + usedDeprecated.join(", ") + ". Check README and CHANGELOG for more up-to-date ways of getting the same functionality."); + console.warn( + "WARNING! Your config is using deprecated options: ", + usedDeprecated.join(", "), + ". Check README and CHANGELOG for more up-to-date ways of getting the same functionality." + ); } } diff --git a/config/deprecated.js b/js/deprecated.js similarity index 52% rename from config/deprecated.js rename to js/deprecated.js index cf305582..8632d775 100644 --- a/config/deprecated.js +++ b/js/deprecated.js @@ -2,11 +2,13 @@ * * By Michael Teeuw http://michaelteeuw.nl * MIT Licensed. + * + * Olex S. original idea this deprecated option */ -var deprecated = [ - 'kioskmode' -]; +var deprecated = { + configs: ["kioskmode"] +}; /*************** DO NOT EDIT THE LINE BELOW ***************/ -if (typeof module !== 'undefined') {module.exports = deprecated;} +if (typeof module !== "undefined") {module.exports = deprecated;} From bd0da63f4c9d9222f0423efa4b14f4869e0c62a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodrigo=20Ram=C3=ADrez=20Norambuena?= Date: Tue, 21 Feb 2017 20:21:46 -0300 Subject: [PATCH 4/4] use colors for warning message in deprecated options --- js/app.js | 12 +++++++----- js/deprecated.js | 5 ++++- package.json | 1 + 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/js/app.js b/js/app.js index 5582df58..9c1ef74d 100644 --- a/js/app.js +++ b/js/app.js @@ -79,7 +79,9 @@ var App = function() { }; var checkDeprecatedOptions = function(userConfig) { - var deprecatedOptions = require(global.root_path + "/js/deprecated.js").configs; + var deprecated = require(global.root_path + "/js/deprecated.js"); + var deprecatedOptions = deprecated.configs; + var usedDeprecated = []; deprecatedOptions.forEach(function(option) { @@ -89,10 +91,10 @@ var App = function() { }); if (usedDeprecated.length > 0) { - console.warn( - "WARNING! Your config is using deprecated options: ", - usedDeprecated.join(", "), - ". Check README and CHANGELOG for more up-to-date ways of getting the same functionality." + console.warn(deprecated.colors.warn( + "WARNING! Your config is using deprecated options: " + + usedDeprecated.join(", ") + + ". Check README and CHANGELOG for more up-to-date ways of getting the same functionality.") ); } } diff --git a/js/deprecated.js b/js/deprecated.js index 8632d775..5df1d71f 100644 --- a/js/deprecated.js +++ b/js/deprecated.js @@ -5,9 +5,12 @@ * * Olex S. original idea this deprecated option */ +var colors = require("colors/safe"); +colors.setTheme({warn: "yellow"}) var deprecated = { - configs: ["kioskmode"] + configs: ["kioskmode"], + colors: colors }; /*************** DO NOT EDIT THE LINE BELOW ***************/ diff --git a/package.json b/package.json index e687ecb8..704f8394 100644 --- a/package.json +++ b/package.json @@ -44,6 +44,7 @@ "time-grunt": "latest" }, "dependencies": { + "colors": "^1.1.2", "electron": "^1.4.7", "express": "^4.14.0", "express-ipfilter": "latest",