Last active
October 15, 2015 00:37
-
-
Save bholloway/749be73742318bc14c29 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var objects = [], | |
MODULES = { | |
ContextModule: require('./ContextModule'), | |
DelegatedModule: require('./DelegatedModule'), | |
DllModule: require('./DllModule'), | |
ExternalModule: require('./ExternalModule'), | |
MultiModule: require('./MultiModule'), | |
NormalModule: require('./NormalModule'), | |
RawModule: require('./RawModule') | |
} | |
Object.keys(compilation.cache).forEach(eachKey); | |
function eachKey(key) { | |
var value = compilation.cache[key]; | |
console.log(key); | |
if (value instanceof require('./Module')) { | |
console.log(Object.keys(MODULES).reduce(matchModule)); | |
console.log(showValues(value).filter(firstOccurance).join('\n')); | |
} | |
console.log('\n'); | |
function firstOccurance(value, i, array) { | |
return (array.indexOf(value) === i); | |
} | |
function matchModule(result, name) { | |
return result || ((value instanceof MODULES[name]) && name); | |
} | |
function showValues() { | |
var candidates = Object.keys(value).map(getValue).filter(isObject).filter(notSeen); | |
var a = candidates.map(getConstructor).filter(Boolean); | |
var b = candidates.map(getValue).filter(Array.isArray).reduce(recurseArray, []); | |
return a.concat(b); | |
} | |
function notSeen(value) { | |
if (objects.indexOf(value) < 0) { | |
objects.push(value); | |
return true; | |
} else { | |
return false; | |
} | |
} | |
function getValue(key) { | |
return value[key]; | |
} | |
function isObject(value) { | |
return value && (typeof value === 'object'); | |
} | |
function getConstructor(value) { | |
return value.constructor && Function.prototype.toString.call(value.constructor) | |
} | |
function recurseArray(reduced, array) { | |
return reduced.concat(array.map(showValues)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment