Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Add the converter for text tables to the repository #29

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ obj/
out/
project.lock.json
.DS_Store
Microsoft.PowerShell.TextUtility.xml
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this the xml help generated during build? we should just exclude the build folder than this specific file

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, it's generated by Invoke-Pester when -test is used with build


# VSCode directories that are not at the repository root
/**/.vscode/
182 changes: 167 additions & 15 deletions build.ps1
Original file line number Diff line number Diff line change
@@ -1,33 +1,185 @@
## Copyright (c) Microsoft Corporation.
## Licensed under the MIT License.

[CmdletBinding()]
# default behavior is build only
[CmdletBinding(SupportsShouldProcess=$true)]
param (
[Parameter()]
[string]
$Configuration = "Debug",

[Parameter()]
[switch]
$Clean
[switch]$Publish,

[Parameter()]
[switch]$Test,

[Parameter()]
[switch]$NoBuild,

[Parameter()]
[switch]$Clean
)

try {
Push-Location "$PSScriptRoot/src/code"
$moduleName = "Microsoft.PowerShell.TextUtility"
$projectRoot = $PSScriptRoot

$srcRoot = Join-Path $ProjectRoot src
$codeRoot = Join-Path $srcRoot code
$tstRoot = Join-Path $ProjectRoot test
$modManifest = Join-Path $srcRoot "${ModuleName}.psd1"

$outPath = "$PSScriptRoot/out/Microsoft.PowerShell.TextUtility"

if ($Clean) {
if (Test-Path $outPath) {
Write-Verbose "Deleting $outPath"
Remove-Item -recurse -force -path $outPath
function AssertFile {
param (
[Parameter(Mandatory=$true)]
[string]$Path
)

if (-not (Test-Path $Path)) {
throw "File not found: $Path"
}
}

function Assert {
param ([Parameter(Mandatory=$true)][bool]$Condition, [Parameter(Mandatory=$true)][string]$Message)
if (! $Condition) {
throw $Message
}
}

foreach ($path in $srcRoot, $codeRoot, $tstRoot, $modManifest) {
AssertFile $path
}

$modInfo = Import-PowerShellDataFile $modManifest
$modVersion = $modInfo.ModuleVersion
Assert ($null -ne $modVersion) "ModuleVersion is null"
$pubRoot = "${PSScriptRoot}/out/${ModuleName}/${modVersion}"

function Build-Assembly {
if (Test-ShouldBuild) {
try {
Push-Location $codeRoot
if($PSCmdlet.ShouldProcess($Configuration)) {
dotnet build --configuration $Configuration
}
}
finally {
Pop-Location
}
}
else {
Write-Verbose -Verbose "No changes to build"
}
}

dotnet clean
function Test-ShouldBuild {
$latestSourceTime = Get-LatestSourceTime
$latestBuildTime = Get-LatestBuildTime
return ($latestBuildTime -lt $latestSourceTime)
}

function Get-LatestFile {
param ([string[]]$Path)
Get-ChildItem -ErrorAction Ignore -File -Path $Path | Sort-Object LastWriteTime | Select-Object -Last 1
}

function Get-LatestSourceTime {
$latestFile = Get-LatestFile -path $codeRoot,"${srcRoot}/${moduleName}*"
($null -eq $latestFile) ? ([datetime]0) : $latestFile.LastWriteTime
}

function Get-LatestPublishTime {
$latestFile = Get-LatestFile $pubRoot
($null -eq $latestFile) ? ([datetime]0) : $latestFile.LastWriteTime
}

function Get-TargetFramework {
[xml]$x = Get-Content "${codeRoot}/${ModuleName}.csproj"
$x.Project.PropertyGroup.TargetFramework
}

function Get-LatestBuildTime {
$targetFramework = Get-TargetFramework
$dllLocation = "${codeRoot}/bin/${Configuration}/${targetFramework}/${ModuleName}.dll"
$latestFile = Get-LatestFile "${dllLocation}"
($null -eq $latestFile) ? ([datetime]0) : $latestFile.LastWriteTime
}

# determine if the sources are younger than the published
function Test-ShouldPublish {
if (-not (Test-Path $pubRoot)) {
return $true
}
$latestSourceTime = Get-LatestSourceTime
$latestPublishTime = Get-LatestPublishTime
return ($latestPublishTime -lt $latestSourceTime)
}

function Test-Module {
if (Test-ShouldPublish) {
Publish-Assembly
}
else {
Write-Verbose -Verbose "No changes to publish"
}
try {
$PSVersionTable | Out-String -Stream | Write-Verbose -Verbose
$pesterInstallations = Get-Module -ListAvailable -Name Pester
if ($pesterInstallations.Version -notcontains "4.10.1") {
Install-Module -Name Pester -RequiredVersion 4.10.1 -Force -Scope CurrentUser
}
$command = "Import-Module ${PSScriptRoot}/out/${ModuleName}; Import-Module Pester -Max 4.10.1; Invoke-Pester -OutputFormat NUnitXml -EnableExit -OutputFile ../Microsoft.PowerShell.TextUtility.xml"
Push-Location $tstRoot
pwsh -noprofile -command $command
}
finally {
Pop-Location
}
}

function Publish-Assembly {
Build-Assembly # check again - the user may have used -noBuild
if (Test-ShouldPublish) {
if (-not (test-path $pubRoot)) {
$null = New-Item -ItemType Directory -Force -Path $pubRoot
}
$targetFramework = Get-TargetFramework

# this needs to be the list of assemblies
Copy-Item "${codeRoot}/bin/${Configuration}/${targetFramework}/${ModuleName}.dll" $pubRoot -Force
# module manifest and formatting
Copy-Item "${SrcRoot}/dictionary.txt" $pubRoot -Force
Copy-Item "${SrcRoot}/${ModuleName}.psd1" $pubRoot -Force
Copy-Item "${SrcRoot}/${ModuleName}.*.ps1xml" $pubRoot -Force
Write-Verbose -Verbose "Module published to $pubRoot"
}
else {
Write-Verbose -Verbose "No changes to publish"
}
}

if ( $Clean ) {
$dirsToRemove = "${PSScriptRoot}/out",
"${codeRoot}/bin",
"${codeRoot}/obj"

foreach ( $dir in $dirsToRemove ) {
if ( Test-Path $dir ) {
Remove-Item -Force -Recurse $dir
}
}
}

dotnet publish --output $outPath --configuration $Configuration
if (-not $NoBuild ) {
Build-Assembly
}
finally {
Pop-Location

if ( $Publish ) {
Publish-Assembly
}

if ( $Test ) {
Test-Module
}

8 changes: 4 additions & 4 deletions src/Microsoft.PowerShell.TextUtility.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

@{
RootModule = '.\Microsoft.PowerShell.TextUtility.dll'
ModuleVersion = '0.1.0'
ModuleVersion = '0.4.0'
CompatiblePSEditions = @('Desktop', 'Core')
GUID = '5cb64356-cd04-4a18-90a4-fa4072126155'
Author = 'Microsoft Corporation'
Expand All @@ -13,14 +13,14 @@
PowerShellVersion = '5.1'
FormatsToProcess = @('Microsoft.PowerShell.TextUtility.format.ps1xml')
CmdletsToExport = @(
'Compare-Text','ConvertFrom-Base64','ConvertTo-Base64'
'Compare-Text','ConvertFrom-Base64','ConvertTo-Base64','Convert-TextTable'
)
PrivateData = @{
PSData = @{
LicenseUri = 'https://github.com/PowerShell/TextUtility/blob/main/LICENSE'
ProjectUri = 'https://github.com/PowerShell/TextUtility'
ReleaseNotes = 'Initial release'
Prerelease = 'Preview1'
ReleaseNotes = 'Second pre-release'
Prerelease = 'Preview'
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/code/Microsoft.PowerShell.TextUtility.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
<PackageReference Include="PowerShellStandard.Library" Version="5.1.0-*">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="System.Text.Json" Version="6.0.6" >

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this module supports PS 5.1 ensure that System.Text.Json dll gets included in the module.

<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
Expand Down
Loading