Skip to content

Instantly share code, notes, and snippets.

@juliandescottes
Created September 14, 2021 21:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juliandescottes/906f96958f69f07ea5daa411146f5eb5 to your computer and use it in GitHub Desktop.
Save juliandescottes/906f96958f69f07ea5daa411146f5eb5 to your computer and use it in GitHub Desktop.
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