Skip to content

Commit 45c7460

Browse files
Merge pull request #55 from StartAutomating/ConvertTo-PSSVG-And-More
ConvertTo-PSSVG and more
2 parents 9a708d4 + df51dc4 commit 45c7460

18 files changed

+410
-59
lines changed

.github/workflows/OnIssue.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
2+
name: OnIssueChanged
3+
on:
4+
issues:
5+
workflow_dispatch:
6+
jobs:
7+
RunGitPub:
8+
runs-on: ubuntu-latest
9+
if: ${{ success() }}
10+
steps:
11+
- name: Check out repository
12+
uses: actions/checkout@v2
13+
- name: Use GitPub Action
14+
uses: StartAutomating/GitPub@main
15+
id: GitPub
16+
with:
17+
TargetBranch: edits-$([DateTime]::Now.ToString("r").Replace(":","-").Replace(" ", ""))
18+
CommitMessage: Posting with GitPub [skip ci]
19+
PublishParameters: |
20+
{
21+
"Get-GitPubIssue": {
22+
"UserName": '${{github.repository_owner}}',
23+
"Repository": "PipeScript"
24+
},
25+
"Get-GitPubRelease": {
26+
"UserName": '${{github.repository_owner}}',
27+
"Repository": "PipeScript"
28+
},
29+
"Publish-GitPubJekyll": {
30+
"OutputPath": "docs/_posts"
31+
}
32+
}
33+

.github/workflows/TestAndPublish.yml

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,8 @@ jobs:
306306
$Parameters.UserName = ${env:UserName}
307307
$Parameters.TagVersionFormat = ${env:TagVersionFormat}
308308
$Parameters.ReleaseNameFormat = ${env:ReleaseNameFormat}
309+
$Parameters.ReleaseAsset = ${env:ReleaseAsset}
310+
$Parameters.ReleaseAsset = $parameters.ReleaseAsset -split ';' -replace '^[''"]' -replace '[''"]$'
309311
foreach ($k in @($parameters.Keys)) {
310312
if ([String]::IsNullOrEmpty($parameters[$k])) {
311313
$parameters.Remove($k)
@@ -331,7 +333,11 @@ jobs:
331333
332334
# The release name format (default value: '$($imported.Name) $($imported.Version)')
333335
[string]
334-
$ReleaseNameFormat = '$($imported.Name) $($imported.Version)'
336+
$ReleaseNameFormat = '$($imported.Name) $($imported.Version)',
337+
338+
# Any assets to attach to the release. Can be a wildcard or file name.
339+
[string[]]
340+
$ReleaseAsset
335341
)
336342
337343
@@ -381,7 +387,7 @@ jobs:
381387
}
382388
383389
384-
Invoke-RestMethod -Uri $releasesURL -Method Post -Body (
390+
$releasedIt = Invoke-RestMethod -Uri $releasesURL -Method Post -Body (
385391
[Ordered]@{
386392
owner = '${{github.owner}}'
387393
repo = '${{github.repository}}'
@@ -403,6 +409,53 @@ jobs:
403409
"Content-type" = "application/json"
404410
"Authorization" = 'Bearer ${{ secrets.GITHUB_TOKEN }}'
405411
}
412+
413+
414+
if (-not $releasedIt) {
415+
throw "Release failed"
416+
} else {
417+
$releasedIt | Out-Host
418+
}
419+
420+
$releaseUploadUrl = $releasedIt.upload_url -replace '\{.+$'
421+
422+
if ($ReleaseAsset) {
423+
$fileList = Get-ChildItem -Recurse
424+
$filesToRelease =
425+
@(:nextFile foreach ($file in $fileList) {
426+
foreach ($relAsset in $ReleaseAsset) {
427+
if ($relAsset -match '[\*\?]') {
428+
if ($file.Name -like $relAsset) {
429+
$file; continue nextFile
430+
}
431+
} elseif ($file.Name -eq $relAsset -or $file.FullName -eq $relAsset) {
432+
$file; continue nextFile
433+
}
434+
}
435+
})
436+
437+
$releasedFiles = @{}
438+
foreach ($file in $filesToRelease) {
439+
if ($releasedFiles[$file.Name]) {
440+
Write-Warning "Already attached file $($file.Name)"
441+
continue
442+
} else {
443+
$fileBytes = [IO.File]::ReadAllBytes($file.FullName)
444+
$releasedFiles[$file.Name] =
445+
Invoke-RestMethod -Uri "${releaseUploadUrl}?name=$($file.Name)" -Headers @{
446+
"Accept" = "application/vnd.github+json"
447+
"ContentType" = "application/octet-stream"
448+
"Authorization" = 'Bearer ${{ secrets.GITHUB_TOKEN }}'
449+
} -Body $fileBytes
450+
$releasedFiles[$file.Name]
451+
}
452+
}
453+
454+
"Attached $($releasedFiles.Count) file(s) to release" | Out-Host
455+
}
456+
457+
458+
406459
} @Parameters
407460
- name: PublishPowerShellGallery
408461
id: PublishPowerShellGallery

Assets/PSSVG.svg

Lines changed: 6 additions & 3 deletions
Loading

CHANGELOG.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
1+
### 0.2.4:
2+
* Adding ConvertTo-PSSVG (Fixes #53)
3+
* Updated Logo to use PowerShell Chevron (Fixes #52)
4+
* Using [GitPub](https://github.com/StartAutomating/GitPub) to generate blog (Fixes #51)
5+
6+
---
7+
18
### 0.2.3:
29
* Adding SVG.Triangle (#47)
310
* Updating SVG.DropShadow (#48)
411
* Adding PowerShell Chevron Example (#49)
12+
513
---
614

715
### 0.2.2:
@@ -21,6 +29,7 @@
2129
* Outputs objects by default (Fixes #33) (with nice formatting (Fixes #35))
2230
* Prettifies -OutputPath (Fixes #45)
2331
* Handles [TimeSpan] values (Fixes #34)
32+
2433
---
2534

2635
### 0.2.1
@@ -30,14 +39,16 @@
3039
* Write-SVG: Allowing 2 value ViewBox (Fixes #28)
3140
* All SVG.* commands allow elements (Fixes #25 )
3241
* All SVG.* commands now have argument completers (Fixes #24)
33-
---
42+
43+
---
3444

3545
### 0.2
3646
* All SVG. commands now support -Data attributes (Fixes #12)
3747
* Improved Command Help
3848
* Linking to docs and MDN (Get-Help SVG.a -Online) (Fixes #15)
3949
* Adding .Examples (Fixes #18)
4050
* Adding Write-SVG (Fixes #14)
51+
4152
---
4253

4354
### 0.1
@@ -50,4 +61,5 @@
5061
* It's own logo (fixes #7)
5162
* The script used to generate every SVG element (fixes #8)
5263
* [A github page](https://PSSVG.start-automating.com) (fixes #9)
53-
---
64+
65+
---
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
function ConvertTo-PSSVG
2+
{
3+
<#
4+
.SYNOPSIS
5+
Converts an SVG to PSSVG
6+
.DESCRIPTION
7+
Converts an SVG to a PowerShell Script that would generate that SVG
8+
.LINK
9+
Write-SVG
10+
.EXAMPLE
11+
ConvertTo-PSSVG -InputObject https://PSSVG.start-automating.com/Assets/PSSVG.svg
12+
.EXAMPLE
13+
ConvertTo-PSSVG -InputObject .\a.svg
14+
.EXAMPLE
15+
ConvertTo-PSSVG -InputObject "<svg><circle cx='5' cy='5' r='3'></svg>"
16+
#>
17+
param(
18+
[Parameter(Mandatory)]
19+
$InputObject
20+
)
21+
22+
begin {
23+
$indentDepth = 0
24+
filter ToPSSVG {
25+
if ($_.LocalName -eq '#whitespace') { return }
26+
if ($_.LocalName -eq '#text') {
27+
"'$($_.Value -replace "'", "''")'"
28+
} elseif ($_.LocalName) {
29+
$xin = $_
30+
$svgCmdName = if ($xin.LocalName -ne 'SVG') {
31+
"=<SVG.$($xin.LocalName)>"
32+
} else {
33+
"=<SVG>"
34+
}
35+
36+
(' ' * (4 * $indentDepth)) + $svgCmdName
37+
$svgFunc = $ExecutionContext.SessionState.InvokeCommand.GetCommand($svgCmdName, 'Alias').ResolvedCommand
38+
39+
40+
foreach ($attr in $xin.Attributes) {
41+
$paramName = $attr.LocalName -replace '-'
42+
if (-not $svgFunc.Parameters.$paramName) {
43+
continue
44+
}
45+
" -$paramName "
46+
"'$($attr.'#text' -replace "'","''")'"
47+
}
48+
49+
$xChildren = @($xin.ChildNodes)
50+
51+
if ($xChildren) {
52+
$indentDepth++
53+
" -Content @("
54+
[Environment]::NewLine
55+
foreach ($childNode in $xin.ChildNodes) {
56+
$childNode | ToPSSVG
57+
}
58+
[Environment]::NewLine
59+
")"
60+
$indentDepth--
61+
}
62+
[Environment]::NewLine
63+
} else {
64+
$_
65+
}
66+
}
67+
}
68+
69+
process {
70+
# If the input looks like a URL
71+
if ($InputObject -match '^https{0,1}://')
72+
{
73+
# go get it
74+
$InputObject = Invoke-RestMethod -Uri $InputObject
75+
} elseif ($InputObject -isnot [xml] -and
76+
$InputObject -isnot [Xml.XmlDocument] -and
77+
(-not $InputObject -as [xml])
78+
) {
79+
# If it's not XML and won't be XML, try loading it from a file.
80+
$resolvedPath = $ExecutionContext.SessionState.Path.GetResolvedPSPathFromPSPath($InputObject)
81+
if (-not $resolvedPath) { return }
82+
if ($resolvedPath) {
83+
$inputObject = [xml][IO.File]::ReadAllText($resolvedPath)
84+
}
85+
} elseif ($InputObject -as [xml]) {
86+
# If the input was castable to XML, cast it to XML.
87+
$InputObject = $InputObject -as [xml]
88+
}
89+
90+
# If the input isn't XML at this point, error out.
91+
if ($InputObject -isnot [xml] -and $InputObject -isnot [Xml.XmlDocument]) {
92+
Write-Error "Could not convert input to XML"
93+
return
94+
}
95+
96+
# If it was an xmldocument, instead of an element
97+
if ($InputObject -is [xml]) {
98+
$InputObject = # set the input to be the first non-whitespace non-declaration child.
99+
foreach ($xChild in $InputObject.ChildNodes) {
100+
if ($xChild.NodeType -in 'XmlDeclaration', 'Whitespace') {
101+
continue
102+
}
103+
$xChild
104+
break
105+
}
106+
}
107+
108+
# Recursively convert this element to a PSSVG script
109+
$scriptText = @($InputObject | ToPSSVG) -join ''
110+
# and try to create a script block
111+
$ScriptBlock = [ScriptBlock]::Create($scriptText)
112+
if ($ScriptBlock) {
113+
$ScriptBlock
114+
} else {
115+
$scriptText
116+
}
117+
}
118+
}

Examples/ManyAnimatedRectangles.svg

Lines changed: 10 additions & 10 deletions
Loading

Examples/ManyRectangles.svg

Lines changed: 10 additions & 10 deletions
Loading

0 commit comments

Comments
 (0)