@echo off
setlocal EnableExtensions DisableDelayedExpansion

echo.
echo JSPM allow list and block list update for RxSystem.com
echo.
pause

rem — Define target directory under the current user’s profile
set "JSPM_DIR=%USERPROFILE%\AppData\Local\.neodynamic\jspm"

rem — Bail out if the directory doesn’t exist
if not exist "%JSPM_DIR%\" (
  echo Directory not found: "%JSPM_DIR%"
  echo.
  echo No changes made.
  echo.
  pause
  exit /B 1
)

pushd "%JSPM_DIR%"

rem — Loop over both files
for %%F in (allow_list block_list) do (
  if exist "%%F" (
    echo.
    echo Cleaning %%F...
    rem — Use findstr to drop lines containing rxsystem.com or blank lines
    findstr /R /I /V /C:"rxsystem\.com" /C:"^$" "%%F" > "%%F.tmp"
    rem — Replace original with cleaned version
    move /Y "%%F.tmp" "%%F" >nul
  ) else (
    echo Skipping, file not found: %%F
  )
)

rem — Finally, append the entries to allow_list
if exist "allow_list" (
  >>"allow_list" echo rxsystem.com
  >>"allow_list" echo *.rxsystem.com
  echo.
  echo Added RxSystem.com to allow_list.
  echo.
  echo JSPM allow list update complete.
  echo.
  echo You may need to reboot ^(Restart^) your computer to make sure the setting got picked up properly for all users.
) else (
  echo.
  echo WARNING: allow_list file not found!
  echo.
)

popd
endlocal

echo.

pause
pause
