Skip to content

Commit

Permalink
Use dl.deno.land; Don't use already used version; Misc improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkTiedemann committed Aug 8, 2021
1 parent bf91bfd commit 9844c6b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

## Installation

Put `dvm.cmd` into a directory in your `%Path%`, e.g. `C:\bin`:
Put `dvm.cmd` into a directory in your `%path%`, e.g. `C:\bin`:

```batch
curl -Lo C:\bin\dvm.cmd https://github.com/MarkTiedemann/dvm.cmd/releases/download/0.7/dvm.cmd
curl -Lo C:\bin\dvm.cmd https://github.com/MarkTiedemann/dvm.cmd/releases/download/0.8/dvm.cmd
```

## Usage
Expand Down
35 changes: 20 additions & 15 deletions dvm.cmd
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@echo off
setlocal enabledelayedexpansion

set dvm_version=0.7
set dvm_version=0.8
set "dvm_script=%~f0"
set "dvm_script_dir=%~dp0"
set "dvm_root=%appdata%\dvm"
Expand Down Expand Up @@ -98,7 +98,7 @@ exit /b 0

:install
if [%2] equ [] (
for /f "delims=/ tokens=6" %%v in ('"curl -s https://github.com/denoland/deno/releases | findstr \/denoland/deno/releases/download/.*/deno-x86_64-pc-windows-msvc.zip | findstr /n . | findstr ^1:"') do (
for /f %%v in ('curl -s https://dl.deno.land/release-latest.txt') do (
call :download _ %%v
call :use _ %%v
)
Expand All @@ -110,12 +110,12 @@ exit /b 0

:download
if [%2] equ [] (
for /f "delims=/ tokens=6" %%v in ('"curl -s https://github.com/denoland/deno/releases | findstr \/denoland/deno/releases/download/.*/deno-x86_64-pc-windows-msvc.zip | findstr /n . | findstr ^1:"') do (
for /f %%v in ('curl -s https://dl.deno.land/release-latest.txt') do (
if exist "%dvm_root%\deno-%%v.exe" (
echo Deno %%v is already downloaded
) else (
echo Downloading Deno %%v
curl -Lo "%dvm_root%\deno-%%v.zip" https://github.com/denoland/deno/releases/download/%%v/deno-x86_64-pc-windows-msvc.zip
curl -o "%dvm_root%\deno-%%v.zip" https://dl.deno.land/release/%%v/deno-x86_64-pc-windows-msvc.zip
tar xf "%dvm_root%\deno-%%v.zip" -C "%dvm_root%"
del "%dvm_root%\deno-%%v.zip"
ren "%dvm_root%\deno.exe" deno-%%v.exe
Expand All @@ -126,7 +126,7 @@ if [%2] equ [] (
echo Deno %2 is already downloaded
) else (
echo Downloading Deno %2
curl -Lo "%dvm_root%\deno-%2.zip" https://github.com/denoland/deno/releases/download/%2/deno-x86_64-pc-windows-msvc.zip
curl -o "%dvm_root%\deno-%2.zip" https://dl.deno.land/release/%2/deno-x86_64-pc-windows-msvc.zip
tar xf "%dvm_root%\deno-%2.zip" -C "%dvm_root%"
del "%dvm_root%\deno-%2.zip"
ren "%dvm_root%\deno.exe" deno-%2.exe
Expand All @@ -142,11 +142,17 @@ if [%2] equ [] (
echo Deno %2 cannot be used since it is not downloaded
exit /b 1
) else (
if exist "%dvm_script_dir%deno.exe" (
del "%dvm_script_dir%deno.exe"
for /f %%v in ('deno eval -p Deno.version.deno') do (
if v%%v equ %2 (
echo Deno %2 is already in use
) else (
if exist "%dvm_script_dir%deno.exe" (
del "%dvm_script_dir%deno.exe"
)
mklink "%dvm_script_dir%deno.exe" "%dvm_root%\deno-%2.exe" > nul
echo Using Deno %2
)
)
mklink "%dvm_script_dir%deno.exe" "%dvm_root%\deno-%2.exe" > nul
echo Using Deno %2
)
)
exit /b 0
Expand All @@ -165,13 +171,12 @@ for /f "delims=/ tokens=6" %%v in ('"curl -s https://github.com/denoland/deno/re
exit /b 0

:clean-up
for /f "tokens=2" %%v in ('deno -V') do (
for /f %%v in ('deno eval -p Deno.version.deno') do (
for %%f in ("%dvm_root%\*") do (
if deno-v%%v neq %%~nf (
set "file_wo_ext=%%~nf"
set "version=!file_wo_ext:~5!"
echo Deleting Deno !version!
del "%dvm_root%\%%~nf.exe"
if deno-v%%v.exe neq %%~nf%%~xf (
set file=%%~nf
echo Deleting Deno !file:~5!
del "%%~ff"
)
)
)
Expand Down

0 comments on commit 9844c6b

Please sign in to comment.