-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGet-ProjectInfo.ps1
More file actions
217 lines (181 loc) · 7.51 KB
/
Copy pathGet-ProjectInfo.ps1
File metadata and controls
217 lines (181 loc) · 7.51 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
<#
.SYNOPSIS
Detect and display project type and information.
.DESCRIPTION
Detects the project type (Node/React, PHP/Laravel, Perl, Python)
and shows relevant information like dependencies, scripts, and structure.
.PARAMETER Path
Path to project directory (defaults to current directory).
.PARAMETER AsJson
Output as JSON for MCP tools.
.EXAMPLE
proj
proj C:\Dev\myapp
proj -AsJson
#>
[CmdletBinding()]
param(
[Parameter(Position = 0)]
[string]$Path = '.',
[switch]$AsJson
)
$Path = Resolve-Path $Path -ErrorAction SilentlyContinue
if (-not $Path) {
Write-Host "Path not found" -ForegroundColor Red
exit 1
}
$info = [ordered]@{
name = Split-Path $Path -Leaf
path = $Path.ToString()
type = 'Unknown'
framework = $null
version = $null
scripts = @()
dependencies = 0
devDependencies = 0
hasGit = Test-Path "$Path\.git"
hasTests = $false
hasDocker = (Test-Path "$Path\Dockerfile") -or (Test-Path "$Path\docker-compose.yml")
}
# Detect Node.js / React
if (Test-Path "$Path\package.json") {
$pkg = Get-Content "$Path\package.json" -Raw | ConvertFrom-Json -ErrorAction SilentlyContinue
$info.type = 'Node.js'
$info.name = $pkg.name
$info.version = $pkg.version
# Detect framework
if ($pkg.dependencies.react -or $pkg.devDependencies.react) {
$info.framework = 'React'
if ($pkg.dependencies.next -or $pkg.devDependencies.next) { $info.framework = 'Next.js' }
} elseif ($pkg.dependencies.vue -or $pkg.devDependencies.vue) {
$info.framework = 'Vue'
if ($pkg.dependencies.nuxt -or $pkg.devDependencies.nuxt) { $info.framework = 'Nuxt' }
} elseif ($pkg.dependencies.express) {
$info.framework = 'Express'
} elseif ($pkg.dependencies.'@nestjs/core') {
$info.framework = 'NestJS'
}
# Count dependencies
$info.dependencies = if ($pkg.dependencies) { ($pkg.dependencies | Get-Member -MemberType NoteProperty).Count } else { 0 }
$info.devDependencies = if ($pkg.devDependencies) { ($pkg.devDependencies | Get-Member -MemberType NoteProperty).Count } else { 0 }
# Get scripts
if ($pkg.scripts) {
$info.scripts = $pkg.scripts | Get-Member -MemberType NoteProperty | Select-Object -ExpandProperty Name
}
# Check for tests
$info.hasTests = (Test-Path "$Path\tests") -or (Test-Path "$Path\__tests__") -or
(Test-Path "$Path\test") -or ($info.scripts -contains 'test')
}
# Detect PHP / Laravel / Symfony
elseif (Test-Path "$Path\composer.json") {
$composer = Get-Content "$Path\composer.json" -Raw | ConvertFrom-Json -ErrorAction SilentlyContinue
$info.type = 'PHP'
$info.name = $composer.name
# Detect framework
if (Test-Path "$Path\artisan") {
$info.framework = 'Laravel'
# Get Laravel version
if ($composer.require.'laravel/framework') {
$info.version = $composer.require.'laravel/framework'
}
} elseif (Test-Path "$Path\symfony.lock") {
$info.framework = 'Symfony'
} elseif (Test-Path "$Path\wp-config.php") {
$info.framework = 'WordPress'
}
# Count dependencies
$info.dependencies = if ($composer.require) { ($composer.require | Get-Member -MemberType NoteProperty | Where-Object { $_.Name -ne 'php' }).Count } else { 0 }
$info.devDependencies = if ($composer.'require-dev') { ($composer.'require-dev' | Get-Member -MemberType NoteProperty).Count } else { 0 }
# Get scripts
if ($composer.scripts) {
$info.scripts = $composer.scripts | Get-Member -MemberType NoteProperty | Select-Object -ExpandProperty Name
}
# Check for tests
$info.hasTests = (Test-Path "$Path\tests") -or (Test-Path "$Path\phpunit.xml") -or (Test-Path "$Path\phpunit.xml.dist")
}
# Detect Perl
elseif ((Test-Path "$Path\Makefile.PL") -or (Test-Path "$Path\cpanfile")) {
$info.type = 'Perl'
# Try to get module name from Makefile.PL
if (Test-Path "$Path\Makefile.PL") {
$makefile = Get-Content "$Path\Makefile.PL" -Raw
if ($makefile -match "NAME\s*=>\s*'([^']+)'") {
$info.name = $Matches[1]
}
}
# Count dependencies from cpanfile
if (Test-Path "$Path\cpanfile") {
$cpanfile = Get-Content "$Path\cpanfile"
$info.dependencies = ($cpanfile | Where-Object { $_ -match '^\s*requires\s+' }).Count
$info.devDependencies = ($cpanfile | Where-Object { $_ -match '^\s*test_requires\s+' }).Count
}
# Check for tests
$info.hasTests = Test-Path "$Path\t"
$info.scripts = @('perl Makefile.PL', 'make', 'make test', 'make install')
}
# Detect Python
elseif ((Test-Path "$Path\requirements.txt") -or (Test-Path "$Path\pyproject.toml") -or (Test-Path "$Path\setup.py")) {
$info.type = 'Python'
# Detect framework
if (Test-Path "$Path\manage.py") {
$info.framework = 'Django'
} elseif ((Test-Path "$Path\app.py") -and (Get-Content "$Path\app.py" -Raw -ErrorAction SilentlyContinue) -match 'Flask') {
$info.framework = 'Flask'
} elseif (Test-Path "$Path\main.py") {
$main = Get-Content "$Path\main.py" -Raw -ErrorAction SilentlyContinue
if ($main -match 'FastAPI') { $info.framework = 'FastAPI' }
}
# Count dependencies
if (Test-Path "$Path\requirements.txt") {
$info.dependencies = (Get-Content "$Path\requirements.txt" | Where-Object { $_ -match '^[a-zA-Z]' }).Count
}
# Check for tests
$info.hasTests = (Test-Path "$Path\tests") -or (Test-Path "$Path\test") -or (Test-Path "$Path\pytest.ini")
$info.scripts = @('pip install -r requirements.txt', 'python main.py', 'pytest')
}
# JSON output
if ($AsJson) {
$info | ConvertTo-Json -Depth 5
exit 0
}
# Pretty output
Write-Host ""
Write-Host "Project: " -NoNewline -ForegroundColor Cyan
Write-Host $info.name -ForegroundColor Yellow
Write-Host ""
Write-Host " Type: " -NoNewline -ForegroundColor Gray
Write-Host $info.type -NoNewline -ForegroundColor White
if ($info.framework) {
Write-Host " / $($info.framework)" -ForegroundColor Green
} else {
Write-Host ""
}
if ($info.version) {
Write-Host " Version: " -NoNewline -ForegroundColor Gray
Write-Host $info.version -ForegroundColor White
}
Write-Host " Path: " -NoNewline -ForegroundColor Gray
Write-Host $info.path -ForegroundColor DarkGray
Write-Host ""
Write-Host " Dependencies: " -NoNewline -ForegroundColor Gray
Write-Host $info.dependencies -ForegroundColor White
Write-Host " Dev Dependencies: " -NoNewline -ForegroundColor Gray
Write-Host $info.devDependencies -ForegroundColor White
Write-Host ""
Write-Host " Git: " -NoNewline -ForegroundColor Gray
Write-Host $(if ($info.hasGit) { "Yes" } else { "No" }) -ForegroundColor $(if ($info.hasGit) { 'Green' } else { 'DarkGray' })
Write-Host " Tests: " -NoNewline -ForegroundColor Gray
Write-Host $(if ($info.hasTests) { "Yes" } else { "No" }) -ForegroundColor $(if ($info.hasTests) { 'Green' } else { 'DarkGray' })
Write-Host " Docker: " -NoNewline -ForegroundColor Gray
Write-Host $(if ($info.hasDocker) { "Yes" } else { "No" }) -ForegroundColor $(if ($info.hasDocker) { 'Green' } else { 'DarkGray' })
if ($info.scripts.Count -gt 0) {
Write-Host ""
Write-Host " Scripts:" -ForegroundColor Cyan
$info.scripts | Select-Object -First 8 | ForEach-Object {
Write-Host " - $_" -ForegroundColor White
}
if ($info.scripts.Count -gt 8) {
Write-Host " ... and $($info.scripts.Count - 8) more" -ForegroundColor DarkGray
}
}
Write-Host ""