init-cursor: авто-bootstrap git на новом ПК, install.ps1 с Gitea.
Один вызов init-cursor настраивает SSH при необходимости и копирует rules в проект.
This commit is contained in:
+82
-23
@@ -1,47 +1,91 @@
|
||||
#Requires -Version 5.1
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Копирует Cursor rules из локального $HOME\CursorRules в текущий проект.
|
||||
Инициализация Cursor в текущем проекте; на новом ПК сначала настраивает git/SSH.
|
||||
|
||||
.DESCRIPTION
|
||||
Источник — локальный клон репозитория Rules ($HOME\CursorRules), не remote напрямую.
|
||||
На новом ПК сначала: bootstrap.ps1 / bootstrap.sh (SSH + clone Rules).
|
||||
Обновить правила из remote: init-cursor -Update
|
||||
Один вызов init-cursor:
|
||||
- если машина не настроена: SSH, Gitea keys, clone Rules в $HOME\CursorRules
|
||||
- затем копирует rules в текущий репозиторий и настраивает remotes
|
||||
|
||||
Первый запуск на голом ПК (из каталога проекта):
|
||||
irm https://git.kalinamall.ru/PapaTramp/Rules/raw/branch/main/install.ps1 | iex
|
||||
|
||||
.EXAMPLE
|
||||
cd C:\Users\papat\Projects\MyRepo
|
||||
init-cursor
|
||||
init-cursor -Update
|
||||
#>
|
||||
function init-cursor {
|
||||
function Get-CursorRulesDest {
|
||||
return (Join-Path $HOME 'CursorRules')
|
||||
}
|
||||
|
||||
function Get-CursorBootstrapRoot {
|
||||
param([string]$RulesDest)
|
||||
|
||||
$scriptRoot = $PSScriptRoot
|
||||
if (Test-Path (Join-Path $scriptRoot 'scripts\Invoke-MachineBootstrap.ps1')) {
|
||||
return $scriptRoot
|
||||
}
|
||||
if (Test-Path (Join-Path $RulesDest 'local\git-ssh-hosts.conf')) {
|
||||
return $RulesDest
|
||||
}
|
||||
if (Test-Path (Join-Path $scriptRoot 'local\git-ssh-hosts.conf')) {
|
||||
return $scriptRoot
|
||||
}
|
||||
return $null
|
||||
}
|
||||
|
||||
function Initialize-CursorRulesEnvironment {
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[switch]$SkipGitRemotes,
|
||||
[switch]$Update
|
||||
)
|
||||
|
||||
$source = Join-Path $HOME 'CursorRules'
|
||||
$rulesSrc = Join-Path $source '.cursor\rules'
|
||||
$scripts = Join-Path $source 'scripts'
|
||||
$rulesDest = Get-CursorRulesDest
|
||||
$bootstrapRoot = Get-CursorBootstrapRoot -RulesDest $rulesDest
|
||||
|
||||
if (-not (Test-Path $source)) {
|
||||
Write-Host "Error: $source not found — run bootstrap.ps1 on this machine first" -ForegroundColor Red
|
||||
return
|
||||
if (-not $bootstrapRoot) {
|
||||
Write-Host 'Error: CursorRules not found. Run install.ps1 from Gitea first:' -ForegroundColor Red
|
||||
Write-Host ' irm https://git.kalinamall.ru/PapaTramp/Rules/raw/branch/main/install.ps1 | iex' -ForegroundColor Yellow
|
||||
return $false
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
$bootstrapScript = Join-Path $bootstrapRoot 'scripts\Invoke-MachineBootstrap.ps1'
|
||||
if (-not (Test-Path -LiteralPath $bootstrapScript)) {
|
||||
Write-Host "Error: bootstrap script not found: $bootstrapScript" -ForegroundColor Red
|
||||
return $false
|
||||
}
|
||||
|
||||
$repoReady = Test-Path (Join-Path $rulesDest '.git')
|
||||
$skipClone = $repoReady
|
||||
|
||||
& $bootstrapScript -Root $bootstrapRoot -RulesDest $rulesDest -SkipClone:$skipClone
|
||||
|
||||
if ($Update -and $repoReady) {
|
||||
Write-Host '[*] Updating CursorRules from remote...' -ForegroundColor Cyan
|
||||
git -C $rulesDest pull --ff-only
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
Write-Host '[!] git pull failed in CursorRules' -ForegroundColor Yellow
|
||||
}
|
||||
else {
|
||||
Write-Host '[+] CursorRules updated' -ForegroundColor Green
|
||||
}
|
||||
}
|
||||
|
||||
return $true
|
||||
}
|
||||
|
||||
function Install-CursorInCurrentProject {
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[switch]$SkipGitRemotes
|
||||
)
|
||||
|
||||
$source = Get-CursorRulesDest
|
||||
$rulesSrc = Join-Path $source '.cursor\rules'
|
||||
$scripts = Join-Path $source 'scripts'
|
||||
|
||||
$cursorIgnore = Join-Path $source '.cursorignore'
|
||||
if (Test-Path $cursorIgnore) {
|
||||
Copy-Item $cursorIgnore . -Force
|
||||
@@ -83,7 +127,7 @@ function init-cursor {
|
||||
|
||||
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
|
||||
Write-Host '[!] Not a git repo - remotes skipped' -ForegroundColor Yellow
|
||||
return
|
||||
}
|
||||
|
||||
@@ -105,3 +149,18 @@ function init-cursor {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function init-cursor {
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[switch]$SkipGitRemotes,
|
||||
[switch]$Update
|
||||
)
|
||||
|
||||
if (-not (Initialize-CursorRulesEnvironment -Update:$Update)) {
|
||||
return
|
||||
}
|
||||
|
||||
Install-CursorInCurrentProject -SkipGitRemotes:$SkipGitRemotes
|
||||
Write-Host '[+] init-cursor complete' -ForegroundColor Green
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user