This repository has been archived by the owner on Aug 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ship.bat
363 lines (335 loc) · 10.1 KB
/
ship.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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
@echo off & setlocal enableDelayedExpansion
set version=0.1
call %~dp0\lib\sound
call %~dp0\lib\util
set gecho.dll=%~dp0\gecho.dll
:main
if /i "%~n0" == "ship" (
goto :correct
) else (
goto :wrong
)
:version
%gecho.dll% "<dgn>ship <white>v%version%"
%gecho.dll% "(C) 2024 <dgn>Asd22 Entertainment"
goto :EOF
:correct
if /i "%1" == "--help" (
goto :help
)
if /i "%1" == "--version" (
goto :version
)
if /i "%1" == "-i" (
call :Download %2 "%2.zip"
goto :EOF
)
if /i "%1" == "install" (
call :Download %2 "%2.zip"
goto :EOF
)
if /i "%1" == "-s" (
call :Search %2
goto :EOF
)
if /i "%1" == "search" (
call :Search %2
goto :EOF
)
if /i "%1" == "-u" (
call :delete %2
goto :EOF
)
if /i "%1" == "uninstall" (
call :delete %2
goto :EOF
)
if /i "%1" == "delete" (
call :delete %2
goto :EOF
)
if /i "%1" == "--all" (
call :All
goto :EOF
)
if /i "%1" == "--create" (
call :newproj %2 %3
goto :EOF
)
if /i "%1" == "create" (
call :newproj %2 %3
goto :EOF
)
if /i "%1" == "new" (
call :newproj %2 %3
goto :EOF
)
if /i "%1" == "--installed" (
call :installed
goto :EOF
)
if /i "%1" == "--open" (
call :openproj %2 %3
goto :EOF
)
if /i "%1" == "open" (
call :openproj %2 %3
goto :EOF
)
if /i "%1" == "--projects" (
if /i "%2" == "" (
%gecho.dll% "<r>No Project Type selected, selecting batch..."
call :projects batch
goto :EOF
)
call :projects %2
goto :EOF
)
if /i "%1" == "--run" (
call :runproj %USERPROFILE%\.ship\projects\%2\%3
goto :EOF
)
if /i "%1" == "run" (
call :runproj %USERPROFILE%\.ship\projects\%2\%3
goto :EOF
)
if /i "%1" == "--details" (
call :pkgdetails %2
goto :EOF
)
if /i "%1" == "--info" (
call :pkgdetails %2
goto :EOF
)
%gecho.dll% "<white>Invalid syntax, use <dgn>ship --help <white>for help"
goto :EOF
:wrong
%gecho.dll% "<r>ERROR: <white>Modified Version of 'ship' is installed!"
goto :EOF
:help
echo /^|~~~
echo ///^|
echo /////^|
echo ///////^|
echo /////////^|
echo \==========^|===/
echo ~~~~~~~~~~~~~~~~~~~~~
type %~dp0\logo
echo.
%gecho.dll% "<white>v!version!"
echo.
%gecho.dll% "Basic Commands:"
echo.
%gecho.dll% "<dgn>ship --help <white>displays help page."
%gecho.dll% "<dgn>ship --version <white>displays <dgn>ship<white>'s version."
%gecho.dll% "<dgn>ship --all <white>displays all the packages."
%gecho.dll% "<dgn>ship -s PACKAGE, ship search PACKAGE <white>searches for PACKAGE. remember to replace it with the actual package"
%gecho.dll% "<dgn>ship -i PACKAGE, ship install PACKAGE <white>installs PACKAGE."
%gecho.dll% "<dgn>ship -u PACKAGE, ship uninstall PACKAGE, ship delete PACKAGE <white>uninstalls PACKAGE."
%gecho.dll% "<dgn>ship --create, ship create [batch|powershell] [Name] <white>Makes a project in Batch or Powershell with name"
%gecho.dll% "<dgn>ship --installed <white>displays all installed packages."
%gecho.dll% "<dgn>ship --open, ship open [batch|powershell] [Name] <white>Opens [Name] in explorer."
%gecho.dll% "<dgn>ship --projects [batch|powershell] <white>Shows projects with type Batch or PowerShell"
%gecho.dll% "<dgn>ship --run, ship run [batch|powershell] [Name] <white>Executes main.bat in [Name]"
%gecho.dll% "<dgn>ship --details PACKAGE, ship --info PACKAGE <white>Views details for PACKAGE"
goto :EOF
:Download
%gecho.dll% "<g>Downloading package '%~1'"
powershell -NoLogo -NoProfile -ExecutionPolicy Bypass -command "Invoke-WebRequest -Uri https://shipapi.vercel.app/v1/%~1.zip -OutFile %~dp0\%~2" >nul
if %ERRORLEVEL% == 0 (
%gecho.dll% "<green>Package Downloaded Successfully!"
%gecho.dll% "<g>Extracting Package..."
powershell -NoLogo -NoProfile -ExecutionPolicy Bypass -Command "Expand-Archive -Path %~dp0\%~2 -DestinationPath '%USERPROFILE%\.ship\packages\'" >nul
if %ERRORLEVEL% == 0 (
rm %~dp0\%~2
%gecho.dll% "<green>Package Installed and Ready to use!"
) else (
rm %~dp0\%~2
%gecho.dll% "<r>Error Extracting Package."
%gecho.dll% "<r>Error code: %ERRORLEVEL%"
)
) else (
%gecho.dll% "<r>Package '%~1' not found!"
%@playSound% "%~dp0\lib\sfx\cancel.wav"
)
exit /b
:Search
%gecho.dll% "<g>Searching for package '%~1'"
powershell -NoLogo -NoProfile -ExecutionPolicy Bypass -Command "Invoke-WebRequest -Uri https://shipapi.vercel.app/api/search?q=%~1 -OutFile ship.tmp" >nul
set "packages="
setlocal EnableDelayedExpansion
for /f "usebackq tokens=*" %%a in (`powershell -NoLogo -NoProfile -ExecutionPolicy Bypass -Command "Get-Content ship.tmp | ConvertFrom-Json | ForEach-Object { $_ }"`) do (
set "line=%%~a"
if defined packages (
set "packages=!packages!, %%~a"
) else (
set "packages=%%~a"
)
)
del ship.tmp
if "%packages%" == "" (
%gecho.dll% "<red>No Package Found!"
) else (
%gecho.dll% "<green>Package(s) Found:"
set count=0
for %%p in (!packages!) do (
set /a count+=1
echo !count!. %%p
)
%gecho.dll% "<white>( <dgn>!count! <white>Package(s) )"
endlocal
)
goto :EOF
:All
%gecho.dll% "<g>Updating Database..."
powershell -NoLogo -NoProfile -ExecutionPolicy Bypass -Command "Invoke-WebRequest -Uri https://shipapi.vercel.app/api/pkgs -OutFile ship.tmp" >nul
set "packages="
setlocal EnableDelayedExpansion
for /f "usebackq tokens=*" %%a in (`powershell -NoLogo -NoProfile -ExecutionPolicy Bypass -Command "Get-Content ship.tmp | ConvertFrom-Json | ForEach-Object { $_ }"`) do (
set "line=%%~a"
if defined packages (
set "packages=!packages!, %%~a"
) else (
set "packages=%%~a"
)
)
del ship.tmp
if "%packages%" == "" (
%gecho.dll% "<red>No Package Found!"
) else (
%gecho.dll% "<green>Package(s) Found:"
set count=0
for %%p in (!packages!) do (
set /a count+=1
echo !count!. %%p
)
%gecho.dll% "<white>( <dgn>!count! <white>Package(s) )"
endlocal
)
goto :EOF
:del
del %USERPROFILE%\.ship\packages\%~1
if /i "%ERRORLEVEL%" == "0" (
%gecho.dll% "<green>Package uninstalled successfully!!"
rmdir %USERPROFILE%\.ship\packages\%~1
) else (
%gecho.dll% "<red>Package uninstallation cancelled!!"
)
goto :EOF
:newproj
if defined %~1 if defined %~2 (
%gecho.dll% "<white>Making Project <dgn>%~2 <white>in langauge <dgn>%~1<white>..."
%SystemRoot%\System32\timeout.exe 2>nul
if not exist "%USERPROFILE%\.ship\projects\%~1\%~2" (
mkdir "%USERPROFILE%\.ship\projects\%~1\%~2" >nul 2>&1
if %errorlevel% equ 0 (
%gecho.dll% "<green>Project Created Successfully"
) else (
%gecho.dll% "<r>Failed to create project."
)
) else (
%gecho.dll% "<r>Project Already Exist!!"
)
if /i "%~1" == "batch" (
type %~dp0\lib\default-template.bat >%USERPROFILE%\.ship\projects\%~1\%~2\main.bat
echo Made with 'ship' >%USERPROFILE%\.ship\projects\%~1\%~2\.ship
) else (
type %~dp0\lib\default-template.ps1 >%USERPROFILE%\.ship\projects\%~1\%~2\main.ps1
echo Made with 'ship' >%USERPROFILE%\.ship\projects\%~1\%~2\.ship
)
%gecho.dll% "<green>Project has been made successfully!!"
) else (
%gecho.dll% "<red>Invalid Syntax, check <dgn>ship --help<white>."
)
goto :EOF
:installed
%gecho.dll% "<g>Please wait..."
powershell -NoLogo -NoProfile -ExecutionPolicy Bypass -Command "Get-ChildItem -Path '%USERPROFILE%\.ship\packages\' -Directory | Select-Object -ExpandProperty Name | Out-File -FilePath ship.tmp" >nul
set "packages="
setlocal EnableDelayedExpansion
for /f "usebackq tokens=*" %%a in (`type ship.tmp`) do (
set "line=%%~a"
if defined packages (
set "packages=!packages!, %%~a"
) else (
set "packages=%%~a"
)
)
del ship.tmp
if "%packages%" == "" (
%gecho.dll% "<red>No Package Installed!"
) else (
%gecho.dll% "<green>Package(s) Installed:"
set count=0
for %%p in (!packages!) do (
set /a count+=1
echo !count!. %%p
)
%gecho.dll% "<white>( <dgn>!count! <white>Package(s) )"
endlocal
)
goto :EOF
:openproj
if exist %USERPROFILE%\.ship\projects\%~1\%~2 (
explorer %USERPROFILE%\.ship\projects\%~1\%~2
%gecho.dll% "<green>Project opened in Explorer"
) else (
%gecho.dll% "<r>Project isn't found!!"
)
goto :EOF
:projects
%gecho.dll% "<g>Please wait..."
powershell -NoLogo -NoProfile -ExecutionPolicy Bypass -Command "Get-ChildItem -Path '%USERPROFILE%\.ship\projects\%~1' -Directory | Select-Object -ExpandProperty Name | Out-File -FilePath ship.tmp" >nul
set "packages="
setlocal EnableDelayedExpansion
for /f "usebackq tokens=*" %%a in (`type ship.tmp`) do (
set "line=%%~a"
if defined packages (
set "packages=!packages!, %%~a"
) else (
set "packages=%%~a"
)
)
del ship.tmp
if "%packages%" == "" (
%gecho.dll% "<red>No Project Created, try ship --create %~1 project-name"
) else (
%gecho.dll% "<green>Projects Located:"
set count=0
for %%p in (!packages!) do (
set /a count+=1
echo !count!. %%p
)
%gecho.dll% "<white>( <dgn>!count! <white>Project )"
endlocal
)
goto :EOF
:runproj
if exist %~1 (
start %~1\main.bat
%gecho.dll% "<green>Project has been ran in another terminal."
) else (
%gecho.dll% "<red>Project doesn't exist!"
)
goto :EOF
:pkgdetails
if defined %~1 (
powershell -NoLogo -NoProfile -ExecutionPolicy Bypass -Command "Invoke-WebRequest -Uri https://shipapi.vercel.app/v1-details/%~1.json -OutFile ship.tmp">nul
set /p tmp=<ship.tmp
echo %tmp% | %~dp0\jq.dll ".name" >ship.tmp
set /p name=<ship.tmp
echo %tmp% | %~dp0\jq.dll ".author">ship.tmp
set /p author=<ship.tmp
if defined %name% (
%gecho.dll% "<green>Package Details:"
%gecho.dll% "<g>Package Name: <white>%name%"
%gecho.dll% "<g>Package Author: <white>%author%"
%gecho.dll% "<white>use <dgn>ship -i %~1 <white>to install this package."
del ship.tmp
) else (
%gecho.dll% "<red>No Package Found with name '%~1'"
)
) else (
%gecho.dll% "<red>No Package Specified."
)
goto :EOF