summaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
authorSamy Pesse <samypesse@gmail.com>2016-10-10 23:18:38 +0200
committerSamy Pesse <samypesse@gmail.com>2016-10-10 23:18:38 +0200
commitaa39b8e71b980ff9100b5afa3d06679de0b2fadd (patch)
tree3073685541842cf06710639df1fcda17d3d43117 /packages
parent3000dcefe109e749ee582a7537924f68e717a7e8 (diff)
downloadgitbook-aa39b8e71b980ff9100b5afa3d06679de0b2fadd.zip
gitbook-aa39b8e71b980ff9100b5afa3d06679de0b2fadd.tar.gz
gitbook-aa39b8e71b980ff9100b5afa3d06679de0b2fadd.tar.bz2
Don't log deprecated when no plugins is using deprecated APIs
Diffstat (limited to 'packages')
-rw-r--r--packages/gitbook/src/api/decodeGlobal.js14
-rw-r--r--packages/gitbook/src/api/deprecate.js90
-rw-r--r--packages/gitbook/src/api/index.js9
-rw-r--r--packages/gitbook/src/browser.js25
-rw-r--r--packages/gitbook/src/index.js15
5 files changed, 73 insertions, 80 deletions
diff --git a/packages/gitbook/src/api/decodeGlobal.js b/packages/gitbook/src/api/decodeGlobal.js
index 063683a..c7bbcc7 100644
--- a/packages/gitbook/src/api/decodeGlobal.js
+++ b/packages/gitbook/src/api/decodeGlobal.js
@@ -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();
diff --git a/packages/gitbook/src/api/deprecate.js b/packages/gitbook/src/api/deprecate.js
index 879355c..c781971 100644
--- a/packages/gitbook/src/api/deprecate.js
+++ b/packages/gitbook/src/api/deprecate.js
@@ -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);
diff --git a/packages/gitbook/src/api/index.js b/packages/gitbook/src/api/index.js
index 5e67525..3956c62 100644
--- a/packages/gitbook/src/api/index.js
+++ b/packages/gitbook/src/api/index.js
@@ -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')
};
diff --git a/packages/gitbook/src/browser.js b/packages/gitbook/src/browser.js
index 771ecd5..1e7fad2 100644
--- a/packages/gitbook/src/browser.js
+++ b/packages/gitbook/src/browser.js
@@ -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'),
diff --git a/packages/gitbook/src/index.js b/packages/gitbook/src/index.js
index 7919000..fc8f254 100644
--- a/packages/gitbook/src/index.js
+++ b/packages/gitbook/src/index.js
@@ -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')
+};