Created
May 10, 2023 13:06
-
-
Save orjan/957d85432f06d70b25f7d68090df1a66 to your computer and use it in GitHub Desktop.
Getting cross module references
This file contains hidden or 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
import file from "./result.json" assert { type: "json" }; | |
const entries = file.entries.map(entry => { | |
//const children = Array.from(extractChildren(entry.children)); | |
const children = entry.children.map(child => child.name); | |
return { | |
name: entry.name, | |
children: children, | |
errors: evaluateErrors(entry.name, children) | |
}; | |
}); | |
function evaluateErrors(name, children) { | |
const errors = []; | |
const module = /src\/modules\/([a-z\-]+)/.exec(name)?.[1] ?? null; | |
let child; | |
for (child of children) { | |
if (module && child.startsWith("/src/modules/") && child.endsWith(".vue") && !child.startsWith("/src/modules/"+module+"/")) { | |
errors.push(child); | |
} | |
} | |
return errors; | |
} | |
function extractChildren(children) { | |
const stack = [...children]; | |
const result = new Set(); | |
let current; | |
while (current = stack.pop()) { | |
stack.push(...current.children); | |
result.add(current.name); | |
} | |
return result; | |
} | |
const errorComponents = entries.filter(entry => entry.errors.length > 0); | |
for (let error of errorComponents) { | |
console.log(error.name); | |
for (let e of error.errors) { | |
console.log(" - ", e); | |
} | |
console.log(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment