Skip to content

Commit

Permalink
Merge pull request #319 from StartAutomating/PipeScriptUpdates
Browse files Browse the repository at this point in the history
PipeScript 0.2.2
  • Loading branch information
StartAutomating authored Dec 24, 2022
2 parents 0109beb + 343a02f commit 084b180
Show file tree
Hide file tree
Showing 39 changed files with 1,320 additions and 204 deletions.
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
## PipeScript 0.2.2:

* Build-PipeScript is now Export-PipeScript (aliases remain) (Fixes #312)
* Export-PipeScript: Running BuildScripts first (Fixes #316)
* Join-PipeScript
* Ensuring end blocks remain unnamed if they can be (Fixes #317)
* Trmming empty param blocks from end (Fixes #302)
* Update-PipeScript:
* Adding -InsertBefore/After (Fixes #309). Improving aliasing (Fixes #310)
* Aliasing RenameVariable to RenameParameter (Fixes #303). Improving inner docs
* requires transpiler: Caching Find-Module results (Fixes #318)
* Extending Types:
* Adding PipeScript.Template (Fixes #315)
* Adding 'ExtensionScript' to PipeScript.PipeScriptType (Fixes #313)
* Greatly extending ParameterAst (Fixes #305)
* Extending ParamBlockAst (Fixes #304)

---

## 0.2.1:

* Adding preliminary 'define' transpiler (Fixes #299)
Expand Down
33 changes: 25 additions & 8 deletions Build-PipeScript.ps1 → Export-PipeScript.ps1
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
function Build-Pipescript {
function Export-Pipescript {
<#
.Synopsis
Builds PipeScript Files
Builds and Exports using PipeScript
.Description
Builds PipeScript Files.
Builds and Exports a path, using PipeScript.
Any Source Generator Files Discovered by PipeScript will be run, which will convert them into source code.
.EXAMPLE
Export-PipeScript
.EXAMPLE
Build-PipeScript
#>
[Alias('bps')]
[Alias('Build-PipeScript','bps','eps')]
param(
# One or more input paths. If no -InputPath is provided, will build all scripts beneath the current directory.
[Parameter(ValueFromPipelineByPropertyName)]
Expand All @@ -20,29 +24,42 @@ function Build-Pipescript {
$filesToBuild =
@(if (-not $InputPath) {
Get-PipeScript -PipeScriptPath $pwd |
Where-Object PipeScriptType -In SourceGenerator
Where-Object PipeScriptType -In Template, BuildScript |
Sort-Object PipeScriptType, Source
} else {
foreach ($inPath in $InputPath) {
Get-PipeScript -PipeScriptPath $inPath |
Where-Object PipeScriptType -In SourceGenerator
Where-Object PipeScriptType -In Template, BuildScript |
Sort-Object PipeScriptType, Source
}
})


$buildStarted = [DateTime]::Now
$alreadyBuilt = [Ordered]@{}
$filesToBuildCount, $filesToBuildTotal, $filesToBuildID = 0, $filesToBuild.Length, $(Get-Random)
foreach ($buildFile in $filesToBuild) {
$ThisBuildStartedAt = [DateTime]::Now

$ThisBuildStartedAt = [DateTime]::Now

Write-Progress "Building PipeScripts [$FilesToBuildCount / $filesToBuildTotal]" "$($buildFile.Source) " -PercentComplete $(
$FilesToBuildCount++
$FilesToBuildCount * 100 / $filesToBuildTotal
) -id $filesToBuildID

if ($alreadyBuilt[$buildFile.Source]) { continue }

$buildFileTemplate = $buildFile.Template
if ($buildFileTemplate -and $buildFile.PipeScriptType -ne 'Template') {
Invoke-PipeScript $buildFileTemplate.Source
$alreadyBuilt[$buildFileTemplate.Source] = $true
}

$EventsFromThisBuild = Get-Event |
Where-Object TimeGenerated -gt $ThisBuildStartedAt |
Where-Object SourceIdentifier -Like 'PipeScript.*'

Invoke-PipeScript $buildFile.Source
$alreadyBuilt[$buildFile.Source] = $true
}


Expand Down
6 changes: 3 additions & 3 deletions Get-PipeScript.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#region Piecemeal [ 0.3.6 ] : Easy Extensible Plugins for PowerShell
#region Piecemeal [ 0.3.7 ] : Easy Extensible Plugins for PowerShell
# Install-Module Piecemeal -Scope CurrentUser
# Import-Module Piecemeal -Force
# Install-Piecemeal -ExtensionNoun 'PipeScript' -ExtensionPattern '\.psx\.ps1{0,1}$','\.ps1{0,1}\.(?<ext>[^.]+$)','\.ps1{0,1}$' -ExtensionTypeName 'PipeScript' -OutputPath '.\Get-PipeScript.ps1'
Expand Down Expand Up @@ -418,7 +418,7 @@ function Get-PipeScript
}
}
elseif ($attr -is [Management.Automation.ValidatePatternAttribute]) {
$matched = [Regex]::new($attr.RegexPattern, $attr.Options, [Timespan]::FromSeconds(1)).Match($ValidateInput)
$matched = [Regex]::new($attr.RegexPattern, $attr.Options, [Timespan]::FromSeconds(1)).Match("$ValidateInput")
if (-not $matched.Success) {
if ($allValid) {
if ($ErrorActionPreference -eq 'ignore') {
Expand Down Expand Up @@ -934,5 +934,5 @@ function Get-PipeScript
}
}
}
#endregion Piecemeal [ 0.3.6 ] : Easy Extensible Plugins for PowerShell
#endregion Piecemeal [ 0.3.7 ] : Easy Extensible Plugins for PowerShell

6 changes: 3 additions & 3 deletions Get-Transpiler.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#region Piecemeal [ 0.3.6 ] : Easy Extensible Plugins for PowerShell
#region Piecemeal [ 0.3.7 ] : Easy Extensible Plugins for PowerShell
# Install-Module Piecemeal -Scope CurrentUser
# Import-Module Piecemeal -Force
# Install-Piecemeal -ExtensionNoun 'Transpiler' -ExtensionPattern '\.psx\.ps1$' -ExtensionTypeName 'PipeScript.Transpiler' -OutputPath '.\Get-Transpiler.ps1'
Expand Down Expand Up @@ -418,7 +418,7 @@ function Get-Transpiler
}
}
elseif ($attr -is [Management.Automation.ValidatePatternAttribute]) {
$matched = [Regex]::new($attr.RegexPattern, $attr.Options, [Timespan]::FromSeconds(1)).Match($ValidateInput)
$matched = [Regex]::new($attr.RegexPattern, $attr.Options, [Timespan]::FromSeconds(1)).Match("$ValidateInput")
if (-not $matched.Success) {
if ($allValid) {
if ($ErrorActionPreference -eq 'ignore') {
Expand Down Expand Up @@ -934,5 +934,5 @@ function Get-Transpiler
}
}
}
#endregion Piecemeal [ 0.3.6 ] : Easy Extensible Plugins for PowerShell
#endregion Piecemeal [ 0.3.7 ] : Easy Extensible Plugins for PowerShell

11 changes: 9 additions & 2 deletions Join-PipeScript.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ function Join-PipeScript
# (don't forget to trim leading whitespace)
} else {
# for every other parameter it is the content between parameters.
$lastParameter = $parameter.Parent.Parameters[$parameterIndex - 1]
$lastParameter = $parameter.Parent.Parameters[$parameterIndex - 1]
$relativeOffset = $lastParameter.Extent.EndOffset + 1 - $parameter.Parent.Extent.StartOffset
$distance = $parameter.Extent.StartOffset - $lastParameter.Extent.EndOffset - 1
# (don't forget to trim leading whitespace and commas)
Expand Down Expand Up @@ -395,7 +395,7 @@ function Join-PipeScript
$StatementsToAdd = $null
}
if ($block.Unnamed) {
$block.Extent.ToString()
$block.Extent.ToString() -replace '^param\(\)[\s\r\n]{0,}'
} else {
$block.Extent.ToString() -replace '^end\s{0,}\{' -replace '\}$' -replace '^param\(\)[\s\r\n]{0,}'
}
Expand Down Expand Up @@ -427,6 +427,13 @@ function Join-PipeScript
#endregion Joining the Scripts

$combinedScriptBlock = [scriptblock]::Create($joinedScript)
if ((-not $combinedScriptBlock.Ast.EndBlock.Unnamed) -and -not (
$combinedScriptBlock.Ast.ProcessBlock -or
$combinedScriptBlock.Ast.BeginBlock -or
$combinedScriptBlock.Ast.DynamicParameterBlock
)) {
$combinedScriptBlock = [ScriptBlock]::Create($combinedScriptBlock.Ast.EndBlock.ToString() -replace '^end\s{0,}\{' -replace '\}$')
}
if ($combinedScriptBlock -and $Transpile) {
$combinedScriptBlock | .>Pipescript
} elseif ($combinedScriptBlock) {
Expand Down
10 changes: 7 additions & 3 deletions PipeScript.Piecemeal.ps1
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
#require -Module Piecemeal
Push-Location $PSScriptRoot

# Push to this directory
Push-Location $PSScriptRoot
# Get-Transpiler is generated with Piecemeal
Install-Piecemeal -ExtensionNoun 'Transpiler' -ExtensionPattern '\.psx\.ps1$' -ExtensionTypeName 'PipeScript.Transpiler' -OutputPath '.\Get-Transpiler.ps1' |
Add-Member Noteproperty CommitMessage "Get-Transpiler: Updating Piecemeal Version" -Force -PassThru
Add-Member Noteproperty CommitMessage "Get-Transpiler: Updating Piecemeal Version" -Force -PassThru

# So is Get-PipeScript
Install-Piecemeal -ExtensionNoun 'PipeScript' -ExtensionPattern '\.psx\.ps1{0,1}$','\.ps1{0,1}\.(?<ext>[^.]+$)','\.ps1{0,1}$' -ExtensionTypeName 'PipeScript' -OutputPath '.\Get-PipeScript.ps1' |
Add-Member Noteproperty CommitMessage "Get-PipeScript: Updating Piecemeal Version" -Force -PassThru


# Pop back to wherever we were
Pop-Location
Loading

0 comments on commit 084b180

Please sign in to comment.