-
Notifications
You must be signed in to change notification settings - Fork 15
/
cleanup.bat
185 lines (161 loc) · 4.52 KB
/
cleanup.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
@echo off
setlocal enabledelayedexpansion
if defined DEBUG ( set _DEBUG=1 ) else ( set _DEBUG=0 )
@rem #########################################################################
@rem ## Environment setup
set _EXITCODE=0
call :env
if not %_EXITCODE%==0 goto end
call :args %*
if not %_EXITCODE%==0 goto end
@rem #########################################################################
@rem ## Main
if %_HELP%==1 (
call :help
exit /b !_EXITCODE!
)
set _N=0
set "_DIR=%_ROOT_DIR%node_modules"
if exist "!_DIR!" (
if %_DEBUG%==1 ( echo %_DEBUG_LABEL% %_RIMRAF_CMD% "!_DIR!" 1>&2
) else if %_VERBOSE%==1 ( echo Delete directory "!_DIR:%_ROOT_DIR%=!" 1>&2
)
call "%_RIMRAF_CMD%" "!_DIR!"
set /a _N+=1
)
for %%i in (auth-passport locales-1 locales-2 webaudio-sample) do (
set "__DIR=%_ROOT_DIR%%%i\node_modules"
if exist "!__DIR!\" (
if %_DEBUG%==1 ( echo %_DEBUG_LABEL% "%_RIMRAF_CMD%" "!__DIR!" 1>&2
) else if %_VERBOSE%==1 ( echo Delete directory "!__DIR:%_ROOT_DIR%=!" 1>&2
)
call "%_RIMRAF_CMD%" "!__DIR!"
set /a _N+=1
)
)
if %_N% gtr 1 ( echo Removed %_N% directories
) else if %_N% gtr 0 ( echo Removed %_N% directory
) else if %_VERBOSE%==1 ( echo No directory 'node_modules' was found 1>&2
)
goto end
@rem #########################################################################
@rem ## Subroutines
@rem output parameters: _DEBUG_LABEL, _ERROR_LABEL, _WARNING_LABEL
:env
set _BASENAME=%~n0
set "_ROOT_DIR=%~dp0"
call :env_colors
set _DEBUG_LABEL=%_NORMAL_BG_CYAN%[%_BASENAME%]%_RESET%
set _ERROR_LABEL=%_STRONG_FG_RED%Error%_RESET%:
set _WARNING_LABEL=%_STRONG_FG_YELLOW%Warning%_RESET%:
set "_RIMRAF_CMD=%NODE_HOME%\rimraf.cmd"
if not exist "%_RIMRAF_CMD%" (
echo %_ERROR_LABEL% Command rimraf.cmd not found 1>&2
set _EXITCODE=1
goto :eof
)
goto :eof
:env_colors
@rem ANSI colors in standard Windows 10 shell
@rem see https://gist.github.com/mlocati/#file-win10colors-cmd
@rem normal foreground colors
set _NORMAL_FG_BLACK=[30m
set _NORMAL_FG_RED=[31m
set _NORMAL_FG_GREEN=[32m
set _NORMAL_FG_YELLOW=[33m
set _NORMAL_FG_BLUE=[34m
set _NORMAL_FG_MAGENTA=[35m
set _NORMAL_FG_CYAN=[36m
set _NORMAL_FG_WHITE=[37m
@rem normal background colors
set _NORMAL_BG_BLACK=[40m
set _NORMAL_BG_RED=[41m
set _NORMAL_BG_GREEN=[42m
set _NORMAL_BG_YELLOW=[43m
set _NORMAL_BG_BLUE=[44m
set _NORMAL_BG_MAGENTA=[45m
set _NORMAL_BG_CYAN=[46m
set _NORMAL_BG_WHITE=[47m
@rem strong foreground colors
set _STRONG_FG_BLACK=[90m
set _STRONG_FG_RED=[91m
set _STRONG_FG_GREEN=[92m
set _STRONG_FG_YELLOW=[93m
set _STRONG_FG_BLUE=[94m
set _STRONG_FG_MAGENTA=[95m
set _STRONG_FG_CYAN=[96m
set _STRONG_FG_WHITE=[97m
@rem strong background colors
set _STRONG_BG_BLACK=[100m
set _STRONG_BG_RED=[101m
set _STRONG_BG_GREEN=[102m
set _STRONG_BG_YELLOW=[103m
set _STRONG_BG_BLUE=[104m
@rem we define _RESET in last position to avoid crazy console output with type command
set _BOLD=[1m
set _UNDERSCORE=[4m
set _INVERSE=[7m
set _RESET=[0m
goto :eof
@rem input parameter: %*
:args
set _HELP=0
set _VERBOSE=0
set __N=0
:args_loop
set "__ARG=%~1"
if not defined __ARG goto args_done
if "%__ARG:~0,1%"=="-" (
@rem option
if "%__ARG%"=="-debug" ( set _DEBUG=1
) else if "%__ARG%"=="-verbose" ( set _VERBOSE=1
) else (
echo %_ERROR_LABEL% Unknown option "%__ARG%" 1>&2
set _EXITCODE=1
goto args_done
)
) else (
@rem subcommand
if "%__ARG%"=="help" ( set _HELP=1
) else (
echo %_ERROR_LABEL% Unknown subcommand "%__ARG%" 1>&2
set _EXITCODE=1
goto args_done
)
set /a __N+=1
)
shift
goto :args_loop
:args_done
if %_DEBUG%==1 (
echo %_DEBUG_LABEL% Options: _VERBOSE=%_VERBOSE% 1>&2
echo %_DEBUG_LABEL% Subcommands: _HELP=%_HELP% 1>&2
)
goto :eof
:help
if %_VERBOSE%==1 (
set __BEG_P=%_STRONG_FG_CYAN%
set __BEG_O=%_STRONG_FG_GREEN%
set __BEG_N=%_NORMAL_FG_YELLOW%
set __END=%_RESET%
) else (
set __BEG_P=
set __BEG_O=
set __BEG_N=
set __END=
)
echo Usage: %__BEG_O%%_BASENAME% { ^<option^> ^| ^<subcommand^> }%__END%
echo.
echo %__BEG_P%Options:%__END%
echo %__BEG_O%-debug%__END% print commands executed by this script
echo %__BEG_O%-verbose%__END% print progress messages
echo.
echo %__BEG_P%Subcommands:%__END%
echo %__BEG_O%help%__END% print this help message
goto :eof
@rem #########################################################################
@rem ## Cleanups
:end
if %_DEBUG%==1 echo %_DEBUG_LABEL% _EXITCODE=%_EXITCODE% 1>&2
exit /b %_EXITCODE%
endlocal