diff options
author | Samy Pessé <samypesse@gmail.com> | 2014-04-19 19:31:02 +0200 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2014-04-19 19:31:02 +0200 |
commit | fb14caf5b3cfc321910ccb3ff57082dd7a43e51a (patch) | |
tree | d4f4a81043721709b35dabee32be78f4a43a23a4 /lib/generate/plugin.js | |
parent | cf51772f541ae09265f37ff0662da529ca857d4f (diff) | |
download | gitbook-fb14caf5b3cfc321910ccb3ff57082dd7a43e51a.zip gitbook-fb14caf5b3cfc321910ccb3ff57082dd7a43e51a.tar.gz gitbook-fb14caf5b3cfc321910ccb3ff57082dd7a43e51a.tar.bz2 |
Add resources to site build
Diffstat (limited to 'lib/generate/plugin.js')
-rw-r--r-- | lib/generate/plugin.js | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/lib/generate/plugin.js b/lib/generate/plugin.js index 1271eb3..f753834 100644 --- a/lib/generate/plugin.js +++ b/lib/generate/plugin.js @@ -1,10 +1,14 @@ var _ = require("lodash"); var Q = require("q"); var semver = require("semver"); +var path = require("path"); +var crc = require('crc'); var fs = require("./fs"); var pkg = require("../../package.json"); +var RESOURCES = ["js", "css"]; + var Plugin = function(name) { this.name = name; this.packageInfos = {}; @@ -12,6 +16,7 @@ var Plugin = function(name) { _.each([ name, + "gitbook-"+name, "gitbook-plugin-"+name, "gitbook-theme-"+name ], function(_name) { @@ -25,7 +30,6 @@ Plugin.prototype.load = function(name) { this.packageInfos = require(name+"/package.json"); this.infos = require(name); this.name = name; - return true; } catch (e) { return false; @@ -37,7 +41,14 @@ Plugin.prototype.getResources = function(resource) { if (!this.infos.book || !this.infos.book[resource]) { return []; } - return this.infos.book[resource]; + return _.chain(this.infos.book[resource]) + .map(function(resource) { + return { + "path": this.resolveFile(resource), + "id": crc.hex32(crc.crc32(resource)) + } + }.bind(this)) + .value(); }; // Test if it's a valid plugin @@ -51,6 +62,11 @@ Plugin.prototype.isValid = function() { ); }; +// Resolve file path +Plugin.prototype.resolveFile = function(filename) { + return path.resolve(path.dirname(require.resolve(this.name)), filename); +}; + // Extract data from a list of plugin Plugin.fromList = function(names) { var failed = []; @@ -65,9 +81,7 @@ Plugin.fromList = function(names) { if (_.size(failed) > 0) return Q.reject(new Error("Error loading plugins: "+failed.join(":"))); // Get all resources - var resources = _.chain([ - "js", "css" - ]) + var resources = _.chain(RESOURCES) .map(function(resource) { return [ resource, |