1- $exeDependencies = @ (
2- @ {
3- ' Name' = ' git' ;
4- ' Url' = ' https://github.com/git-for-windows/git/releases/download/v2.9.2.windows.1/Git-2.9.2-32-bit.exe' ;
5- ' Args' = @ (' /silent' ;' /norestart' );
6- ' Test' = @ {
7- ' Cmd' = ' git' ;
8- ' Args' = @ (' --version' )
9- }
10- } )
11-
12- $msiDependencies = @ (
13- @ {
14- ' Name' = ' Python' ;
15- ' Url' = " https://www.python.org/ftp/python/2.7.12/python-2.7.12.msi" ;
16- ' Path' = ' C:\Python27\'
17- ' Test' = @ {
18- ' Cmd' = ' C:\Python27\python.exe' ;
19- ' Args' = @ (' -V' )
20- }
21- } ;
22- @ {
23- ' Name' = ' nodejs' ;
24- ' Url' = " https://nodejs.org/dist/v12.19.0/node-v12.19.0-x86.msi" ;
25- ' Path' = ' C:\Program Files (x86)\nodejs'
26- ' Test' = @ {
27- ' Cmd' = ' C:\Program Files (x86)\nodejs\node.exe' ;
28- ' Args' = @ (' -v' )
29- }
30- } )
31-
321$zipDependencies = @ (
33- @ {
34- ' Name' = ' Wix' ;
35- ' Url' = " https://wix.codeplex.com/downloads/get/1587180" ;
36- ' Path' = " C:\Program Files (x86)\WiX Toolset v3.8\bin"
37- ' Test' = @ {
38- ' Cmd' = ' C:\Program Files (x86)\WiX Toolset v3.8\bin\heat.exe' ;
39- ' Args' = @ (' -?' )
40- }
41- } ;
422 @ {
433 ' Name' = ' nssm' ;
444 ' Url' = " http://nssm.cc/release/nssm-2.24.zip" ;
@@ -48,11 +8,6 @@ $zipDependencies = @(
488 }
499 } )
5010
51- $npmPackages = @ (
52- @ {' Name' = ' npm' ; ' Version' = " 6.14.8" } ;
53- @ {' Name' = ' node-gyp' ; ' Version' = " 3.4.0" }
54- )
55-
5611function Get-TempPath
5712{
5813 [io.path ]::GetTempPath()
@@ -63,107 +18,6 @@ function Get-TempFileName
6318 [io.path ]::GetTempFileName()
6419}
6520
66- function Test-Command
67- {
68- param (
69- [Parameter (Mandatory = $true )] $Command
70- )
71-
72- try
73- {
74- $result = $true ;
75- if ($Command.Cmd -ne $null )
76- {
77- if ($Command.Args -eq $null )
78- {
79- $Command.Args = @ ();
80- }
81-
82- $process = Start-Process - Wait - PassThru - File $Command.Cmd - ArgumentList $Command.Args - NoNewWindow
83- $result = $result -and ($process.exitCode -eq 0 )
84- }
85-
86- if ($Command.Path -ne $null )
87- {
88- $result = $result -and (Test-Path $Command.Path )
89- }
90-
91- $result
92- }
93- catch
94- {
95- $false
96- }
97- }
98-
99- function Expand-ZipFile
100- {
101- param (
102- [Parameter (Mandatory = $true )][String ] $File ,
103- [Parameter (Mandatory = $true )][String ] $Path
104- )
105-
106- if (-not (Test-Path $Path ) )
107- {
108- Write-Verbose " Creting Directory $Path "
109- New-Item - Path $Path - ItemType directory - force | Out-Null
110- }
111-
112- $shell = New-Object - com Shell.Application
113- $zip = $shell.NameSpace ($File )
114- foreach ($item in $zip.items ())
115- {
116- $shell.Namespace ($Path ).copyhere($item )
117- }
118- }
119-
120- function InstallFrom-Exe
121- {
122- param (
123- [Parameter (Mandatory = $true )][String ] $Url ,
124- [Parameter (Mandatory = $false )]$Args = @ (),
125- [Parameter (Mandatory = $false )][String ] $TempFile = (Get-TempFileName ) + ' .exe'
126- )
127-
128- Write-Verbose " ==>Downloading executable $Url ==> $TempFile "
129- Invoke-WebRequest - Uri $Url - OutFile $TempFile
130-
131- Write-Verbose " Starting process"
132-
133- Start-Process - Wait - Verb runas - FilePath $TempFile - ArgumentList $Args
134-
135- Write-Debug " Removing $TempFile "
136- Remove-Item $TempFile
137- }
138-
139- function InstallFrom-Url
140- {
141- param (
142- [Parameter (Mandatory = $true )][String ] $Url ,
143- [Parameter (Mandatory = $false )][String ] $Path = $null ,
144- [Parameter (Mandatory = $false )][String ] $TempFile = (Get-TempFileName )
145- )
146-
147- Write-Verbose " ==>Downloading installer $Url ==> $TempFile "
148- Invoke-WebRequest - Uri $Url - OutFile $TempFile
149-
150- Write-Verbose " Starting msiexec process"
151- $args = @ (" /i" ;$TempFile ;" /qb" )
152- if ($Path -ne $null )
153- {
154- $args = @ (" /i" ;$TempFile ;" TARGETDIR=`" $Path `" " ; " INSTALLDIR=`" $Path `" " , " /qb" )
155- }
156- else
157- {
158- $args = @ (" /i" ;$TempFile ;" /qb" )
159- }
160-
161- Start-Process - Wait - Verb runas - FilePath msiexec - ArgumentList $args
162-
163- Write-Debug " Removing $TempFile "
164- Remove-Item $TempFile
165- }
166-
16721function UnpackFrom-Url
16822{
16923 param (
@@ -178,37 +32,7 @@ function UnpackFrom-Url
17832 Invoke-WebRequest - Uri $Url - OutFile $TempFile
17933
18034 Write-Verbose " Unpacking file into $Path "
181- Expand-ZipFile - File $TempFile - Path $Path
182-
183- Write-Debug " Removing $TempFile "
184- # Remove-Item $TempFile
185- }
186-
187- function Install-NpmPackage
188- {
189- param (
190- [Parameter (Mandatory = $true )][String ] $Name ,
191- [Parameter (Mandatory = $false )][String ] $Version = $null ,
192- [Parameter (Mandatory = $false )][switch ] $Global
193- )
194-
195- if ($Version -ne $null )
196- {
197- $Name = $Name + " @" + $Version
198- }
199-
200- Write-Verbose " Starting NPM install of package $Name "
201-
202- if ($global )
203- {
204- $args = @ (" install" ;$Name ; " -g" )
205- }
206- else
207- {
208- $args = @ (" install" ;$Name )
209- }
210-
211- Start-Process - FilePath " npm" - ArgumentList $args - Wait - NoNewWindow
35+ Expand-Archive - Path $TempFile - DestinationPath $Path - Force
21236}
21337
21438function Test-IsAdmin ()
@@ -236,42 +60,11 @@ if (-not (Test-IsAdmin))
23660}
23761else
23862{
239- Write-Host " Installing Dependencies"
240-
241- $exeDependencies | ForEach-Object {
242- if (-not (Test-Command $_.Test ))
243- {
244- Write-Host " ==> Installing $ ( $_.Name ) " ;
245- InstallFrom- Exe - Url $_.Url - Args $_.Args
246- }
247- }
248-
249- $msiDependencies | ForEach-Object {
250- if (-not (Test-Command $_.Test ))
251- {
252- Write-Host " ==> Installing $ ( $_.Name ) " ;
253- InstallFrom- Url - Url $_.Url - Path $_.Path
254- }
255- }
256-
25763 $zipDependencies | ForEach-Object {
258- if (-not (Test-Command $_.Test ))
259- {
260- Write-Host " ==> Installing $ ( $_.Name ) " ;
261- UnpackFrom- Url - Url $_.Url - Path $_.Path
262- }
263- }
64+ Write-Host " ==> Installing $ ( $_.Name ) " ;
65+ UnpackFrom- Url - Url $_.Url - Path $_.Path
66+ }
26467
26568 # reloads path to execute NPM
26669 $env: Path = [System.Environment ]::GetEnvironmentVariable(" Path" , " Machine" ) + " ;" + [System.Environment ]::GetEnvironmentVariable(" Path" , " User" )
267-
268- Write-Host " Updating NPM packages"
269-
270- $npmPackages | ForEach-Object {
271- Write-Host " ==> Installing $ ( $_.Name ) version $ ( $_.Version ) " ;
272- Install-NpmPackage - Name $_.Name - Version $_.Version - Global
273- }
274-
275- Write-Host " Adding Python path to NPM"
276- Start-Process - FilePath " npm" - ArgumentList @ (" config" ;" set" ;" python" ;" C:\Python27\python.exe" ) - Wait - NoNewWindow
27770}
0 commit comments