summaryrefslogtreecommitdiffstats
path: root/lib/plugins/listResources.js
diff options
context:
space:
mode:
authorSamy Pesse <samypesse@gmail.com>2016-04-30 20:15:08 +0200
committerSamy Pesse <samypesse@gmail.com>2016-04-30 20:15:08 +0200
commit36b49c66c6b75515bc84dd678fd52121a313e8d2 (patch)
treebc7e0f703d4557869943ec7f9495cac7a5027d4f /lib/plugins/listResources.js
parent87db7cf1d412fa6fbd18e9a7e4f4755f2c0c5547 (diff)
parent80b8e340dadc54377ff40500f86b1de631395806 (diff)
downloadgitbook-36b49c66c6b75515bc84dd678fd52121a313e8d2.zip
gitbook-36b49c66c6b75515bc84dd678fd52121a313e8d2.tar.gz
gitbook-36b49c66c6b75515bc84dd678fd52121a313e8d2.tar.bz2
Merge branch 'fixes'
Diffstat (limited to 'lib/plugins/listResources.js')
-rw-r--r--lib/plugins/listResources.js45
1 files changed, 45 insertions, 0 deletions
diff --git a/lib/plugins/listResources.js b/lib/plugins/listResources.js
new file mode 100644
index 0000000..4a73a2c
--- /dev/null
+++ b/lib/plugins/listResources.js
@@ -0,0 +1,45 @@
+var Immutable = require('immutable');
+var path = require('path');
+
+var LocationUtils = require('../utils/location');
+var PLUGIN_RESOURCES = require('../constants/pluginResources');
+
+/**
+ List all resources from a list of plugins
+
+ @param {OrderedMap<String:Plugin>}
+ @param {String} type
+ @return {Map<String:List<{url, path}>}
+*/
+function listResources(plugins, type) {
+ return plugins.reduce(function(result, plugin) {
+ var npmId = plugin.getNpmID();
+ var resources = plugin.getResources(type);
+
+ PLUGIN_RESOURCES.forEach(function(resourceType) {
+ var assets = resources.get(resourceType);
+ if (!assets) return;
+
+ var list = result.get(resourceType) || Immutable.List();
+
+ assets = assets.map(function(assetFile) {
+ if (LocationUtils.isExternal(assetFile)) {
+ return {
+ url: assetFile
+ };
+ } else {
+ return {
+ path: LocationUtils.normalize(path.join(npmId, assetFile))
+ };
+ }
+ });
+
+ list = list.concat(assets);
+ result = result.set(resourceType, list);
+ });
+
+ return result;
+ }, Immutable.Map());
+}
+
+module.exports = listResources;