-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.ps1
69 lines (64 loc) · 2.32 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
using namespace System
using namespace System.IO
using namespace System.Management.Automation
<#
.SYNOPSIS
PsImport buildScript v0.1.4
.DESCRIPTION
A custom Psake buildScript for the module PsImport.
.LINK
https://github.com/alainQtec/PsImport/blob/main/build.ps1
.EXAMPLE
Running ./build.ps1 will only "Init, Compile & Import" the module; That's it, no tests.
To run tests Use:
./build.ps1 -Task Test
This Will build the module, Import it and run tests using the ./Test-Module.ps1 script.
.EXAMPLE
./build.ps1 -Task deploy
Will build the module, test it and deploy it to PsGallery (only if $psake.build_success)
#>
[cmdletbinding(DefaultParameterSetName = 'task')]
param(
[parameter(Mandatory = $false, Position = 0, ParameterSetName = 'task')]
[ValidateScript({
$task_seq = [string[]]$_; $IsValid = $true
$Tasks = @('Clean', 'Compile', 'Test', 'Deploy')
foreach ($name in $task_seq) {
$IsValid = $IsValid -and ($name -in $Tasks)
}
if ($IsValid) {
return $true
} else {
throw [System.ArgumentException]::new('Task', "ValidSet: $($Tasks -join ', ').")
}
}
)][ValidateNotNullOrEmpty()][Alias('t')]
[string[]]$Task = 'Test',
# Module buildRoot
[Parameter(Mandatory = $false, Position = 1, ParameterSetName = 'task')]
[ValidateScript({
if (Test-Path -Path $_ -PathType Container -ea Ignore) {
return $true
} else {
throw [System.ArgumentException]::new('Path', "Path: $_ is not a valid directory.")
}
})][Alias('p')]
[string]$Path = (Resolve-Path .).Path,
[Parameter(Mandatory = $false, ParameterSetName = 'task')]
[string[]]$RequiredModules = @(),
[parameter(ParameterSetName = 'task')]
[Alias('i')]
[switch]$Import,
[parameter(ParameterSetName = 'help')]
[Alias('h', '-help')]
[switch]$Help
)
begin {
if ($PSCmdlet.ParameterSetName -eq 'help') { Get-Help $MyInvocation.MyCommand.Source -Full | Out-String | Write-Host -f Green; return }
$req = Invoke-WebRequest -Method Get -Uri https://raw.githubusercontent.com/alainQtec/PsCraft/refs/heads/main/Public/Build-Module.ps1 -SkipHttpErrorCheck
if ($req.StatusCode -ne 200) { throw "Failed to download Build-Module.ps1" }
. ([ScriptBlock]::Create("$($req.Content)"))
}
process {
Build-Module -Task $Task -Path $Path -Import:$Import
}