mirror of
https://github.com/arkuznetsov/1CFilesConverter.git
synced 2024-11-24 08:33:30 +02:00
feat: Добавлены скрипты для работы с watchman и примеры.
This commit is contained in:
parent
4bec2d92f7
commit
4ec633c0e1
51
wmscripts/convert.cmd
Normal file
51
wmscripts/convert.cmd
Normal file
@ -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!"
|
||||
)
|
112
wmscripts/settrigger.cmd
Normal file
112
wmscripts/settrigger.cmd
Normal file
@ -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
|
21
wmscripts/trigger_example.json
Normal file
21
wmscripts/trigger_example.json
Normal file
@ -0,0 +1,21 @@
|
||||
[
|
||||
"trigger",
|
||||
"<path to my repo>\\ext",
|
||||
{
|
||||
"name": "myEPFTrigger",
|
||||
"expression": [
|
||||
"anyof",
|
||||
[
|
||||
"imatch",
|
||||
"*.epf"
|
||||
]
|
||||
],
|
||||
"command": [
|
||||
"convert.cmd",
|
||||
"dp2xml",
|
||||
"<path to my repo>\\ext",
|
||||
"<path to my repo>\\src\\ext"
|
||||
],
|
||||
"stdin": "NAME_PER_LINE"
|
||||
}
|
||||
]
|
1
wmscripts/watch_example.json
Normal file
1
wmscripts/watch_example.json
Normal file
@ -0,0 +1 @@
|
||||
["watch", ".\D:\\Repo\\1CFilesConverters\\out\\231_dp2epf_xml2epf"]
|
Loading…
Reference in New Issue
Block a user