-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy path.compressor.ps1
87 lines (67 loc) · 1.7 KB
/
.compressor.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
Set-Location $PSScriptRoot
if (-Not (Test-Path "$env:ProgramFiles\7-Zip\7z.exe")) {
Write-Host "7z.exe not found"
return Read-Host
}
Set-Alias 7z "$env:ProgramFiles\7-Zip\7z.exe"
function Remove-Kaka([Parameter(Mandatory, ValueFromPipeline)] $file) {
process {
$canWrite = $true
$out = ""
foreach ($line in Get-Content $file) {
if ($line -match "--@do-not-package@") {
$canWrite = $false
}
elseif ($line -match "--@end-do-not-package@") {
$canWrite = $true
if (-not $foreach.MoveNext()) {
break
}
$line = $foreach.Current
}
if ($canWrite) {
$out += "$line`n"
}
}
Set-Content $file -Value $out.TrimEnd()
}
}
$name = (Get-Item .).Name
if (-Not (Test-Path (".\$name\$name.toc"))) {
Write-Host ".toc not found"
return Read-Host
}
if (Get-Content (".\$name\$name.toc") | Where-Object { $_ -match "Version:\s*([a-zA-Z0-9.-]+)" }) {
$version = $matches[1]
} else {
Write-Host "Bad version format"
return Read-Host
}
$foldersToInclude = @(
".\ls_UI\",
".\ls_UI_Options\"
)
$filesToExclude = @(
"*.doc*"
"*.editorconfig",
"*.git*",
"*.luacheck*",
"*.pkg*",
"*.ps1",
"*.sh",
"*.yml"
)
$foldersToRemove = @(
".github",
"utils"
)
$temp = ".\temp\"
if (Test-Path $temp) {
Remove-Item $temp -Recurse -Force
}
New-Item -Path $temp -ItemType Directory | Out-Null
Copy-Item $foldersToInclude -Destination $temp -Exclude $filesToExclude -Recurse
Get-ChildItem $temp -Recurse | Where-Object { $_.PSIsContainer -and $_.Name -cin $foldersToRemove } | Remove-Item -Recurse -Force
Get-ChildItem $temp -Recurse | Where-Object { $_.Extension -eq ".lua"} | Remove-Kaka
7z a -tzip -mx9 "..\$name-$version.zip" (Get-ChildItem $temp)
Remove-Item $temp -Recurse -Force