Initial changes testing and running vue3
This commit is contained in:
1 parent
68f71c9d6c
commit
9f37d3faf1
68 files changed
+23452
-12
No files matched your search
@@ -1,22 +1,116 @@
|
||||
{ backupFile ? "" }:
|
||||
with import <nixpkgs> { };
|
||||
|
||||
let
|
||||
pythonPackages = python311Packages;
|
||||
in pkgs.mkShell rec {
|
||||
pkgs.mkShell {
|
||||
name = "Solid Scribe Env";
|
||||
|
||||
buildInputs = [
|
||||
# node for server
|
||||
buildInputs = [
|
||||
nodejs
|
||||
#nodePackages.npm
|
||||
nodemon
|
||||
pnpm
|
||||
pm2
|
||||
mariadb
|
||||
openssl
|
||||
];
|
||||
|
||||
postShellHook = ''
|
||||
echo("Welcome to solid scribe")
|
||||
shellHook = ''
|
||||
echo "Welcome to Solid Scribe"
|
||||
alias npm=pnpm
|
||||
'';
|
||||
|
||||
MYSQL_DATADIR="$PWD/.mysql/data"
|
||||
MYSQL_SOCKET="$PWD/.mysql/mysql.sock"
|
||||
MYSQL_PIDFILE="$PWD/.mysql/mysql.pid"
|
||||
|
||||
mkdir -p "$MYSQL_DATADIR"
|
||||
|
||||
# Initialize data directory on first run
|
||||
if [ ! -d "$MYSQL_DATADIR/mysql" ]; then
|
||||
echo "Initializing MySQL data directory (first run)..."
|
||||
mysql_install_db \
|
||||
--datadir="$MYSQL_DATADIR" \
|
||||
--skip-test-db \
|
||||
--auth-root-authentication-method=normal \
|
||||
2>/dev/null
|
||||
echo "Initialization complete."
|
||||
fi
|
||||
|
||||
# Start mysqld if not already running
|
||||
STARTED_MYSQL=0
|
||||
if ! mysqladmin --socket="$MYSQL_SOCKET" ping &>/dev/null 2>&1; then
|
||||
STARTED_MYSQL=1
|
||||
echo "Starting MySQL..."
|
||||
mysqld --no-defaults \
|
||||
--datadir="$MYSQL_DATADIR" \
|
||||
--socket="$MYSQL_SOCKET" \
|
||||
--pid-file="$MYSQL_PIDFILE" \
|
||||
--port=3306 \
|
||||
--bind-address=127.0.0.1 \
|
||||
--log-error="$PWD/.mysql/error.log" &
|
||||
|
||||
until mysqladmin --socket="$MYSQL_SOCKET" ping &>/dev/null 2>&1; do
|
||||
sleep 0.5
|
||||
done
|
||||
echo "MySQL ready."
|
||||
|
||||
mysql -u root --socket="$MYSQL_SOCKET" \
|
||||
-e "CREATE DATABASE IF NOT EXISTS application;" 2>/dev/null
|
||||
fi
|
||||
|
||||
# Set app DB env vars — dotenv won't override these since they're already in process.env
|
||||
export DB_HOST=127.0.0.1
|
||||
export DB_USER=root
|
||||
export DB_PASS=
|
||||
|
||||
# Stable dev JWT key, persisted across shell sessions
|
||||
if [ -z "''${JSON_KEY:-}" ]; then
|
||||
if [ -s "$PWD/.mysql/jwt_key" ]; then
|
||||
export JSON_KEY=$(cat "$PWD/.mysql/jwt_key")
|
||||
else
|
||||
export JSON_KEY=$(openssl rand -hex 32)
|
||||
echo "$JSON_KEY" > "$PWD/.mysql/jwt_key"
|
||||
echo "Generated dev JSON_KEY (saved to .mysql/jwt_key)"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Restore a SQL dump — handles both plain .sql and .gz files
|
||||
restore-db() {
|
||||
local file="''${1:-}"
|
||||
if [ -z "$file" ]; then
|
||||
echo "Usage: restore-db <backup.sql[.gz]>"
|
||||
return 1
|
||||
fi
|
||||
echo "Restoring database from $file ..."
|
||||
if [[ "$file" == *.gz ]]; then
|
||||
gunzip -c "$file" | mysql -u root --socket="$MYSQL_SOCKET"
|
||||
else
|
||||
mysql -u root --socket="$MYSQL_SOCKET" < "$file"
|
||||
fi
|
||||
# The dump is --all-databases, so it includes the `mysql` schema and
|
||||
# overwrites local root with production's credentials. In-memory grants
|
||||
# are still the old ones until FLUSH, so fix root now while we can
|
||||
# still authenticate.
|
||||
mysql -u root --socket="$MYSQL_SOCKET" -e "
|
||||
ALTER USER 'root'@'localhost' IDENTIFIED VIA mysql_native_password USING PASSWORD(''');
|
||||
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION;
|
||||
FLUSH PRIVILEGES;"
|
||||
|
||||
echo "Restore complete."
|
||||
}
|
||||
export -f restore-db
|
||||
|
||||
# Auto-restore if --argstr backupFile was passed to nix-shell
|
||||
if [ -n "${backupFile}" ]; then
|
||||
restore-db "${backupFile}"
|
||||
fi
|
||||
|
||||
if [ "$STARTED_MYSQL" = "1" ]; then
|
||||
trap "echo 'Stopping MySQL...'; mysqladmin -u root --socket=$MYSQL_SOCKET shutdown 2>/dev/null" EXIT
|
||||
else
|
||||
echo "MySQL already running (started by another shell) -- leaving it up on exit."
|
||||
fi
|
||||
|
||||
# Do not start the app here.
|
||||
# This same shell.nix is used for hosting the app on dev
|
||||
# use the startDevServerAndClient.sh script
|
||||
'';
|
||||
}
|
||||
Reference in new issue
Block a user