-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodesys-diff.ps1
More file actions
104 lines (71 loc) · 2.84 KB
/
codesys-diff.ps1
File metadata and controls
104 lines (71 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<#
.SYNOPSIS
Generate diff between two CODESYS text exports
.DESCRIPTION
Compares two directories of exported CODESYS text files (.st) and generates
unified diffs showing additions, modifications, and removals.
.PARAMETER BaseDir
Directory containing the base/original export (before changes)
.PARAMETER TargetDir
Directory containing the target export (after changes)
.PARAMETER OutputDir
Directory to write diff files to
.EXAMPLE
.\codesys-diff.ps1 -BaseDir ".\export_v1" -TargetDir ".\export_v2" -OutputDir ".\diffs"
#>
param(
[Parameter(Mandatory=$true)]
[string]$BaseDir,
[Parameter(Mandatory=$true)]
[string]$TargetDir,
[Parameter(Mandatory=$true)]
[string]$OutputDir
)
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
# Validate inputs
if (-not (Test-Path $BaseDir)) {
Write-Host "Error: Base directory not found: $BaseDir" -ForegroundColor Red
exit 1
}
if (-not (Test-Path $TargetDir)) {
Write-Host "Error: Target directory not found: $TargetDir" -ForegroundColor Red
exit 1
}
Write-Host "=== CODESYS Diff ===" -ForegroundColor Cyan
Write-Host " Base: $BaseDir" -ForegroundColor Gray
Write-Host " Target: $TargetDir" -ForegroundColor Gray
Write-Host " Output: $OutputDir" -ForegroundColor Gray
$pythonScript = Join-Path $scriptDir "scripts\codesys_diff.py"
if (-not (Test-Path $pythonScript)) {
Write-Host "Error: Diff script not found: $pythonScript" -ForegroundColor Red
exit 1
}
& python $pythonScript $BaseDir $TargetDir $OutputDir
if ($LASTEXITCODE -eq 0) {
Write-Host "`nDiff completed successfully!" -ForegroundColor Green
# Display summary if it exists
$summaryFile = Join-Path $OutputDir "diff_summary.txt"
if (Test-Path $summaryFile) {
Write-Host "`n--- Diff Summary ---" -ForegroundColor Yellow
Get-Content $summaryFile
}
# List generated diff files
$diffFiles = Get-ChildItem -Path $OutputDir -Filter "*.diff" -ErrorAction SilentlyContinue
$addedFiles = Get-ChildItem -Path $OutputDir -Filter "*.added" -ErrorAction SilentlyContinue
$removedFiles = Get-ChildItem -Path $OutputDir -Filter "*.removed" -ErrorAction SilentlyContinue
if ($diffFiles -or $addedFiles -or $removedFiles) {
Write-Host "`n--- Generated Files ---" -ForegroundColor Yellow
if ($diffFiles) {
$diffFiles | ForEach-Object { Write-Host " [DIFF] $($_.Name)" -ForegroundColor Cyan }
}
if ($addedFiles) {
$addedFiles | ForEach-Object { Write-Host " [ADD] $($_.Name)" -ForegroundColor Green }
}
if ($removedFiles) {
$removedFiles | ForEach-Object { Write-Host " [DEL] $($_.Name)" -ForegroundColor Red }
}
}
} else {
Write-Host "`nDiff failed with exit code: $LASTEXITCODE" -ForegroundColor Red
exit $LASTEXITCODE
}