forked from adamdriscoll/selenium-powershell
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSelenium.build.ps1
144 lines (114 loc) · 4.97 KB
/
Selenium.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
task . Clean, Build, Tests, UpdateHelp, ExportHelp, Stats
task Tests ImportCompipledModule, Pester
task CreateManifest CopyPSD, UpdatPublicFunctionsToExport, CopyAdditionalFiles
task Build Compile, CreateManifest
task Stats WriteStats
$script:ModuleName = 'Selenium' # Split-Path -Path $PSScriptRoot -Leaf
$script:ModuleRoot = $PSScriptRoot
$script:OutPutFolder = "$PSScriptRoot\Output"
$script:ModuleOutPutFolder = "$PSScriptRoot\Output\$script:ModuleName"
$script:ImportFolders = @('Public', 'Internal', 'Classes')
$script:PsmPath = Join-Path -Path $PSScriptRoot -ChildPath "Output\$($script:ModuleName)\$($script:ModuleName).psm1"
$script:PsdPath = Join-Path -Path $PSScriptRoot -ChildPath "Output\$($script:ModuleName)\$($script:ModuleName).psd1"
$script:HelpPath = Join-Path -Path $PSScriptRoot -ChildPath "Output\$($script:ModuleName)\en-US"
$script:PublicFolder = 'Public'
$script:DSCResourceFolder = 'DSCResources'
task "Clean" {
if (-not(Test-Path $script:OutPutFolder)) {
New-Item -ItemType Directory -Path $script:OutPutFolder > $null
}
Remove-Item -Path "$($script:OutPutFolder)\*" -Force -Recurse
}
$compileParams = @{
Inputs = {
foreach ($folder in $script:ImportFolders) {
Get-ChildItem -Path $folder -Recurse -File -Filter '*.ps1'
}
}
Output = {
$script:PsmPath
}
}
task Compile @compileParams {
if (Test-Path -Path $script:PsmPath) {
Remove-Item -Path $script:PsmPath -Recurse -Force
}
New-Item -Path $script:PsmPath -Force > $null
$currentFolder = Join-Path -Path $script:ModuleRoot -ChildPath 'Internal'
Get-Content -Path "$CurrentFolder\init.ps1" >> $script:PsmPath
foreach ($folder in $script:ImportFolders) {
$currentFolder = Join-Path -Path $script:ModuleRoot -ChildPath $folder
Write-Verbose -Message "Checking folder [$currentFolder]"
if (Test-Path -Path $currentFolder) {
$files = Get-ChildItem -Path $currentFolder -File -Filter '*.ps1'
foreach ($file in $files) {
if ($file.Name -eq 'init.ps1' -and $folder -eq 'Internal') { continue }
Write-Verbose -Message "Adding $($file.FullName)"
Get-Content -Path $file.FullName >> $script:PsmPath
}
}
}
}
task CopyPSD {
New-Item -Path (Split-Path $script:PsdPath) -ItemType Directory -ErrorAction 0
$copy = @{
Path = "$($script:ModuleName).psd1"
Destination = $script:PsdPath
Force = $true
Verbose = $true
}
Copy-Item @copy
}
task CopyAdditionalFiles {
$CopyContainer = @{
Container = $true
Recurse = $true
}
$CopyFile = { Param($Name) Copy-Item -Path "$script:ModuleRoot\$Name" -Destination "$script:ModuleOutPutFolder\$Name" -Force -Verbose }
$CopyFolder = { Param($Name) Copy-Item -Path "$script:ModuleRoot\$Name" -Destination "$script:ModuleOutPutFolder" -Force -Verbose -Container -Recurse }
& $CopyFolder 'assemblies'
& $CopyFolder 'types'
& $CopyFolder 'formats'
& $CopyFolder 'Examples'
& $CopyFile 'SeleniumClasses.ps1'
& $CopyFile 'Selenium-Binary-Updater.ps1'
& $CopyFile 'ChangeLog.md'
& $CopyFile 'README.md'
& $CopyFile 'Selenium.tests.ps1'
}
task UpdatPublicFunctionsToExport -if (Test-Path -Path $script:PublicFolder) {
$publicFunctions = (Get-ChildItem -Path $script:PublicFolder |
Select-Object -ExpandProperty BaseName) -join "', '"
$publicFunctions = "FunctionsToExport = @('{0}')" -f $publicFunctions
(Get-Content -Path $script:PsdPath) -replace "FunctionsToExport\s*?= '\*'", $publicFunctions |
Set-Content -Path $script:PsdPath
}
task ImportCompipledModule -if (Test-Path -Path $script:PsmPath) {
Get-Module -Name $script:ModuleName |
Remove-Module -Force
Import-Module -Name $script:PsdPath -Force
}
task Pester {
$resultFile = "{0}\testResults{1}.xml" -f $script:OutPutFolder, (Get-date -Format 'yyyyMMdd_hhmmss')
$testFolder = Join-Path -Path $PSScriptRoot -ChildPath 'Tests\*'
Invoke-Pester -Path $testFolder -OutputFile $resultFile -OutputFormat NUnitxml
}
task WriteStats {
$folders = Get-ChildItem -Directory |
Where-Object { $PSItem.Name -ne 'Output' }
$stats = foreach ($folder in $folders) {
$files = Get-ChildItem "$($folder.FullName)\*" -File
if ($files) {
Get-Content -Path $files |
Measure-Object -Word -Line -Character |
Select-Object -Property @{N = "FolderName"; E = { $folder.Name } }, Words, Lines, Characters
}
}
$stats | ConvertTo-Json > "$script:OutPutFolder\stats.json"
}
task UpdateHelp -if (Test-Path -Path "$Script:ModuleRoot\Help") {
Update-MarkdownHelpModule -Path "$Script:ModuleRoot\Help" -ModulePagePath "$Script:ModuleRoot\Help\README.MD" -RefreshModulePage
}
task ExportHelp -if (Test-Path -Path "$script:ModuleRoot\Help") {
New-ExternalHelp -Path "$script:ModuleRoot\Help" -OutputPath $script:HelpPath
}