-
Notifications
You must be signed in to change notification settings - Fork 567
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
Add new entries on property object #356
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"size": { | ||
"padding": { | ||
"tiny": { | ||
"value": "3" | ||
}, | ||
"small": { | ||
"value": "5" | ||
}, | ||
"base": { | ||
"value": "10" | ||
}, | ||
"large": { | ||
"value": "15" | ||
}, | ||
"xl": { | ||
"value": "20" | ||
}, | ||
"xxl": { | ||
"value": "30" | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,16 +19,26 @@ var glob = require('glob'), | |
path = require('path'), | ||
resolveCwd = require('resolve-cwd'); | ||
|
||
function traverseObj(obj, fn) { | ||
for (let key in obj) { | ||
fn.apply(null, [obj, key, obj[key]]); | ||
if (obj[key] && typeof obj[key] === 'object') { | ||
traverseObj(obj[key], fn); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Takes an array of json files and merges | ||
* them together. Optionally does a deep extend. | ||
* @private | ||
* @param {String[]} arr - Array of paths to json (or node modules that export objects) files | ||
* @param {Boolean} [deep=false] - If it should perform a deep merge | ||
* @param {Function} collision - A function to be called when a name collision happens that isn't a normal deep merge of objects | ||
* @param {Boolean} [source=true] - If json files are "sources", tag properties | ||
* @returns {Object} | ||
*/ | ||
function combineJSON(arr, deep, collision) { | ||
function combineJSON(arr, deep, collision, source) { | ||
var i, files = [], | ||
to_ret = {}; | ||
|
||
|
@@ -39,17 +49,26 @@ function combineJSON(arr, deep, collision) { | |
|
||
for (i = 0; i < files.length; i++) { | ||
var resolvedPath = resolveCwd(path.isAbsolute(files[i]) ? files[i] : './' + files[i]); | ||
var file_content; | ||
var file_content = {}; | ||
|
||
try { | ||
// This delete force require(resolvedPath) to take the latest version of the file. It's handfull when using the node package along chokidar. | ||
delete require.cache[resolvedPath] | ||
file_content = require(resolvedPath); | ||
file_content = deepExtend([file_content, require(resolvedPath)]); | ||
} catch (e) { | ||
e.message = 'Failed to load or parse JSON or JS Object: ' + e.message; | ||
throw e; | ||
} | ||
|
||
// Add some side data on each property to make filtering easier | ||
traverseObj(file_content, (obj) => { | ||
if (obj.value && !obj.filePath) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can't comment on lines you don't change, but we will need to change the line
to:
Now mutating |
||
obj.filePath = resolvedPath; | ||
|
||
obj.isSource = source || source === undefined ? true : false; | ||
} | ||
}); | ||
|
||
if (deep) { | ||
deepExtend([to_ret, file_content], collision); | ||
} else { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think it would make sense to move this to its own file so we don't have to duplicate it here?