11# !/usr/bin/env pwsh
22# #############################################################################################################
33
4- Function PrivClipper {
4+ Function Show-Usage {
55 Return "
66Usage: pwsh -File $ ( $PSCommandPath ) [OPTIONS]
77Options:
88 build Build program
99"
1010}
1111
12- Function PrivWget {
12+ Function Request-File {
1313 ForEach ($REPLY in $args ) {
1414 $params = @ {
1515 Uri = $REPLY
@@ -20,77 +20,71 @@ Function PrivWget {
2020 }
2121}
2222
23- Function PrivMsiexec {
23+ Function Install-Program {
2424 While ($Input.MoveNext ()) {
25- $params = @ {}
2625 Switch ((Split-Path - Path $Input.Current - Leaf).Split(' .' )[-1 ]) {
2726 ' msi' {
28- $params = @ {
29- FilePath = ' msiexec'
30- ArgumentList = ' /passive' , ' /package' , $Input.Current
31- }
27+ & msiexec / passive / package $Input.Current | Out-Host
3228 }
3329 ' exe' {
34- $params = @ {
35- FilePath = $Input.Current
36- ArgumentList = ' /SP-' , ' /VERYSILENT' , ' /SUPPRESSMSGBOXES' , ' /NORESTART'
37- }
30+ & " .\$ ( $Input.Current ) " / SP- / VERYSILENT / SUPPRESSMSGBOXES / NORESTART | Out-Host
3831 }
3932 }
40- Start-Process - PassThru - Wait @params
4133 Remove-Item $Input.Current
4234 }
4335}
4436
45- Function PrivLazBuild {
37+ Function Build-Project {
4638 $VAR = @ {
4739 Cmd = ' lazbuild'
4840 Url = ' https://netix.dl.sourceforge.net/project/lazarus/Lazarus%20Windows%2064%20bits/Lazarus%203.6/lazarus-3.6-fpc-3.2.2-win64.exe?viasf=1'
4941 Path = " C:\Lazarus"
5042 }
51- If (-not (Get-Command $VAR.Cmd - ea ' continue' )) {
52- PrivWget $VAR.Url | PrivMsiexec
43+ Try {
44+ Get-Command $VAR.Cmd
45+ } Catch {
46+ Request-File $VAR.Url | Install-Program
5347 $env: PATH += " ;$ ( $VAR.Path ) "
5448 Get-Command $VAR.Cmd
5549 }
5650 If ( Test-Path - Path ' use\components.txt' ) {
57- Start-Process - Wait - FilePath ' git' - ArgumentList ' submodule' , ' update' , ' --recursive' , ' --init'
58- Start-Process - Wait - FilePath ' git' - ArgumentList ' submodule' , ' update' , ' --recursive' , ' --remote'
51+ & git submodule update -- recursive -- init | Out-Host
52+ & git submodule update -- recursive -- remote | Out-Host
5953 Get-Content - Path ' use\components.txt' | ForEach-Object {
60- If ((-not (Start-Process - ea ' continue ' - Wait - FilePath ' lazbuild' - ArgumentList ' -- verbose-pkgsearch' , $_ )) -and
61- (-not (Start-Process - ea ' continue ' - Wait - FilePath ' lazbuild' - ArgumentList ' -- add-package' , $_ )) -and
54+ If ((-not (& lazbuild -- verbose- pkgsearch $_ | Out-Null )) -and
55+ (-not (& lazbuild -- add-package $_ | Out-Null )) -and
6256 (-not (Test-Path - Path ' use\components.txt' ))) {
63- $OutFile = PrivWget " https://packages.lazarus-ide.org/$ ( $_ ) .zip"
57+ $OutFile = Request-File " https://packages.lazarus-ide.org/$ ( $_ ) .zip"
6458 Expand-Archive - Path $OutFile - DestinationPath " use\$ ( $_ ) " - Force
6559 Remove-Item $OutFile
66- }
60+ }
6761 }
6862 Get-ChildItem - Filter ' *.lpk' - Recurse - File –Path ' use' | ForEach-Object {
69- Start-Process - Wait - FilePath ' lazbuild' - ArgumentList ' -- add-package-link' , $_.Name
63+ & lazbuild -- add-package - link $_ | Out-Host
7064 }
7165 }
7266 Get-ChildItem - Filter ' *.lpi' - Recurse - File –Path ' src' | ForEach-Object {
73- Start-Process - Wait - FilePath ' lazbuild' - ArgumentList ' -- no-write-project' , ' --recursive' , ' --build-mode=release' , $_.Name
67+ & lazbuild -- no- write-project -- recursive -- build-mode = release $_ | Out-Host
7468 }
7569}
7670
77- Function PrivMain {
71+ Function Switch-Action {
7872 $ErrorActionPreference = ' stop'
7973 Set-PSDebug - Strict - Trace 1
8074 Invoke-ScriptAnalyzer - EnableExit - Path $PSCommandPath
8175 If ($args.count -gt 0 ) {
8276 Switch ($args [0 ]) {
8377 ' build' {
84- PrivLazBuild
78+ Build-Project
8579 }
8680 Default {
87- PrivClipper
81+ Show-Usage
8882 }
8983 }
9084 } Else {
91- PrivClipper
85+ Show-Usage
9286 }
9387}
9488
9589# #############################################################################################################
96- PrivMain @args
90+ Switch-Action @args | Out-Null
0 commit comments