-
Notifications
You must be signed in to change notification settings - Fork 0
/
new.bat
101 lines (81 loc) · 2.09 KB
/
new.bat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
IF ERRORLEVEL 1 (
ECHO no delayed expansion!
GOTO FAULT
)
SET ROOT=%~dp0
REM strip trailing backslash:
SET ROOT=%ROOT:~0,-1%
IF /I x%1==xWDX (
SET PLUGIN_TYPE=WDX
GOTO GOT_TYPE
)
IF /I x%1==xWCX (
SET PLUGIN_TYPE=WCX
GOTO NYI
)
IF /I x%1==xWLX (
SET PLUGIN_TYPE=WLX
GOTO NYI
)
IF /I x%1==xWFX (
SET PLUGIN_TYPE=WFX
GOTO NYI
)
ECHO invalid plugin type "%1" - must be one of WDX, WCX, WLX or WFX
GOTO FAULT
:GOT_TYPE
SET PLUGIN_NAME=%2
IF x%PLUGIN_NAME%==x (
ECHO missing arg: plugin name
GOTO FAULT
)
:GOT_NAME
SET DUMMY=x%3
SET DESCRIPTION=%DUMMY:"=%
IF "%DESCRIPTION%"=="x" (
ECHO missing arg: one-line description ^(enclose in double-quotes^)
GOTO FAULT
)
SET TEMPLATES=%ROOT%\templates
SET PLUGIN_DIR=%ROOT%\example-plugins\%PLUGIN_NAME%.%PLUGIN_TYPE%
SET SRC=%PLUGIN_DIR%\src
SET DIST=%PLUGIN_DIR%\dist
IF EXIST "%ROOT%\example-plugins\%PLUGIN_NAME%*" (
ECHO plugin "%PLUGIN_NAME%" already exists ^("%PLUGIN_DIR%"^)
GOTO FAULT
)
REM TODO: check for valid plugin name (no spaces etc)
ECHO initializing %PLUGIN_TYPE% project %PLUGIN_NAME%: "%PLUGIN_DIR%"...
MKDIR "%PLUGIN_DIR%"
IF ERRORLEVEL 1 (
ECHO error creating dir %PLUGIN_DIR%
ECHO.
GOTO FAULT
)
REM strip leading x:
ECHO %DESCRIPTION:~1%>>"%PLUGIN_DIR%\description.txt"
type "%PLUGIN_DIR%\description.txt"
COPY "%TEMPLATES%\build.bat" "%PLUGIN_DIR%\"
MKDIR "%SRC%"
TYPE "%TEMPLATES%\%PLUGIN_TYPE%-0.java" >>"%SRC%\%PLUGIN_NAME%.java"
REM like ECHO but without newline:
<NUL SET /p dummyName=%PLUGIN_NAME%>>"%SRC%\%PLUGIN_NAME%.java"
TYPE templates\%PLUGIN_TYPE%-1.java >>"%SRC%\%PLUGIN_NAME%.java"
<NUL SET /p dummyName=%PLUGIN_NAME%>>"%SRC%\%PLUGIN_NAME%.java"
TYPE templates\%PLUGIN_TYPE%-2.java >>"%SRC%\%PLUGIN_NAME%.java"
MKDIR "%DIST%"
ECHO done.
ECHO(
ECHO Now let's build and run it on this file (%~nx0) and README.md:
ECHO `run.bat %PLUGIN_NAME% %PLUGIN_NAME% %~nx0 README.md`
ECHO(
CALL "%ROOT%\run.bat" %PLUGIN_NAME% %PLUGIN_NAME% %~nx0 README.md
:DONE
ENDLOCAL & EXIT /b 0
:FAULT
ENDLOCAL & EXIT /B 1
:NYI
ECHO sorry, %PLUGIN_TYPE% not yet supported.
GOTO FAULT