@echo off
setlocal EnableExtensions
setlocal EnableDelayedExpansion
rem Versioner script v1 haha
rem How this works:
rem Call verisoner.bat file.ext, it will create file.ext.version.txt
rem This file contains the revision count for the day. Don't mess with it.
rem Deleting it resets the day's revisions to 1.
rem .
rem It will also search for the string "~VERSION~" and replace it with
rem YYYY.MM.DD.VVV, where VVV = number of times this script was called today.
rem .
rem Automatically resets to 1 on new day. Output is STDOUT, so use something like
rem versioner.bat myfile.work.js > myfile.js if myfile.work.js has ~VERSION~ to be replaced.
rem .
rem Note: This script was designed for use with the "YYYY-MM-DD" "Short Date" format option enabled in Windows
rem Using with other schemes (such as DD/MM/YYYY or MM/DD/YYYY) may not work as intended.
if NOT exist "%1" exit /B
set ztmp_file="%1.version.txt"
if NOT exist "%ztmp_file%" echo 0 > "%ztmp_file%"
if exist "%ztmp_file%" (
for %%a in (%ztmp_file%) do set ztmp_filedate=%%~ta
for /F "tokens=* USEBACKQ" %%a in (`date /T`) do set ztmp_todaysdate=%%a
set ztmp_filedate=!ztmp_filedate:~0,10!
set ztmp_todaysdate=!ztmp_todaysdate:~0,10!
if NOT !ztmp_filedate!==!ztmp_todaysdate! echo 0 > "%ztmp_file%"
for /F "tokens=* USEBACKQ" %%a in (%ztmp_file%) do set ztmp_revision=%%a
set /a ztmp_revision="!ztmp_revision!+1"
echo !ztmp_revision! > %ztmp_file%
set ztmp_todaysdate=!ztmp_todaysdate:-=.!
set ztmp_revision=00!ztmp_revision!
sed -e "s|~VERSION~|!ztmp_todaysdate!.!ztmp_revision:~-3!|g" %1
)
set "ztmp_file="
set "ztmp_filedate="
set "ztmp_todaysdate="
set "ztmp_filerevision="