Skip to content

Commit

Permalink
Merge pull request #750 from pattern-lab/feature/749-default-config
Browse files Browse the repository at this point in the history
Adding getDefaultConfig function to core
  • Loading branch information
bmuenzenmeyer authored Nov 15, 2017
2 parents 8d0e031 + d892c4e commit 537ccbd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
14 changes: 12 additions & 2 deletions core/lib/patternlab.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const cleanHtml = require('js-beautify').html;
const inherits = require('util').inherits;
const pm = require('./plugin_manager');
const packageInfo = require('../../package.json');
const defaultConfig = require('../../patternlab-config.json');
const dataLoader = require('./data_loader')();
const logger = require('./log');
const jsonCopy = require('./json_copy');
Expand Down Expand Up @@ -269,7 +270,6 @@ class PatternLab {


// info methods

getVersion() {
return this.package.version;
}
Expand Down Expand Up @@ -422,6 +422,15 @@ function installPlugin(pluginName) {
plugin_manager.install_plugin(pluginName);
}

/**
* Returns the standardized default config
*
* @return {object} Returns the object representation of the patternlab-config.json
*/
function getDefaultConfig() {
return defaultConfig
}

const patternlab_engine = function (config) {
const patternlab = new PatternLab(config);
const paths = patternlab.config.paths;
Expand Down Expand Up @@ -730,7 +739,7 @@ const patternlab_engine = function (config) {
version: function () {
return patternlab.logVersion();
},

/**
* return current version
*
Expand Down Expand Up @@ -869,5 +878,6 @@ const patternlab_engine = function (config) {
patternlab_engine.build_pattern_data = buildPatternData;
patternlab_engine.process_all_patterns_iterative = processAllPatternsIterative;
patternlab_engine.process_all_patterns_recursive = processAllPatternsRecursive;
patternlab_engine.getDefaultConfig = getDefaultConfig;

module.exports = patternlab_engine;
8 changes: 8 additions & 0 deletions test/patternlab_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const tap = require('tap');
const rewire = require("rewire");
const _ = require('lodash');
const fs = require('fs-extra');
const defaultConfig = require('../patternlab-config.json');
var config = require('./util/patternlab-config.json');

var plEngineModule = rewire('../core/lib/patternlab');
Expand Down Expand Up @@ -81,3 +82,10 @@ tap.test('buildPatternData - can load json, yaml, and yml files', function(test)
test.equals(dataResult.from_json, "from_json");
test.end();
});

tap.test('getDefaultConfig - should return the default config object', function(test) {
const requestedConfig = plEngineModule.getDefaultConfig();
test.type(requestedConfig, 'object');
test.equals(requestedConfig, defaultConfig);
test.end();
});

0 comments on commit 537ccbd

Please sign in to comment.