Batch file to build in a click under windows

Batch file to build in a click under windows

Since I had to get the latest trunk version of jQuery for latest patch, I decided to re-adapt my work in progress "yuibompressor" to build in a click under windows via batch files.
<b>
jquery/modules.txt</b>
<span style="font-family: courier new,monospace;">intro.js</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">core.js</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">data.js</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">selector.js</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">traversing.js</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">attributes.js</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">manipulation.js</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">event.js</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">support.js</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">css.js</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">ajax.js</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">fx.js</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">offset.js</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">dimensions.js</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">outro.js</span>
Above file is basically the list of files to include to create a single version of jQuery, copy and paste into jquery folder and be sure that there are no spaces at the beginning or at the end (new lines as well)
To make the build possible we need the batch script:
<b>build.bat</b>
<span style="font-family: courier new,monospace;">@echo off</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">rem ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">rem ;; WebReflection YUI Compressor Batch Manager ;;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">rem ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">rem ;; your project name. will produce two files</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">rem ;; projectname.min.[js/css]</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">rem ;; projectname.debug.[js/css]</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">rem ;; debug version is a single big file not compressed</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">set YUI_BUILD_NAME=jquery-dev</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">rem ;; pause program execution or each main step [1/0]</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">set YUI_DEBUG=0</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">rem ;; specify the project type [js/css]</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">set YUI_TYPE=js</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">rem ;; where is yuicompressor-ver.jar</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">set YUI_FOLDER=build</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">rem ;; a txt file with a list of files to include in the project</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">rem ;; NOTE: the file order is preserved</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">rem ;; NOTE: if YUI_FOLDER_SOURCE is not set each file must have an absolute path</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">set YUI_FILE_LIST=modules.txt</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">rem ;; where to put min and debug version of the project</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">set YUI_FOLDER_DEST=dist</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">rem ;; where are files specified in the list</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">rem ;; NOTE: if files in the list have absolute path please remove this variable</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">rem ;;       writing "rem" instead of "set" as prefix</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">set YUI_FOLDER_SOURCE=src</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">rem ;; specify if you do not want to munge file (obfuscation)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">rem ;; NOTE: YUICompressor is a great tool but sometimes it could have some problem with munge option</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">set YUI_NO_MUNGE=1</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">rem ;; yuicompressor jar file version</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">rem ;; NOTE: this variable is used as yuicompressor-%YUI_COMPRESSOR_VERSION%.jar</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">rem ;;       please be sure that jar file respects this naming convention</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">rem ;; EXAMPLE: yuicompressor-2.4.2.jar</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">set YUI_COMPRESSOR_VERSION=2.4.2</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">rem ;; Set --no-mounge Only If Necessary</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">if "%YUI_NO_MUNGE%"=="1" (</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">    if "%YUI_TYPE%"=="js" set YUI_NOMUNGE=--nomunge</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    if not "%YUI_TYPE%"=="js" set YUI_NOMUNGE=</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">if not "%YUI_NO_MUNGE%"=="1" set YUI_NOMUNGE=</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">rem ;; Start Script Execution</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">goto show_summary</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">:build_minified_version</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    rem ;; After The Unique Big File Has Been Created Creates The Single Compressed One</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">    echo.</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    echo   Creating build</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">    echo.</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    java -jar "%YUI_FOLDER%\yuicompressor-%YUI_COMPRESSOR_VERSION%.jar" --charset=UTF-8 --type=%YUI_TYPE% %YUI_NOMUNGE% "%YUI_FOLDER%\full.%YUI_TYPE%" -o "%YUI_FOLDER%\min.%YUI_TYPE%"</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">    echo  ____________________________________</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    echo.</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">    if "%YUI_DEBUG%"=="1" pause>nul</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    goto copy_and_remove</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">:copy_and_remove</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    rem ;; Merge With An Header The Compressed File. Move Files Into Destination Folder</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">    echo.</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    echo   Copying and removing files</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">    echo.</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    echo./** %YUI_BUILD_NAME% - %DATE% %TIME% */>"%YUI_FOLDER%\%YUI_BUILD_NAME%.min.%YUI_TYPE%"</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">    TYPE "%YUI_FOLDER%\min.%YUI_TYPE%">>"%YUI_FOLDER%\%YUI_BUILD_NAME%.min.%YUI_TYPE%"</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    rem ;; NOTE: If Files Are Not Present This Command May Ask If It Is A File Or A Directory - Please Press F</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">    rem ;; NOTE: If Files Were Present This Command Forces Overwrites (In Visual Studio Solution Folders As Well)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    xcopy /Y /V /R /Q /Z "%YUI_FOLDER%\%YUI_BUILD_NAME%.min.%YUI_TYPE%" "%YUI_FOLDER_DEST%\%YUI_BUILD_NAME%.min.%YUI_TYPE%"</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">    xcopy /Y /V /R /Q /Z "%YUI_FOLDER%\full.%YUI_TYPE%" "%YUI_FOLDER_DEST%\%YUI_BUILD_NAME%.debug.%YUI_TYPE%"</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">    del "%YUI_FOLDER%\min.%YUI_TYPE%"</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    del "%YUI_FOLDER%\full.%YUI_TYPE%"</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">    del "%YUI_FOLDER%\%YUI_BUILD_NAME%.min.%YUI_TYPE%"</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    echo  ____________________________________</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">    echo.</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    if "%YUI_DEBUG%"=="1" pause>nul</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">    goto end_procedure</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">:end_procedure</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">    rem ;; Hopefully Everything Is OK - It Is Time To Exit</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    echo.</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">    echo   Done</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    echo  ____________________________________</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">    if "%YUI_DEBUG%"=="1" pause>nul</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    exit</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">:show_file_list_and_append_content</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    rem ;; Performs Checks For Each File In The List</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">    echo.</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    echo   File Analysis</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">    echo  ------------------------------------</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    for /f "delims=" %%G in (%YUI_FILE_LIST%) do (</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">        echo   %%G</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">        type "%YUI_FOLDER_SOURCE%\%%G">"%YUI_FOLDER%\tmp"</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">        if "%YUI_DEBUG%"=="1" (</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            if not "%%G"=="intro.js" (</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">                if not "%%G"=="outro.js" (</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">                    java -jar "%YUI_FOLDER%\yuicompressor-%YUI_COMPRESSOR_VERSION%.jar" --charset=UTF-8 --type=%YUI_TYPE% %YUI_NOMUNGE% "%YUI_FOLDER%\tmp" -o "%YUI_FOLDER%\tmp.min"</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">                    del "%YUI_FOLDER%\tmp.min"</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">                    if not "%errorlevel%"=="0" (</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">                        echo.Warning: Errors during compression</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">                        pause>nul</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">                        del "%YUI_FOLDER%\tmp"</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">                        exit</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">                    )</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">                )</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">            )</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">        )</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">        TYPE "%YUI_FOLDER%\tmp">>"%YUI_FOLDER%\full.%YUI_TYPE%"</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">        del "%YUI_FOLDER%\tmp"</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">    )</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    echo  ____________________________________</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">    echo.</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    if "%YUI_DEBUG%"=="1" pause>nul</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">    goto build_minified_version</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">:show_summary</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">    rem ;; Initial Screen Mit Style License Please Do Not Remove My Credits</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    echo  ____________________________________</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">    echo.</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    echo  (C) Andrea Giammarchi @WebReflection</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">    echo       YUI Batch Build System V 1.0</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    echo.</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">    echo  ------------------------------------</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    echo   %YUI_BUILD_NAME%</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">    echo  ------------------------------------</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    echo   Date         %DATE% %TIME%</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">    echo   Type         %YUI_TYPE%</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    echo   Place        %YUI_FOLDER%</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">    echo   Destination  %YUI_FOLDER_DEST%</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    echo   List         %YUI_FILE_LIST%</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">    if "%YUI_DEBUG%"=="1" (echo   Debug        ON)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    if not "%YUI_DEBUG%"=="1" (echo   Debug        OFF)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">    echo  ____________________________________</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    echo.</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">    if "%YUI_DEBUG%"=="1" pause>nul</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    goto show_file_list_and_append_content</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">rem ;; Enjoy Your Compressed File - Thank You YUICompressor</span>
The first time it could ask if destination file is a file or a directory, just press F.
Best Regards