Skip to content

Commit

Permalink
feat: support npm package as theme
Browse files Browse the repository at this point in the history
  • Loading branch information
benjycui committed Jan 20, 2017
1 parent d7790d1 commit 0d9dc61
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 20 deletions.
2 changes: 2 additions & 0 deletions src/utils/get-bisheng-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const fs = require('fs');
const path = require('path');
const resolve = require('resolve');

const defaultConfig = {
port: 8000,
Expand All @@ -24,5 +25,6 @@ const defaultConfig = {
module.exports = function getBishengConfig(configFile) {
const customizedConfig = fs.existsSync(configFile) ? require(configFile) : {};
const config = Object.assign({}, defaultConfig, customizedConfig);
config.theme = resolve.sync(config.theme, { basedir: process.cwd() });
return config;
};
1 change: 1 addition & 0 deletions test/fixtures/_theme/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// placeholder
1 change: 1 addition & 0 deletions test/fixtures/bisheng.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

module.exports = {
source: './content',
theme: './test/fixtures/_theme',
};
21 changes: 1 addition & 20 deletions test/utils/get-config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,6 @@ const getBishengConfig = require('../../lib/utils/get-bisheng-config');
const getThemeConfig = require('../../lib/utils/get-theme-config');

describe('utils/get-bisheng-config', function() {
it('should return default config when no custom config is provided', function() {
const bishengConfig = getBishengConfig('./no-such.config.js.');

assert.strictEqual(bishengConfig.webpackConfig(1), 1);
delete bishengConfig.webpackConfig;
delete bishengConfig.filePathMapper;

assert.deepEqual(bishengConfig, {
source: './posts',
output: './_site',
entryName: 'index',
theme: './_theme',
htmlTemplate: path.join(__dirname, '../../lib/template.html'),
port: 8000,
root: '/',
doraConfig: {},
});
});

it('should merge custom config to default config', function() {
const bishengConfig = getBishengConfig(path.join(__dirname, '../fixtures/bisheng.config.js'));
delete bishengConfig.webpackConfig;
Expand All @@ -34,7 +15,7 @@ describe('utils/get-bisheng-config', function() {
source: './content',
output: './_site',
entryName: 'index',
theme: './_theme',
theme: path.join(process.cwd(), './test/fixtures/_theme/index.js'),
htmlTemplate: path.join(__dirname, '../../lib/template.html'),
port: 8000,
root: '/',
Expand Down

0 comments on commit 0d9dc61

Please sign in to comment.