-
Notifications
You must be signed in to change notification settings - Fork 0
Collapse file tree
Files
Search this repository(forward slash) forward slash/
/
Copy pathStart-LeanSERP-Build.ps1
More file actions
More file actions
Latest commit
216 lines (170 loc) · 3.74 KB
/
Copy pathStart-LeanSERP-Build.ps1
File metadata and controls
216 lines (170 loc) · 3.74 KB
You must be signed in to make or propose changes
More edit options
Edit and raw actions
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
[CmdletBinding()]
param()
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
Add-Type -AssemblyName System.Windows.Forms
$studioDirectory =
"C:\Users\PC\Downloads\LeanSERP-Studio"
$builderPath =
Join-Path $studioDirectory "LeanSERP-Studio.ps1"
$defaultOutput =
"C:\Users\PC\Downloads\LeanSERP-Output"
if (
-not (
Test-Path `
-LiteralPath $builderPath `
-PathType Leaf
)
) {
throw "LeanSERP-Studio.ps1 was not found."
}
$fileDialog =
[System.Windows.Forms.OpenFileDialog]::new()
$fileDialog.Title =
"Select LeanSERP source files"
$fileDialog.Filter =
"Text and list files|*.txt;*.list;*.dat|All files|*.*"
$fileDialog.Multiselect = $true
$fileDialog.CheckFileExists = $true
try {
if (
$fileDialog.ShowDialog() -ne
[System.Windows.Forms.DialogResult]::OK
) {
Write-Host "No source files selected."
exit 0
}
$inputFiles = @($fileDialog.FileNames)
}
finally {
$fileDialog.Dispose()
}
$folderDialog =
[System.Windows.Forms.FolderBrowserDialog]::new()
$folderDialog.Description =
"Select the LeanSERP output directory"
$folderDialog.SelectedPath =
$defaultOutput
try {
if (
$folderDialog.ShowDialog() -eq
[System.Windows.Forms.DialogResult]::OK
) {
$outputDirectory =
$folderDialog.SelectedPath
}
else {
$outputDirectory =
$defaultOutput
}
}
finally {
$folderDialog.Dispose()
}
New-Item `
-ItemType Directory `
-Path $outputDirectory `
-Force |
Out-Null
$timestamp =
Get-Date -Format "yyyyMMdd-HHmmss"
$logDirectory =
Join-Path $outputDirectory "logs"
New-Item `
-ItemType Directory `
-Path $logDirectory `
-Force |
Out-Null
$logPath =
Join-Path `
$logDirectory `
("console-build-" + $timestamp + ".log")
$arguments =
[System.Collections.Generic.List[string]]::new()
[void]$arguments.Add(
"-NoProfile"
)
[void]$arguments.Add(
"-ExecutionPolicy"
)
[void]$arguments.Add(
"Bypass"
)
[void]$arguments.Add(
"-NoExit"
)
[void]$arguments.Add(
"-Command"
)
$commandParts =
[System.Collections.Generic.List[string]]::new()
[void]$commandParts.Add(
"& '" +
$builderPath.Replace("'", "''") +
"'"
)
foreach ($inputFile in $inputFiles) {
[void]$commandParts.Add(
"-InputFile '" +
$inputFile.Replace("'", "''") +
"'"
)
}
[void]$commandParts.Add(
"-OutputDirectory '" +
$outputDirectory.Replace("'", "''") +
"'"
)
[void]$commandParts.Add(
"-ChunkSize 250000"
)
[void]$commandParts.Add(
"-KeepUnderscores"
)
$buildCommand =
$commandParts -join " "
$wrappedCommand =
"& { " +
$buildCommand +
" } *>&1 | Tee-Object -FilePath '" +
$logPath.Replace("'", "''") +
"'; " +
"Write-Host ''; " +
"Write-Host 'LeanSERP build process finished.' " +
"-ForegroundColor Cyan; " +
"Write-Host 'Log: " +
$logPath.Replace("'", "''") +
"'"
[void]$arguments.Add(
$wrappedCommand
)
$quotedArguments = @(
$arguments |
ForEach-Object {
'"' +
$_.Replace('"', '\"') +
'"'
}
)
$argumentString =
$quotedArguments -join " "
$startInfo =
[System.Diagnostics.ProcessStartInfo]::new()
$startInfo.FileName =
"powershell.exe"
$startInfo.Arguments =
$argumentString
$startInfo.UseShellExecute =
$true
$startInfo.WorkingDirectory =
$studioDirectory
$process =
[System.Diagnostics.Process]::Start(
$startInfo
)
if ($null -eq $process) {
throw "Could not open the build console."
}
Write-Host "LeanSERP build console opened." -ForegroundColor Green
Write-Host "Process ID: $($process.Id)"
Write-Host "Log: $logPath"