-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathinstall.ps1
More file actions
105 lines (89 loc) · 2.6 KB
/
install.ps1
File metadata and controls
105 lines (89 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
[CmdletBinding(PositionalBinding = $false)]
param (
[Parameter(Position = 0)]
[int]$Option
)
function Invoke-PackageSearch {
process {
try {
if (!$PSItem.EndsWith('\node_modules') -and !$PSItem.EndsWith('\Obsolete')) {
[IO.Directory]::GetFiles($PSItem, 'package.json')
[IO.Directory]::GetDirectories($PSItem) | Invoke-PackageSearch
}
} catch {
Write-Warning $PSItem.Exception.Message
}
}
}
$ErrorActionPreference = 'Stop'
node -v
if (!$Option) {
Write-Host -ForegroundColor Green '1) npm i'
Write-Host -ForegroundColor Green '2) npm run build:prod'
Write-Host -ForegroundColor Green '3) npm i & npm run build:prod'
Write-Host -ForegroundColor Cyan '8) npm i --package-lock-only (update package-lock.json)'
Write-Host -ForegroundColor Cyan '100) npm ci & npm run build:prod (node_modules junction)'
Write-Host -ForegroundColor Yellow '0) Exit'
$Option = Read-Host -Prompt 'Select'
}
$INSTALL = $BUILD = $LOCK = $SEARCH = $CI = $false
switch ($Option) {
1 { $INSTALL = $true; break }
2 { $BUILD = $true; break }
3 { $INSTALL = $BUILD = $true; break }
8 { $LOCK = $true; break }
9 { $SEARCH = $true; break }
100 { $CI = $BUILD = $true; break }
default { exit }
}
$PackageList = $PSScriptRoot | Invoke-PackageSearch
if ($SEARCH) {
$PackageList | Resolve-Path -Relative
exit
}
if ($CI) {
$CacheMap = [System.Collections.Generic.Dictionary[string, string]]::new()
$CachePath = $null
}
foreach ($Package in $PackageList) {
Split-Path -Path $Package | Set-Location
if ($CI) {
if (!(Test-Path -Path 'package-lock.json' -PathType Leaf)) {
Write-Warning "$PWD does not contain package-lock.json"
continue
}
$Junction = $false
$Hash = (Get-FileHash -Path 'package.json').Hash.ToLower()
if (Test-Path -Path 'node_modules') {
Remove-Item -Path 'node_modules' -Recurse -Force
}
if ($CacheMap.TryGetValue($Hash, [ref]$CachePath)) {
$null = New-Item -Path 'node_modules' -ItemType Junction -Value $CachePath -Verbose
$Junction = $true
} else {
npm ci
if (!$?) { Write-Error 'npm ci failed' }
$CacheMap[$Hash] = "$PWD\node_modules"
$null = robocopy "$PSScriptRoot\Typings\@docsvision" 'node_modules\@docsvision' /MIR
}
}
if ($INSTALL) {
npm i
if (!$?) { Write-Warning 'npm i failed' }
}
if ($BUILD) {
npm run build:prod
if (!$?) { Write-Warning 'npm run build:prod failed' }
}
if ($LOCK) {
Remove-Item -Path 'package-lock.json' -Verbose
npm i --package-lock-only
if (!$?) { Write-Warning 'npm i --package-lock-only failed' }
}
if ($CI) {
if ($Junction) {
Remove-Item -Path 'node_modules' -Recurse -Force -Verbose
}
}
}
Set-Location $PSScriptRoot