-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPsiPS.AzureAutomation.build.ps1
88 lines (68 loc) · 2.76 KB
/
PsiPS.AzureAutomation.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
Task . Clean, Build, Import;
Task Build Compile, CreateManifest;
Task CreateManifest CopyPSD, UpdatePublicFunctionsToExport;
Task Stats RemoveStats, WriteStats;
$script:ModuleRoot = "$PSScriptRoot\src";
$script:ModuleName = $MyInvocation.MyCommand.Name.Replace('.build.ps1', '');
$script:ModulePSDPath = "$script:ModuleRoot\$($script:ModuleName).psd1";
$script:PublicFolder = "$script:ModuleRoot\public";
$script:ImportFolders = @(
"$script:ModuleRoot\startup",
"$script:ModuleRoot\private",
$script:PublicFolder
);
$script:OutputFolderName = 'release';
$script:OutPutFolder = "$PSScriptRoot\$script:OutputFolderName";
$script:OutPutModuleFolder = "$($script:OutPutFolder)\$($script:ModuleName)";
$script:OutputPSMPath = "$($script:OutPutModuleFolder)\$($script:ModuleName).psm1";
$script:OutputPSDPath = "$($script:OutPutModuleFolder)\$($script:ModuleName).psd1";
Task Clean `
{
if (-not (Test-Path $script:OutPutFolder))
{
New-Item -ItemType Directory -Path $script:OutPutFolder | Out-Null;
}
Remove-Item -Path "$($script:OutPutFolder)\*" -Recurse -Force | Out-Null;
}
Task CopyPSD -if (Test-Path -Path $script:ModulePSDPath) `
{
Copy-Item $script:ModulePSDPath -Destination $script:OutputPSDPath -Force;
}
Task Compile `
{
if (Test-Path -Path $script:OutputPSMPath)
{
Remove-Item -Path $script:OutputPSMPath -Force;
}
New-Item -Path $script:OutputPSMPath -ItemType File -Force | Out-Null;
foreach ($importFolder in $script:ImportFolders)
{
Write-Verbose -Message "Checking folder '$importFolder'";
if (Test-Path -Path $importFolder)
{
$files = Get-ChildItem -Path $importFolder -Filter '*.ps1' -Recurse;
foreach ($file in $files)
{
Write-Verbose -Message "Adding $($file.FullName)";
Get-Content -Path $file.FullName | Out-File $script:OutputPSMPath -Append -Confirm:$false -Force;
}
}
}
}
Task UpdatePublicFunctionsToExport -if (Test-Path -Path $script:PublicFolder) `
{
$publicFunctions = Get-ChildItem -Path $script:PublicFolder -Filter *.ps1 -Recurse;
$Tab = ' ' * 4;
if ($publicFunctions.count -gt 0)
{
$publicFunctionsString = ($publicFunctions | Select-Object -ExpandProperty BaseName) -join "',`n${Tab}${Tab}'";
$publicFunctionsString = "FunctionsToExport = @(`n${Tab}${Tab}'{0}'`n${Tab})" -f $publicFunctionsString;
(Get-Content -Path $script:OutputPSDPath) -replace "FunctionsToExport = '\*'", $publicFunctionsString `
| Set-Content -Path $script:OutputPSDPath;
}
}
Task Import -if (Test-Path -Path $script:OutputPSMPath) `
{
Get-Module -Name $script:ModuleName | Remove-Module -Force;
Import-Module -Name $script:OutputPSDPath -Force;
}