-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathx.ps1
More file actions
129 lines (108 loc) · 4.44 KB
/
x.ps1
File metadata and controls
129 lines (108 loc) · 4.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# This file is generated by gen-x.sh. Do not change it directly.
param(
[Parameter(Position=0)]
[ValidateSet("test", "format", "debug", "loc")]
[string]$Command
)
switch ($Command) {
"test" {
Write-Output "Building module..."
Write-Output ""
Set-Location examples\test
spacetime publish --server local spacetimedsl
Write-Output ""
Write-Output "Testing module..."
Write-Output ""
spacetime call --server local spacetimedsl tester
Write-Output ""
Write-Output "Showing logs..."
Write-Output ""
spacetime logs --server local spacetimedsl
Write-Output ""
Write-Output "Cleaning up module..."
Write-Output ""
spacetime delete --server local spacetimedsl
Write-Output ""
Set-Location ..\..
}
"format" {
cargo fmt --all -- --check
Set-Location derive
cargo clippy --fix --allow-dirty --all-features
Set-Location ..\examples\test
cargo clippy --fix --allow-dirty --all-features
Set-Location ..\blackholio
cargo clippy --fix --allow-dirty --all-features
Set-Location ..\..
}
"debug" {
Set-Location examples\test
$env:RUSTFLAGS = "-Zmacro-backtrace"
cargo +nightly expand > ..\..\debug-helper\output\lib.expanded.rs
Set-Location ..\..\debug-helper
cargo run -- ..\examples\test\src\lib.rs > output\lib.rs.ast
Set-Location ..
}
"loc" {
# Get all .rs files recursively from the current directory
$files = Get-ChildItem -Path . -Filter "*.rs" -Recurse -File | Where-Object {
$_.FullName -like "*\src\*"
} | ForEach-Object {
# Count lines in each file
$lineCount = (Get-Content $_.FullName | Measure-Object -Line).Lines
# Create a custom object with line count and relative path
$relativePath = $_.FullName.Replace("$PWD\", "")
$firstDir = $relativePath.Split('\')[0]
$pathWithoutFirstDir = $relativePath.Substring($firstDir.Length + 1)
# Remove 'src\' prefix if present
if ($pathWithoutFirstDir.StartsWith("src\")) {
$pathWithoutFirstDir = $pathWithoutFirstDir.Substring(4)
}
# Extract second directory (first segment after removing first dir and src)
$secondDir = if ($pathWithoutFirstDir.Contains('\')) {
$pathWithoutFirstDir.Split('\')[0]
} else {
""
}
[PSCustomObject]@{
Lines = $lineCount
Path = $relativePath
FirstDir = $firstDir
SecondDir = $secondDir
PathWithoutFirstDir = $pathWithoutFirstDir
}
} | Sort-Object -Property FirstDir, SecondDir, @{Expression = {$_.Lines}; Descending = $true}
# Find the maximum line count length for padding
$maxLineLength = ($files | ForEach-Object { $_.Lines.ToString().Length } | Measure-Object -Maximum).Maximum
# Print with aligned paths, grouped by first directory
$currentGroup = $null
$files | ForEach-Object {
# Print group header when directory changes
if ($currentGroup -ne $_.FirstDir) {
if ($currentGroup -ne $null) {
Write-Output ""
}
Write-Output "$($_.FirstDir):"
$currentGroup = $_.FirstDir
}
# Print in the format: {lines_of_code} {path_without_first_dir} with padding
$paddedLines = $_.Lines.ToString().PadLeft($maxLineLength)
Write-Output "$paddedLines $($_.PathWithoutFirstDir)"
}
# Sum lines for src, derive-input, derive
$total = ($files | Where-Object { $_.FirstDir -in @("src", "derive-input", "derive") } | Measure-Object -Property Lines -Sum).Sum
Write-Output "Total: $total"
# Add final newline
Write-Output ""
}
default {
Write-Output "Usage: .\x.ps1 {test|format|debug|loc}"
Write-Output ""
Write-Output "Commands:"
Write-Output " test - Build, test, show logs, and clean up the module"
Write-Output " format - Run cargo fmt check and clippy fixes"
Write-Output " debug - Expand macros and generate AST output"
Write-Output " loc - Count lines of Rust code grouped by directory"
exit 1
}
}