bdf405e2c1
SSH-ключи и Gitea API до clone Rules; init-cursor копирует из локального $HOME/CursorRules.
108 lines
3.8 KiB
PowerShell
108 lines
3.8 KiB
PowerShell
#Requires -Version 5.1
|
|
<#
|
|
.SYNOPSIS
|
|
Копирует Cursor rules из локального $HOME\CursorRules в текущий проект.
|
|
|
|
.DESCRIPTION
|
|
Источник — локальный клон репозитория Rules ($HOME\CursorRules), не remote напрямую.
|
|
На новом ПК сначала: bootstrap.ps1 / bootstrap.sh (SSH + clone Rules).
|
|
Обновить правила из remote: init-cursor -Update
|
|
|
|
.EXAMPLE
|
|
cd C:\Users\papat\Projects\MyRepo
|
|
init-cursor
|
|
init-cursor -Update
|
|
#>
|
|
function init-cursor {
|
|
[CmdletBinding()]
|
|
param(
|
|
[switch]$SkipGitRemotes,
|
|
[switch]$Update
|
|
)
|
|
|
|
$source = Join-Path $HOME 'CursorRules'
|
|
$rulesSrc = Join-Path $source '.cursor\rules'
|
|
$scripts = Join-Path $source 'scripts'
|
|
|
|
if (-not (Test-Path $source)) {
|
|
Write-Host "Error: $source not found — run bootstrap.ps1 on this machine first" -ForegroundColor Red
|
|
return
|
|
}
|
|
|
|
if ($Update) {
|
|
if (Test-Path (Join-Path $source '.git')) {
|
|
Write-Host '[*] Updating CursorRules from remote...' -ForegroundColor Cyan
|
|
git -C $source pull --ff-only
|
|
if ($LASTEXITCODE -ne 0) {
|
|
Write-Host '[!] git pull failed in CursorRules' -ForegroundColor Yellow
|
|
}
|
|
else {
|
|
Write-Host '[+] CursorRules updated' -ForegroundColor Green
|
|
}
|
|
}
|
|
}
|
|
|
|
$cursorIgnore = Join-Path $source '.cursorignore'
|
|
if (Test-Path $cursorIgnore) {
|
|
Copy-Item $cursorIgnore . -Force
|
|
Write-Host '[+] .cursorignore copied' -ForegroundColor Green
|
|
}
|
|
|
|
if (Test-Path $rulesSrc) {
|
|
New-Item -ItemType Directory -Path '.\.cursor\rules' -Force | Out-Null
|
|
Copy-Item (Join-Path $rulesSrc '*.mdc') '.\.cursor\rules\' -Force
|
|
Write-Host '[+] .cursor/rules (*.mdc) copied' -ForegroundColor Green
|
|
}
|
|
|
|
$gitIgnorePath = Join-Path (Get-Location) '.gitignore'
|
|
$ignoreLines = @('.cursor/', '.cursorignore')
|
|
if (Test-Path (Join-Path (Get-Location) '.git')) {
|
|
if (-not (Test-Path $gitIgnorePath)) {
|
|
Set-Content -Path $gitIgnorePath -Value ($ignoreLines -join "`n") -Encoding UTF8
|
|
Write-Host '[+] .gitignore created (.cursor/, .cursorignore)' -ForegroundColor Green
|
|
}
|
|
else {
|
|
$existing = Get-Content $gitIgnorePath -Raw
|
|
$added = @()
|
|
foreach ($line in $ignoreLines) {
|
|
if ($existing -notmatch "(?m)^$([regex]::Escape($line))\s*$") {
|
|
Add-Content -Path $gitIgnorePath -Value $line
|
|
$added += $line
|
|
}
|
|
}
|
|
if ($added.Count -gt 0) {
|
|
Write-Host "[+] .gitignore updated: $($added -join ', ')" -ForegroundColor Green
|
|
}
|
|
}
|
|
}
|
|
|
|
if ($SkipGitRemotes) {
|
|
Write-Host '[!] Git remotes skipped (-SkipGitRemotes)' -ForegroundColor Yellow
|
|
return
|
|
}
|
|
|
|
git rev-parse --is-inside-work-tree 2>$null | Out-Null
|
|
if ($LASTEXITCODE -ne 0) {
|
|
Write-Host '[!] Not a git repo — remotes skipped' -ForegroundColor Yellow
|
|
return
|
|
}
|
|
|
|
$setRemotes = Join-Path $scripts 'Set-GitRemotes.ps1'
|
|
if (Test-Path $setRemotes) {
|
|
Write-Host '[*] Configuring git remotes...' -ForegroundColor Cyan
|
|
& powershell -NoProfile -ExecutionPolicy Bypass -File $setRemotes
|
|
}
|
|
|
|
$ensureRepo = Join-Path $scripts 'Ensure-GiteaHomeRepo.ps1'
|
|
if (Test-Path $ensureRepo) {
|
|
$repoName = Split-Path -Leaf (git rev-parse --show-toplevel)
|
|
Write-Host "[*] Ensuring home Gitea repo: $repoName" -ForegroundColor Cyan
|
|
try {
|
|
& powershell -NoProfile -ExecutionPolicy Bypass -File $ensureRepo -RepoName $repoName
|
|
}
|
|
catch {
|
|
Write-Host "[!] home Gitea ensure failed: $($_.Exception.Message)" -ForegroundColor Yellow
|
|
}
|
|
}
|
|
}
|