Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Finally make the build.psd1 file optional per #44
  • Loading branch information
Jaykul committed Jan 11, 2020
commit 7d519fa54d7f70a79cf3a7e9636bf1c964961a28
33 changes: 18 additions & 15 deletions Source/Private/GetBuildInfo.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,7 @@ function GetBuildInfo {
[CmdletBinding()]
param(
# The path to the Build Manifest Build.psd1
[Parameter(Mandatory)]
[ValidateScript( {
if ((Test-Path $_) -and (Split-path -Leaf $_) -eq 'build.psd1') {
$true
}
else {
throw "The Module Manifest must point to a valid build.psd1 Data file"
}
})]
[Parameter()][AllowNull()]
[string]$BuildManifest,

# Pass MyInvocation from the Build-Command so we can read parameter values
Expand All @@ -19,9 +11,23 @@ function GetBuildInfo {
$BuildCommandInvocation
)

# Read the Module Manifest configuration file for default parameter values
Write-Debug "Load Build Manifest $BuildManifest"
$BuildInfo = Import-Metadata -Path $BuildManifest
$BuildInfo = if ($BuildManifest -and (Test-Path $BuildManifest)) {
if ((Split-path -Leaf $BuildManifest) -eq 'build.psd1') {
$BuildManifestParent = if ($BuildManifest) {
Split-Path -Parent $BuildManifest
} else {
Get-Location -PSProvider FileSystem
}
# Read the Module Manifest configuration file for default parameter values
Write-Debug "Load Build Manifest $BuildManifest"
Import-Metadata -Path $BuildManifest
} else {
@{ SourcePath = $BuildManifest }
}
} else {
@{}
}

$CommonParameters = [System.Management.Automation.Cmdlet]::CommonParameters +
[System.Management.Automation.Cmdlet]::OptionalCommonParameters
$BuildParameters = $BuildCommandInvocation.MyCommand.Parameters
Expand Down Expand Up @@ -71,9 +77,6 @@ function GetBuildInfo {

$BuildInfo = $BuildInfo | Update-Object $ParameterValues

# Resolve Build Manifest's parent folder to find the Absolute path
$BuildManifestParent = (Split-Path -Parent $BuildManifest)

# Resolve Module manifest if not defined in Build.psd1
if (-Not $BuildInfo.SourcePath -and $BuildManifestParent) {
# Resolve Build Manifest's parent folder to find the Absolute path
Expand Down
6 changes: 2 additions & 4 deletions Source/Private/ResolveBuildManifest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function ResolveBuildManifest {
if ((Split-Path $SourcePath -Leaf) -eq 'build.psd1') {
$BuildManifest = $SourcePath
} elseif (Test-Path $SourcePath -PathType Leaf) {
# When you pass the ModuleManifest as parameter, you must have the Build Manifest in the same folder
# When you pass the SourcePath as parameter, you must have the Build Manifest in the same folder
$BuildManifest = Join-Path (Split-Path -Parent $SourcePath) [Bb]uild.psd1
} else {
# It's a container, assume the Build Manifest is directly under
Expand All @@ -19,9 +19,7 @@ function ResolveBuildManifest {
# Make sure we are resolving the absolute path to the manifest, and test it exists
$ResolvedBuildManifest = (Resolve-Path $BuildManifest -ErrorAction SilentlyContinue).Path

if (-Not ($ResolvedBuildManifest)) {
throw "Couldn't resolve the Build Manifest at $BuildManifest"
} else {
if ($ResolvedBuildManifest) {
$ResolvedBuildManifest
}

Expand Down
33 changes: 33 additions & 0 deletions Tests/Integration/Source1.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,39 @@ Describe "Build-Module With Source1" {
It "Should update AliasesToExport in the manifest" {
$Metadata.AliasesToExport | Should -Be @("GS","GSou", "SS", "SSou")
}
}

Context "Supports building without a build.psd1" {
Copy-Item $PSScriptRoot\Source1 $PSScriptRoot\Copy1 -Recurse
Remove-Item $PSScriptRoot\Copy1\build.psd1
Rename-Item $PSScriptRoot\Copy1\Source1.psd1 Copy1.psd1

$Build = @{ }

It "No longer fails if there's no build.psd1" {
$BuildParameters = @{
SourcePath = "$PSScriptRoot\Copy1\Copy1.psd1"
OutputDirectory = "..\Result1"
VersionedOutputDirectory = $true
}

$Build.Output = Build-Module @BuildParameters -Passthru
}

Remove-Item -Recurse $PSScriptRoot\Copy1


It "Creates the same module as with a build.psd1" {
$Build.Metadata = Import-Metadata $Build.Output.Path
}

It "Should update AliasesToExport in the manifest" {
$Build.Metadata.AliasesToExport | Should -Be @("GS", "GSou", "SS", "SSou")
}

It "Should update FunctionsToExport in the manifest" {
$Build.Metadata.FunctionsToExport | Should -Be @("Get-Source", "Set-Source")
}

}
}