Skip to content

Commit d77dee7

Browse files
committed
Add retry mechanism and cleanup for failed dependency installations
- if cloning fails, should try to remove this .cwc/[cloned repo] directory and try once again - when `pnpm i` fails, remove all .cwc/[clone] folders, and run pruning, then try pnpm i once again - assess translations
1 parent 6641db1 commit d77dee7

2 files changed

Lines changed: 95 additions & 20 deletions

File tree

‎install.ps1‎

Lines changed: 62 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ $msg_step_install="Installing to"
4949
$msg_vsix_error="VSIX file was not generated."
5050
$msg_install_fail="Failed to install to"
5151
$msg_success="Successfully installed to"
52+
$msg_deps_retry="Dependency installation failed. Cleaning up and retrying..."
5253

5354
switch -Regex ($lang) {
5455
"^pl" {
@@ -68,6 +69,7 @@ switch -Regex ($lang) {
6869
$msg_vsix_error="Plik VSIX nie został wygenerowany."
6970
$msg_install_fail="Nie udało się zainstalować w"
7071
$msg_success="Pomyślnie zainstalowano w"
72+
$msg_deps_retry="Instalacja zależności nie powiodła się. Czyszczenie i ponawianie próby..."
7173
break
7274
}
7375
"^zh-(tw|hk)" {
@@ -87,6 +89,7 @@ switch -Regex ($lang) {
8789
$msg_vsix_error="未產生 VSIX 檔案。"
8890
$msg_install_fail="無法安裝至"
8991
$msg_success="成功安裝至"
92+
$msg_deps_retry="依賴套件安裝失敗。正在清理並重試..."
9093
break
9194
}
9295
"^zh" {
@@ -106,6 +109,7 @@ switch -Regex ($lang) {
106109
$msg_vsix_error="未生成 VSIX 文件。"
107110
$msg_install_fail="未能安装到"
108111
$msg_success="成功安装到"
112+
$msg_deps_retry="依赖安装失败。正在清理并重试..."
109113
break
110114
}
111115
"^ja" {
@@ -125,6 +129,7 @@ switch -Regex ($lang) {
125129
$msg_vsix_error="VSIXファイルが生成されませんでした。"
126130
$msg_install_fail="インストールに失敗しました:"
127131
$msg_success="正常にインストールされました:"
132+
$msg_deps_retry="依存関係のインストールに失敗しました。クリーンアップして再試行中..."
128133
break
129134
}
130135
"^de" {
@@ -144,6 +149,7 @@ switch -Regex ($lang) {
144149
$msg_vsix_error="VSIX-Datei wurde nicht generiert."
145150
$msg_install_fail="Fehler bei der Installation in"
146151
$msg_success="Erfolgreich installiert in"
152+
$msg_deps_retry="Fehler bei der Installation der Abhängigkeiten. Aufräumen und erneuter Versuch..."
147153
break
148154
}
149155
"^es" {
@@ -163,6 +169,7 @@ switch -Regex ($lang) {
163169
$msg_vsix_error="No se generó el archivo VSIX."
164170
$msg_install_fail="Fallo al instalar en"
165171
$msg_success="Instalado correctamente en"
172+
$msg_deps_retry="La instalación de dependencias falló. Limpiando y reintentando..."
166173
break
167174
}
168175
"^fr" {
@@ -182,6 +189,7 @@ switch -Regex ($lang) {
182189
$msg_vsix_error="Le fichier VSIX n'a pas été généré."
183190
$msg_install_fail="Échec de l'installation sur"
184191
$msg_success="Installé avec succès sur"
192+
$msg_deps_retry="L'installation des dépendances a échoué. Nettoyage et nouvelle tentative..."
185193
break
186194
}
187195
"^pt" {
@@ -201,6 +209,7 @@ switch -Regex ($lang) {
201209
$msg_vsix_error="O arquivo VSIX não foi gerado."
202210
$msg_install_fail="Falha ao instalar no"
203211
$msg_success="Instalado com sucesso no"
212+
$msg_deps_retry="A instalação das dependências falhou. Limpando e tentando novamente..."
204213
break
205214
}
206215
"^ru" {
@@ -220,6 +229,7 @@ switch -Regex ($lang) {
220229
$msg_vsix_error="Файл VSIX не был сгенерирован."
221230
$msg_install_fail="Не удалось установить в"
222231
$msg_success="Успешно установлено в"
232+
$msg_deps_retry="Сбой установки зависимостей. Очистка и повторная попытка..."
223233
break
224234
}
225235
"^ko" {
@@ -239,6 +249,7 @@ switch -Regex ($lang) {
239249
$msg_vsix_error="VSIX 파일이 생성되지 않았습니다."
240250
$msg_install_fail="설치 실패:"
241251
$msg_success="성공적으로 설치되었습니다:"
252+
$msg_deps_retry="종속성 설치에 실패했습니다. 정리 및 재시도 중..."
242253
break
243254
}
244255
"^it" {
@@ -258,6 +269,7 @@ switch -Regex ($lang) {
258269
$msg_vsix_error="Il file VSIX non è stato generato."
259270
$msg_install_fail="Installazione non riuscita su"
260271
$msg_success="Installato con successo su"
272+
$msg_deps_retry="Installazione delle dipendenze non riuscita. Pulizia e nuovo tentativo..."
261273
break
262274
}
263275
"^tr" {
@@ -277,6 +289,7 @@ switch -Regex ($lang) {
277289
$msg_vsix_error="VSIX dosyası oluşturulmadı."
278290
$msg_install_fail="Şuraya kurulum başarısız:"
279291
$msg_success="Şuraya başarıyla kuruldu:"
292+
$msg_deps_retry="Bağımlılık yüklemesi başarısız oldu. Temizleniyor ve yeniden deneniyor..."
280293
break
281294
}
282295
"^cs" {
@@ -285,7 +298,7 @@ switch -Regex ($lang) {
285298
$msg_node_required="Nepodařilo se najít kompatibilní verzi Node.js a žádný podporovaný správce verzí (fnm, nvm) ji nedokázal přepnout."
286299
$msg_no_editors="Ve vaší proměnné PATH nebyly nalezeny žádné podporované editory."
287300
$msg_invalid="Neplatná volba. Ukončování."
288-
$msg_all_editors="Všechny zjištěěné editory"
301+
$msg_all_editors="Všechny zjištěné editory"
289302
$msg_quit="Ukončit"
290303
$msg_select_install="Vyberte, kam nainstalovat CWC: "
291304
$msg_cancelled="Instalace zrušena."
@@ -296,6 +309,7 @@ switch -Regex ($lang) {
296309
$msg_vsix_error="Soubor VSIX nebyl vygenerován."
297310
$msg_install_fail="Nepodařilo se nainstalovat do"
298311
$msg_success="Úspěšně nainstalováno do"
312+
$msg_deps_retry="Instalace závislostí selhala. Probíhá čištění a nový pokus..."
299313
break
300314
}
301315
"^hu" {
@@ -315,6 +329,7 @@ switch -Regex ($lang) {
315329
$msg_vsix_error="A VSIX fájl nem jött létre."
316330
$msg_install_fail="Nem sikerült telepíteni ide:"
317331
$msg_success="Sikeresen telepítve ide:"
332+
$msg_deps_retry="A függőségek telepítése sikertelen. Tisztítás és újrapróbálkozás..."
318333
break
319334
}
320335
"^bg" {
@@ -334,6 +349,7 @@ switch -Regex ($lang) {
334349
$msg_vsix_error="VSIX файлът не бе създаден."
335350
$msg_install_fail="Неуспешно инсталиране в"
336351
$msg_success="Успешно инсталирано в"
352+
$msg_deps_retry="Инсталирането на зависимостите е неуспешно. Почистване и нов опит..."
337353
break
338354
}
339355
}
@@ -445,6 +461,27 @@ $originalLocation = Get-Location
445461

446462
$cwcDir = Join-Path $env:USERPROFILE ".cwc"
447463

464+
function Clone-Repo {
465+
git clone -c core.longpaths=true --quiet https://github.com/CodeWebChat/CWC.git $repoDir *>$null
466+
if ($LASTEXITCODE -ne 0) {
467+
if (Test-Path $repoDir) {
468+
Remove-Item -Path $repoDir -Recurse -Force -ErrorAction SilentlyContinue
469+
}
470+
git clone -c core.longpaths=true --quiet https://github.com/CodeWebChat/CWC.git $repoDir *>$null
471+
if ($LASTEXITCODE -ne 0) { throw "Failed to clone" }
472+
}
473+
if ($tagName) {
474+
git -C $repoDir checkout $tagName --quiet *>$null
475+
if ($LASTEXITCODE -ne 0) { throw "Failed to checkout" }
476+
} else {
477+
$latestTag = git -C $repoDir tag -l '*-vscode' --sort=-creatordate | Select-Object -First 1
478+
if ($latestTag) {
479+
git -C $repoDir checkout $latestTag --quiet *>$null
480+
if ($LASTEXITCODE -ne 0) { throw "Failed to checkout latest tag" }
481+
}
482+
}
483+
}
484+
448485
try {
449486

450487
if (!(Test-Path $cwcDir)) {
@@ -488,26 +525,36 @@ foreach ($i in $indices) {
488525
Remove-Item -Path $repoDir -Recurse -Force -ErrorAction SilentlyContinue
489526
}
490527
$null = Invoke-Step "$msg_step_cloning..." {
491-
git clone -c core.longpaths=true --quiet https://github.com/CodeWebChat/CWC.git $repoDir *>$null
492-
if ($LASTEXITCODE -ne 0) { throw "Failed to clone" }
493-
if ($tagName) {
494-
git -C $repoDir checkout $tagName --quiet *>$null
495-
if ($LASTEXITCODE -ne 0) { throw "Failed to checkout" }
496-
} else {
497-
$latestTag = git -C $repoDir tag -l '*-vscode' --sort=-creatordate | Select-Object -First 1
498-
if ($latestTag) {
499-
git -C $repoDir checkout $latestTag --quiet *>$null
500-
if ($LASTEXITCODE -ne 0) { throw "Failed to checkout latest tag" }
501-
}
502-
}
528+
Clone-Repo
503529
} $msg_step_cloning
504530
}
505531

506532
Set-Location $repoDir
507533

508-
$null = Invoke-Step "$msg_step_deps..." {
534+
$depsOk = Invoke-Step "$msg_step_deps..." {
509535
npx.cmd --yes pnpm install *>$null
510-
} $msg_step_deps
536+
}
537+
538+
if (-not $depsOk) {
539+
Write-Host " $msg_deps_retry" -ForegroundColor Yellow
540+
Set-Location $cwcDir
541+
Get-ChildItem -Path $cwcDir -Filter "repository-*" -Directory | Remove-Item -Recurse -Force -ErrorAction SilentlyContinue
542+
543+
$prevPreference = $ErrorActionPreference
544+
$ErrorActionPreference = "Continue"
545+
try { npx.cmd --yes pnpm store prune *>$null } catch {}
546+
$ErrorActionPreference = $prevPreference
547+
548+
$null = Invoke-Step "$msg_step_cloning..." {
549+
Clone-Repo
550+
} $msg_step_cloning
551+
552+
Set-Location $repoDir
553+
554+
$null = Invoke-Step "$msg_step_deps..." {
555+
npx.cmd --yes pnpm install *>$null
556+
} $msg_step_deps
557+
}
511558

512559
Set-Location apps/editor
513560

‎install.sh‎

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ msg_step_install="Installing to"
3232
msg_vsix_error="VSIX file was not generated."
3333
msg_install_fail="Failed to install to"
3434
msg_success="Successfully installed to"
35+
msg_deps_retry="Dependency installation failed. Cleaning up and retrying..."
3536

3637
case "$LANGUAGE" in
3738
pl*)
@@ -53,6 +54,7 @@ case "$LANGUAGE" in
5354
msg_vsix_error="Plik VSIX nie został wygenerowany."
5455
msg_install_fail="Nie udało się zainstalować w"
5556
msg_success="Pomyślnie zainstalowano w"
57+
msg_deps_retry="Instalacja zależności nie powiodła się. Czyszczenie i ponawianie próby..."
5658
;;
5759
zh-tw* | zh-hk*)
5860
msg_error="錯誤:"
@@ -73,6 +75,7 @@ case "$LANGUAGE" in
7375
msg_vsix_error="未產生 VSIX 檔案。"
7476
msg_install_fail="無法安裝至"
7577
msg_success="成功安裝至"
78+
msg_deps_retry="依賴套件安裝失敗。正在清理並重試..."
7679
;;
7780
zh*)
7881
msg_error="错误:"
@@ -93,6 +96,7 @@ case "$LANGUAGE" in
9396
msg_vsix_error="未生成 VSIX 文件。"
9497
msg_install_fail="未能安装到"
9598
msg_success="成功安装到"
99+
msg_deps_retry="依赖安装失败。正在清理并重试..."
96100
;;
97101
ja*)
98102
msg_error="エラー:"
@@ -113,6 +117,7 @@ case "$LANGUAGE" in
113117
msg_vsix_error="VSIXファイルが生成されませんでした。"
114118
msg_install_fail="インストールに失敗しました:"
115119
msg_success="正常にインストールされました:"
120+
msg_deps_retry="依存関係のインストールに失敗しました。クリーンアップして再試行中..."
116121
;;
117122
de*)
118123
msg_error="Fehler:"
@@ -133,6 +138,7 @@ case "$LANGUAGE" in
133138
msg_vsix_error="VSIX-Datei wurde nicht generiert."
134139
msg_install_fail="Fehler bei der Installation in"
135140
msg_success="Erfolgreich installiert in"
141+
msg_deps_retry="Fehler bei der Installation der Abhängigkeiten. Aufräumen und erneuter Versuch..."
136142
;;
137143
es*)
138144
msg_error="Error:"
@@ -153,6 +159,7 @@ case "$LANGUAGE" in
153159
msg_vsix_error="No se generó el archivo VSIX."
154160
msg_install_fail="Fallo al instalar en"
155161
msg_success="Instalado correctamente en"
162+
msg_deps_retry="La instalación de dependencias falló. Limpiando y reintentando..."
156163
;;
157164
fr*)
158165
msg_error="Erreur :"
@@ -173,6 +180,7 @@ case "$LANGUAGE" in
173180
msg_vsix_error="Le fichier VSIX n'a pas été généré."
174181
msg_install_fail="Échec de l'installation sur"
175182
msg_success="Installé avec succès sur"
183+
msg_deps_retry="L'installation des dépendances a échoué. Nettoyage et nouvelle tentative..."
176184
;;
177185
pt*)
178186
msg_error="Erro:"
@@ -193,6 +201,7 @@ case "$LANGUAGE" in
193201
msg_vsix_error="O arquivo VSIX não foi gerado."
194202
msg_install_fail="Falha ao instalar no"
195203
msg_success="Instalado com sucesso no"
204+
msg_deps_retry="A instalação das dependências falhou. Limpando e tentando novamente..."
196205
;;
197206
ru*)
198207
msg_error="Ошибка:"
@@ -213,6 +222,7 @@ case "$LANGUAGE" in
213222
msg_vsix_error="Файл VSIX не был сгенерирован."
214223
msg_install_fail="Не удалось установить в"
215224
msg_success="Успешно установлено в"
225+
msg_deps_retry="Сбой установки зависимостей. Очистка и повторная попытка..."
216226
;;
217227
ko*)
218228
msg_error="오류:"
@@ -233,6 +243,7 @@ case "$LANGUAGE" in
233243
msg_vsix_error="VSIX 파일이 생성되지 않았습니다."
234244
msg_install_fail="설치 실패:"
235245
msg_success="성공적으로 설치되었습니다:"
246+
msg_deps_retry="종속성 설치에 실패했습니다. 정리 및 재시도 중..."
236247
;;
237248
it*)
238249
msg_error="Errore:"
@@ -253,6 +264,7 @@ case "$LANGUAGE" in
253264
msg_vsix_error="Il file VSIX non è stato generato."
254265
msg_install_fail="Installazione non riuscita su"
255266
msg_success="Installato con successo su"
267+
msg_deps_retry="Installazione delle dipendenze non riuscita. Pulizia e nuovo tentativo..."
256268
;;
257269
tr*)
258270
msg_error="Hata:"
@@ -273,6 +285,7 @@ case "$LANGUAGE" in
273285
msg_vsix_error="VSIX dosyası oluşturulmadı."
274286
msg_install_fail="Şuraya kurulum başarısız:"
275287
msg_success="Şuraya başarıyla kuruldu:"
288+
msg_deps_retry="Bağımlılık yüklemesi başarısız oldu. Temizleniyor ve yeniden deneniyor..."
276289
;;
277290
cs*)
278291
msg_error="Chyba:"
@@ -282,7 +295,7 @@ case "$LANGUAGE" in
282295
msg_invalid="Neplatná volba. Ukončování."
283296
msg_hint="Tip: Pokud je váš editor nainstalován, ale není uveden v seznamu, možná budete muset přidat jeho příkaz do PATH."
284297
msg_hint2="Otevřete svůj editor, otevřete Paletu příkazů (Ctrl+Shift+P / Cmd+Shift+P) a najděte příkaz jako: \"Shell Command: Install 'cursor' command in PATH\" (nebo 'agy-ide' atd.)."
285-
msg_all_editors="Všechny zjištěěné editory"
298+
msg_all_editors="Všechny zjištěné editory"
286299
msg_quit="Ukončit"
287300
msg_select_install="Vyberte, kam nainstalovat CWC: "
288301
msg_cancelled="Instalace zrušena."
@@ -293,6 +306,7 @@ case "$LANGUAGE" in
293306
msg_vsix_error="Soubor VSIX nebyl vygenerován."
294307
msg_install_fail="Nepodařilo se nainstalovat do"
295308
msg_success="Úspěšně nainstalováno do"
309+
msg_deps_retry="Instalace závislostí selhala. Probíhá čištění a nový pokus..."
296310
;;
297311
hu*)
298312
msg_error="Hiba:"
@@ -313,6 +327,7 @@ case "$LANGUAGE" in
313327
msg_vsix_error="A VSIX fájl nem jött létre."
314328
msg_install_fail="Nem sikerült telepíteni ide:"
315329
msg_success="Sikeresen telepítve ide:"
330+
msg_deps_retry="A függőségek telepítése sikertelen. Tisztítás és újrapróbálkozás..."
316331
;;
317332
bg*)
318333
msg_error="Грешка:"
@@ -333,6 +348,7 @@ case "$LANGUAGE" in
333348
msg_vsix_error="VSIX файлът не бе създаден."
334349
msg_install_fail="Неуспешно инсталиране в"
335350
msg_success="Успешно инсталирано в"
351+
msg_deps_retry="Инсталирането на зависимостите е неуспешно. Почистване и нов опит..."
336352
;;
337353
esac
338354

@@ -497,13 +513,17 @@ update_repo() {
497513
}
498514

499515
clone_repo() {
500-
git clone -c core.longpaths=true --quiet https://github.com/CodeWebChat/CWC.git "$REPO_DIR" && \
516+
if ! git clone -c core.longpaths=true --quiet https://github.com/CodeWebChat/CWC.git "$REPO_DIR"; then
517+
rm -rf "$REPO_DIR"
518+
git clone -c core.longpaths=true --quiet https://github.com/CodeWebChat/CWC.git "$REPO_DIR" || return 1
519+
fi
520+
501521
if [ -n "$TAG_NAME" ]; then
502-
git -C "$REPO_DIR" checkout "$TAG_NAME" --quiet
522+
git -C "$REPO_DIR" checkout "$TAG_NAME" --quiet || return 1
503523
else
504524
LATEST_TAG=$(git -C "$REPO_DIR" tag -l '*-vscode' --sort=-creatordate | head -n 1)
505525
if [ -n "$LATEST_TAG" ]; then
506-
git -C "$REPO_DIR" checkout "$LATEST_TAG" --quiet
526+
git -C "$REPO_DIR" checkout "$LATEST_TAG" --quiet || return 1
507527
fi
508528
fi
509529
}
@@ -535,7 +555,15 @@ for i in "${indices[@]}"; do
535555

536556
cd "$REPO_DIR"
537557

538-
run_step "$msg_step_deps" npx --yes pnpm install
558+
if ! run_step "$msg_step_deps" npx --yes pnpm install; then
559+
echo -e " \033[33m$msg_deps_retry\033[0m"
560+
cd "$CWC_DIR"
561+
rm -rf "$CWC_DIR"/repository-*
562+
npx --yes pnpm store prune > /dev/null 2>&1 || true
563+
run_step "$msg_step_cloning" clone_repo
564+
cd "$REPO_DIR"
565+
run_step "$msg_step_deps" npx --yes pnpm install
566+
fi
539567

540568
cd apps/editor
541569

0 commit comments

Comments
 (0)