1
0
mirror of https://github.com/chylex/TweetDuck.git synced 2025-04-14 03:15:49 +02:00

Move most of post build event (copying, cleanup) to PostBuild.ps1

This commit is contained in:
chylex 2018-04-04 20:05:59 +02:00
parent 24224ab4c6
commit caea8d4315
2 changed files with 73 additions and 58 deletions

View File

@ -1,41 +1,71 @@
Param([Parameter(Mandatory = $True, Position = 1)][string] $dir)
Param(
[Parameter(Mandatory = $True, Position = 1)][string] $targetDir,
[Parameter(Mandatory = $True, Position = 2)][string] $projectDir
)
$ErrorActionPreference = "Stop"
Set-Location $dir
$version = (Get-Item TweetDuck.exe).VersionInfo.FileVersion
Write-Host "TweetDuck version" $version
function Check-Carriage-Return{
Param([Parameter(Mandatory = $True, Position = 1)] $fname)
$file = @(Get-ChildItem -Include $fname -Recurse)[0]
if ((Get-Content -Path $file.FullName -Raw).Contains("`r")){
Throw "$fname cannot contain carriage return"
}
Write-Host "Verified" $file.FullName.Substring($dir.Length)
}
function Rewrite-File{
[CmdletBinding()]
Param([Parameter(Mandatory = $True, ValueFromPipeline = $True)][array] $lines, [Parameter(Mandatory = $True, Position = 1)] $file)
$relative = $file.FullName.Substring($dir.Length)
if ($relative.StartsWith("scripts\")){
$lines = (,("#" + $version) + $lines)
}
$lines | Where { $_ -ne '' } | Set-Content -Path $file.FullName
Write-Host "Processed" $relative
}
try{
Write-Host "------------------------------"
$version = (Get-Item (Join-Path $targetDir "TweetDuck.exe")).VersionInfo.FileVersion
Write-Host "TweetDuck version" $version
Write-Host "------------------------------"
# Cleanup
Remove-Item -Path (Join-Path $targetDir "locales\*.pak") -Exclude "en-US.pak"
# Copy resources
Copy-Item (Join-Path $projectDir "bld\Resources\CEFSHARP-LICENSE.txt") -Destination $targetDir -Force
Copy-Item (Join-Path $projectDir "LICENSE.md") -Destination (Join-Path $targetDir "LICENSE.txt") -Force
New-Item -ItemType directory -Path $targetDir -Name "scripts" | Out-Null
New-Item -ItemType directory -Path $targetDir -Name "plugins" | Out-Null
New-Item -ItemType directory -Path $targetDir -Name "plugins\official" | Out-Null
New-Item -ItemType directory -Path $targetDir -Name "plugins\user" | Out-Null
Copy-Item (Join-Path $projectDir "Resources\Scripts\*") -Destination (Join-Path $targetDir "scripts") -Recurse
Copy-Item (Join-Path $projectDir "Resources\Plugins\*") -Exclude ".debug", "emoji-instructions.txt" -Destination (Join-Path $targetDir "plugins\official") -Recurse
# Post processing
function Check-Carriage-Return{
Param(
[Parameter(Mandatory = $True, Position = 1)] $fname
)
$file = @(Get-ChildItem -Path $targetDir -Include $fname -Recurse)[0]
if ((Get-Content -Path $file.FullName -Raw).Contains("`r")){
Throw "$fname cannot contain carriage return"
}
Write-Host "Verified" $file.FullName.Substring($targetDir.Length)
}
function Rewrite-File{
[CmdletBinding()]
Param(
[Parameter(Mandatory = $True, ValueFromPipeline = $True)][array] $lines,
[Parameter(Mandatory = $True, Position = 1)] $file
)
$relativePath = $file.FullName.Substring($targetDir.Length)
if ($relativePath.StartsWith("scripts\")){
$lines = (,("#" + $version) + $lines)
}
$lines | Where { $_ -ne '' } | Set-Content -Path $file.FullName
Write-Host "Processed" $relativePath
}
Check-Carriage-Return("emoji-ordering.txt")
ForEach($file in Get-ChildItem -Filter *.js -Exclude configuration.default.js -Recurse){
ForEach($file in Get-ChildItem -Path $targetDir -Filter "*.js" -Exclude "configuration.default.js" -Recurse){
$lines = Get-Content -Path $file.FullName
$lines = $lines | % { $_.TrimStart() }
$lines = $lines -Replace '^(.*?)((?<=^|[;{}()])\s?//(?:\s.*|$))?$', '$1'
@ -43,7 +73,7 @@ try{
,$lines | Rewrite-File $file
}
ForEach($file in Get-ChildItem -Filter *.css -Recurse){
ForEach($file in Get-ChildItem -Path $targetDir -Filter "*.css" -Recurse){
$lines = Get-Content -Path $file.FullName
$lines = $lines -Replace '\s*/\*.*?\*/', ''
$lines = $lines -Replace '^\s+(.+):\s?(.+?)(?:\s?(!important))?;$', '$1:$2$3;'
@ -51,10 +81,12 @@ try{
@(($lines | Where { $_ -ne '' }) -Join ' ') | Rewrite-File $file
}
ForEach($file in Get-ChildItem -Filter *.html -Recurse){
ForEach($file in Get-ChildItem -Path $targetDir -Filter "*.html" -Recurse){
$lines = Get-Content -Path $file.FullName
,($lines | % { $_.TrimStart() }) | Rewrite-File $file
}
Write-Host "------------------------------"
}catch{
Write-Host "Encountered an error while running PostBuild.ps1 on line" $_.InvocationInfo.ScriptLineNumber
Write-Host $_

View File

@ -402,37 +402,20 @@
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>xcopy "$(ProjectDir)LICENSE.md" "$(TargetDir)" /Y
del "$(TargetDir)LICENSE.txt"
ren "$(TargetDir)LICENSE.md" "LICENSE.txt"
xcopy "$(ProjectDir)bld\Resources\CEFSHARP-LICENSE.txt" "$(TargetDir)" /Y
rmdir "$(TargetDir)scripts" /S /Q
mkdir "$(TargetDir)scripts"
xcopy "$(ProjectDir)Resources\Scripts\*" "$(TargetDir)scripts\" /E /Y
rmdir "$(TargetDir)plugins" /S /Q
mkdir "$(TargetDir)plugins"
mkdir "$(TargetDir)plugins\official"
mkdir "$(TargetDir)plugins\user"
xcopy "$(ProjectDir)Resources\Plugins\*" "$(TargetDir)plugins\official\" /E /Y
rmdir "$(TargetDir)plugins\official\.debug" /S /Q
del "$(TargetDir)plugins\official\emoji-keyboard\emoji-instructions.txt"
rmdir "$(ProjectDir)bin\Debug"
<PostBuildEvent>rmdir "$(ProjectDir)bin\Debug"
rmdir "$(ProjectDir)bin\Release"
attrib +R "$(TargetDir)locales\en-US.pak"
del /Q /A:-R "$(TargetDir)locales\*.pak"
attrib -R "$(TargetDir)locales\en-US.pak"
rmdir "$(TargetDir)scripts" /S /Q
rmdir "$(TargetDir)plugins" /S /Q
powershell -ExecutionPolicy Unrestricted -File "$(ProjectDir)Resources\PostBuild.ps1" "$(TargetDir)\" "$(ProjectDir)\"
if $(ConfigurationName) == Debug (
rmdir "$(TargetDir)plugins\official\.debug" /S /Q
mkdir "$(TargetDir)plugins\user\.debug"
xcopy "$(ProjectDir)Resources\Plugins\.debug\*" "$(TargetDir)plugins\user\.debug\" /E /Y
)
powershell -ExecutionPolicy Unrestricted -File "$(ProjectDir)Resources\PostBuild.ps1" "$(TargetDir)\"</PostBuildEvent>
</PostBuildEvent>
</PropertyGroup>
<Target Name="AfterBuild" Condition="$(ConfigurationName) == Release">
<Exec Command="del &quot;$(TargetDir)*.pdb&quot;" />