Skip to content

Adding getDefaultConfig function to core #750

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
});