|
51 | 51 | $dimensionsAggregated = $dimensions; |
52 | 52 | } |
53 | 53 |
|
| 54 | +$dependencies = array(); |
| 55 | +$activityIndex = array(); |
54 | 56 | foreach ($dimensionsAggregated as $dimension => $subdimensions) { |
55 | 57 | ksort($subdimensions); |
56 | 58 | foreach ($subdimensions as $subdimension => $elements) { |
|
68 | 70 | array_push($errorMsg,"Missing 'level' attribute in activity: $activityName"); |
69 | 71 | } |
70 | 72 |
|
71 | | - echo "$subdimension | $activityName\n"; |
| 73 | + // echo "$subdimension | $activityName\n"; |
72 | 74 | if (!array_key_exists("uuid", $activity)) { |
73 | 75 | array_push($errorMsg, "$activityName is missing an uuid in $dimension"); |
74 | 76 | } else { |
|
147 | 149 | array_push($errorMsg,"DependsOn non-existing activity: '$dependsOn' (in activity: $activityName)"); |
148 | 150 | } |
149 | 151 | } |
| 152 | + |
| 153 | + // Build dependency graph |
| 154 | + if (!array_key_exists($activityName, $activityIndex)) { |
| 155 | + $activityIndex[$activityName] = count($activityIndex); |
| 156 | + } |
| 157 | + if (!array_key_exists($dependsOn, $activityIndex)) { |
| 158 | + $activityIndex[$dependsOn] = count($activityIndex); |
| 159 | + } |
| 160 | + array_push_item_to($dependencies, $activityIndex[$dependsOn], $activityIndex[$activityName]); |
| 161 | + |
150 | 162 | } |
151 | 163 | } |
152 | 164 | } |
|
188 | 200 | file_put_contents($targetGeneratedFile, $dimensionsString); |
189 | 201 |
|
190 | 202 |
|
| 203 | +// Store dependency graph |
| 204 | +$graphFilename = getcwd() . "/src/assets/YAML/generated/dependency-tree.md"; |
| 205 | +$graphFile = fopen($graphFilename, "w"); |
| 206 | +fwrite($graphFile, "```mermaid\n\n"); |
| 207 | +fwrite($graphFile, "graph LR\n\n"); |
| 208 | +// List all nodes |
| 209 | +foreach ($activityIndex as $activityName => $key) { |
| 210 | + $level = getActivityByActivityName($activityName, $dimensionsAggregated)["level"]; |
| 211 | + $activityName = "L$level $activityName"; |
| 212 | + $activityName = str_replace('(', '', $activityName); |
| 213 | + $activityName = str_replace(')', '', $activityName); |
| 214 | + fwrite($graphFile, "$key($activityName)\n"); |
| 215 | +} |
| 216 | +// Add links between nodes |
| 217 | +fwrite($graphFile, "\n\n"); |
| 218 | +foreach ($dependencies as $dad => $children) { |
| 219 | + foreach ($children as $child) { |
| 220 | + fwrite($graphFile, "$dad --> $child\n"); |
| 221 | + } |
| 222 | +} |
| 223 | +// Tie all orphans to a common start node |
| 224 | +fwrite($graphFile, "\n"); |
| 225 | +foreach ($activityIndex as $activityName => $key) { |
| 226 | + $isOrphan = true; |
| 227 | + foreach ($dependencies as $dad => $children) { |
| 228 | + if ($dad == $key) continue; |
| 229 | + if (in_array($key, $children)) { |
| 230 | + $isOrphan = false; |
| 231 | + break; |
| 232 | + } |
| 233 | + } |
| 234 | + if ($isOrphan) { |
| 235 | + fwrite($graphFile, "O --> $key\n"); |
| 236 | + } |
| 237 | +} |
| 238 | + |
| 239 | +// Close the file |
| 240 | +fwrite($graphFile, "```\n"); |
| 241 | +fclose($graphFile); |
| 242 | +echo "\nSaved dependency graph '$graphFilename'\n\n"; |
| 243 | + |
| 244 | + |
191 | 245 |
|
192 | 246 | function assertUniqueRefs($all_references, &$errorMsg) { |
193 | 247 | foreach ($all_references as $references) { |
|
0 commit comments