Skip to content
Permalink
Browse files
Fix multiple config issue #2518 (#2520)
* Update index.js

* Update index.js

* Create _config.json

* Update hexo.js
  • Loading branch information
NoahDragon committed Apr 20, 2017
1 parent ed1fb58 commit fbdee9043655a89fe0284f61cbaae88fd9a783e9
Showing with 21 additions and 5 deletions.
  1. +6 −4 lib/hexo/index.js
  2. +6 −0 test/fixtures/_config.json
  3. +9 −1 test/scripts/hexo/hexo.js
@@ -23,6 +23,7 @@ var Theme = require('../theme');
var Locals = require('./locals');
var defaultConfig = require('./default_config');
var loadDatabase = require('./load_database');
var MultiConfigPath = require('./multi_config_path');

var libDir = pathFn.dirname(__dirname);
var sep = pathFn.sep;
@@ -32,6 +33,8 @@ function Hexo(base, args) {
base = base || process.cwd();
args = args || {};

var mcp = new MultiConfigPath(this);

EventEmitter.call(this);

this.base_dir = base + sep;
@@ -53,10 +56,6 @@ function Hexo(base, args) {
init: false
};

var multiConfigPath = require('./multi_config_path')(this);
this.config_path = args.config ? multiConfigPath(base, args.config)
: pathFn.join(base, '_config.yml');

this.extend = {
console: new extend.Console(),
deployer: new extend.Deployer(),
@@ -90,6 +89,9 @@ function Hexo(base, args) {
path: pathFn.join(base, 'db.json')
});

this.config_path = args.config ? mcp(base, args.config)
: pathFn.join(base, '_config.yml');

registerModels(this);

this.source = new Source(this);
@@ -0,0 +1,6 @@
{
"author": "waldo",
"favorites": {
"food": "ice cream"
}
}
@@ -7,8 +7,9 @@ var sep = pathFn.sep;
var testUtil = require('../../util');

describe('Hexo', () => {
var base_dir = pathFn.join(__dirname, 'hexo_test');
var Hexo = require('../../../lib/hexo');
var hexo = new Hexo(pathFn.join(__dirname, 'hexo_test'), {silent: true});
var hexo = new Hexo(base_dir, {silent: true});
var coreDir = pathFn.join(__dirname, '../../..');
var version = require('../../../package.json').version;
var Post = hexo.model('Post');
@@ -65,6 +66,13 @@ describe('Hexo', () => {
hexo.config_path.should.eql(pathFn.join(__dirname, '_config.yml'));
});

it('constructs mutli-config', () => {
var configs = [ '../../../fixtures/_config.json', '../../../fixtures/_config.json' ];
var args = { _: [], config: configs.join(',') };
var hexo = new Hexo(base_dir, args);
hexo.config_path.should.eql(pathFn.join(base_dir, '_multiconfig.yml'));
});

it('call()', () => hexo.call('test', {foo: 'bar'}).then(data => {
data.should.eql({foo: 'bar'});
}));

0 comments on commit fbdee90

Please sign in to comment.