-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-example.ps1
More file actions
131 lines (108 loc) · 4.14 KB
/
Copy pathtest-example.ps1
File metadata and controls
131 lines (108 loc) · 4.14 KB
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
# For local testing, you can pass buildVersion.
# Example usage:
# ./test-example.ps1 -buildVersion 25.2.7
param (
[string]$buildVersion = $Env:CodeCentralBuildVersion
)
# Masstest-specific parameter. Specifies the minor version (example: '25.2.7')
$global:BUILD_VERSION = $buildVersion
$global:ERROR_CODE = 0
$global:FAILED_PROJECTS = @()
function Test-NpmVersionExists {
param ([string]$Pkg, [string]$Ver)
npm view "$Pkg@$Ver" > $null 2>&1
return ($LASTEXITCODE -eq 0)
}
function Get-ValidNpmVersion {
param (
[string]$PackageName,
[string]$Version
)
Write-Host "Checking $PackageName@$Version..."
if (Test-NpmVersionExists -Pkg $PackageName -Ver $Version) {
Write-Host "$PackageName@$Version exists."
return $Version
}
try {
$v = [version]$Version
$fallback = "$($v.Major).$($v.Minor)-stable"
} catch {
Write-Host "Invalid version format: $Version"
return $null
}
Write-Host "$PackageName@$Version not found. Trying fallback: $PackageName@$fallback..."
if (Test-NpmVersionExists -Pkg $PackageName -Ver $fallback) {
Write-Host "$PackageName@$fallback exists (fallback)."
return $fallback
}
Write-Host "Neither $PackageName@$Version nor @$fallback exist."
return $null
}
function Install-Packages {
param (
[string]$folderName,
[string[]]$packages,
[string]$buildVersion
)
Write-Output "`nInstalling packages in folder: $folderName"
foreach ($package in $packages) {
$packageVersion = Get-ValidNpmVersion -PackageName $package -Version $buildVersion
$packageWithVersion = "$package@$packageVersion"
Write-Output "Installing $packageWithVersion..."
npm install --save --save-exact --no-fund --loglevel=error --force $packageWithVersion
if (-not $?) {
Write-Error "`nERROR: Failed to install $packageWithVersion in $folderName"
throw "Installation failed for $packageWithVersion in $folderName"
}
}
Write-Output "`nAll packages installed successfully in $folderName"
}
function Process-Project {
param (
[string]$buildVersion
)
Write-Output "`n--== Starting RequireJS Project Processing ==--"
$folderName = "requirejs-jquery"
$packages = @("devextreme")
Push-Location $folderName
try {
Write-Output "`nRemoving node_modules and generated AMD modules: $pwd"
Remove-Item -Recurse -Force node_modules -ErrorAction SilentlyContinue
Remove-Item -Force package-lock.json -ErrorAction SilentlyContinue
Remove-Item -Recurse -Force devextreme_amd -ErrorAction SilentlyContinue
Remove-Item -Recurse -Force '@devextreme' -ErrorAction SilentlyContinue
Install-Packages -folderName $folderName -packages $packages -buildVersion $buildVersion
Write-Output "`nInstalling remaining packages in $folderName (postinstall converts DevExtreme to AMD)"
npm install --no-fund --loglevel=error
if (-not $?) {
throw "ERROR: Failed to install packages in $folderName"
}
if (-not (Test-Path "devextreme_amd")) {
throw "ERROR: AMD conversion output 'devextreme_amd' was not generated in $folderName"
}
Write-Output "`nAMD conversion output found."
} catch {
Write-Error "`nAn error occurred: $_"
$global:LASTEXITCODE = 1
$global:ERROR_CODE = 1
$global:FAILED_PROJECTS += $folderName
} finally {
Pop-Location
}
Write-Output "`n--== RequireJS Project Processing Completed ==--"
}
function Write-BuildInfo {
$BUILD_VERSION = if ($global:BUILD_VERSION -ne $null -and $global:BUILD_VERSION -ne "") {
$global:BUILD_VERSION
} else {
"(empty)"
}
Write-Output "Build Version: $BUILD_VERSION"
}
Write-BuildInfo
Process-Project -buildVersion $global:BUILD_VERSION
Write-Output "`nFinished testing version: $global:BUILD_VERSION. Error code: $global:ERROR_CODE"
if ($global:ERROR_CODE -ne 0 -and $global:FAILED_PROJECTS.Count -gt 0) {
Write-Output "`FAILED PROJECTS: $(($global:FAILED_PROJECTS -join ", "))"
}
exit $global:ERROR_CODE