It's my first time to creating the batch script file. My question can be duplicate but I didn't find any question or solution which fulfils my requirement.
I need to create a batch script file on windows for changing the URL in min.js multiple files and one index.html file from the config.json file values.
For example, I have a JSON file:
{
"APIUrl": "http:\\service.test.com",
"BaseUrl": "http:\\www.test.com"
}
Now, I need to change "http:\service2.test.com" with APIUrl and "http:\www.test2.com" with BaseURL.
I found many solutions to find and replace the script for the batch file. But when I run the batch file it's removing the whole script from the min.js without replacing the URLs string.
Maybe the script logic was checking the end line and the min.js file script always written in a single line so replacing the text removing the whole script, it's just my thinking because of the end line script was written in the script.
I google and found below code from the StackOverflow and pasted it to batchscript.bat, but on run the batchscript.bat it is removing the whole script and just left the last line comment "//# sourceMappingURL=app.min.map" in the file. That's why I'm not posting this code.
@echo off
setlocal EnableExtensions DisableDelayedExpansion
set "search=<http://server/application/>0"
set "replace=<http://someurl.test.com>"
set "textFile=*.*.js"
set "rootDir=./js"
for /R "%rootDir%" %%j in ("%textFile%") do (
for /f "delims=" %%i in ('type "%%~j" ^& break ^> "%%~j"') do (
set "line=%%i"
setlocal EnableDelayedExpansion
set "line=!line:%search%=%replace%!"
>>"%%~j" echo(!line!
endlocal
)
)
endlocal
pause
For executing this you can take any ".min.js" file and find and replace the text from that file.