125 lines
No EOL
3.6 KiB
Bash
125 lines
No EOL
3.6 KiB
Bash
#!/usr/bin/env bash
|
|
# framework/laravel.module.sh
|
|
#
|
|
# Laravel framework implementation.
|
|
# Implements the framework:: interface for Laravel projects.
|
|
|
|
# ============================================
|
|
# Skip messages
|
|
# ============================================
|
|
|
|
function framework::laravel::init_skip_message() { echo "Skipping Laravel bootstrap (--skip-framework-init)"; }
|
|
function framework::laravel::config_skip_message() { echo "Skipping Laravel config (--skip-framework-config)"; }
|
|
function framework::laravel::vendor_skip_message() { echo "Skipping Vendors (--skip-vendors)"; }
|
|
|
|
# ============================================
|
|
# Scaffold
|
|
# ============================================
|
|
|
|
function framework::laravel::scaffold() {
|
|
local target="$1"
|
|
|
|
log::run_step env "Building Laravel application (${target})..." \
|
|
composer::run_isolated create-project laravel/laravel "$target" --no-install
|
|
}
|
|
|
|
# ============================================
|
|
# Init
|
|
# ============================================
|
|
|
|
function framework::laravel::init() {
|
|
local env="$1"
|
|
local laravel_env
|
|
laravel_env="$(framework::laravel::resolve_env "$env")"
|
|
|
|
log::run_step env "Bootstrapping Laravel (${laravel_env})..." \
|
|
framework::laravel::_write_env_file "$env"
|
|
}
|
|
|
|
# ============================================
|
|
# Config
|
|
# ============================================
|
|
|
|
function framework::laravel::config() {
|
|
log::run_step env "Generating Laravel config cache..." \
|
|
framework::laravel::console config:cache
|
|
|
|
log::run_step env "Generating Laravel route cache..." \
|
|
framework::laravel::console route:cache
|
|
}
|
|
|
|
# ============================================
|
|
# Console
|
|
# ============================================
|
|
|
|
function framework::laravel::console_name() { echo "artisan"; }
|
|
function framework::laravel::console() { runtime::exec php artisan "$@"; }
|
|
|
|
# ============================================
|
|
# Resolve env
|
|
# ============================================
|
|
|
|
function framework::laravel::resolve_env() {
|
|
case "$1" in
|
|
dev) echo "local" ;;
|
|
qly) echo "staging" ;;
|
|
prd) echo "production" ;;
|
|
*) echo "$1" ;;
|
|
esac
|
|
}
|
|
|
|
# ============================================
|
|
# Vendors
|
|
# ============================================
|
|
|
|
function framework::laravel::install_vendors() {
|
|
log::run_step auth info "Setting Composer auth for domain ${GIT_DOMAIN}..." \
|
|
composer::config_auth nocache "$GIT_DOMAIN" "$GIT_AUTH_TOKEN_ID" "$GIT_AUTH_TOKEN_PW"
|
|
|
|
log::run_step fs "Installing vendors..." \
|
|
composer::install
|
|
}
|
|
|
|
# ============================================
|
|
# Post-init hint
|
|
# ============================================
|
|
|
|
function framework::laravel::post_init_hint() {
|
|
cat <<EOF
|
|
Next steps (run manually after):
|
|
dx artisan migrate
|
|
dx artisan db:seed
|
|
dx artisan key:generate
|
|
EOF
|
|
}
|
|
|
|
# ============================================
|
|
# Private
|
|
# ============================================
|
|
|
|
function framework::laravel::_write_env_file() {
|
|
local env="$1"
|
|
local env_file
|
|
env_file="$(ctx::root)/.env"
|
|
|
|
if [[ -f "$env_file" ]]; then
|
|
log::info ".env already exists — skipping"
|
|
return 0
|
|
fi
|
|
|
|
if [[ ! -f "$(ctx::root)/.env.example" ]]; then
|
|
log::error ".env.example not found — cannot generate .env"
|
|
return 1
|
|
fi
|
|
|
|
cp "$(ctx::root)/.env.example" "$env_file"
|
|
|
|
local laravel_env
|
|
laravel_env="$(framework::laravel::resolve_env "$env")"
|
|
|
|
# Patch APP_ENV and APP_URL in the generated .env
|
|
sed -i "s/^APP_ENV=.*/APP_ENV=${laravel_env}/" "$env_file"
|
|
sed -i "s|^APP_URL=.*|APP_URL=http://${DOMAIN}|" "$env_file"
|
|
|
|
log::success ".env generated for environment: ${laravel_env}"
|
|
} |