Don't log deprecated when no plugins is using deprecated APIs

This commit is contained in:
Samy Pesse
2016-10-10 23:18:38 +02:00
parent 3000dcefe1
commit aa39b8e71b
5 changed files with 73 additions and 80 deletions
+7 -7
View File
@@ -1,13 +1,13 @@
const decodeConfig = require('./decodeConfig');
/**
Decode changes from a JS API to a output object.
Only the configuration can be edited by plugin's hooks
@param {Output} output
@param {Object} result: result from API
@return {Output}
*/
* Decode changes from a JS API to a output object.
* Only the configuration can be edited by plugin's hooks
*
* @param {Output} output
* @param {Object} result: result from API
* @return {Output} output
*/
function decodeGlobal(output, result) {
let book = output.getBook();
let config = book.getConfig();
+44 -46
View File
@@ -5,12 +5,12 @@ const logged = {};
const disabled = {};
/**
Log a deprecated notice
@param {Book|Output} book
@param {String} key
@param {String} message
*/
* Log a deprecated notice
*
* @param {Book|Output} book
* @param {String} key
* @param {String} message
*/
function logNotice(book, key, message) {
if (logged[key] || disabled[key]) return;
@@ -21,49 +21,49 @@ function logNotice(book, key, message) {
}
/**
Deprecate a function
@param {Book|Output} book
@param {String} key: unique identitifer for the deprecated
@param {Function} fn
@param {String} msg: message to print when called
@return {Function}
*/
* Deprecate a function
*
* @param {Book|Output} book
* @param {String} key: unique identitifer for the deprecated
* @param {Function} fn
* @param {String} msg: message to print when called
* @return {Function}
*/
function deprecateMethod(book, key, fn, msg) {
return function() {
return function(...args) {
logNotice(book, key, msg);
return fn.apply(this, arguments);
return fn.apply(this, args);
};
}
/**
Deprecate a property of an object
@param {Book|Output} book
@param {String} key: unique identitifer for the deprecated
@param {Object} instance
@param {String|Function} property
@param {String} msg: message to print when called
@return {Function}
*/
* Deprecate a property of an object
*
* @param {Book|Output} book
* @param {String} key: unique identitifer for the deprecated
* @param {Object} instance
* @param {String|Function} property
* @param {String} msg: message to print when called
* @return {Function}
*/
function deprecateField(book, key, instance, property, value, msg) {
let store = undefined;
const prepare = function() {
const prepare = () => {
if (!is.undefined(store)) return;
if (is.fn(value)) store = value();
else store = value;
};
const getter = function() {
const getter = () => {
prepare();
logNotice(book, key, msg);
return store;
};
const setter = function(v) {
const setter = (v) => {
prepare();
logNotice(book, key, msg);
@@ -74,38 +74,36 @@ function deprecateField(book, key, instance, property, value, msg) {
Object.defineProperty(instance, property, {
get: getter,
set: setter,
enumerable: true,
enumerable: false,
configurable: true
});
}
/**
Enable a deprecation
@param {String} key: unique identitifer
*/
* Enable a deprecation
* @param {String} key: unique identitifer
*/
function enableDeprecation(key) {
disabled[key] = false;
}
/**
Disable a deprecation
@param {String} key: unique identitifer
*/
* Disable a deprecation
* @param {String} key: unique identitifer
*/
function disableDeprecation(key) {
disabled[key] = true;
}
/**
Deprecate a method in favor of another one
@param {Book} book
@param {String} key
@param {Object} instance
@param {String} oldName
@param {String} newName
*/
* Deprecate a method in favor of another one.
*
* @param {Book} book
* @param {String} key
* @param {Object} instance
* @param {String} oldName
* @param {String} newName
*/
function deprecateRenamedMethod(book, key, instance, oldName, newName, msg) {
msg = msg || ('"' + oldName + '" is deprecated, use "' + newName + '()" instead');
const fn = objectPath.get(instance, newName);
+4 -5
View File
@@ -1,8 +1,7 @@
module.exports = {
encodePage: require('./encodePage'),
decodePage: require('./decodePage'),
encodeGlobal: require('./encodeGlobal'),
decodeGlobal: require('./decodeGlobal')
encodePage: require('./encodePage'),
decodePage: require('./decodePage'),
encodeGlobal: require('./encodeGlobal'),
decodeGlobal: require('./decodeGlobal')
};
+11 -14
View File
@@ -1,22 +1,19 @@
const Modifiers = require('./modifiers');
module.exports = {
Parse: require('./parse'),
Parse: require('./parse'),
// Models
Book: require('./models/book'),
FS: require('./models/fs'),
File: require('./models/file'),
Summary: require('./models/summary'),
Glossary: require('./models/glossary'),
Config: require('./models/config'),
Page: require('./models/page'),
PluginDependency: require('./models/pluginDependency'),
Book: require('./models/book'),
FS: require('./models/fs'),
File: require('./models/file'),
Summary: require('./models/summary'),
Glossary: require('./models/glossary'),
Config: require('./models/config'),
Page: require('./models/page'),
PluginDependency: require('./models/pluginDependency'),
// Modifiers
SummaryModifier: Modifiers.Summary,
ConfigModifier: Modifiers.Config,
SummaryModifier: Modifiers.Summary,
ConfigModifier: Modifiers.Config,
// Constants
CONFIG_FILES: require('./constants/configFiles.js'),
IGNORE_FILES: require('./constants/ignoreFiles.js'),
+7 -8
View File
@@ -1,10 +1,9 @@
const extend = require('extend');
const common = require('./browser');
module.exports = extend({
initBook: require('./init'),
createNodeFS: require('./fs/node'),
Output: require('./output'),
commands: require('./cli')
}, common);
module.exports = {
...common,
initBook: require('./init'),
createNodeFS: require('./fs/node'),
Output: require('./output'),
commands: require('./cli')
};