File size: 2,988 Bytes
c7d34c1
 
 
 
 
 
 
 
f250aec
c7d34c1
 
 
 
 
 
 
 
 
 
704e84f
c7d34c1
 
 
96bdf6c
c7d34c1
 
 
704e84f
c7d34c1
 
 
 
704e84f
c7d34c1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
704e84f
 
c7d34c1
704e84f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c7d34c1
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env bash
set -euo pipefail

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"

echo
echo "========================================"
echo "Visual Journal Launcher"
echo "========================================"
echo

if [ ! -f "package.json" ]; then
    echo "[ERROR] package.json was not found. Please keep this file in the project root."
    exit 1
fi

if ! command -v node >/dev/null 2>&1; then
    echo "[ERROR] Node.js was not found."
    echo "Please install Node.js 22.15.0 or later: https://nodejs.org/"
    exit 1
fi

if ! node -e "import('./scripts/node-version.mjs').then(function(module){process.exit(module.isSupportedNodeVersion()?0:1)})"; then
    echo "[ERROR] Node.js version is too old."
    echo "Current version:"
    node -v
    echo "Required: Node.js 22.15.0 or later. Download: https://nodejs.org/"
    exit 1
fi

if ! command -v npm >/dev/null 2>&1; then
    echo "[ERROR] npm was not found. Please reinstall Node.js 22.15.0 or later."
    exit 1
fi

if ! node -e "const net=require('net'); const s=net.createServer(); s.once('error',()=>process.exit(1)); s.once('listening',()=>s.close(()=>process.exit(0))); s.listen(4783)" >/dev/null 2>&1; then
    echo "[ERROR] Port 4783 is already in use. Please stop the existing service and run this script again."
    exit 1
fi

if [ ! -f ".env.local" ]; then
    if [ -f ".env.example" ]; then
        cp ".env.example" ".env.local"
        echo "[INFO] Created .env.local from .env.example."
        echo "[INFO] You can edit .env.local or use API Settings in the browser."
        echo
    else
        echo "[WARN] .env.example was not found. Skipping env file setup."
        echo
    fi
else
    echo "[INFO] .env.local found."
fi

if node scripts/dependency-installation.mjs; then
    echo "[INFO] Dependencies match package-lock.json. Skipping installation."
else
    echo "[INFO] Dependencies are missing or incomplete. Installing from package-lock.json. This may take a few minutes."
    echo
    if ! npm run install-scripts:check; then
        echo "[ERROR] Dependency install script policy validation failed."
        exit 1
    fi
    if ! node scripts/npm-install-policy.mjs; then
        echo "[ERROR] Current npm does not support --strict-allow-scripts. Upgrade npm before installing dependencies."
        exit 1
    fi
    if ! npm ci --strict-allow-scripts; then
        echo "[ERROR] Dependency installation failed. Please check the network and run again."
        exit 1
    fi
    if ! npm run dependencies:check; then
        echo "[ERROR] Dependency installation completed with an incomplete package tree. Please run the install command again."
        exit 1
    fi
fi

echo
echo "[INFO] Starting local server. Keep this terminal open."
echo "[INFO] Browser URL: http://localhost:4783"
echo "[INFO] If the browser does not open automatically, copy the URL above."
echo

(sleep 5; open "http://localhost:4783" >/dev/null 2>&1 || true) &
PORT=4783 npm run dev