Skip to content

Commit

Permalink
Allow specify plugin list in config. Resolve #1670
Browse files Browse the repository at this point in the history
  • Loading branch information
tommy351 committed Jan 9, 2016
1 parent 58971dc commit f6407dc
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
16 changes: 14 additions & 2 deletions lib/hexo/load_plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ module.exports = function(ctx) {
]);
};

function loadModules(ctx) {
function loadModuleList(ctx) {
if (ctx.config && Array.isArray(ctx.config.plugins)) {
return Promise.resolve(ctx.config.plugins).filter(function(item) {
return typeof item === 'string';
});
}

var packagePath = pathFn.join(ctx.base_dir, 'package.json');
var pluginDir = ctx.plugin_dir;

Expand All @@ -36,7 +42,13 @@ function loadModules(ctx) {
// Make sure the plugin exists
var path = pathFn.join(pluginDir, name);
return fs.exists(path);
}).map(function(name) {
});
}

function loadModules(ctx) {
var pluginDir = ctx.plugin_dir;

return loadModuleList(ctx).map(function(name) {
var path = require.resolve(pathFn.join(pluginDir, name));

// Load plugins
Expand Down
26 changes: 26 additions & 0 deletions test/scripts/hexo/load_plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,32 @@ describe('Load plugins', function() {
});
});

it('specify plugin list in config', function() {
var names = ['hexo-plugin-test', 'another-plugin'];
var paths = names.map(function(name) {
return pathFn.join(hexo.plugin_dir, name, 'index.js');
});

return Promise.all([
createPackageFile.apply(null, names),
fs.writeFile(paths[0], 'hexo._script_test0 = true'),
fs.writeFile(paths[1], 'hexo._script_test1 = true')
]).then(function() {
hexo.config.plugins = [names[1]];
return loadPlugins(hexo);
}).then(function() {
should.not.exist(hexo._script_test0);
hexo._script_test1.should.be.true;

delete hexo.config.plugins;
delete hexo._script_test1;

return Promise.map(paths, function(path) {
return fs.unlink(path);
});
});
});

it('ignore plugins whose name is not started with "hexo-"', function() {
var script = 'hexo._script_test = true';
var name = 'another-plugin';
Expand Down

0 comments on commit f6407dc

Please sign in to comment.