update to work with more than just bun ( oversight )
This commit is contained in:
parent
427adb32ac
commit
2e56e132fb
5 changed files with 170 additions and 90 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -175,3 +175,5 @@ dist
|
||||||
.DS_Store
|
.DS_Store
|
||||||
/.vscode
|
/.vscode
|
||||||
bun.lockb
|
bun.lockb
|
||||||
|
pnpm-lock.yaml
|
||||||
|
yarn.lock
|
||||||
|
|
|
@ -6,7 +6,7 @@ import type{ IEnvironment } from "../src/interfaces/environment";
|
||||||
const __dirname : string = join(dirname(fileURLToPath(import.meta.url)), "..");
|
const __dirname : string = join(dirname(fileURLToPath(import.meta.url)), "..");
|
||||||
|
|
||||||
const environment : IEnvironment = {
|
const environment : IEnvironment = {
|
||||||
development: process.argv.includes("--development"),
|
development: process.argv.includes("--development") || process.argv.includes("--dev"),
|
||||||
|
|
||||||
fastify: {
|
fastify: {
|
||||||
host: "0.0.0.0",
|
host: "0.0.0.0",
|
||||||
|
|
11
package.json
11
package.json
|
@ -3,11 +3,18 @@
|
||||||
"module": "src/index.ts",
|
"module": "src/index.ts",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "bun run --watch src/index.ts --development"
|
"bun-dev": "bun run --watch src/index.ts --development",
|
||||||
|
"bun-prod": "bun run src/index.ts",
|
||||||
|
"dev": "nodemon --watch src --exec 'tsx src/index.ts'",
|
||||||
|
"npm-prod": "tsx src/index.ts",
|
||||||
|
"pnpm-prod": "tsx src/index.ts",
|
||||||
|
"yarn-prod": "tsx src/index.ts"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/bun": "latest",
|
"@types/bun": "latest",
|
||||||
"@types/ejs": "^3.1.5"
|
"@types/ejs": "^3.1.5",
|
||||||
|
"tsx": "^3.8.0",
|
||||||
|
"nodemon": "^3.1.4"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"typescript": "^5.0.0"
|
"typescript": "^5.0.0"
|
||||||
|
|
191
start.bat
191
start.bat
|
@ -1,47 +1,36 @@
|
||||||
@echo off
|
@echo off
|
||||||
setlocal enabledelayedexpansion
|
setlocal enabledelayedexpansion
|
||||||
|
|
||||||
for %%I in ("%~dp0.") do set "SCRIPT_DIR=%%~fI"
|
cd /d %~dp0
|
||||||
cd /d "!SCRIPT_DIR!"
|
|
||||||
|
|
||||||
if not exist package.json (
|
if not exist "package.json" (
|
||||||
echo package.json not found in !SCRIPT_DIR!
|
echo package.json not found in %~dp0
|
||||||
exit /b 1
|
exit /b 1
|
||||||
)
|
)
|
||||||
|
|
||||||
set "PKG_MANAGER=bun"
|
set "PKG_MANAGER=bun"
|
||||||
set "MODE=dev"
|
set "MODE=dev"
|
||||||
|
|
||||||
set "next_is_value=0"
|
set "next_is_value=0"
|
||||||
set "last_key="
|
set "last_key="
|
||||||
|
|
||||||
for %%a in (%*) do (
|
for %%a in (%*) do (
|
||||||
set "arg=%%a"
|
if "!next_is_value!" == "1" (
|
||||||
|
if "!last_key!" == "manager" (
|
||||||
if "!next_is_value!"=="1" (
|
|
||||||
if "!last_key!"=="manager" (
|
|
||||||
set "PKG_MANAGER=%%a"
|
set "PKG_MANAGER=%%a"
|
||||||
)
|
) else if "!last_key!" == "mode" (
|
||||||
if "!last_key!"=="mode" (
|
|
||||||
set "MODE=%%a"
|
set "MODE=%%a"
|
||||||
)
|
)
|
||||||
set "next_is_value=0"
|
set "next_is_value=0"
|
||||||
)
|
)
|
||||||
|
|
||||||
if "!arg!"=="clean" (
|
if "%%a" == "clean" (
|
||||||
goto cleanup
|
set "goto_cleanup=1"
|
||||||
)
|
) else if "%%a" == "cleanup" (
|
||||||
|
set "goto_cleanup=1"
|
||||||
if "!arg!"=="cleanup" (
|
) else if "%%a" == "manager" (
|
||||||
goto cleanup
|
|
||||||
)
|
|
||||||
|
|
||||||
if "!arg!"=="manager" (
|
|
||||||
set "last_key=manager"
|
set "last_key=manager"
|
||||||
set "next_is_value=1"
|
set "next_is_value=1"
|
||||||
)
|
) else if "%%a" == "mode" (
|
||||||
|
|
||||||
if "!arg!"=="mode" (
|
|
||||||
set "last_key=mode"
|
set "last_key=mode"
|
||||||
set "next_is_value=1"
|
set "next_is_value=1"
|
||||||
)
|
)
|
||||||
|
@ -51,98 +40,142 @@ set "ALLOWED_MANAGERS=bun npm yarn pnpm"
|
||||||
set "ALLOWED_MODES=dev prod development production"
|
set "ALLOWED_MODES=dev prod development production"
|
||||||
|
|
||||||
set "manager_allowed=0"
|
set "manager_allowed=0"
|
||||||
for %%a in (!ALLOWED_MANAGERS!) do (
|
for %%m in (%ALLOWED_MANAGERS%) do (
|
||||||
if "!PKG_MANAGER!"=="%%a" (
|
if "!PKG_MANAGER!" == "%%m" (
|
||||||
set "manager_allowed=1"
|
set "manager_allowed=1"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
set "mode_allowed=0"
|
set "mode_allowed=0"
|
||||||
for %%a in (!ALLOWED_MODES!) do (
|
for %%m in (%ALLOWED_MODES%) do (
|
||||||
if "!MODE!"=="%%a" (
|
if "!MODE!" == "%%m" (
|
||||||
set "mode_allowed=1"
|
set "mode_allowed=1"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
if "!manager_allowed!"=="0" (
|
if "!manager_allowed!" == "0" (
|
||||||
echo !PKG_MANAGER! is not a valid package manager, please use one of the following: !ALLOWED_MANAGERS!
|
echo !PKG_MANAGER! is not a valid package manager. Use one of: %ALLOWED_MANAGERS%
|
||||||
exit /b 1
|
exit /b 1
|
||||||
)
|
)
|
||||||
|
|
||||||
if "!mode_allowed!"=="0" (
|
if "!mode_allowed!" == "0" (
|
||||||
echo !MODE! is not a valid mode, please use one of the following: !ALLOWED_MODES!
|
echo !MODE! is not a valid mode. Use one of: %ALLOWED_MODES%
|
||||||
exit /b 1
|
exit /b 1
|
||||||
)
|
)
|
||||||
|
|
||||||
echo Using package manager: !PKG_MANAGER!
|
echo Using package manager: !PKG_MANAGER!
|
||||||
echo Mode: !MODE!
|
echo Mode: !MODE!
|
||||||
|
|
||||||
set "NPM_MARKER=node_modules/.npm_used"
|
set "NPM_MARKER=node_modules\.npm_used"
|
||||||
set "YARN_MARKER=node_modules/.yarn_used"
|
set "YARN_MARKER=node_modules\.yarn_used"
|
||||||
set "PNPM_MARKER=node_modules/.pnpm_used"
|
set "PNPM_MARKER=node_modules\.pnpm_used"
|
||||||
set "BUN_MARKER=node_modules/.bun_used"
|
set "BUN_MARKER=node_modules\.bun_used"
|
||||||
|
|
||||||
if "!PKG_MANAGER!"=="npm" (
|
if not "!PKG_MANAGER!" == "bun" (
|
||||||
|
where nodemon >nul 2>&1
|
||||||
|
if errorlevel 1 (
|
||||||
|
echo nodemon not found, installing...
|
||||||
|
if "!PKG_MANAGER!" == "npm" (
|
||||||
|
npm install -g nodemon
|
||||||
|
) else if "!PKG_MANAGER!" == "yarn" (
|
||||||
|
yarn global add nodemon
|
||||||
|
) else if "!PKG_MANAGER!" == "pnpm" (
|
||||||
|
pnpm add -g nodemon
|
||||||
|
) else (
|
||||||
|
echo Unsupported package manager: !PKG_MANAGER!
|
||||||
|
exit /b 1
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
where tsx >nul 2>&1
|
||||||
|
if errorlevel 1 (
|
||||||
|
echo tsx not found, installing...
|
||||||
|
if "!PKG_MANAGER!" == "npm" (
|
||||||
|
npm install -g tsx
|
||||||
|
) else if "!PKG_MANAGER!" == "yarn" (
|
||||||
|
yarn add tsx --dev
|
||||||
|
) else if "!PKG_MANAGER!" == "pnpm" (
|
||||||
|
pnpm add -D tsx
|
||||||
|
) else (
|
||||||
|
echo Unsupported package manager: !PKG_MANAGER!
|
||||||
|
exit /b 1
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
if "!PKG_MANAGER!" == "npm" (
|
||||||
set "INSTALL_CMD=npm install"
|
set "INSTALL_CMD=npm install"
|
||||||
set "RUN_CMD=npm run !MODE!"
|
if "!MODE!" == "dev" (
|
||||||
|
set "RUN_CMD=nodemon --watch src --exec npm exec tsx src/index.ts"
|
||||||
|
) else (
|
||||||
|
set "RUN_CMD=npm exec tsx src/index.ts"
|
||||||
|
)
|
||||||
set "CURRENT_MARKER=!NPM_MARKER!"
|
set "CURRENT_MARKER=!NPM_MARKER!"
|
||||||
) else if "!PKG_MANAGER!"=="yarn" (
|
) else if "!PKG_MANAGER!" == "yarn" (
|
||||||
set "INSTALL_CMD=yarn"
|
set "INSTALL_CMD=yarn install"
|
||||||
set "RUN_CMD=yarn !MODE!"
|
if "!MODE!" == "dev" (
|
||||||
|
set "RUN_CMD=nodemon --watch src --exec yarn exec tsx src/index.ts"
|
||||||
|
) else (
|
||||||
|
set "RUN_CMD=yarn exec tsx src/index.ts"
|
||||||
|
)
|
||||||
set "CURRENT_MARKER=!YARN_MARKER!"
|
set "CURRENT_MARKER=!YARN_MARKER!"
|
||||||
) else if "!PKG_MANAGER!"=="pnpm" (
|
) else if "!PKG_MANAGER!" == "pnpm" (
|
||||||
set "INSTALL_CMD=pnpm install"
|
set "INSTALL_CMD=pnpm install"
|
||||||
set "RUN_CMD=pnpm !MODE!"
|
if "!MODE!" == "dev" (
|
||||||
|
set "RUN_CMD=nodemon --watch src --exec pnpm exec tsx src/index.ts"
|
||||||
|
) else (
|
||||||
|
set "RUN_CMD=pnpm exec tsx src/index.ts"
|
||||||
|
)
|
||||||
set "CURRENT_MARKER=!PNPM_MARKER!"
|
set "CURRENT_MARKER=!PNPM_MARKER!"
|
||||||
) else if "!PKG_MANAGER!"=="bun" (
|
) else if "!PKG_MANAGER!" == "bun" (
|
||||||
set "INSTALL_CMD=bun install"
|
set "INSTALL_CMD=bun install"
|
||||||
set "RUN_CMD=bun !MODE!"
|
if "!MODE!" == "dev" (
|
||||||
|
set "RUN_CMD=bun run --watch src/index.ts --development"
|
||||||
|
) else (
|
||||||
|
set "RUN_CMD=bun run src/index.ts"
|
||||||
|
)
|
||||||
set "CURRENT_MARKER=!BUN_MARKER!"
|
set "CURRENT_MARKER=!BUN_MARKER!"
|
||||||
)
|
)
|
||||||
|
|
||||||
if exist "!NPM_MARKER!" if not "!CURRENT_MARKER!"=="!NPM_MARKER!" goto cleanup
|
if exist "!NPM_MARKER!" if not "!CURRENT_MARKER!" == "!NPM_MARKER!" set "goto_cleanup=1"
|
||||||
if exist "!YARN_MARKER!" if not "!CURRENT_MARKER!"=="!YARN_MARKER!" goto cleanup
|
if exist "!YARN_MARKER!" if not "!CURRENT_MARKER!" == "!YARN_MARKER!" set "goto_cleanup=1"
|
||||||
if exist "!PNPM_MARKER!" if not "!CURRENT_MARKER!"=="!PNPM_MARKER!" goto cleanup
|
if exist "!PNPM_MARKER!" if not "!CURRENT_MARKER!" == "!PNPM_MARKER!" set "goto_cleanup=1"
|
||||||
if exist "!BUN_MARKER!" if not "!CURRENT_MARKER!"=="!BUN_MARKER!" goto cleanup
|
if exist "!BUN_MARKER!" if not "!CURRENT_MARKER!" == "!BUN_MARKER!" set "goto_cleanup=1"
|
||||||
|
|
||||||
goto run
|
if defined goto_cleanup (
|
||||||
|
set "files_to_delete=package-lock.json yarn.lock pnpm-lock.yaml bun.lockb"
|
||||||
|
set "folders_to_delete=node_modules dist logs"
|
||||||
|
set "markers_to_delete=!NPM_MARKER! !YARN_MARKER! !PNPM_MARKER! !BUN_MARKER!"
|
||||||
|
|
||||||
:cleanup
|
echo Cleaning up files and folders...
|
||||||
set "files_to_delete=package-lock.json yarn.lock pnpm-lock.yaml bun.lockb"
|
|
||||||
set "folders_to_delete=node_modules dist logs"
|
|
||||||
set "markers_to_delete=node_modules/.npm_used node_modules/.yarn_used node_modules/.pnpm_used node_modules/.bun_used"
|
|
||||||
|
|
||||||
echo Cleaning up files and folders...
|
for %%f in (!files_to_delete!) do (
|
||||||
|
if exist "%%f" (
|
||||||
for %%a in (!files_to_delete!) do (
|
echo Deleting %%f...
|
||||||
if exist "%%a" (
|
del /q "%%f"
|
||||||
echo Found %%a in !SCRIPT_DIR! - deleting...
|
)
|
||||||
del "%%a"
|
|
||||||
)
|
)
|
||||||
)
|
|
||||||
|
|
||||||
for %%a in (!folders_to_delete!) do (
|
for %%d in (!folders_to_delete!) do (
|
||||||
if exist "%%a" (
|
if exist "%%d" (
|
||||||
echo Found %%a in !SCRIPT_DIR! - deleting...
|
echo Deleting %%d...
|
||||||
rmdir /s /q "%%a"
|
rmdir /s /q "%%d"
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
for %%m in (!markers_to_delete!) do (
|
||||||
|
if exist "%%m" (
|
||||||
|
del /q "%%m"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
exit /b 0
|
||||||
)
|
)
|
||||||
|
|
||||||
for %%a in (!markers_to_delete!) do (
|
if not "%RUN_CMD%" == "" (
|
||||||
if exist "%%a" del "%%a"
|
echo Running %RUN_CMD%...
|
||||||
)
|
%INSTALL_CMD%
|
||||||
|
%RUN_CMD%
|
||||||
if defined RUN_CMD (
|
|
||||||
goto run
|
|
||||||
)
|
|
||||||
|
|
||||||
exit /b 0
|
|
||||||
|
|
||||||
:run
|
|
||||||
if defined RUN_CMD (
|
|
||||||
echo Running !RUN_CMD!...
|
|
||||||
!INSTALL_CMD!
|
|
||||||
!RUN_CMD!
|
|
||||||
) else (
|
) else (
|
||||||
echo No run command set, exiting...
|
echo No run command set, exiting...
|
||||||
)
|
)
|
||||||
|
|
48
start.sh
48
start.sh
|
@ -75,24 +75,62 @@ YARN_MARKER="node_modules/.yarn_used"
|
||||||
PNPM_MARKER="node_modules/.pnpm_used"
|
PNPM_MARKER="node_modules/.pnpm_used"
|
||||||
BUN_MARKER="node_modules/.bun_used"
|
BUN_MARKER="node_modules/.bun_used"
|
||||||
|
|
||||||
|
if [ "$PKG_MANAGER" != "bun" ]; then
|
||||||
|
if ! command -v nodemon >/dev/null 2>&1; then
|
||||||
|
echo "nodemon not found, installing..."
|
||||||
|
case "$PKG_MANAGER" in
|
||||||
|
npm)
|
||||||
|
npm install -g nodemon
|
||||||
|
;;
|
||||||
|
yarn)
|
||||||
|
yarn global add nodemon
|
||||||
|
;;
|
||||||
|
pnpm)
|
||||||
|
pnpm add -g nodemon
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Unsupported package manager: $PKG_MANAGER"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
if [ "$PKG_MANAGER" == "npm" ]; then
|
if [ "$PKG_MANAGER" == "npm" ]; then
|
||||||
INSTALL_CMD="npm install"
|
INSTALL_CMD="npm install"
|
||||||
RUN_CMD="npm run $MODE"
|
if [ "$MODE" == "dev" ] || [ "$MODE" == "development" ]; then
|
||||||
|
RUN_CMD="nodemon --watch src --exec npm exec tsx src/index.ts"
|
||||||
|
else
|
||||||
|
RUN_CMD="npm exec tsx src/index.ts"
|
||||||
|
fi
|
||||||
CURRENT_MARKER="$NPM_MARKER"
|
CURRENT_MARKER="$NPM_MARKER"
|
||||||
elif [ "$PKG_MANAGER" == "yarn" ]; then
|
elif [ "$PKG_MANAGER" == "yarn" ]; then
|
||||||
INSTALL_CMD="yarn"
|
INSTALL_CMD="yarn install"
|
||||||
RUN_CMD="yarn $MODE"
|
if [ "$MODE" == "dev" ] || [ "$MODE" == "development" ]; then
|
||||||
|
RUN_CMD="nodemon --watch src --exec yarn exec tsx src/index.ts"
|
||||||
|
else
|
||||||
|
RUN_CMD="yarn exec tsx src/index.ts"
|
||||||
|
fi
|
||||||
CURRENT_MARKER="$YARN_MARKER"
|
CURRENT_MARKER="$YARN_MARKER"
|
||||||
elif [ "$PKG_MANAGER" == "pnpm" ]; then
|
elif [ "$PKG_MANAGER" == "pnpm" ]; then
|
||||||
INSTALL_CMD="pnpm install"
|
INSTALL_CMD="pnpm install"
|
||||||
RUN_CMD="pnpm $MODE"
|
if [ "$MODE" == "dev" ] || [ "$MODE" == "development" ]; then
|
||||||
|
RUN_CMD="nodemon --watch src --exec pnpm exec tsx src/index.ts"
|
||||||
|
else
|
||||||
|
RUN_CMD="pnpm exec tsx src/index.ts"
|
||||||
|
fi
|
||||||
CURRENT_MARKER="$PNPM_MARKER"
|
CURRENT_MARKER="$PNPM_MARKER"
|
||||||
elif [ "$PKG_MANAGER" == "bun" ]; then
|
elif [ "$PKG_MANAGER" == "bun" ]; then
|
||||||
INSTALL_CMD="bun install"
|
INSTALL_CMD="bun install"
|
||||||
RUN_CMD="bun $MODE"
|
if [ "$MODE" == "dev" ] || [ "$MODE" == "development" ]; then
|
||||||
|
RUN_CMD="bun run --watch src/index.ts --development"
|
||||||
|
else
|
||||||
|
RUN_CMD="bun run src/index.ts"
|
||||||
|
fi
|
||||||
CURRENT_MARKER="$BUN_MARKER"
|
CURRENT_MARKER="$BUN_MARKER"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
if [ -f "$NPM_MARKER" ] && [ "$CURRENT_MARKER" != "$NPM_MARKER" ]; then goto_cleanup=1; fi
|
if [ -f "$NPM_MARKER" ] && [ "$CURRENT_MARKER" != "$NPM_MARKER" ]; then goto_cleanup=1; fi
|
||||||
if [ -f "$YARN_MARKER" ] && [ "$CURRENT_MARKER" != "$YARN_MARKER" ]; then goto_cleanup=1; fi
|
if [ -f "$YARN_MARKER" ] && [ "$CURRENT_MARKER" != "$YARN_MARKER" ]; then goto_cleanup=1; fi
|
||||||
if [ -f "$PNPM_MARKER" ] && [ "$CURRENT_MARKER" != "$PNPM_MARKER" ]; then goto_cleanup=1; fi
|
if [ -f "$PNPM_MARKER" ] && [ "$CURRENT_MARKER" != "$PNPM_MARKER" ]; then goto_cleanup=1; fi
|
||||||
|
|
Loading…
Reference in a new issue