Skip to content

Commit

Permalink
Format workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaunLawrie committed Mar 3, 2024
1 parent c9c44dd commit ea1e475
Show file tree
Hide file tree
Showing 53 changed files with 341 additions and 361 deletions.
30 changes: 15 additions & 15 deletions PwshSpectreConsole.Docs/UpdateDocs.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Import-Module "$PSScriptRoot\..\PwshSpectreConsole\PwshSpectreConsole.psd1" -For
Remove-Item -Recurse -Path "$PSScriptRoot\src\content\docs\reference\*" -Force
$module = Get-Module PwshSpectreConsole

if($null -eq $module) {
if ($null -eq $module) {
throw "Failed to import PwshSpectreConsole module"
}

Expand Down Expand Up @@ -45,55 +45,55 @@ $groups = @(
)

$docs = Get-ChildItem "$PSScriptRoot\src\content\docs\reference\" -Filter "*.md" -Recurse
foreach($doc in $docs) {
if($remove -contains $doc.Name -or $doc.Name -notlike "*-*") {
foreach ($doc in $docs) {
if ($remove -contains $doc.Name -or $doc.Name -notlike "*-*") {
Remove-Item $doc.FullName
continue
}

$group = $null
foreach($testGroup in $groups) {
foreach($match in $testGroup.Matches) {
if($doc.Name -like "*$match*") {
foreach ($testGroup in $groups) {
foreach ($match in $testGroup.Matches) {
if ($doc.Name -like "*$match*") {
$group = $testGroup
break
}
}
}

$outLocation = "$PSScriptRoot\src\content\docs\reference\$($group.Name)\$($doc.Name)"
if($null -eq $group) {
if ($null -eq $group) {
$outLocation = $doc.FullName
}
New-Item -ItemType Directory -Path "$PSScriptRoot\src\content\docs\reference\$($group.Name)" -Force | Out-Null
$content = Get-Content $doc.FullName -Raw
Remove-Item $doc.FullName
$content = $content -replace '```PowerShell', '```powershell' -replace '(?m)^.+\n^[\-]{10,99}', '' -replace "`r", ""
if($experimental -contains $doc.Name) {
if ($experimental -contains $doc.Name) {
$content = $content -replace '(?s)^---', "---`n$experimentalTag"
} elseif($new -contains $doc.Name) {
} elseif ($new -contains $doc.Name) {
$content = $content -replace '(?s)^---', "---`n$newTag"
}
$content | Out-File $outLocation -NoNewline
}

# Build the docs site
npm ci --prefix $PSScriptRoot
if($LASTEXITCODE -ne 0) {
if ($LASTEXITCODE -ne 0) {
throw "Failed to install npm dependencies"
}

npm run build --prefix $PSScriptRoot
if($LASTEXITCODE -ne 0) {
if ($LASTEXITCODE -ne 0) {
throw "Failed to run npm build"
}

if($NonInteractive) {
if ($NonInteractive) {
return
}

# Deploy to preview
if(npx --yes wrangler whoami | Where-Object { $_ -like "*You are logged in*" }) {
if (npx --yes wrangler whoami | Where-Object { $_ -like "*You are logged in*" }) {
Write-Host "Already logged into cloudflare"
} else {
npx wrangler login
Expand All @@ -102,8 +102,8 @@ npx wrangler pages deploy "$PSScriptRoot\dist" --project-name pwshspectreconsole

# Yeet it to cloudflare
$choice = Read-Host "`nDeploy to Prod CF pages? (y/n)"
if($choice -eq "y") {
if(npx wrangler whoami | Where-Object { $_ -like "*You are logged in*" }) {
if ($choice -eq "y") {
if (npx wrangler whoami | Where-Object { $_ -like "*You are logged in*" }) {
Write-Host "Already logged into cloudflare"
} else {
npx wrangler login
Expand Down
3 changes: 2 additions & 1 deletion PwshSpectreConsole.Docs/astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ export default defineConfig({
starlight({
title: "PwshSpectreConsole",
editLink: {
baseUrl: "https://github.com/ShaunLawrie/PwshSpectreConsole/edit/main/PwshSpectreConsole.Docs/",
baseUrl:
"https://github.com/ShaunLawrie/PwshSpectreConsole/edit/main/PwshSpectreConsole.Docs/",
},
favicon: "/favicon.png",
customCss: ["./src/tailwind.css"],
Expand Down
2 changes: 1 addition & 1 deletion PwshSpectreConsole.Docs/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion PwshSpectreConsole.Docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
"sharp": "^0.32.5",
"tailwindcss": "^3.3.3"
}
}
}
8 changes: 4 additions & 4 deletions PwshSpectreConsole.Docs/src/content/config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineCollection } from 'astro:content';
import { docsSchema, i18nSchema } from '@astrojs/starlight/schema';
import { defineCollection } from "astro:content";
import { docsSchema, i18nSchema } from "@astrojs/starlight/schema";

export const collections = {
docs: defineCollection({ schema: docsSchema() }),
i18n: defineCollection({ type: 'data', schema: i18nSchema() }),
docs: defineCollection({ schema: docsSchema() }),
i18n: defineCollection({ type: "data", schema: i18nSchema() }),
};
12 changes: 6 additions & 6 deletions PwshSpectreConsole.Docs/src/tailwind.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
@tailwind utilities;

:root {
--sl-sidebar-width: 28rem;
--sl-content-width: 80rem;
--sl-sidebar-width: 28rem;
--sl-content-width: 80rem;
}

@media (min-width: 50rem) {
.hero {
padding-block: clamp(2.5rem,calc(1rem + 10vmin),5rem);
}
}
.hero {
padding-block: clamp(2.5rem, calc(1rem + 10vmin), 5rem);
}
}
26 changes: 13 additions & 13 deletions PwshSpectreConsole.Docs/tailwind.config.mjs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import starlightPlugin from '@astrojs/starlight-tailwind';
import colors from 'tailwindcss/colors';
import starlightPlugin from "@astrojs/starlight-tailwind";
import colors from "tailwindcss/colors";

/** @type {import('tailwindcss').Config} */
export default {
content: ['./src/**/*.{astro,html,js,jsx,md,mdx,svelte,ts,tsx,vue}'],
theme: {
extend: {
colors: {
accent: colors.gray,
gray: colors.slate,
}
},
},
plugins: [starlightPlugin()],
}
content: ["./src/**/*.{astro,html,js,jsx,md,mdx,svelte,ts,tsx,vue}"],
theme: {
extend: {
colors: {
accent: colors.gray,
gray: colors.slate,
},
},
},
plugins: [starlightPlugin()],
};
2 changes: 1 addition & 1 deletion PwshSpectreConsole.Docs/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"extends": "astro/tsconfigs/strictest"
}
}
10 changes: 4 additions & 6 deletions PwshSpectreConsole.Tests/TestHelpers.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@ function Get-SpectreRenderable {
$console = [Spectre.Console.AnsiConsole]::Create($settings)
$console.Write($RenderableObject)
$writer.ToString()
}
finally {
} finally {
$writer.Dispose()
}
}
Expand All @@ -155,8 +154,7 @@ function Get-AnsiEscapeSequence {
$Escaped = $String.EnumerateRunes() | ForEach-Object {
if ($_.Value -le 0x1f) {
[Text.Rune]::new($_.Value + 0x2400)
}
else {
} else {
$_
}
} | Join-String
Expand Down Expand Up @@ -234,7 +232,7 @@ function Get-SpectreTableRowData {
1..$Count | ForEach-Object {
if ($Markup) {
return '[{0}] {1} [/]' -f (Get-RandomColor), (Get-RandomString)
}
}
Get-RandomString
}
}
Expand All @@ -250,7 +248,7 @@ function Assert-OutputMatchesSnapshot {
Set-Content -Path $snapShotComparisonPath -Value $compare -NoNewline
$snapshot = Get-Content -Path $snapShotPath -Raw
$snapshot = $snapshot -replace "`r", ""
if($compare -ne $snapshot) {
if ($compare -ne $snapshot) {
Write-Host "Expected to match snapshot:`n`n$snapshot"
Write-Host "But the output was:`n`n$compare"
Write-Host "You can diff the snapshot files at:`n - $snapShotPath`n - $snapShotComparisonPath"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Describe "Format-SpectreBarChart" {
$testWidth = Get-Random -Minimum 10 -Maximum 100
$testTitle = "Test Chart $([guid]::NewGuid())"
$testData = @()
for($i = 0; $i -lt (Get-Random -Minimum 3 -Maximum 10); $i++) {
for ($i = 0; $i -lt (Get-Random -Minimum 3 -Maximum 10); $i++) {
$testData += New-SpectreChartItem -Label (Get-RandomString) -Value (Get-Random -Minimum -100 -Maximum 100) -Color (Get-RandomColor)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Describe "Format-SpectreBreakdownChart" {
$testConsole.EmitAnsiSequences = $true
$testWidth = Get-Random -Minimum 10 -Maximum 100
$testData = @()
for($i = 0; $i -lt (Get-Random -Minimum 3 -Maximum 10); $i++) {
for ($i = 0; $i -lt (Get-Random -Minimum 3 -Maximum 10); $i++) {
$testData += Get-RandomChartItem
}

Expand Down
24 changes: 12 additions & 12 deletions PwshSpectreConsole.Tests/formatting/Format-SpectreJson.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ Describe "Format-SpectreJson" {
$testConsole.EmitAnsiSequences = $true
$testData = @(
[pscustomobject]@{
Name = "John"
Age = 25
City = "New York"
Name = "John"
Age = 25
City = "New York"
IsEmployed = $true
Salary = 10
Hobbies = @("Reading", "Swimming")
Address = [pscustomobject]@{
Salary = 10
Hobbies = @("Reading", "Swimming")
Address = [pscustomobject]@{
Street = "123 Main St"
City = "New York"
Deep = @{
City = "New York"
Deep = @{
Nested = @{
Value = @{
That = @{
Expand All @@ -32,8 +32,8 @@ Describe "Format-SpectreJson" {
}
}
}
State = "NY"
Zip = "10001"
State = "NY"
Zip = "10001"
}
}
)
Expand Down Expand Up @@ -63,7 +63,7 @@ Describe "Format-SpectreJson" {
Mock Write-AnsiConsole {
$RenderableObject | Should -BeOfType [Spectre.Console.Panel]
$RenderableObject.Header.Text | Should -Be $testTitle
if($testBorder -ne "None") {
if ($testBorder -ne "None") {
$RenderableObject.Border.GetType().Name | Should -BeLike "*$testBorder*"
}
$RenderableObject.BorderStyle.Foreground.ToMarkup() | Should -Be $testColor
Expand Down Expand Up @@ -112,7 +112,7 @@ Describe "Format-SpectreJson" {
)
$data | ConvertTo-Json | Format-SpectreJson -Border None
$roundtrip = $testConsole.Output | StripAnsi | ConvertFrom-Json
(Compare-Object -ReferenceObject $data -DifferenceObject $roundtrip -Property Name, Age, City -CaseSensitive -IncludeEqual).SideIndicator | Should -Be @('==','==')
(Compare-Object -ReferenceObject $data -DifferenceObject $roundtrip -Property Name, Age, City -CaseSensitive -IncludeEqual).SideIndicator | Should -Be @('==', '==')
}

It "Should roundtrip json string input" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Describe "Format-SpectrePanel" {
$RenderableObject.Header.Text | Should -Be $testTitle
$RenderableObject.Expand | Should -Be $testExpand
$RenderableObject.BorderStyle.Foreground.ToMarkup() | Should -Be $testColor
if($testBorder -ne "None") {
if ($testBorder -ne "None") {
$RenderableObject.Border.GetType().Name | Should -BeLike "*$testBorder*"
}

Expand Down
18 changes: 8 additions & 10 deletions PwshSpectreConsole.Tests/formatting/Format-SpectreTable.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ Describe "Format-SpectreTable" {
Mock Write-AnsiConsole {
$RenderableObject | Should -BeOfType [Spectre.Console.Table]
$RenderableObject.Rows.Count | Should -Be $testData.Count
if($testBorder -ne "None") {
if ($testBorder -ne "None") {
$RenderableObject.Border.GetType().Name | Should -BeLike "*$testBorder*"
}
if($testColor) {
if ($testColor) {
$RenderableObject.BorderStyle.Foreground.ToMarkup() | Should -Be $testColor
}

Expand Down Expand Up @@ -46,8 +46,7 @@ Describe "Format-SpectreTable" {
# i have no idea whats truncating LastWriteTime
# $defaultDisplayMembers.Properties.GetEnumerator().Name | Should -Be @("UnixMode", "User", "Group", "LastWriteTime", "Size", "Name")
$defaultDisplayMembers.keys | Should -Match 'UnixMode|User|Group|LastWrite|Size|Name'
}
else {
} else {
$defaultDisplayMembers.keys | Should -Be @("Mode", "LastWriteTime", "Length", "Name")
}
}
Expand Down Expand Up @@ -141,8 +140,7 @@ Describe "Format-SpectreTable" {
}
if ($IsLinux -or $IsMacOS) {
$verification.keys | Should -Match 'UnixMode|User|Group|LastWrite|Size|Name'
}
else {
} else {
$verification.keys | Should -Be $properties
}
Assert-MockCalled -CommandName "Write-AnsiConsole" -Times 1 -Exactly
Expand All @@ -165,7 +163,7 @@ Describe "Format-SpectreTable" {
$testBorder = 'Markdown'
$testColor = $null
Write-Debug "Setting testcolor to $testColor"
$testData | Format-SpectreTable ProcessName, @{Label="TotalRunningTime"; Expression={(Get-Date) - $_.StartTime}} -Border $testBorder
$testData | Format-SpectreTable ProcessName, @{Label = "TotalRunningTime"; Expression = { (Get-Date) - $_.StartTime } } -Border $testBorder
$testResult = $testConsole.Output
$obj = $testResult -split "\r?\n" | Select-Object -Skip 1 -SkipLast 2
$deconstructed = $obj -split '\|' | StripAnsi | ForEach-Object {
Expand All @@ -184,15 +182,15 @@ Describe "Format-SpectreTable" {
$testConsole.Write($RenderableObject)
}
[pscustomobject]@{
"Name" = "Test 1"
"Name" = "Test 1"
"Value" = 10
"Color" = "Turquoise2"
}, [pscustomobject]@{
"Name" = "Test 2"
"Name" = "Test 2"
"Value" = 20
"Color" = "#ff0000"
}, [pscustomobject]@{
"Name" = "Test 3"
"Name" = "Test 3"
"Value" = 30
"Color" = "Turquoise2"
} | Format-SpectreTable -Border "Rounded" -Color "Turquoise2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ Describe "Format-SpectreTree" {
$testConsole.Write($RenderableObject)
}
$testData = @{
Label = "Root"
Label = "Root"
Children = @(
@{
Label = "Child 1"
Label = "Child 1"
Children = @(
@{
Label = "Grandchild 1"
Label = "Grandchild 1"
Children = @(
@{
Label = "Great Grandchild 1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Describe "Read-SpectreConfirm" {
Mock Invoke-SpectrePromptAsync {
$Prompt | Should -BeOfType [Spectre.Console.TextPrompt[string]]
(Compare-Object -ReferenceObject $Prompt.Choices -DifferenceObject $choices) | Should -BeNullOrEmpty
if($testColor) {
if ($testColor) {
$Prompt.ChoicesStyle.Foreground.ToMarkup() | Should -Be $testColor
}
return $testDefaultAnswer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Describe "Read-SpectreMultiSelection" {
}

It "prompts with an object input and allows multiple selection" {
$itemsToBeSelectedNames = @("toBeSelected", "also to be selected")
$itemsToBeSelectedNames = @("toBeSelected", "also to be selected")
$itemToBeSelected = [PSCustomObject]@{ ColumnToSelectFrom = $itemsToBeSelectedNames[0]; Other = Get-RandomString }
$anotherItemToBeSelected = [PSCustomObject]@{ ColumnToSelectFrom = $itemsToBeSelectedNames[1]; Other = Get-RandomString }
Read-SpectreMultiSelection -Title $testTitle -ChoiceLabelProperty "ColumnToSelectFrom" -PageSize $testPageSize -Color $testColor -Choices @(
Expand Down
Loading

0 comments on commit ea1e475

Please sign in to comment.