forked from mdhom/node-red-contrib-bring-shopping
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.ps1
116 lines (90 loc) · 3.52 KB
/
install.ps1
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
106
107
108
109
110
111
112
113
114
115
116
function copy-files {
PARAM (
$src,
$destRoot,
$destFolder
)
$src = Resolve-Path $src
$destRoot = Resolve-Path $destRoot
Write-Output "From : $src"
Write-Output "To : $destRoot"
$files = Get-ChildItem -Recurse $src | Where-Object { ! $_.PSIsContainer }
foreach ($file in $files) {
$relativeFile = $file.FullName.Substring($src.Path.Length)
$dest = Join-Path -Path $destRoot -ChildPath "$destFolder\$relativeFile"
$folder = $dest.Substring(0, $dest.LastIndexOf("\"))
if (-not (Test-Path $folder)) {
New-Item -ItemType Directory $folder
}
Write-Output $dest
[System.IO.File]::Copy($file.FullName, $dest, $true);
}
}
if (-not (Test-Path ".\debug\package.json")) {
$check = docker container inspect -f '{{.State.Running}}' "nodered_testing"
if ($check) {
docker-compose down
}
docker-compose up -d
Write-Host "Waiting for node-red to boot ..." -NoNewLine
while (!(Test-Path ".\debug\package.json")) {
Start-Sleep 2
}
Write-Host -ForegroundColor Green " done"
}
docker-compose down
$origin = [Environment]::CurrentDirectory;
$repoName = $origin.Split('\') | Select-Object -Last 1
Write-Host "Name: $repoName"
if (-not (Test-Path ".\debug\myModules\$repoName")) {
Write-Output "Creating Path..."
New-Item -ItemType Directory ".\debug\myModules\$repoName"
New-Item -ItemType Directory ".\debug\myModules\$repoName\lib"
}
Write-Output "Copy files..."
copy-files -src '.\src' -destRoot ".\debug\myModules\$repoName" -destFolder "src"
copy-files -src '.\lib' -destRoot ".\debug\myModules\$repoName" -destFolder "lib"
$packageModified = $false
$destRoot = Resolve-Path ".\debug\myModules\$repoName"
# Check if package.json needs install
if (Test-Path $destRoot/package.json) {
Write-Output "Comparing package.json ..."
$packageModified = (Get-FileHash ./package.json).hash -ne (Get-FileHash $destRoot/package.json).hash
if ($packageModified) {
Write-Host "package.json was modified. Reinstall again after copy!" -ForegroundColor Red
}
else {
Write-Host "Unmodified. No reinstallation needed!" -ForegroundColor Green
}
}
else {
$packageModified = $true;
}
Copy-Item -Path ./package.json -Destination $destRoot/package.json
$destination = Resolve-Path .\debug\
Write-Output "Change location to: $destination"
Set-Location $destination
if ($packageModified) {
npm install ".\myModules\$repoName"
}
Write-Output "Switching back to: $origin"
Set-Location $origin
# fix for windwos docker
# windows docker can't handle links so we need to copy the files....
if ($IsWindows -or $Env:OS -eq "Windows_NT") {
Write-Host "Fixing Windows Docker Problems" -ForegroundColor Red
Write-Host "Resolve symlink" -ForegroundColor Yellow
$files = Get-ChildItem "./debug/node_modules/" | Where-Object { $_.Attributes -match "ReparsePoint" }
Write-Host "Updating modules..." -ForegroundColor Yellow
$files = Get-ChildItem "./debug/node_modules/" -Directory
foreach ($file in $files) {
$moduleName = $file.FullName.Split("\") | Select-Object -Last 1
if (Test-Path "./debug/myModules/$moduleName") {
Write-Host "Update module: " -NoNewline -ForegroundColor Magenta
Write-Host $moduleName
Remove-Item $file.FullName -Force -Recurse
Copy-Item -Recurse -Path "./debug/myModules/$moduleName/" -Destination "./debug/node_modules/"
}
}
}
docker-compose up -d