/
init.bat
90 lines (73 loc) · 2.11 KB
/
init.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
@echo off
:: Script directory
SET scriptDir=%~dp0
:: Colored output support
SETLOCAL EnableDelayedExpansion
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (
set "DEL=%%a"
)
echo Checking NodeJS
call :run "node --version" || call :error "NodeJS not installed!"
echo.
echo Installing json tool
call :run "call npm install -g json" || call :error "Error while installing json"
echo.
echo Creating package
call :run "call npm init --yes" || call :error "Error while initializing package"
echo.
echo Adding scripts
(
call :run "call json -I -f package.json -e this.scripts.build='tstl'"
:: сука как же я люблю batch скрипты
call :color 0B "+ call json -I -f package.json -e this.scripts.watch='tstl --watch'"
echo.
call json -I -f package.json -e "this.scripts.watch=""tstl --watch"""
) || call :error "Error while editing scripts"
echo.
echo Creating tsconfig.json
copy %scriptDir%assets\tsconfig.json- tsconfig.json || call :error "Error while creating tsconfig.json"
echo.
echo Creating src directory
call :run "mkdir src" || call :error "Error while creating src directory"
echo.
echo Creating main.ts
copy %scriptDir%assets\main.ts- src\main.ts || call :error "Error while creating main.ts"
echo.
echo Installing dependencies
(
call npm install typescript-to-lua ^@opct/openos -D
) || call :error "Error while installing dependencies"
echo.
call :success "Your work environment has been successfully prepared!"
:: Leave with confirmation
:leave
set /p temp="Hit any key to close the terminal"
exit 0
EXIT /B 0
:: Run command and write it to output
:run
call :color 0B "+ %~1"
echo.
%~1%
EXIT /B 0
:: Show error and leave with confirmation
:success
call :color 0A "%~1"
echo.
call :leave
exit
EXIT /B 0
:: Show error and leave with confirmation
:error
call :color 0C "%~1"
echo.
call :leave
exit
EXIT /B 0
:: Color text (https://stackoverflow.com/a/23072489/10502674)
:color
echo off
<nul set /p ".=%DEL%" > "%~2"
findstr /v /a:%1 /R "^$" "%~2" nul
del "%~2" > nul 2>&1
EXIT /B 0