-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathchargersync.PS1
154 lines (123 loc) · 5.14 KB
/
chargersync.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# Define a script block to handle cleanup
$cleanupScript = {
Write-Host "Shutting Down" -ForegroundColor DarkBlue
# Find the PID (Process ID) of processes using port 3000
$pidList = netstat -ano | Select-String "3000" | ForEach-Object { $_.ToString().Trim() -split "\s+" } | Where-Object { $_ -match "\d+$" } | ForEach-Object { $_.Trim() }
# Terminate processes using the found PID(s)
foreach ($pid in $pidList) {
taskkill /F /PID $pid
}
docker kill chargersync-backend-1
exit 1 # Exit the script
}
# Register the cleanup script block as an event handler for the Ctrl+C event
$null = Register-ObjectEvent -InputObject ([console]) -EventName CancelKeyPress -Action $cleanupScript
$asciiArt = @"
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@...................@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@......@@..@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@........@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@..@@@@@@@@..@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@........@@.........@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@..@@@@@@@@@........@@@.......@@@.....@@........@@.......@@@.....@@........@@.........@@@..@@@@...@@........@@@......@@
@..@@@@@@@@@..@@@@@..@@@@@@@@..@@..@@@@..@@@@@.@@@.@@@@@..@@..@@@@@........@@.........@@@...@@@..@@@..@@@@..@@..@@@@@@@
@..@@@@@@@@@..@@@@@..@@..@@@@..@@..@@@@@.......@@.........@@..@@@@@@@@@@@@@@@.........@@@@..@@..@@@@..@@@@..@@..@@@@@@@
@@...@@@@.@@..@@@@@..@...@@@...@@..@@@@..@@@@@@@@@..@@@@@@@@..@@@@@...................@@@@@....@@@@@..@@@@..@@...@@@@@@
@@@@@....@@@@@@@@@@@@@@@@..@@@@@@@@@@@@@@.......@@@@@...@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@..@@@@@@@@@@@@@@@@@@@...@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@.......@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@....@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
"@
function AsciiArt {
param(
[string]$Art
)
# Print the ASCII art
Write-Output $Art
}
AsciiArt -Art $asciiArt
Write-Host "Performing background loading actions..." -ForegroundColor DarkBlue
$npmInstallLogFile = "NodeJS_install_logs.txt"
$npmDevLogFile = "NodeJS_dev_logs.txt"
# $dockerLogFile = "Docker_exec_logs.txt"
Set-Location ./frontend
$npmJob = Start-Job -ScriptBlock {
param($workingDirectory)
Set-Location $workingDirectory
npm install > $using:npmInstallLogFile
npm run dev > $using:npmDevLogFile
} -ArgumentList (Get-Location)
Set-Location ..
# Define paths and service name
$dockerCLI = "C:\Program Files\Docker\Docker\DockerCli.exe"
$dockerDesktop = "C:\Program Files\Docker\Docker\Docker Desktop.exe"
$dockerServiceName = "com.docker.service"
$dockerLogFile = "dockerlogfile.txt" # Specify the path to your log file
# Check if Docker service exists
$dockerService = Get-Service -Name $dockerServiceName
if ($dockerService -eq $null) {
Write-Host "Docker service '$dockerServiceName' not found."
exit 1
}
# Start Docker service if it's not running
if ($dockerService.Status -ne "Running") {
try {
Start-Service -Name $dockerServiceName -ErrorAction Stop
}
catch {
Write-Host "Error starting Docker service: $_"
exit 1
}
}
# Start Docker CLI
try {
Start-Process -FilePath $dockerCLI -NoNewWindow -Wait
}
catch {
Write-Host "Error starting Docker CLI: $_"
exit 1
}
# Start Docker Desktop
try {
Start-Process -FilePath $dockerDesktop -NoNewWindow -Wait
}
catch {
Write-Host "Error starting Docker Desktop: $_"
exit 1
}
# Change directory to where your docker-compose.yml file resides
$composeDirectory = Join-Path -Path $PSScriptRoot -ChildPath "ChargerSync"
Set-Location $composeDirectory
# Run docker-compose up command to build and start services defined in docker-compose.yml
try {
docker-compose up --build | Out-File -FilePath $dockerLogFile -Append
}
catch {
Write-Host "Error running docker-compose: $_"
exit 1
}
function Show-LoadingBar {
param(
[int]$TotalSteps
)
for ($i = 1; $i -le $TotalSteps; $i++) {
# Calculate the percentage completion
$percentage = [math]::Round(($i / $TotalSteps) * 100)
# Clear the current line
Write-Host -NoNewline "`r"
# Draw the loading bar
$progressWidth = [console]::WindowWidth - 20 # Adjust the width as needed
$barLength = [math]::Round(($progressWidth * $i) / $TotalSteps)
$bar = "-" * $barLength
$emptySpace = " " * ($progressWidth - $barLength)
Write-Host -NoNewline "`rProgress: [$bar$emptySpace] $percentage%" -ForegroundColor DarkBlue
# Wait for a short duration (adjust as needed)
Start-Sleep -Milliseconds 125
}
Write-Host # Move to the next line after completion
}
# Example usage:
$TotalSteps = 300 # Total number of steps
Show-LoadingBar -TotalSteps $TotalSteps
# Start the job to open localhost after npm and Docker are ready
Start-Process "http://localhost:3000"
# Wait for npm and Docker jobs to complete
$npmJob | Wait-Job
$dockerJob | Wait-Job