-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathapply-license-header.ps1
108 lines (75 loc) · 3.34 KB
/
apply-license-header.ps1
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# Copyright (c) 2025 Sander van Vliet
# Licensed under Artistic License 2.0
# See LICENSE or https://choosealicense.com/licenses/artistic-2.0/
$csharpFiles = Get-ChildItem -Recurse -Filter *.cs | where-object {!$_.fullname.Contains("\obj\") -and !$_.fullname.Contains("\bin\")}
$prepend = Get-Content "csharp-license.txt" -Raw
$licenseFirstLine = (Get-Content "csharp-license.txt" -head 1).Trim()
foreach($file in $csharpFiles)
{
$contents = get-content $file -head 1
$contentsTrimmed = $contents.Trim()
if(!$contentsTrimmed.StartsWith("// Copyright (c) "))
{
$fullPath = $file.FullName
Write-Host "$fullPath doesn't have a license header, adding it"
$rawContents = Get-Content $file -Raw
$targetContent = $prepend + $rawContents
$targetContent | Out-File $file -NoNewline
}
elseif($contentsTrimmed -ne $licenseFirstLine)
{
$fullPath = $file.FullName
Write-Host "$fullPath has a license header but it's not up to date, changing it"
$rawContents = Get-Content $file -Raw
$targetContent = $rawContents.Replace($contents.Trim(), $licenseFirstLine)
$targetContent | Out-File $file -NoNewline
}
}
$xamlFiles = Get-ChildItem -Recurse -Filter *.axaml | where-object {!$_.fullname.Contains("\obj\") -and !$_.fullname.Contains("\bin\")}
$prepend = Get-Content "xaml-license.txt" -Raw
$licenseFirstLine = (Get-Content "xaml-license.txt" | Select-Object -Skip 1 -First 1).Trim()
foreach($file in $xamlFiles)
{
$contents = (get-content $file | Select-Object -Skip 1 -First 1)
$contentsTrimmed = $contents.Trim()
if(!$contentsTrimmed.StartsWith("// Copyright (c) "))
{
$fullPath = $file.FullName
Write-Host "$fullPath doesn't have a license header"
$rawContents = Get-Content $file -Raw
$targetContent = $prepend + $rawContents
$targetContent | Out-File $file -NoNewline
}
elseif($contentsTrimmed -ne $licenseFirstLine)
{
$fullPath = $file.FullName
Write-Host "$fullPath has a license header but it's not up to date, changing it"
$rawContents = Get-Content $file -Raw
$targetContent = $rawContents.Replace($contentsTrimmed, $licenseFirstLine)
$targetContent | Out-File $file -NoNewline
}
}
$powershellFiles = Get-ChildItem -Recurse -Filter *.ps1 | where-object {!$_.fullname.Contains("\obj\") -and !$_.fullname.Contains("\bin\")}
$prepend = Get-Content "powershell-license.txt" -Raw
$licenseFirstLine = (Get-Content "powershell-license.txt" -head 1).Trim()
foreach($file in $powershellFiles)
{
$contents = get-content $file -head 1
$contentsTrimmed = $contents.Trim()
if(!$contentsTrimmed.StartsWith("# Copyright (c) "))
{
$fullPath = $file.FullName
Write-Host "$fullPath doesn't have a license header"
$rawContents = Get-Content $file -Raw
$targetContent = $prepend + $rawContents
$targetContent | Out-File $file -NoNewline
}
elseif($contentsTrimmed -ne $licenseFirstLine)
{
$fullPath = $file.FullName
Write-Host "$fullPath has a license header but it's not up to date, changing it"
$rawContents = Get-Content $file -Raw
$targetContent = $rawContents.Replace($contents.Trim(), $licenseFirstLine)
$targetContent | Out-File $file -NoNewline
}
}