Create a merged psm1 file when published (#16) !deploy
* Added auto discovery fo files to monitor. * Fixed scriptanalyzer rule * Adjusted the parameter attributes * testing feature specifications * Added module building * Exceptions and spacing
This commit is contained in:
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
function Write-ScriptLine
|
function Write-ScriptLine
|
||||||
{
|
{
|
||||||
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingWriteHost", "")]
|
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingWriteHost", "")]
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
|
|
||||||
|
|
||||||
function Format-Chronometer
|
function Format-Chronometer
|
||||||
{
|
{
|
||||||
<#
|
<#
|
||||||
@@ -44,6 +42,8 @@ function Format-Chronometer
|
|||||||
)
|
)
|
||||||
|
|
||||||
process
|
process
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
foreach ( $script in $InputObject )
|
foreach ( $script in $InputObject )
|
||||||
{
|
{
|
||||||
@@ -62,4 +62,9 @@ function Format-Chronometer
|
|||||||
Write-ScriptLine $command -WarningAt $WarningAt -ErrorAt $ErrorAt
|
Write-ScriptLine $command -WarningAt $WarningAt -ErrorAt $ErrorAt
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
$PSCmdlet.ThrowTerminatingError($PSItem)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,9 +27,12 @@ function Get-Chronometer
|
|||||||
[alias('Script', 'CommandScript')]
|
[alias('Script', 'CommandScript')]
|
||||||
[scriptblock]
|
[scriptblock]
|
||||||
$ScriptBlock
|
$ScriptBlock
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
process
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
if ( $null -eq $Path )
|
if ( $null -eq $Path )
|
||||||
{
|
{
|
||||||
$Path = Get-ChildItem -Recurse -Include *.psm1, *.ps1 -File
|
$Path = Get-ChildItem -Recurse -Include *.psm1, *.ps1 -File
|
||||||
@@ -67,3 +70,9 @@ function Get-Chronometer
|
|||||||
Write-Warning "Parsing files did not result in any breakpoints"
|
Write-Warning "Parsing files did not result in any breakpoints"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
$PSCmdlet.ThrowTerminatingError($PSItem)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
13
Spec/distribution.Steps.ps1
Normal file
13
Spec/distribution.Steps.ps1
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
Given 'We have functions to publish' {
|
||||||
|
"$psscriptroot\..\chronometer\public\*.ps1" | Should Exist
|
||||||
|
}
|
||||||
|
And 'We have a module' {
|
||||||
|
"$psscriptroot\..\chronometer\chronometer.psd1" | Should Exist
|
||||||
|
"$psscriptroot\..\chronometer\chronometer.psm1" | Should Exist
|
||||||
|
}
|
||||||
|
When 'The user searches for our module' {
|
||||||
|
Find-Module chronometer | Should Not BeNullOrEmpty
|
||||||
|
}
|
||||||
|
Then 'They can install the module' {
|
||||||
|
{Install-Module chronometer -Scope CurrentUser -WhatIf *>&1} | Should Not Throw
|
||||||
|
}
|
||||||
8
Spec/distribution.feature
Normal file
8
Spec/distribution.feature
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
Feature: We need distribute our module to the public
|
||||||
|
It should be published someplace that is easy to find
|
||||||
|
|
||||||
|
Scenario: A user needs to be able to find our module in the PSGallery
|
||||||
|
Given We have functions to publish
|
||||||
|
And We have a module
|
||||||
|
When The user searches for our module
|
||||||
|
Then They can install the module
|
||||||
24
psake.ps1
24
psake.ps1
@@ -93,6 +93,30 @@ Task Build -Depends Test {
|
|||||||
Write-Host "Using version: $version"
|
Write-Host "Using version: $version"
|
||||||
|
|
||||||
Update-Metadata -Path $env:BHPSModuleManifest -PropertyName ModuleVersion -Value $version
|
Update-Metadata -Path $env:BHPSModuleManifest -PropertyName ModuleVersion -Value $version
|
||||||
|
|
||||||
|
$psm1 = "$PSScriptRoot\$env:BHProjectName\$env:BHProjectName.psm1"
|
||||||
|
|
||||||
|
# keep the first line in the psm1 file and clear the rest
|
||||||
|
( Get-Content -Path $psm1 -TotalCount 1 ) | Set-Content -Path $psm1
|
||||||
|
foreach ( $folder in ('Classes', 'Public', 'Private') )
|
||||||
|
{
|
||||||
|
Add-Content -Path $psm1 -Value "Write-Verbose 'Importing from [$folder]'"
|
||||||
|
$imports = Get-ChildItem "$PSScriptRoot\$env:BHProjectName\$folder\*.ps1" -Exclude *.Tests.ps1
|
||||||
|
foreach ( $file in $imports )
|
||||||
|
{
|
||||||
|
Add-Content -Path $psm1 -Value ''
|
||||||
|
Add-Content -Path $psm1 -Value "Write-Verbose ' Source [\$folder\$($file.name)]'"
|
||||||
|
[System.IO.File]::ReadAllText($file.fullname) | Add-Content -Path $psm1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Remove folders after import
|
||||||
|
Remove-Item "$PSScriptRoot\$env:BHProjectName\$folder" -Recurse
|
||||||
|
}
|
||||||
|
|
||||||
|
# Add exports
|
||||||
|
Add-Content -Path $psm1 -Value "Export-ModuleMember -Function $($functions -join ', ')"
|
||||||
|
|
||||||
|
Import-Module $psm1 -Force
|
||||||
}
|
}
|
||||||
|
|
||||||
Task Deploy -Depends Build {
|
Task Deploy -Depends Build {
|
||||||
|
|||||||
Reference in New Issue
Block a user