github.com/sapplications/sb@v0.0.0-20240116135441-1a13cafe3497/.build.ps1 (about) 1 function GenDoc { 2 param ( 3 [string]$PackageName 4 ) 5 $CurrLocation = Get-Location 6 Set-Location -Path $PackageName 7 $Status = Start-Process -FilePath 'go' -ArgumentList 'doc -all' -RedirectStandardOutput 'readme.txt' -NoNewWindow -PassThru -Wait 8 Set-Location -Path $CurrLocation 9 Assert($Status.ExitCode -eq 0) 'The "go doc" command failed' 10 } 11 12 # Synopsis: Generate sources 13 task code { 14 $Status = Start-Process -FilePath 'sb' -ArgumentList 'code' -NoNewWindow -PassThru -Wait 15 Assert($Status.ExitCode -eq 0) 'The "code" command failed' 16 } 17 18 # Synopsis: Build sources 19 task build { 20 $Status = Start-Process -FilePath 'sb' -ArgumentList 'build' -NoNewWindow -PassThru -Wait 21 Assert($Status.ExitCode -eq 0) 'The "build" command failed' 22 } 23 24 # Synopsis: Generate & build sources 25 task cbuild code, build 26 27 # Synopsis: Remove generated files 28 task clean { 29 $AppPath = './sb/sb' 30 if ($PSVersionTable.Platform -ne 'Unix') { 31 $AppPath += '.exe' 32 } 33 if (Test-Path -Path $AppPath) { 34 Remove-Item -Path $AppPath 35 } 36 } 37 38 # Synopsis: Build samples 39 task build-samples { 40 Set-Location -Path 'samples' 41 $Status = Start-Process -FilePath 'sb' -ArgumentList 'code helloworld' -NoNewWindow -PassThru -Wait 42 Assert($Status.ExitCode -eq 0) 'The "code helloworld" command failed' 43 $Status = Start-Process -FilePath 'sb' -ArgumentList 'build helloworld' -NoNewWindow -PassThru -Wait 44 Assert($Status.ExitCode -eq 0) 'The "build helloworld" command failed' 45 } 46 47 # Synopsis: Clean samples 48 task clean-samples { 49 Set-Location -Path 'samples' 50 $Status = Start-Process -FilePath 'sb' -ArgumentList 'clean helloworld' -NoNewWindow -PassThru -Wait 51 Assert($Status.ExitCode -eq 0) 'The "clean helloworld" command failed' 52 } 53 54 # Synopsis: Remove all generated files 55 task clean-all clean, clean-samples 56 57 # Synopsis: Install application 58 task install { 59 $AppName = 'sb' 60 if ($PSVersionTable.Platform -eq 'Unix') { 61 $GoPath = "${Env:HOME}/go" 62 } else { 63 $GoPath = "${Env:GOPATH}".TrimEnd(';') 64 $AppName += '.exe' 65 } 66 Set-Location -Path 'sb' 67 Copy-Item -Path $AppName -Destination '../bin/' 68 Copy-Item -Path $AppName -Destination "$GoPath/bin/" 69 } 70 71 # Synopsis: Generate, build & install application 72 task cinstall cbuild, install 73 74 # Synopsis: Run tests 75 task test { 76 Set-Location -Path 'cmd' 77 $Status = Start-Process -FilePath 'go' -ArgumentList 'test' -NoNewWindow -PassThru -Wait 78 Assert($Status.ExitCode -eq 0) 'The test command failed' 79 } 80 81 # Synopsis: Generate documentation 82 task doc { 83 GenDoc -PackageName '.' 84 GenDoc -PackageName 'cmd' 85 GenDoc -PackageName 'plugins' 86 } 87 88 task . cbuild, build-samples, test, clean-all, doc