-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdeploy.ps1
More file actions
190 lines (159 loc) · 5.82 KB
/
deploy.ps1
File metadata and controls
190 lines (159 loc) · 5.82 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
<#
.SYNOPSIS
Compila y despliega el plugin Claudian para Obsidian.
.DESCRIPTION
Script de PowerShell para compilar y desplegar el plugin de Obsidian.
Equivalente a deploy.sh para sistemas Windows.
.PARAMETER Source
Ruta del proyecto (por defecto: directorio actual)
.PARAMETER Destination
Ruta de la carpeta del plugin en la boveda de Obsidian
.PARAMETER Dev
Compilar en modo desarrollo (muestra todos los logs en consola)
.EXAMPLE
.\deploy.ps1 -Destination "C:\Users\User\MiBoveda\.obsidian\plugins\claudian"
.EXAMPLE
.\deploy.ps1 -Source "." -Destination "D:\Obsidian\Vault\.obsidian\plugins\claudian" -Dev
.EXAMPLE
.\deploy.ps1 -Destination "$env:USERPROFILE\Documents\Obsidian\.obsidian\plugins\claudian"
#>
[CmdletBinding()]
param(
[Parameter(Position = 0)]
[string]$Source = ".",
[Parameter(Position = 1)]
[string]$Destination = "",
[Parameter()]
[Alias("d")]
[switch]$Dev
)
# Configurar encoding para caracteres especiales
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
# Funcion para escribir con colores
function Write-ColorOutput {
param(
[string]$Message,
[string]$ForegroundColor = "White"
)
Write-Host $Message -ForegroundColor $ForegroundColor
}
function Write-Step {
param(
[string]$Step,
[string]$Message,
[string]$Extra = ""
)
Write-Host "[$Step] " -ForegroundColor Yellow -NoNewline
Write-Host $Message -NoNewline
if ($Extra) {
Write-Host " $Extra" -ForegroundColor Cyan
} else {
Write-Host ""
}
}
function Write-Success {
param([string]$Message)
Write-Host " " -NoNewline
Write-Host "[OK]" -ForegroundColor Green -NoNewline
Write-Host " $Message"
}
function Write-Error {
param([string]$Message)
Write-Host " " -NoNewline
Write-Host "[X]" -ForegroundColor Red -NoNewline
Write-Host " $Message"
}
# Validar directorio origen
$SourcePath = Resolve-Path -Path $Source -ErrorAction SilentlyContinue
if (-not $SourcePath) {
Write-ColorOutput "Error: El directorio origen no existe: $Source" -ForegroundColor Red
exit 1
}
# Cambiar al directorio origen
Push-Location $SourcePath
try {
# Verificar que es un proyecto valido
if (-not (Test-Path "package.json") -or -not (Test-Path "manifest.json")) {
Write-ColorOutput "Error: No se encontro package.json o manifest.json en $SourcePath" -ForegroundColor Red
exit 1
}
# Header
Write-Host ""
Write-ColorOutput "================================================" -ForegroundColor Blue
Write-ColorOutput " Claudian - Deploy Script (PowerShell)" -ForegroundColor Blue
Write-ColorOutput "================================================" -ForegroundColor Blue
Write-Host ""
# Paso 1: Compilar
if ($Dev) {
Write-Step "1/3" "Compilando plugin" "(DESARROLLO)"
Write-Host " -> Logs de debug habilitados" -ForegroundColor Cyan
npm run dev
} else {
Write-Step "1/3" "Compilando plugin" "(PRODUCCION)"
npm run build
}
if ($LASTEXITCODE -ne 0) {
Write-ColorOutput "Error: La compilacion fallo." -ForegroundColor Red
exit 1
}
if (-not (Test-Path "dist/main.js")) {
Write-ColorOutput "Error: La compilacion fallo. No se encontro dist/main.js" -ForegroundColor Red
exit 1
}
Write-Success "Compilacion exitosa"
Write-Host ""
# Paso 2: Verificar archivos generados
Write-Step "2/3" "Verificando archivos..."
$requiredFiles = @("main.js", "manifest.json", "styles.css")
$allFilesExist = $true
foreach ($file in $requiredFiles) {
$filePath = "dist/$file"
if (Test-Path $filePath) {
$size = (Get-Item $filePath).Length
$sizeFormatted = if ($size -gt 1KB) { "{0:N1} KB" -f ($size / 1KB) } else { "$size B" }
Write-Success "$file ($sizeFormatted)"
} else {
Write-Error "$file no encontrado"
$allFilesExist = $false
}
}
if (-not $allFilesExist) {
exit 1
}
Write-Host ""
# Paso 3: Copiar a destino (si se especifico)
if ($Destination) {
Write-Step "3/3" "Desplegando a: $Destination"
# Crear directorio destino si no existe
if (-not (Test-Path $Destination)) {
New-Item -ItemType Directory -Path $Destination -Force | Out-Null
}
# Copiar archivos
Copy-Item "dist/main.js" -Destination $Destination -Force
Copy-Item "dist/manifest.json" -Destination $Destination -Force
Copy-Item "dist/styles.css" -Destination $Destination -Force
Write-Success "Archivos copiados exitosamente"
Write-Host ""
Write-ColorOutput "================================================" -ForegroundColor Green
if ($Dev) {
Write-Host " Deploy completado " -ForegroundColor Green -NoNewline
Write-Host "(DESARROLLO)" -ForegroundColor Cyan
Write-Host " Logs de debug visibles en consola (F12)" -ForegroundColor Cyan
} else {
Write-ColorOutput " Deploy completado (PRODUCCION)" -ForegroundColor Green
}
Write-ColorOutput " Recarga Obsidian (Ctrl+R)" -ForegroundColor Green
Write-ColorOutput "================================================" -ForegroundColor Green
} else {
Write-Step "3/3" "Sin destino especificado. Archivos listos en dist/"
Write-Host ""
Write-ColorOutput "Para desplegar manualmente, copia los archivos de dist/ a:" -ForegroundColor Blue
Write-Host " <tu-boveda>\.obsidian\plugins\claudian\"
Write-Host ""
Write-ColorOutput "O ejecuta con destino:" -ForegroundColor Blue
Write-Host " .\deploy.ps1 -Destination 'C:\ruta\a\boveda\.obsidian\plugins\claudian'"
}
} finally {
# Volver al directorio original
Pop-Location
}