summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/models/plugin.js7
-rw-r--r--lib/plugins/findInstalled.js29
-rw-r--r--lib/plugins/listAll.js10
-rw-r--r--lib/plugins/listForBook.js14
-rw-r--r--lib/plugins/loadForBook.js31
5 files changed, 62 insertions, 29 deletions
diff --git a/lib/models/plugin.js b/lib/models/plugin.js
index c8bb2f7..acabba9 100644
--- a/lib/models/plugin.js
+++ b/lib/models/plugin.js
@@ -18,6 +18,9 @@ var Plugin = Immutable.Record({
// Depth of this plugin in the dependency tree
depth: Number(0),
+ // Parent depending on this plugin
+ parent: String(),
+
// Content of the "package.json"
package: Immutable.Map(),
@@ -49,6 +52,10 @@ Plugin.prototype.getDepth = function() {
return this.get('depth');
};
+Plugin.prototype.getParent = function() {
+ return this.get('parent');
+};
+
/**
* Return the ID on NPM for this plugin
* @return {String}
diff --git a/lib/plugins/findInstalled.js b/lib/plugins/findInstalled.js
index dca3cbf..06cc6c4 100644
--- a/lib/plugins/findInstalled.js
+++ b/lib/plugins/findInstalled.js
@@ -8,21 +8,21 @@ var Plugin = require('../models/plugin');
var PREFIX = require('../constants/pluginPrefix');
/**
- Validate if a package name is a GitBook plugin
-
- @return {Boolean}
-*/
+ * Validate if a package name is a GitBook plugin
+ *
+ * @return {Boolean}
+ */
function validateId(name) {
return name && name.indexOf(PREFIX) === 0;
}
/**
- List all packages installed inside a folder
-
- @param {String} folder
- @return {OrderedMap<String:Plugin>}
-*/
+ * List all packages installed inside a folder
+ *
+ * @param {String} folder
+ * @return {OrderedMap<String:Plugin>}
+ */
function findInstalled(folder) {
var options = {
dev: false,
@@ -31,7 +31,7 @@ function findInstalled(folder) {
};
var results = Immutable.OrderedMap();
- function onPackage(pkg, isRoot) {
+ function onPackage(pkg, parent) {
if (!pkg.name) return;
var name = pkg.name;
@@ -43,18 +43,19 @@ function findInstalled(folder) {
var pluginName = name.slice(PREFIX.length);
if (!validateId(name)){
- if (!isRoot) return;
+ if (parent) return;
} else {
results = results.set(pluginName, Plugin({
name: pluginName,
version: version,
path: pkgPath,
- depth: depth
+ depth: depth,
+ parent: parent
}));
}
Immutable.Map(dependencies).forEach(function(dep) {
- onPackage(dep);
+ onPackage(dep, pluginName);
});
}
@@ -77,7 +78,7 @@ function findInstalled(folder) {
var module_folder = path.join(node_modules, module);
return Promise.nfcall(readInstalled, module_folder, options)
.then(function(data) {
- onPackage(data, true);
+ onPackage(data);
});
});
})
diff --git a/lib/plugins/listAll.js b/lib/plugins/listAll.js
index 70bf9cd..e8c3008 100644
--- a/lib/plugins/listAll.js
+++ b/lib/plugins/listAll.js
@@ -5,11 +5,11 @@ var DEFAULT_PLUGINS = require('../constants/defaultPlugins');
var sortPlugins = require('./sortPlugins');
/**
- List all plugins for a book
-
- @param {List<PluginDependency>} deps
- @return {OrderedMap<Plugin>}
-*/
+ * List all plugins for a book
+ *
+ * @param {List<PluginDependency>} deps
+ * @return {OrderedMap<Plugin>}
+ */
function listAll(deps) {
// Extract list of plugins to disable (starting with -)
var toRemove = deps
diff --git a/lib/plugins/listForBook.js b/lib/plugins/listForBook.js
index 5fb920f..6764403 100644
--- a/lib/plugins/listForBook.js
+++ b/lib/plugins/listForBook.js
@@ -1,13 +1,13 @@
var listAll = require('./listAll');
/**
- List all plugin requirements for a book.
- It can be different from the final list of plugins,
- since plugins can have their own dependencies
-
- @param {Book}
- @return {OrderedMap<Plugin>}
-*/
+ * List all plugin requirements for a book.
+ * It can be different from the final list of plugins,
+ * since plugins can have their own dependencies
+ *
+ * @param {Book}
+ * @return {OrderedMap<Plugin>}
+ */
function listForBook(book) {
var config = book.getConfig();
var plugins = config.getPluginDependencies();
diff --git a/lib/plugins/loadForBook.js b/lib/plugins/loadForBook.js
index 96a0cb5..a3f9dd0 100644
--- a/lib/plugins/loadForBook.js
+++ b/lib/plugins/loadForBook.js
@@ -6,7 +6,8 @@ var loadPlugin = require('./loadPlugin');
/**
- * Load a list of plugins in a book
+ * Load all plugins in a book
+ *
* @param {Book}
* @return {Promise<Map<String:Plugin>}
*/
@@ -19,12 +20,36 @@ function loadForBook(book) {
.then(function(installed) {
// Filter out plugins not listed of first level
// (aka pre-installed plugins)
- installed = installed.filter(function(plugin) {
+ /*installed = installed.filter(function(plugin) {
return (
+ // Plugin is a dependency of another one
plugin.getDepth() > 0 ||
+
+ // Plugin is specified in "book.json"
requirements.has(plugin.getName())
);
- });
+ });*/
+
+ // Insert installed plugins not listed in required
+ var pluginsToLoad = installed.reduce(function(pluginSeq, plugin) {
+ var name = plugin.getName();
+
+ if (requirements.has(name)) {
+ return pluginSeq;
+ }
+
+ var parentName = plugin.getParent();
+
+
+ pluginSeq = pluginSeq.push([
+ name,
+ plugin
+ ]);
+
+ return pluginSeq;
+ }, requirements.entrySeq());
+
+
// Log state
logger.info.ln(installed.size + ' plugins are installed');