From 4ec633c0e1536d8f254b08e2eac0f4f3198d9270 Mon Sep 17 00:00:00 2001 From: Artem Kuznetsov Date: Tue, 1 Aug 2023 15:52:50 +0300 Subject: [PATCH] =?UTF-8?q?feat:=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D1=8B=20=D1=81=D0=BA=D1=80=D0=B8=D0=BF=D1=82=D1=8B?= =?UTF-8?q?=20=D0=B4=D0=BB=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D1=8B=20?= =?UTF-8?q?=D1=81=20watchman=20=D0=B8=20=D0=BF=D1=80=D0=B8=D0=BC=D0=B5?= =?UTF-8?q?=D1=80=D1=8B.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- wmscripts/convert.cmd | 51 +++++++++++++++ wmscripts/settrigger.cmd | 112 +++++++++++++++++++++++++++++++++ wmscripts/trigger_example.json | 21 +++++++ wmscripts/watch_example.json | 1 + 4 files changed, 185 insertions(+) create mode 100644 wmscripts/convert.cmd create mode 100644 wmscripts/settrigger.cmd create mode 100644 wmscripts/trigger_example.json create mode 100644 wmscripts/watch_example.json diff --git a/wmscripts/convert.cmd b/wmscripts/convert.cmd new file mode 100644 index 0000000..5e26999 --- /dev/null +++ b/wmscripts/convert.cmd @@ -0,0 +1,51 @@ +@ECHO OFF + +SETLOCAL ENABLEDELAYEDEXPANSION + +chcp 65001 + +set ERROR_CODE=0 + +set CONVERT_SCRIPT=%1 +IF defined CONVERT_SCRIPT set CONVERT_SCRIPT=%CONVERT_SCRIPT:"=% +IF not defined CONVERT_SCRIPT ( + echo [ERROR] Missed parameter 1 - "path to conversion script file (could be 1C converter script name or full path to script file)" + set ERROR_CODE=1 +) +IF not exist "%CONVERT_SCRIPT%" ( + FOR /F "usebackq tokens=1 delims=" %%i IN (`FORFILES /P "%~dp0.." /M "scripts" /C "cmd /c echo @path"`) DO set CONVERT_SCRIPT_PATH=%%i + echo [WARN] Script file "%CONVERT_SCRIPT%" doesn't exist ^(parameter 4^). Trying to find in "!CONVERT_SCRIPT_PATH!" directory. + set CONVERT_SCRIPT_PATH=!CONVERT_SCRIPT_PATH:"=! + set CONVERT_SCRIPT=!CONVERT_SCRIPT_PATH!\%WCONVERT_SCRIPT%.cmd +) +IF not exist "%CONVERT_SCRIPT%" ( + echo [ERROR] Script file "%CONVERT_SCRIPT%" doesn't exist ^(parameter 1^). + set ERROR_CODE=1 +) +set CONVERT_SRC_PATH=%2 +IF defined CONVERT_SRC_PATH set CONVERT_SRC_PATH=%CONVERT_SRC_PATH:"=% +IF not defined CONVERT_SRC_PATH ( + echo [ERROR] Missed parameter 1 - "path to convertion source" + set ERROR_CODE=1 +) ELSE ( + IF not exist "%CONVERT_SRC_PATH%" ( + echo [ERROR] Path "%CONVERT_SRC_PATH%" doesn't exist ^(parameter 2^). + set ERROR_CODE=1 + ) +) + +set CONVERT_DST_PATH=%3 +IF defined CONVERT_DST_PATH set CONVERT_DST_PATH=%CONVERT_DST_PATH:"=% +IF not defined CONVERT_DST_PATH ( + echo [ERROR] Missed parameter 3 - "output path to save conversion results" + set ERROR_CODE=1 +) +IF not exist "%CONVERT_DST_PATH%" md "%CONVERT_DST_PATH%" + +FOR /F "tokens=*" %%a in ('more') do ( + set CURRENT_FILE=%%a + set CURRENT_FILE=!CURRENT_FILE:^/=^\! + set RELATIVE_PATH=!CURRENT_FILE:%%~nxa=! + set RELATIVE_PATH=!RELATIVE_PATH:~0,-1! + call "%CONVERT_SCRIPT%" "%CONVERT_SRC_PATH%\!CURRENT_FILE!" "%CONVERT_DST_PATH%\!RELATIVE_PATH!" +) diff --git a/wmscripts/settrigger.cmd b/wmscripts/settrigger.cmd new file mode 100644 index 0000000..0a4e2bf --- /dev/null +++ b/wmscripts/settrigger.cmd @@ -0,0 +1,112 @@ +@ECHO OFF + +SETLOCAL ENABLEDELAYEDEXPANSION + +set ERROR_CODE=0 + +IF not defined WATCH_TOOL ( + FOR /F "usebackq tokens=1 delims=" %%i IN (`where watchman`) DO ( + set WATCH_TOOL="%%i" + ) +) +IF not exist %WATCH_TOOL% ( + echo [ERROR] Can't find "watchman" tool add path to "watchman.exe" to "PATH" environment variable, or set fool specified path to "WATCH_TOOL" variable + set ERROR_CODE=1 +) + +set ARG=%1 +IF defined ARG set ARG=%ARG:"=% +IF "%ARG%" neq "" set TRIGGER_NAME=%ARG% +IF not defined TRIGGER_NAME ( + echo [ERROR] Missed parameter 1 - "watchman trigger name" + set ERROR_CODE=1 +) + +set ARG=%2 +IF defined ARG set ARG=%ARG:"=% +IF "%ARG%" neq "" set WATCH_PATH=%ARG% +IF not defined WATCH_PATH ( + echo [ERROR] Missed parameter 2 - "path to watched root" + set ERROR_CODE=1 +) ELSE ( + IF not exist "%WATCH_PATH%" ( + echo [ERROR] Path "%WATCH_PATH%" doesn't exist ^(parameter 2^). + set ERROR_CODE=1 + ) +) + +set ARG=%3 +IF defined ARG set ARG=%ARG:"=% +IF "%ARG%" neq "" set WATCH_FILES=%ARG% +IF not defined WATCH_FILES ( + echo [ERROR] Missed parameter 4 - "files extension to watch for" + set ERROR_CODE=1 +) +IF "%WATCH_FILES%" equ "1cdpr" ( + set WATCH_FILES=epf erf +) ELSE IF "%WATCH_FILES%" equ "1cxml" ( + set WATCH_FILES=xml bsl bin mxl png grs geo txt +) ELSE IF "%WATCH_FILES%" equ "1cedt" ( + set WATCH_FILES=mdo bsl bin mxl png grs geo txt +) + +set ARG=%4 +IF defined ARG set ARG=%ARG:"=% +IF "%ARG%" neq "" set WATCH_SCRIPT=%ARG% +IF not defined WATCH_SCRIPT ( + echo [ERROR] Missed parameter 2 - "path to triggered script file (could be 1C converter script name or full path to script file)" + set ERROR_CODE=1 +) +IF not exist "%WATCH_SCRIPT%" ( + FOR /F "usebackq tokens=1 delims=" %%i IN (`FORFILES /P "%~dp0.." /M "scripts" /C "cmd /c echo @path"`) DO set WATCH_SCRIPT_PATH=%%i + echo [WARN] Script file "%WATCH_SCRIPT%" doesn't exist ^(parameter 4^). Trying to find in "!WATCH_SCRIPT_PATH!" directory. + set WATCH_SCRIPT_PATH=!WATCH_SCRIPT_PATH:"=! + set WATCH_SCRIPT=!WATCH_SCRIPT_PATH!\%WATCH_SCRIPT%.cmd +) +IF not exist "%WATCH_SCRIPT%" ( + echo [ERROR] Script file "%WATCH_SCRIPT%" doesn't exist ^(parameter 4^). + set ERROR_CODE=1 +) + +set ARG=%5 +IF defined ARG set ARG=%ARG:"=% +IF "%ARG%" neq "" set WATCH_OUT_PATH=%ARG% +IF not defined WATCH_OUT_PATH ( + echo [ERROR] Missed parameter 5 - "output path to save script results" + set ERROR_CODE=1 +) +IF not exist "%WATCH_OUT_PATH%" md "%WATCH_OUT_PATH%" + +IF %ERROR_CODE% neq 0 ( + echo === + echo [ERROR] Input parameters error. Expected: + echo %%1 - watchman trigger name + echo %%2 - path to watched root + echo %%3 - files masks to watch for, devided by spaces or one of extension set name: + echo 1cdpr - 1C dataprocessors ^& reports binaries + echo 1cxml - 1C configuration, extension, dataprocessors or reports in 1C:Designer XML format + echo 1cedt - 1C configuration, extension, dataprocessors or reports in 1C:EDT project + echo %%4 - path to triggered script file ^(could be 1C converter script name or full path to script file^) + echo %%5 - output path to save script results + echo. + exit /b %ERROR_CODE% +) + +set WATCH_JSON=["watch", "%WATCH_PATH:\=\\%"] +echo %WATCH_JSON% | %WATCH_TOOL% -j + +set TRIGGER_EXPRESSION=["anyof" +FOR %%i IN (%WATCH_FILES%) DO ( + set TRIGGER_EXPRESSION=!TRIGGER_EXPRESSION!,["imatch","*.%%i"] +) +set TRIGGER_EXPRESSION=!TRIGGER_EXPRESSION!] + +set TRIGGER_SCRIPT=%~dp0convert.cmd +set TRIGGER_COMMAND=["%TRIGGER_SCRIPT:\=\\%", "%WATCH_SCRIPT:\=\\%", "%WATCH_PATH:\=\\%", "%WATCH_OUT_PATH:\=\\%"] + +set TRIGGER_STDIN="NAME_PER_LINE" +set TRIGGER_STDOUT=, "stdout": "%TRIGGER_STDOUT%" ^>D:\\Repo\\1CFilesConverters\\out\\output.txt + +set TRIGGER_JSON=["trigger", "%WATCH_PATH:\=\\%", ^{"name": "%TRIGGER_NAME%", "expression": %TRIGGER_EXPRESSION%, "command": %TRIGGER_COMMAND%, "stdin": %TRIGGER_STDIN%, "stdout": "%TRIGGER_STDOUT%"^}] + +echo %TRIGGER_JSON% | %WATCH_TOOL% -j \ No newline at end of file diff --git a/wmscripts/trigger_example.json b/wmscripts/trigger_example.json new file mode 100644 index 0000000..e9c1f22 --- /dev/null +++ b/wmscripts/trigger_example.json @@ -0,0 +1,21 @@ +[ + "trigger", + "\\ext", + { + "name": "myEPFTrigger", + "expression": [ + "anyof", + [ + "imatch", + "*.epf" + ] + ], + "command": [ + "convert.cmd", + "dp2xml", + "\\ext", + "\\src\\ext" + ], + "stdin": "NAME_PER_LINE" + } +] \ No newline at end of file diff --git a/wmscripts/watch_example.json b/wmscripts/watch_example.json new file mode 100644 index 0000000..e643e58 --- /dev/null +++ b/wmscripts/watch_example.json @@ -0,0 +1 @@ +["watch", ".\D:\\Repo\\1CFilesConverters\\out\\231_dp2epf_xml2epf"] \ No newline at end of file