chore: automated housekeeping...

This commit is contained in:
Pieter Vander Vennet 2025-05-03 23:48:35 +02:00
parent 612e71a4b6
commit 511d20eb34
245 changed files with 43884 additions and 8661 deletions

View file

@ -1,18 +1,17 @@
import { LayerConfigJson } from "./Json/LayerConfigJson"
export interface LevelInfo {
ids: string[],
ids: string[]
loop?: boolean
}
export class LayerConfigDependencyGraph {
/**
* Calculates the dependencies for the given layer
* @param layerconfig
*/
public static getLayerImports(layerconfig: LayerConfigJson): string[] {
const defaultImports: ReadonlyArray<string> = ["questions", "filters","icons"]
const defaultImports: ReadonlyArray<string> = ["questions", "filters", "icons"]
if (defaultImports.indexOf(layerconfig.id) >= 0) {
return []
}
@ -41,7 +40,6 @@ export class LayerConfigDependencyGraph {
return Array.from(imports)
}
public static buildDirectDependencies(layers: LayerConfigJson[]) {
const dependsOn = new Map<string, string[]>()
for (const layer of layers) {
@ -50,8 +48,7 @@ export class LayerConfigDependencyGraph {
}
return dependsOn
}
public static buildLevels(dependsOn: Map<string, string[]>): LevelInfo[]{
public static buildLevels(dependsOn: Map<string, string[]>): LevelInfo[] {
const levels: LevelInfo[] = []
const seenIds = new Set<string>()
while (Array.from(dependsOn.keys()).length > 0) {
@ -73,19 +70,21 @@ export class LayerConfigDependencyGraph {
continue
}
const dependencies = dependsOn.get(layerId)
newDependsOn.set(layerId, dependencies.filter(d => !seenIds.has(d)))
newDependsOn.set(
layerId,
dependencies.filter((d) => !seenIds.has(d))
)
}
const oldSize = dependsOn.size
if(oldSize === newDependsOn.size){
if (oldSize === newDependsOn.size) {
// We detected a loop.
currentLevel.loop = true
const allLayers =Array.from(newDependsOn.keys())
currentLevel.ids.push(...allLayers )
allLayers.forEach(l => seenIds.add(l))
const allLayers = Array.from(newDependsOn.keys())
currentLevel.ids.push(...allLayers)
allLayers.forEach((l) => seenIds.add(l))
}
dependsOn = newDependsOn
}
return levels
}
}