diff --git a/.gitignore b/.gitignore index db81e2f..3f5028b 100644 --- a/.gitignore +++ b/.gitignore @@ -173,4 +173,5 @@ dist # Finder (MacOS) folder config .DS_Store -/.vscode \ No newline at end of file +/.vscode +bun.lockb \ No newline at end of file diff --git a/bun.lockb b/bun.lockb deleted file mode 100644 index 1170bf3..0000000 Binary files a/bun.lockb and /dev/null differ diff --git a/src/fastify/manager.ts b/src/fastify/manager.ts index 28b4432..1499507 100644 --- a/src/fastify/manager.ts +++ b/src/fastify/manager.ts @@ -87,10 +87,10 @@ class FastifyManager { routePath = routePath === "/" ? prefix : join(prefix, routePath); } - routePath = routePath.replace(/\\/g, '/'); + routePath = routePath.replace(/\\/g, "/"); - if (!routePath.startsWith('/')) { - routePath = '/' + routePath; + if (!routePath.startsWith("/")) { + routePath = "/" + routePath; } routePath = routePath.replace(/\/+/g, "/"); diff --git a/start.sh b/start.sh index db3ccb4..3169354 100644 --- a/start.sh +++ b/start.sh @@ -1,10 +1,9 @@ #!/bin/bash -set -e -SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" cd "$SCRIPT_DIR" -if [ ! -f package.json ]; then +if [ ! -f "package.json" ]; then echo "package.json not found in $SCRIPT_DIR" exit 1 fi @@ -12,60 +11,59 @@ fi PKG_MANAGER="bun" MODE="dev" -while [[ "$#" -gt 0 ]]; do - arg="$1" - shift +next_is_value=0 +last_key="" - if [[ "$next_is_value" == "1" ]]; then - if [[ "$last_key" == "manager" ]]; then +for arg in "$@"; do + if [ "$next_is_value" == "1" ]; then + if [ "$last_key" == "manager" ]; then PKG_MANAGER="$arg" - elif [[ "$last_key" == "mode" ]]; then + fi + if [ "$last_key" == "mode" ]; then MODE="$arg" fi next_is_value=0 fi - case "$arg" in - clean|cleanup) - cleanup=true - ;; - manager) - last_key="manager" - next_is_value=1 - ;; - mode) - last_key="mode" - next_is_value=1 - ;; - esac + if [ "$arg" == "clean" ] || [ "$arg" == "cleanup" ]; then + goto_cleanup=1 + fi + + if [ "$arg" == "manager" ]; then + last_key="manager" + next_is_value=1 + fi + + if [ "$arg" == "mode" ]; then + last_key="mode" + next_is_value=1 + fi done -ALLOWED_MANAGERS="bun npm yarn pnpm" -ALLOWED_MODES="dev prod development production" +ALLOWED_MANAGERS=("bun" "npm" "yarn" "pnpm") +ALLOWED_MODES=("dev" "prod" "development" "production") manager_allowed=0 -for allowed in $ALLOWED_MANAGERS; do - if [[ "$PKG_MANAGER" == "$allowed" ]]; then +for allowed_manager in "${ALLOWED_MANAGERS[@]}"; do + if [ "$PKG_MANAGER" == "$allowed_manager" ]; then manager_allowed=1 - break fi done mode_allowed=0 -for allowed in $ALLOWED_MODES; do - if [[ "$MODE" == "$allowed" ]]; then +for allowed_mode in "${ALLOWED_MODES[@]}"; do + if [ "$MODE" == "$allowed_mode" ]; then mode_allowed=1 - break fi done -if [[ "$manager_allowed" == "0" ]]; then - echo "$PKG_MANAGER is not a valid package manager, please use one of the following: $ALLOWED_MANAGERS" +if [ "$manager_allowed" == "0" ]; then + echo "$PKG_MANAGER is not a valid package manager, please use one of the following: ${ALLOWED_MANAGERS[@]}" exit 1 fi -if [[ "$mode_allowed" == "0" ]]; then - echo "$MODE is not a valid mode, please use one of the following: $ALLOWED_MODES" +if [ "$mode_allowed" == "0" ]; then + echo "$MODE is not a valid mode, please use one of the following: ${ALLOWED_MODES[@]}" exit 1 fi @@ -77,65 +75,60 @@ YARN_MARKER="node_modules/.yarn_used" PNPM_MARKER="node_modules/.pnpm_used" BUN_MARKER="node_modules/.bun_used" -case "$PKG_MANAGER" in - npm) - INSTALL_CMD="npm install" - RUN_CMD="npm run $MODE" - CURRENT_MARKER="$NPM_MARKER" - ;; - yarn) - INSTALL_CMD="yarn" - RUN_CMD="yarn $MODE" - CURRENT_MARKER="$YARN_MARKER" - ;; - pnpm) - INSTALL_CMD="pnpm install" - RUN_CMD="pnpm $MODE" - CURRENT_MARKER="$PNPM_MARKER" - ;; - bun) - INSTALL_CMD="bun install" - RUN_CMD="bun $MODE" - CURRENT_MARKER="$BUN_MARKER" - ;; -esac - -if [[ -f "$NPM_MARKER" && "$CURRENT_MARKER" != "$NPM_MARKER" ]] || \ - [[ -f "$YARN_MARKER" && "$CURRENT_MARKER" != "$YARN_MARKER" ]] || \ - [[ -f "$PNPM_MARKER" && "$CURRENT_MARKER" != "$PNPM_MARKER" ]] || \ - [[ -f "$BUN_MARKER" && "$CURRENT_MARKER" != "$BUN_MARKER" ]]; then - cleanup=true +if [ "$PKG_MANAGER" == "npm" ]; then + INSTALL_CMD="npm install" + RUN_CMD="npm run $MODE" + CURRENT_MARKER="$NPM_MARKER" +elif [ "$PKG_MANAGER" == "yarn" ]; then + INSTALL_CMD="yarn" + RUN_CMD="yarn $MODE" + CURRENT_MARKER="$YARN_MARKER" +elif [ "$PKG_MANAGER" == "pnpm" ]; then + INSTALL_CMD="pnpm install" + RUN_CMD="pnpm $MODE" + CURRENT_MARKER="$PNPM_MARKER" +elif [ "$PKG_MANAGER" == "bun" ]; then + INSTALL_CMD="bun install" + RUN_CMD="bun $MODE" + CURRENT_MARKER="$BUN_MARKER" fi -if [[ "$cleanup" == "true" ]]; then - files_to_delete="package-lock.json yarn.lock pnpm-lock.yaml bun.lockb" - folders_to_delete="node_modules dist logs" - markers_to_delete="$NPM_MARKER $YARN_MARKER $PNPM_MARKER $BUN_MARKER" +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 +if [ -f "$BUN_MARKER" ] && [ "$CURRENT_MARKER" != "$BUN_MARKER" ]; then goto_cleanup=1; fi + +if [ "$goto_cleanup" == "1" ]; then + files_to_delete=("package-lock.json" "yarn.lock" "pnpm-lock.yaml" "bun.lockb") + folders_to_delete=("node_modules" "dist" "logs") + markers_to_delete=("$NPM_MARKER" "$YARN_MARKER" "$PNPM_MARKER" "$BUN_MARKER") echo "Cleaning up files and folders..." - for file in $files_to_delete; do - if [[ -f "$file" ]]; then + for file in "${files_to_delete[@]}"; do + if [ -f "$file" ]; then echo "Found $file in $SCRIPT_DIR - deleting..." rm -f "$file" fi done - for folder in $folders_to_delete; do - if [[ -d "$folder" ]]; then + for folder in "${folders_to_delete[@]}"; do + if [ -d "$folder" ]; then echo "Found $folder in $SCRIPT_DIR - deleting..." rm -rf "$folder" fi done - for marker in $markers_to_delete; do - if [[ -f "$marker" ]]; then + for marker in "${markers_to_delete[@]}"; do + if [ -f "$marker" ]; then rm -f "$marker" fi done + + exit 0 fi -if [[ -n "$RUN_CMD" ]]; then +if [ -n "$RUN_CMD" ]; then echo "Running $RUN_CMD..." $INSTALL_CMD $RUN_CMD