Created
September 14, 2021 21:21
-
-
Save juliandescottes/906f96958f69f07ea5daa411146f5eb5 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
const moduleLayout = { | |
root: { | |
windowglobal: {}, | |
contentprocess: { | |
worker: {}, | |
}, | |
}, | |
}; | |
const modules = {}; | |
const modulePaths = {}; | |
const visitModule = function(moduleType, parent, ancestors) { | |
modulePaths[moduleType] = { | |
[moduleType]: [moduleType], | |
}; | |
modules[moduleType] = {}; | |
for (let i = 0; i < ancestors.length; i++) { | |
const ancestor = ancestors[i]; | |
modules[`${moduleType}-in-${ancestor}`] = {}; | |
modulePaths[ancestor][moduleType] = [moduleType]; | |
for (let j = i; j < ancestors.length; j++) { | |
modulePaths[ancestor][moduleType].push( | |
`${moduleType}-in-${ancestors[j]}` | |
); | |
} | |
} | |
for (const childType in parent[moduleType]) { | |
visitModule(childType, parent[moduleType], [...ancestors, moduleType]); | |
} | |
}; | |
visitModule("root", moduleLayout, []); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment