update to work with more than just bun ( oversight )

This commit is contained in:
creations 2024-09-06 14:16:00 -04:00
parent 427adb32ac
commit 2e56e132fb
5 changed files with 170 additions and 90 deletions

2
.gitignore vendored
View file

@ -175,3 +175,5 @@ dist
.DS_Store
/.vscode
bun.lockb
pnpm-lock.yaml
yarn.lock

View file

@ -6,7 +6,7 @@ import type{ IEnvironment } from "../src/interfaces/environment";
const __dirname : string = join(dirname(fileURLToPath(import.meta.url)), "..");
const environment : IEnvironment = {
development: process.argv.includes("--development"),
development: process.argv.includes("--development") || process.argv.includes("--dev"),
fastify: {
host: "0.0.0.0",

View file

@ -3,11 +3,18 @@
"module": "src/index.ts",
"type": "module",
"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": {
"@types/bun": "latest",
"@types/ejs": "^3.1.5"
"@types/ejs": "^3.1.5",
"tsx": "^3.8.0",
"nodemon": "^3.1.4"
},
"peerDependencies": {
"typescript": "^5.0.0"

191
start.bat
View file

@ -1,47 +1,36 @@
@echo off
setlocal enabledelayedexpansion
for %%I in ("%~dp0.") do set "SCRIPT_DIR=%%~fI"
cd /d "!SCRIPT_DIR!"
cd /d %~dp0
if not exist package.json (
echo package.json not found in !SCRIPT_DIR!
if not exist "package.json" (
echo package.json not found in %~dp0
exit /b 1
)
set "PKG_MANAGER=bun"
set "MODE=dev"
set "next_is_value=0"
set "last_key="
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"
)
if "!last_key!"=="mode" (
) else if "!last_key!" == "mode" (
set "MODE=%%a"
)
set "next_is_value=0"
)
if "!arg!"=="clean" (
goto cleanup
)
if "!arg!"=="cleanup" (
goto cleanup
)
if "!arg!"=="manager" (
if "%%a" == "clean" (
set "goto_cleanup=1"
) else if "%%a" == "cleanup" (
set "goto_cleanup=1"
) else if "%%a" == "manager" (
set "last_key=manager"
set "next_is_value=1"
)
if "!arg!"=="mode" (
) else if "%%a" == "mode" (
set "last_key=mode"
set "next_is_value=1"
)
@ -51,98 +40,142 @@ set "ALLOWED_MANAGERS=bun npm yarn pnpm"
set "ALLOWED_MODES=dev prod development production"
set "manager_allowed=0"
for %%a in (!ALLOWED_MANAGERS!) do (
if "!PKG_MANAGER!"=="%%a" (
for %%m in (%ALLOWED_MANAGERS%) do (
if "!PKG_MANAGER!" == "%%m" (
set "manager_allowed=1"
)
)
set "mode_allowed=0"
for %%a in (!ALLOWED_MODES!) do (
if "!MODE!"=="%%a" (
for %%m in (%ALLOWED_MODES%) do (
if "!MODE!" == "%%m" (
set "mode_allowed=1"
)
)
if "!manager_allowed!"=="0" (
echo !PKG_MANAGER! is not a valid package manager, please use one of the following: !ALLOWED_MANAGERS!
if "!manager_allowed!" == "0" (
echo !PKG_MANAGER! is not a valid package manager. Use one of: %ALLOWED_MANAGERS%
exit /b 1
)
if "!mode_allowed!"=="0" (
echo !MODE! is not a valid mode, please use one of the following: !ALLOWED_MODES!
if "!mode_allowed!" == "0" (
echo !MODE! is not a valid mode. Use one of: %ALLOWED_MODES%
exit /b 1
)
echo Using package manager: !PKG_MANAGER!
echo Mode: !MODE!
set "NPM_MARKER=node_modules/.npm_used"
set "YARN_MARKER=node_modules/.yarn_used"
set "PNPM_MARKER=node_modules/.pnpm_used"
set "BUN_MARKER=node_modules/.bun_used"
set "NPM_MARKER=node_modules\.npm_used"
set "YARN_MARKER=node_modules\.yarn_used"
set "PNPM_MARKER=node_modules\.pnpm_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 "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!"
) else if "!PKG_MANAGER!"=="yarn" (
set "INSTALL_CMD=yarn"
set "RUN_CMD=yarn !MODE!"
) else if "!PKG_MANAGER!" == "yarn" (
set "INSTALL_CMD=yarn install"
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!"
) else if "!PKG_MANAGER!"=="pnpm" (
) else if "!PKG_MANAGER!" == "pnpm" (
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!"
) else if "!PKG_MANAGER!"=="bun" (
) else if "!PKG_MANAGER!" == "bun" (
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!"
)
if exist "!NPM_MARKER!" if not "!CURRENT_MARKER!"=="!NPM_MARKER!" goto cleanup
if exist "!YARN_MARKER!" if not "!CURRENT_MARKER!"=="!YARN_MARKER!" goto cleanup
if exist "!PNPM_MARKER!" if not "!CURRENT_MARKER!"=="!PNPM_MARKER!" goto cleanup
if exist "!BUN_MARKER!" if not "!CURRENT_MARKER!"=="!BUN_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!" set "goto_cleanup=1"
if exist "!PNPM_MARKER!" if not "!CURRENT_MARKER!" == "!PNPM_MARKER!" set "goto_cleanup=1"
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
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...
echo Cleaning up files and folders...
for %%a in (!files_to_delete!) do (
if exist "%%a" (
echo Found %%a in !SCRIPT_DIR! - deleting...
del "%%a"
for %%f in (!files_to_delete!) do (
if exist "%%f" (
echo Deleting %%f...
del /q "%%f"
)
)
)
for %%a in (!folders_to_delete!) do (
if exist "%%a" (
echo Found %%a in !SCRIPT_DIR! - deleting...
rmdir /s /q "%%a"
for %%d in (!folders_to_delete!) do (
if exist "%%d" (
echo Deleting %%d...
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 exist "%%a" del "%%a"
)
if defined RUN_CMD (
goto run
)
exit /b 0
:run
if defined RUN_CMD (
echo Running !RUN_CMD!...
!INSTALL_CMD!
!RUN_CMD!
if not "%RUN_CMD%" == "" (
echo Running %RUN_CMD%...
%INSTALL_CMD%
%RUN_CMD%
) else (
echo No run command set, exiting...
)

View file

@ -75,24 +75,62 @@ YARN_MARKER="node_modules/.yarn_used"
PNPM_MARKER="node_modules/.pnpm_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
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"
elif [ "$PKG_MANAGER" == "yarn" ]; then
INSTALL_CMD="yarn"
RUN_CMD="yarn $MODE"
INSTALL_CMD="yarn install"
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"
elif [ "$PKG_MANAGER" == "pnpm" ]; then
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"
elif [ "$PKG_MANAGER" == "bun" ]; then
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"
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 "$PNPM_MARKER" ] && [ "$CURRENT_MARKER" != "$PNPM_MARKER" ]; then goto_cleanup=1; fi