-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuild.ps1
118 lines (101 loc) · 2.51 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
param(
[Parameter(Position = 0, Mandatory = $false, ValueFromRemainingArguments = $true)]
[string[]]$ScriptArgs = @("--build", "--tests")
)
$ErrorActionPreference = 'Stop'
function UpdateAppveyorBuildVersion {
$pkgJson = Get-Content -Raw -Encoding utf8 -LiteralPath "package.json" | ConvertFrom-Json
$buildVersion = $env:APPVEYOR_BUILD_NUMBER
$commitSha = $env:APPVEYOR_REPO_COMMIT
$newVersion = "$($pkgJson.version)+build.$buildVersion.sha.$commitSha"
try {
Update-AppveyorBuild -Version $newVersion
}
catch {
Write-Warning "Unable to update build version, ignoring..."
}
}
function runSetup() {
"Compiling gulp build file..."
yarn setup
if ($LASTEXITCODE -ne 0) {
exit($LASTEXITCODE)
}
}
function runInstall() {
"Installing generator dependencies..."
yarn install --frozen-lockfile
if ($LASTEXITCODE -ne 0) {
exit($LASTEXITCODE)
}
}
function runBuild() {
"Building generator..."
yarn build
if ($LASTEXITCODE -ne 0) {
exit($LASTEXITCODE)
}
}
function runTest() {
"Running unit tests..."
$arguments = @(
"test"
"--reporters=default"
if ($env:CI -ieq "true") { "--reporters=jest-junit"; "--coverage"; "--ci" }
)
yarn @arguments
if ($LASTEXITCODE -ne 0) {
exit($LASTEXITCODE)
}
}
function runPack() {
"Creating npm package..."
Remove-Item "*.tgz"
yarn pack
if ($LASTEXITCODE -ne 0) {
exit($LASTEXITCODE)
}
}
function installGenerator() {
"Installing cake addin generator..."
npm install --global "$(Get-Item "*.tgz" | Select-Object -ExpandProperty FullName)"
if ($LASTEXITCODE -ne 0) {
exit($LASTEXITCODE)
}
}
function uninstallGenerator() {
"Uninstalling cake addin generator..."
npm uninstall --global generator-cake-addin
if ($LASTEXITCODE -ne 0) {
exit($LASTEXITCODE)
}
}
$BUILD = $false
$TEST = $false
$INSTALL = $false
$UNINSTALL = $false
foreach ($arg in $ScriptArgs) {
switch ($arg) {
"--build" { $BUILD = $true }
{ $_ -in "--test", "--tests" } { $TEST = $true }
"--install" {
if (!(Test-Path "*.tgz")) { $BUILD = $true }
$INSTALL = $true
}
"--uninstall" { $UNINSTALL = $true }
}
}
if ($BUILD) {
if (Test-Path Env:\APPVEYOR) { UpdateAppveyorBuildVersion }
runInstall
runSetup
runBuild
runPack
}
if ($TEST) {
runTest
}
if ($INSTALL) {
installGenerator
}
if ($UNINSTALL) { uninstallGenerator }