Skip to content

Commit 093ddf0

Browse files
committed
Refactor install scripts to clone, build, and install per editor using separate repository directories
- currently, multiple vscode-based editors can't be updated concurrently. You should clone into their own subdirectories.
1 parent 812354f commit 093ddf0

2 files changed

Lines changed: 82 additions & 74 deletions

File tree

‎install.ps1‎

Lines changed: 43 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -464,58 +464,64 @@ Write-Host ""
464464
$originalLocation = Get-Location
465465

466466
$cwcDir = Join-Path $env:USERPROFILE ".cwc"
467-
$repoDir = Join-Path $cwcDir "repository"
468467

469468
try {
470469

471470
if (!(Test-Path $cwcDir)) {
472471
New-Item -ItemType Directory -Path $cwcDir | Out-Null
473472
}
474473

475-
$updated = $false
476-
if (Test-Path (Join-Path $repoDir ".git")) {
477-
$updated = Invoke-Step "$msg_step_cloning..." {
478-
git -C $repoDir fetch origin main --quiet *>$null
479-
if ($LASTEXITCODE -ne 0) { throw "Failed to fetch" }
480-
git -C $repoDir reset --hard FETCH_HEAD --quiet *>$null
481-
if ($LASTEXITCODE -ne 0) { throw "Failed to reset" }
482-
git -C $repoDir clean -fd --quiet *>$null
483-
if ($LASTEXITCODE -ne 0) { throw "Failed to clean" }
484-
} $msg_step_cloning
485-
}
474+
$indices = if ($installAll) { 0..($availableEditors.Count - 1) } else { $selectedIndex }
475+
foreach ($i in $indices) {
476+
$editor = $availableEditors[$i]
477+
$repoDir = Join-Path $cwcDir "repository-$($editor.Scheme)"
486478

487-
if (-not $updated) {
488-
if (Test-Path $repoDir) {
489-
Remove-Item -Path $repoDir -Recurse -Force -ErrorAction SilentlyContinue
479+
if ($installAll) {
480+
Write-Host "`n=== $($editor.Name) ===" -ForegroundColor Cyan
490481
}
491-
$null = Invoke-Step "$msg_step_cloning..." {
492-
git clone -b main -c core.longpaths=true --quiet https://github.com/CodeWebChat/CWC.git $repoDir *>$null
493-
if ($LASTEXITCODE -ne 0) { throw "Failed to clone" }
494-
} $msg_step_cloning
495-
}
496482

497-
Set-Location $repoDir
483+
$updated = $false
484+
if (Test-Path (Join-Path $repoDir ".git")) {
485+
$updated = Invoke-Step "$msg_step_cloning..." {
486+
git -C $repoDir fetch origin main --quiet *>$null
487+
if ($LASTEXITCODE -ne 0) { throw "Failed to fetch" }
488+
git -C $repoDir reset --hard FETCH_HEAD --quiet *>$null
489+
if ($LASTEXITCODE -ne 0) { throw "Failed to reset" }
490+
git -C $repoDir clean -fd --quiet *>$null
491+
if ($LASTEXITCODE -ne 0) { throw "Failed to clean" }
492+
} $msg_step_cloning
493+
}
498494

499-
$null = Invoke-Step "$msg_step_deps..." {
500-
npx.cmd --yes pnpm install *>$null
501-
} $msg_step_deps
495+
if (-not $updated) {
496+
if (Test-Path $repoDir) {
497+
Remove-Item -Path $repoDir -Recurse -Force -ErrorAction SilentlyContinue
498+
}
499+
$null = Invoke-Step "$msg_step_cloning..." {
500+
git clone -b main -c core.longpaths=true --quiet https://github.com/CodeWebChat/CWC.git $repoDir *>$null
501+
if ($LASTEXITCODE -ne 0) { throw "Failed to clone" }
502+
} $msg_step_cloning
503+
}
502504

503-
Set-Location apps/editor
505+
Set-Location $repoDir
504506

505-
Remove-Item *.vsix -Force -ErrorAction SilentlyContinue
507+
$null = Invoke-Step "$msg_step_deps..." {
508+
npx.cmd --yes pnpm install *>$null
509+
} $msg_step_deps
506510

507-
$null = Invoke-Step "$msg_step_build..." {
508-
npx.cmd --yes pnpm run build *>$null
509-
} $msg_step_build
511+
Set-Location apps/editor
510512

511-
$vsixFile = Get-ChildItem *.vsix -ErrorAction SilentlyContinue | Select-Object -First 1
513+
Remove-Item *.vsix -Force -ErrorAction SilentlyContinue
512514

513-
if (!$vsixFile) {
514-
Fail $msg_vsix_error
515-
}
515+
$null = Invoke-Step "$msg_step_build..." {
516+
npx.cmd --yes pnpm run build *>$null
517+
} $msg_step_build
518+
519+
$vsixFile = Get-ChildItem *.vsix -ErrorAction SilentlyContinue | Select-Object -First 1
520+
521+
if (!$vsixFile) {
522+
Fail $msg_vsix_error
523+
}
516524

517-
function Install-ToEditor($idx) {
518-
$editor = $availableEditors[$idx]
519525
$ok = Invoke-Step "$msg_step_install $($editor.Name)..." {
520526
& $editor.Cmd --install-extension $vsixFile.FullName --force *>$null
521527
}
@@ -530,12 +536,9 @@ function Install-ToEditor($idx) {
530536
} else {
531537
Write-Host "$msg_error $msg_install_fail $($editor.Name)." -ForegroundColor Red
532538
}
533-
}
534539

535-
$indices = if ($installAll) { 0..($availableEditors.Count - 1) } else { $selectedIndex }
536-
foreach ($i in $indices) { Install-ToEditor $i }
537-
538-
Set-Location $originalLocation
540+
Set-Location $originalLocation
541+
}
539542

540543
} finally {
541544
Set-Location $originalLocation -ErrorAction SilentlyContinue

‎install.sh‎

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,6 @@ run_step() {
482482
echo ""
483483

484484
CWC_DIR="$HOME/.cwc"
485-
REPO_DIR="$CWC_DIR/repository"
486485

487486
mkdir -p -m 700 "$CWC_DIR"
488487
chmod 700 "$CWC_DIR" 2>/dev/null || true
@@ -497,55 +496,61 @@ clone_repo() {
497496
git clone -b main -c core.longpaths=true --quiet https://github.com/CodeWebChat/CWC.git "$REPO_DIR"
498497
}
499498

500-
if [ -d "$REPO_DIR/.git" ] && run_step "$msg_step_cloning" update_repo; then
501-
:
499+
if [[ "$choice" == [aA] ]]; then
500+
indices=("${!AVAILABLE_EDITORS[@]}")
502501
else
503-
rm -rf "$REPO_DIR"
504-
run_step "$msg_step_cloning" clone_repo
502+
indices=($((choice-1)))
505503
fi
506504

507-
cd "$REPO_DIR"
505+
for i in "${indices[@]}"; do
506+
editor_name="${AVAILABLE_EDITORS[$i]}"
507+
editor_cmd="${EDITOR_CMDS[$i]}"
508+
editor_scheme="${EDITOR_SCHEMES[$i]}"
508509

509-
run_step "$msg_step_deps" npx --yes pnpm install
510+
if [[ "$choice" == [aA] ]]; then
511+
echo -e "\n\033[36m=== $editor_name ===\033[0m"
512+
fi
510513

511-
cd apps/editor
514+
REPO_DIR="$CWC_DIR/repository-${editor_scheme}"
512515

513-
rm -f ./*.vsix
516+
if [ -d "$REPO_DIR/.git" ] && run_step "$msg_step_cloning" update_repo; then
517+
:
518+
else
519+
rm -rf "$REPO_DIR"
520+
run_step "$msg_step_cloning" clone_repo
521+
fi
514522

515-
run_step "$msg_step_build" npx --yes pnpm run build
523+
cd "$REPO_DIR"
516524

517-
vsix_files=(*.vsix)
518-
VSIX_FILE="${vsix_files[0]}"
525+
run_step "$msg_step_deps" npx --yes pnpm install
519526

520-
if [ ! -f "$VSIX_FILE" ]; then
521-
echo "$msg_error $msg_vsix_error"
522-
exit 1
523-
fi
527+
cd apps/editor
528+
529+
rm -f ./*.vsix
530+
531+
run_step "$msg_step_build" npx --yes pnpm run build
524532

525-
install_to_editor() {
526-
local idx=$1
527-
local editor_name="${AVAILABLE_EDITORS[$idx]}"
528-
local editor_cmd="${EDITOR_CMDS[$idx]}"
533+
vsix_files=(*.vsix)
534+
VSIX_FILE="${vsix_files[0]}"
535+
536+
if [ ! -f "$VSIX_FILE" ]; then
537+
echo "$msg_error $msg_vsix_error"
538+
exit 1
539+
fi
529540

530541
if ! run_step "$msg_step_install $editor_name" "$editor_cmd" --install-extension "$VSIX_FILE" --force; then
531542
echo ""
532543
echo "$msg_error $msg_install_fail $editor_name."
533-
return 1
534-
fi
535-
536-
echo ""
537-
if [ -n "$TARGET_SCHEME" ]; then
538-
echo "$msg_updated"
539544
else
540-
echo "$msg_success $editor_name!"
545+
echo ""
546+
if [ -n "$TARGET_SCHEME" ]; then
547+
echo "$msg_updated"
548+
else
549+
echo "$msg_success $editor_name!"
550+
fi
541551
fi
542-
}
543552

544-
if [[ "$choice" == [aA] ]]; then
545-
indices=("${!AVAILABLE_EDITORS[@]}")
546-
else
547-
indices=($((choice-1)))
548-
fi
549-
for i in "${indices[@]}"; do install_to_editor "$i"; done
553+
cd "$ORIGINAL_DIR"
554+
done
550555

551556
cd "$ORIGINAL_DIR" || cd /

0 commit comments

Comments
 (0)