-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.ps1
More file actions
107 lines (88 loc) · 2.97 KB
/
Copy pathinstall.ps1
File metadata and controls
107 lines (88 loc) · 2.97 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
param(
[switch]$DryRun
)
$ErrorActionPreference = "Stop"
$marketplaceName = "ryan-plugins"
$preferredPluginName = 'project-doctor@ryan-plugins'
$pluginSlug = "project-doctor"
$legacyPluginSlug = "project-dotcor"
$repoUrl = "https://github.com/Ryanabcraft/project-doctor-marketplace.git"
$codexDir = Join-Path $env:USERPROFILE ".codex"
$configPath = Join-Path $codexDir "config.toml"
$timestamp = Get-Date -Format "yyyyMMdd-HHmmss"
$backupPath = "$configPath.bak-$timestamp"
function Add-BlockIfMissing {
param(
[string]$Content,
[string]$Header,
[string]$Block
)
if ($Content -match [regex]::Escape($Header)) {
return $Content
}
if ([string]::IsNullOrWhiteSpace($Content)) {
return $Block.Trim() + [Environment]::NewLine
}
return $Content.TrimEnd() + [Environment]::NewLine + [Environment]::NewLine + $Block.Trim() + [Environment]::NewLine
}
function Get-EnabledProjectDoctorPlugin {
param([string]$Content)
$pattern = '(?ms)^\[plugins\."((?:project-doctor|project-dotcor)@[^"]+)"\]\s*enabled\s*=\s*true\s*$'
$matches = [regex]::Matches($Content, $pattern)
if ($matches.Count -gt 0) {
return $matches[0].Groups[1].Value
}
return $null
}
Write-Host ""
Write-Host "Project Doctor installer" -ForegroundColor Cyan
Write-Host "------------------------" -ForegroundColor Cyan
if (!(Test-Path -Path $codexDir)) {
Write-Host "Criando pasta: $codexDir"
if (!$DryRun) {
New-Item -ItemType Directory -Force -Path $codexDir | Out-Null
}
}
$current = ""
if (Test-Path -Path $configPath) {
$current = Get-Content -Raw -Path $configPath
Write-Host "Config encontrado: $configPath"
} else {
Write-Host "Config ainda nao existe, vou criar: $configPath"
}
$alreadyEnabledPlugin = Get-EnabledProjectDoctorPlugin -Content $current
if ($alreadyEnabledPlugin) {
Write-Host "Project Doctor ja esta instalado e ativado como: $alreadyEnabledPlugin" -ForegroundColor Green
Write-Host "Nao vou duplicar a entrada do plugin."
$updated = $current
} else {
$marketplaceBlock = @"
[marketplaces.$marketplaceName]
source_type = "git"
source = "$repoUrl"
"@
$pluginBlock = @"
[plugins."$preferredPluginName"]
enabled = true
"@
$updated = Add-BlockIfMissing -Content $current -Header "[marketplaces.$marketplaceName]" -Block $marketplaceBlock
$updated = Add-BlockIfMissing -Content $updated -Header "[plugins.`"$preferredPluginName`"]" -Block $pluginBlock
}
if ($updated -eq $current -and (Test-Path -Path $configPath)) {
Write-Host "Nenhuma alteracao necessaria." -ForegroundColor Green
} else {
if (Test-Path -Path $configPath) {
Write-Host "Backup: $backupPath"
if (!$DryRun) {
Copy-Item -Force -Path $configPath -Destination $backupPath
}
}
Write-Host "Atualizando config.toml..."
if (!$DryRun) {
Set-Content -Path $configPath -Value $updated -Encoding UTF8
}
}
Write-Host ""
Write-Host "Instalacao concluida." -ForegroundColor Green
Write-Host "Agora feche e abra o Codex, depois procure por Project Doctor em Plugins."
Write-Host ""