Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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