-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpsakefile.ps1
108 lines (90 loc) · 3.61 KB
/
psakefile.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
Task Publish -Depends Pack {
Exec { docker login docker.io --username=ashotnazaryan45 }
foreach ($VersionTag in $VersionTags) {
$localTag = ($script:imageName + ":" + $VersionTag)
$remoteTag = ("docker.io/" + $localTag)
Exec { docker tag $localTag $remoteTag }
Exec { docker push $remoteTag }
try {
Exec { keybase chat send --nonblock --private lionize "BUILD: Published $remoteTag" }
}
catch {
Write-Warning "Failed to send notification"
}
}
}
Task Pack -Depends CopyArtefacts, EstimateVersions {
$tagsArguments = @()
foreach ($VersionTag in $VersionTags) {
$tagsArguments += "-t"
$tagsArguments += ($script:imageName + ":" + $VersionTag)
}
Exec { docker build -f Dockerfile $script:artefacts $tagsArguments }
}
Task EstimateVersions {
$script:VersionTags = @()
if ($Latest) {
$script:VersionTags += 'latest'
}
if (!!($Version)) {
$Version = [Version]$Version
Assert ($Version.Revision -eq -1) "Version should be formatted as Major.Minor.Patch like 1.2.3"
Assert ($Version.Build -ne -1) "Version should be formatted as Major.Minor.Patch like 1.2.3"
$Version = $Version.ToString()
$script:VersionTags += $Version
}
Assert $script:VersionTags "No version parameter (latest or specific version) is passed."
}
Task CopyArtefacts -Depends Build {
$script:artefacts = Join-Path -Path $script:trashFolder -ChildPath "artefacts"
Copy-Item -Path (Join-Path -Path $script:SourceRootFolder -ChildPath ".\dist\lionize") -Destination (Join-Path -Path $script:artefacts -ChildPath "build") -Recurse
Copy-Item -Path (Join-Path -Path $script:SourceRootFolder -ChildPath "nginx.conf") -Destination (Join-Path -Path $script:artefacts -ChildPath "nginx.conf")
}
Task Build -Depends NpmInstall {
try {
Push-Location
Set-Location $script:SourceRootFolder
Exec { npm run "build:prod" }
}
finally {
Pop-Location
}
}
Task NpmInstall -Depends Init, Clean, TranspileModels {
try {
Push-Location
Set-Location $script:SourceRootFolder
Exec { npm install }
}
finally {
Pop-Location
}
}
Task TranspileModels -Depends Clean {
$models = @(
@{InputFile = "./ui/apis/habitica/ApiModels.yml"; OutputFolder = "./ui/src/app/shared/models/habitica" },
@{InputFile = "./ui/apis/identity/ApiModels.yml"; OutputFolder = "./ui/src/app/shared/models/identity" },
@{InputFile = "./ui/apis/tasks/ApiModels.yml"; OutputFolder = "./ui/src/app/shared/models/tasks" },
@{InputFile = "./ui/apis/tasks/RealtimeModels.yml"; OutputFolder = "./ui/src/app/shared/models/tasks/realtime" }
)
foreach ($model in $models) {
$inputFile = Resolve-Path $model.InputFile
if (-not (Test-Path -Path $model.OutputFolder)) {
New-Item -Path $model.OutputFolder -ItemType Directory | Out-Null
}
$outputFolder = Resolve-Path -Path $model.OutputFolder
Exec { smite --input-file $inputFile --lang typescript --output-folder $outputFolder }
}
}
Task Clean -Depends Init {
}
Task Init {
$date = Get-Date
$ticks = $date.Ticks
$script:imageName = "ashotnazaryan45/lionize-web-ui"
$script:trashFolder = Join-Path -Path . -ChildPath ".trash"
$script:trashFolder = Join-Path -Path $script:trashFolder -ChildPath $ticks.ToString("D19")
New-Item -Path $script:trashFolder -ItemType Directory
$script:trashFolder = Resolve-Path -Path $script:trashFolder
$script:SourceRootFolder = (Resolve-Path ".\ui\").Path
}