forked from Badgerati/Pode.Web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.build.ps1
361 lines (292 loc) · 13.8 KB
/
.build.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
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
param (
[string]
$Version = ''
)
$dest_path = './src/Templates/Public'
$src_path = './pode_modules'
<#
# Dependency Versions
#>
$Versions = @{
MkDocs = '1.5.3'
MkDocsTheme = '9.4.6'
PlatyPS = '0.14.2'
}
<#
# Helper Functions
#>
function Test-PodeBuildIsWindows {
$v = $PSVersionTable
return ($v.Platform -ilike '*win*' -or ($null -eq $v.Platform -and $v.PSEdition -ieq 'desktop'))
}
function Test-PodeBuildCommand($cmd) {
$path = $null
if (Test-PodeBuildIsWindows) {
$path = (Get-Command $cmd -ErrorAction Ignore)
}
else {
$path = (which $cmd)
}
return (![string]::IsNullOrWhiteSpace($path))
}
function Invoke-PodeBuildInstall($name, $version) {
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
if (Test-PodeBuildIsWindows) {
if (Test-PodeBuildCommand 'choco') {
choco install $name --version $version -y
}
}
else {
if (Test-PodeBuildCommand 'brew') {
brew install $name
}
elseif (Test-PodeBuildCommand 'apt-get') {
sudo apt-get install $name -y
}
elseif (Test-PodeBuildCommand 'yum') {
sudo yum install $name -y
}
}
}
function Install-PodeBuildModule($name) {
if ($null -ne ((Get-Module -ListAvailable $name) | Where-Object { $_.Version -ieq $Versions[$name] })) {
return
}
Write-Host "Installing $($name) v$($Versions[$name])"
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Install-Module -Name "$($name)" -Scope CurrentUser -RequiredVersion "$($Versions[$name])" -Force -SkipPublisherCheck
}
<#
# Dependencies
#>
# Synopsis: Installs Chocolatey
task ChocoDeps -If (Test-PodeBuildIsWindows) {
if (!(Test-PodeBuildCommand 'choco')) {
Set-ExecutionPolicy Bypass -Scope Process -Force
Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
}
}
# Synopsis: Install dependencies for documentation
task DocsDeps ChocoDeps, {
# install mkdocs
if (!(Test-PodeBuildCommand 'mkdocs')) {
Invoke-PodeBuildInstall 'mkdocs' $Versions.MkDocs
}
$_installed = (pip list --format json --disable-pip-version-check | ConvertFrom-Json)
if (($_installed | Where-Object { $_.name -ieq 'mkdocs-material' -and $_.version -ieq $Versions.MkDocsTheme } | Measure-Object).Count -eq 0) {
pip install "mkdocs-material==$($Versions.MkDocsTheme)" --force-reinstall --disable-pip-version-check
}
# install platyps
Install-PodeBuildModule PlatyPS
}
<#
# Building
#>
# Synopsis: Install the frontend libraries
task Build {
yarn install --force --ignore-scripts --modules-folder pode_modules
}, MoveLibs
# Synopsis: Move the libraries to the public directory
task MoveLibs {
$libs_path = "$($dest_path)/libs"
if (Test-Path $libs_path) {
Remove-Item -Path $libs_path -Recurse -Force | Out-Null
}
New-Item -Path $libs_path -ItemType Directory -Force | Out-Null
# jquery
New-Item -Path "$($libs_path)/jquery" -ItemType Directory -Force | Out-Null
Copy-Item -Path "$($src_path)/jquery/dist/jquery.min.js" -Destination "$($libs_path)/jquery/" -Force
# jquery-ui
New-Item -Path "$($libs_path)/jquery-ui" -ItemType Directory -Force | Out-Null
Copy-Item -Path "$($src_path)/jquery-ui-dist/jquery-ui.min.js" -Destination "$($libs_path)/jquery-ui/" -Force
Copy-Item -Path "$($src_path)/jquery-ui-dist/jquery-ui.min.css" -Destination "$($libs_path)/jquery-ui/" -Force
# popper.js
New-Item -Path "$($libs_path)/popperjs" -ItemType Directory -Force | Out-Null
Copy-Item -Path "$($src_path)/popper.js/dist/umd/popper.min.js" -Destination "$($libs_path)/popperjs/" -Force
Copy-Item -Path "$($src_path)/popper.js/dist/umd/popper.min.js.map" -Destination "$($libs_path)/popperjs/" -Force
# bootstrap
New-Item -Path "$($libs_path)/bootstrap" -ItemType Directory -Force | Out-Null
Copy-Item -Path "$($src_path)/bootstrap/dist/js/bootstrap.bundle.min.js*" -Destination "$($libs_path)/bootstrap/" -Force
Copy-Item -Path "$($src_path)/bootstrap/dist/css/bootstrap.min.css*" -Destination "$($libs_path)/bootstrap/" -Force
# bs-stepper
New-Item -Path "$($libs_path)/bs-stepper" -ItemType Directory -Force | Out-Null
Copy-Item -Path "$($src_path)/bs-stepper/dist/js/bs-stepper.min.js*" -Destination "$($libs_path)/bs-stepper/" -Force
Copy-Item -Path "$($src_path)/bs-stepper/dist/css/bs-stepper.min.css*" -Destination "$($libs_path)/bs-stepper/" -Force
# moment
New-Item -Path "$($libs_path)/moment" -ItemType Directory -Force | Out-Null
Copy-Item -Path "$($src_path)/moment/min/moment.min.js*" -Destination "$($libs_path)/moment/" -Force
# chart.js
New-Item -Path "$($libs_path)/chartjs" -ItemType Directory -Force | Out-Null
Copy-Item -Path "$($src_path)/chart.js/dist/chart.umd.js*" -Destination "$($libs_path)/chartjs/" -Force
# mdi fonts - icons
New-Item -Path "$($libs_path)/mdi-font/css" -ItemType Directory -Force | Out-Null
Copy-Item -Path "$($src_path)/@mdi/font/css/materialdesignicons.min.css*" -Destination "$($libs_path)/mdi-font/css/" -Force
Copy-Item -Path "$($src_path)/@mdi/font/css/materialdesignicons.css.map" -Destination "$($libs_path)/mdi-font/css/" -Force
New-Item -Path "$($libs_path)/mdi-font/fonts" -ItemType Directory -Force | Out-Null
Copy-Item -Path "$($src_path)/@mdi/font/fonts/materialdesignicons-webfont*" -Destination "$($libs_path)/mdi-font/fonts/" -Force
# highlight.js
New-Item -Path "$($libs_path)/highlightjs" -ItemType Directory -Force | Out-Null
Copy-Item -Path "$($src_path)/@highlightjs/cdn-assets/highlight.min.js" -Destination "$($libs_path)/highlightjs/" -Force
New-Item -Path "$($libs_path)/highlightjs/languages" -ItemType Directory -Force | Out-Null
$langs = @(
'bash',
'c',
'cpp',
'csharp',
'css',
'dockerfile',
'fsharp',
'go',
'http',
'java',
'javascript',
'json',
'markdown'
'php',
'powershell',
'puppet',
'python',
'ruby',
'sql',
'typescript',
'xml',
'yaml'
)
$langs | ForEach-Object {
Copy-Item -Path "$($src_path)/@highlightjs/cdn-assets/languages/$($_).min.js" -Destination "$($libs_path)/highlightjs/languages/" -Force
}
New-Item -Path "$($libs_path)/highlightjs/styles" -ItemType Directory -Force | Out-Null
Copy-Item -Path "$($src_path)/@highlightjs/cdn-assets/styles/tomorrow-night-blue.min.css" -Destination "$($libs_path)/highlightjs/styles/" -Force
Copy-Item -Path "$($src_path)/@highlightjs/cdn-assets/styles/default.min.css" -Destination "$($libs_path)/highlightjs/styles/" -Force
# monaco
New-Item -Path "$($libs_path)/monaco" -ItemType Directory -Force | Out-Null
New-Item -Path "$($libs_path)/vs" -ItemType Directory -Force | Out-Null
New-Item -Path "$($libs_path)/monaco/editor" -ItemType Directory -Force | Out-Null
New-Item -Path "$($libs_path)/monaco/basic-languages" -ItemType Directory -Force | Out-Null
Copy-Item -Path "$($src_path)/monaco-editor/min/vs/loader.js" -Destination "$($libs_path)/monaco/" -Force
Copy-Item -Path "$($src_path)/monaco-editor/min/vs/editor/*.*" -Destination "$($libs_path)/monaco/editor/" -Force
New-Item -Path "$($libs_path)/monaco/base/worker" -ItemType Directory -Force | Out-Null
Copy-Item -Path "$($src_path)/monaco-editor/min/vs/base/worker/*.*" -Destination "$($libs_path)/monaco/base/worker/" -Force
New-Item -Path "$($libs_path)/monaco/base/browser/ui/codicons/codicon" -ItemType Directory -Force | Out-Null
Copy-Item -Path "$($src_path)/monaco-editor/min/vs/base/browser/ui/codicons/codicon/*.*" -Destination "$($libs_path)/monaco/base/browser/ui/codicons/codicon/" -Force
$langs = @(
'bat',
'cpp',
'csharp',
'css',
'dockerfile',
'fsharp',
'go',
'html',
'java',
'javascript',
'markdown',
'mysql',
'php',
'powershell',
'python',
'ruby',
'sql',
'typescript',
'xml',
'yaml'
)
(Get-ChildItem -Path "$($src_path)/monaco-editor/min/vs/basic-languages" -Directory).Name | ForEach-Object {
if ($_ -iin $langs) {
New-Item -Path "$($libs_path)/monaco/basic-languages/$($_)/" -ItemType Directory -Force | Out-Null
Copy-Item -Path "$($src_path)/monaco-editor/min/vs/basic-languages/$($_)/*.*" -Destination "$($libs_path)/monaco/basic-languages/$($_)/" -Force
}
}
New-Item -Path "$($libs_path)/monaco/language" -ItemType Directory -Force | Out-Null
New-Item -Path "$($libs_path)/vs/language" -ItemType Directory -Force | Out-Null
(Get-ChildItem -Path "$($src_path)/monaco-editor/min/vs/language" -Directory).Name | ForEach-Object {
New-Item -Path "$($libs_path)/monaco/language/$($_)/" -ItemType Directory -Force | Out-Null
Copy-Item -Path "$($src_path)/monaco-editor/min/vs/language/$($_)/*.*" -Destination "$($libs_path)/monaco/language/$($_)/" -Force
New-Item -Path "$($libs_path)/vs/language/$($_)/" -ItemType Directory -Force | Out-Null
Copy-Item -Path "$($src_path)/monaco-editor/min/vs/language/$($_)/*.*" -Destination "$($libs_path)/vs/language/$($_)/" -Force
}
New-Item -Path "$($libs_path)/vs/base/common/worker" -ItemType Directory -Force | Out-Null
Copy-Item -Path "$($src_path)/monaco-editor/min/vs/base/common/worker/simpleWorker.nls.js" -Destination "$($libs_path)/vs/base/common/worker/" -Force
$vs_maps_path = "$($dest_path)/min-maps/vs"
if (Test-Path $vs_maps_path) {
Remove-Item -Path $vs_maps_path -Recurse -Force | Out-Null
}
New-Item -Path "$($vs_maps_path)/editor" -ItemType Directory -Force | Out-Null
New-Item -Path "$($vs_maps_path)/base/worker" -ItemType Directory -Force | Out-Null
New-Item -Path "$($vs_maps_path)/base/common/worker" -ItemType Directory -Force | Out-Null
Copy-Item -Path "$($src_path)/monaco-editor/min-maps/vs/loader.js.map" -Destination $vs_maps_path -Force
Copy-Item -Path "$($src_path)/monaco-editor/min-maps/vs/editor/*.*" -Destination "$($vs_maps_path)/editor/" -Force
Copy-Item -Path "$($src_path)/monaco-editor/min-maps/vs/base/worker/*.*" -Destination "$($vs_maps_path)/base/worker/" -Force
Copy-Item -Path "$($src_path)/monaco-editor/min-maps/vs/base/common/worker/simpleWorker.nls.js*" -Destination "$($vs_maps_path)/base/common/worker/" -Force
}
<#
# Pack
#>
# Synopsis: Package up the Module
task Pack -If (Test-PodeBuildIsWindows) Build, {
if (!$Version) {
$Version = (Import-PowerShellDataFile -Path './src/Pode.Web.psd1').ModuleVersion
}
}, DockerPack
# Synopsis: Create docker tags
task DockerPack {
docker build -t badgerati/pode.web:$Version -f ./Dockerfile .
docker build -t badgerati/pode.web:latest -f ./Dockerfile .
docker build -t badgerati/pode.web:$Version-alpine -f ./alpine.dockerfile .
docker build -t badgerati/pode.web:latest-alpine -f ./alpine.dockerfile .
docker build -t badgerati/pode.web:$Version-arm32 -f ./arm32.dockerfile .
docker build -t badgerati/pode.web:latest-arm32 -f ./arm32.dockerfile .
docker tag badgerati/pode.web:latest docker.pkg.github.com/badgerati/pode.web/pode.web:latest
docker tag badgerati/pode.web:$Version docker.pkg.github.com/badgerati/pode.web/pode.web:$Version
docker tag badgerati/pode.web:latest-alpine docker.pkg.github.com/badgerati/pode.web/pode.web:latest-alpine
docker tag badgerati/pode.web:$Version-alpine docker.pkg.github.com/badgerati/pode.web/pode.web:$Version-alpine
docker tag badgerati/pode.web:latest-arm32 docker.pkg.github.com/badgerati/pode.web/pode.web:latest-arm32
docker tag badgerati/pode.web:$Version-arm32 docker.pkg.github.com/badgerati/pode.web/pode.web:$Version-arm32
}
<#
# Docs
#>
# Synopsis: Run the documentation locally
task Docs DocsDeps, DocsHelpBuild, {
Write-Host 'Documentation available at 127:0.0.1:8000...' -ForegroundColor Yellow
mkdocs serve --quiet
}
# Synopsis: Build the function help documentation
task DocsHelpBuild DocsDeps, {
# import the local module
Remove-Module Pode.Web -Force -ErrorAction Ignore | Out-Null
Import-Module ./src/Pode.Web.psm1 -Force | Out-Null
# build the function docs
$path = './docs/Functions'
$map = @{}
(Get-Module Pode.Web).ExportedFunctions.Keys | ForEach-Object {
$type = [System.IO.Path]::GetFileNameWithoutExtension((Split-Path -Leaf -Path (Get-Command $_ -Module Pode.Web).ScriptBlock.File))
New-MarkdownHelp -Command $_ -OutputFolder (Join-Path $path $type) -Force -Metadata @{ PodeType = $type } -AlphabeticParamsOrder | Out-Null
$map[$_] = $type
}
# update docs to bind links to unlinked functions
$path = Join-Path $pwd 'docs'
Get-ChildItem -Path $path -Recurse -Filter '*.md' | ForEach-Object {
$depth = ($_.FullName.Replace($path, [string]::Empty).trim('\/') -split '[\\/]').Length
$updated = $false
$content = (Get-Content -Path $_.FullName | ForEach-Object {
$line = $_
while ($line -imatch '\[`(?<name>[a-z]+\-podeweb[a-z]+)`\](?<char>([^(]|$))') {
$updated = $true
$name = $Matches['name']
$char = $Matches['char']
$line = ($line -ireplace "\[``$($name)``\]([^(]|$)", "[``$($name)``]($('../' * $depth)Functions/$($map[$name])/$($name))$($char)")
}
$line
})
if ($updated) {
$content | Out-File -FilePath $_.FullName -Force -Encoding ascii
}
}
# remove the module
Remove-Module Pode.Web -Force -ErrorAction Ignore | Out-Null
}
# Synopsis: Build the documentation
task DocsBuild DocsDeps, DocsHelpBuild, {
mkdocs build --quiet
}