You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
iot/publish/build.ps1

54 lines
2.8 KiB

#https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/copy-item?view=powershell-7.1
echo 'start:'
Get-Date -Format 'yyyy-MM-dd HH:mm:ss'
if(Test-Path dist)
{
echo 'clear dist folder'
Remove-Item ./dist/* -Recurse -Force
}
echo 'copy src to dist'
Copy-Item ./src/* ./dist -Recurse -Exclude @('.gitignore','dev.cmd','docker-compose.override.yml','nginx.dev.conf')
Remove-Item ./dist/linux-x64/publish/log/* -recurse -force
Remove-Item ./dist/linux-x64/publish/data/* -recurse -force
echo 'copy project files to dist folder'
Copy-Item -Path ../projects/WebMVC/wwwroot/* -Destination ./dist/linux-x64/publish/apps/WebMVC/wwwroot/ -Recurse
Copy-Item -Path ../projects/WebSPA/wwwroot/* -Destination ./dist/linux-x64/publish/apps/WebSPA/wwwroot/ -Recurse
dotnet publish ../projects/Platform/Platform.csproj -c Release -r linux-x64 -p:PublishSingleFile=true -o ../publish/dist/linux-x64/publish/apps/Platform
dotnet publish ../projects/IoTNode/IoTNode.csproj -c Release -r linux-arm64 -p:PublishSingleFile=true -o ../publish/dist/linux-arm64/publish/apps/IoTNode
dotnet publish ../projects/IoTDameon/IoTDameon.csproj -c Release -r linux-arm64 -p:PublishSingleFile=true -o ../publish/dist/linux-arm64/publish/apps/IoTDameon
$source=@"
public class Encoding : System.Text.UTF8Encoding
{
public override byte[] GetBytes(string s)
{
s = s.Replace("\\", "/");
return base.GetBytes(s);
}
}
"@
Add-Type -TypeDefinition $source
$encoding=New-Object Encoding
Add-Type -Assembly "System.IO.Compression.FileSystem"
echo 'create zip file'
$level = [System.IO.Compression.CompressionLevel]::Optimal
[System.IO.Compression.ZipFile]::CreateFromDirectory((Get-Item .).FullName+"/dist/linux-arm64/publish", (Get-Item .).FullName+"/dist/linux-arm64/publish.zip",$level,$true,$encoding)
[System.IO.Compression.ZipFile]::CreateFromDirectory((Get-Item .).FullName+"/dist/linux-arm64/publish/apps/IoTNode", (Get-Item .).FullName+"/dist/linux-arm64/IoTNode.zip",$level,$true,$encoding)
$zip=(Get-Item .).FullName+"/dist/linux-arm64/IoTNode.zip"
echo 'create xml file'
$v= [System.Text.RegularExpressions.Regex]::Match((Get-Content "../projects/IoTNode/IoTNode.csproj"),'<Version>(.+)</Version>').Groups[1].Value
$sha1 = New-Object System.Security.Cryptography.SHA1CryptoServiceProvider
$checksum=[System.BitConverter]::ToString( $sha1.ComputeHash([System.IO.File]::ReadAllBytes($zip))).Replace('-','')
$file = (Get-Item .).FullName+'/dist/linux-arm64/iotnode.xml'
$xml = New-Object System.Xml.XmlDocument
$xml.PreserveWhitespace = $true
$xml.LoadXml('<?xml version="1.0" encoding="utf-8" ?><app><version>'+$v+'</version><checksum>'+$checksum+'</checksum></app>')
$xml.Save($file)
echo end!
Get-Date -Format 'yyyy-MM-dd HH:mm:ss'
Read-Host -Prompt "Press any key to continue"