summaryrefslogtreecommitdiffstats
path: root/lib/plugins/findInstalled.js
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2016-12-22 10:18:38 +0100
committerGitHub <noreply@github.com>2016-12-22 10:18:38 +0100
commit194ebc3da9641ff96f083f9d8ab43c2d27944f9a (patch)
treec50988f32ccf18df93ae7ab40be78e9459642818 /lib/plugins/findInstalled.js
parent64ccb6b00b4b63fa0e516d4e35351275b34f8c07 (diff)
parent16af264360e48e8a833e9efa9ab8d194574dbc70 (diff)
downloadgitbook-194ebc3da9641ff96f083f9d8ab43c2d27944f9a.zip
gitbook-194ebc3da9641ff96f083f9d8ab43c2d27944f9a.tar.gz
gitbook-194ebc3da9641ff96f083f9d8ab43c2d27944f9a.tar.bz2
Merge pull request #1543 from GitbookIO/dream
React for rendering website with plugins
Diffstat (limited to 'lib/plugins/findInstalled.js')
-rw-r--r--lib/plugins/findInstalled.js91
1 files changed, 0 insertions, 91 deletions
diff --git a/lib/plugins/findInstalled.js b/lib/plugins/findInstalled.js
deleted file mode 100644
index 06cc6c4..0000000
--- a/lib/plugins/findInstalled.js
+++ /dev/null
@@ -1,91 +0,0 @@
-var readInstalled = require('read-installed');
-var Immutable = require('immutable');
-var path = require('path');
-
-var Promise = require('../utils/promise');
-var fs = require('../utils/fs');
-var Plugin = require('../models/plugin');
-var PREFIX = require('../constants/pluginPrefix');
-
-/**
- * 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>}
- */
-function findInstalled(folder) {
- var options = {
- dev: false,
- log: function() {},
- depth: 4
- };
- var results = Immutable.OrderedMap();
-
- function onPackage(pkg, parent) {
- if (!pkg.name) return;
-
- var name = pkg.name;
- var version = pkg.version;
- var pkgPath = pkg.realPath;
- var depth = pkg.depth;
- var dependencies = pkg.dependencies;
-
- var pluginName = name.slice(PREFIX.length);
-
- if (!validateId(name)){
- if (parent) return;
- } else {
- results = results.set(pluginName, Plugin({
- name: pluginName,
- version: version,
- path: pkgPath,
- depth: depth,
- parent: parent
- }));
- }
-
- Immutable.Map(dependencies).forEach(function(dep) {
- onPackage(dep, pluginName);
- });
- }
-
- // Search for gitbook-plugins in node_modules folder
- var node_modules = path.join(folder, 'node_modules');
-
- // List all folders in node_modules
- return fs.readdir(node_modules)
- .fail(function() {
- return Promise([]);
- })
- .then(function(modules) {
- return Promise.serie(modules, function(module) {
- // Not a gitbook-plugin
- if (!validateId(module)) {
- return Promise();
- }
-
- // Read gitbook-plugin package details
- var module_folder = path.join(node_modules, module);
- return Promise.nfcall(readInstalled, module_folder, options)
- .then(function(data) {
- onPackage(data);
- });
- });
- })
- .then(function() {
- // Return installed plugins
- return results;
- });
-}
-
-module.exports = findInstalled;