Skip to content
This repository has been archived by the owner on Apr 23, 2019. It is now read-only.

Commit

Permalink
Move flattening of inputs to mendel-config so more code has access to…
Browse files Browse the repository at this point in the history
… it.
  • Loading branch information
irae committed Aug 23, 2016
1 parent 4c646fc commit b9f33f5
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 26 deletions.
22 changes: 0 additions & 22 deletions bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ async.each(rawConfig.bundles, function(rawBundle, doneBundle) {

mkdirp.sync(path.dirname(conf.outfile));

flattenFilenameArrays(bundle);

var entries = normalizeEntries(bundle.entries);
delete bundle.entries;
var requires = bundle.require;
Expand Down Expand Up @@ -113,26 +111,6 @@ function normalizeEntries(entries) {
});
}

function flattenFilenameArrays(bundle) {
['entries', 'require', 'external', 'exclude', 'ignore']
.forEach(function(param) {
var inputArray = bundle[param];
if (!Array.isArray(inputArray)) return;

var i = 0;
while (i <= inputArray.length) {
var item = inputArray[i];
if (Array.isArray(item)) {
Array.prototype.splice.apply(
inputArray,
[i, 1].concat(item)
);
}
i++;
}
});
}

function logObj(obj) {
console.log(require('util').inspect(obj,false,null,true));
return obj;
Expand Down
21 changes: 21 additions & 0 deletions packages/mendel-config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ function parseBundles(bundles) {
bundle.id = bundleName;
bundle.bundleName = bundleName;
bundle.manifest = bundleName + '.manifest.json';
flattenFilenameArrays(bundle);

return bundle;
}).filter(Boolean);
Expand All @@ -126,6 +127,26 @@ function mergeRecursive(dest, src) {
return dest;
}

function flattenFilenameArrays(bundle) {
['entries', 'require', 'external', 'exclude', 'ignore']
.forEach(function(param) {
var inputArray = bundle[param];
if (!Array.isArray(inputArray)) return;

var i = 0;
while (i <= inputArray.length) {
var item = inputArray[i];
if (Array.isArray(item)) {
Array.prototype.splice.apply(
inputArray,
[i, 1].concat(item)
);
}
i++;
}
});
}

function isObject(obj) {
return ({}).toString.call(obj).slice(8, -1).toLowerCase() === 'object';
}
2 changes: 1 addition & 1 deletion packages/mendel-config/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mendel-config",
"version": "1.1.0",
"version": "1.1.1",
"description": "Mendel core configuration parser",
"main": "config.js",
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions packages/mendel-development-middleware/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mendel-development-middleware",
"version": "1.1.0",
"version": "1.1.1",
"description": "express middleware for meldel",
"main": "index.js",
"scripts": {
Expand All @@ -20,7 +20,7 @@
"dependencies": {
"browserify": "^13.0.0",
"fs-extra": "^0.30.0",
"mendel-config": "^1.1.0",
"mendel-config": "^1.1.1",
"mendel-development": "^1.1.0",
"mendel-development-loader": "^1.1.0",
"mendel-requirify": "^1.0.6",
Expand Down
4 changes: 3 additions & 1 deletion test/config-samples/.mendelrc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ bundles:
- main.js
# defaults to bundle_id
dest: path_relative_to_dest/main.js
external: *vendor_list
external:
- *vendor_list
- './foo.js'
transform:
- reactify

Expand Down
12 changes: 12 additions & 0 deletions test/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@ t.match(config(where), {
]
}, 'default environment');

t.match(config(where), {
bundles: [
{id: 'vendor'},
{ id: 'main', external: [
'react',
'react-dom',
'xml-beautifier',
'./foo.js'
]}
]
}, 'flattens arrays if externals');

process.env.MENDEL_ENV = 'test';
t.match(config(where), {
bundles: [
Expand Down

0 comments on commit b9f33f5

Please sign in to comment.