dx/dxkit/commands/init.command.sh

150 lines
No EOL
3.3 KiB
Bash

#!/usr/bin/env bash
# commands/init.command.sh
#
# Initializes the project for a given environment.
# Brings the stack to a runnable state: containers up, vendors installed,
# proxy started, framework initialized and configured.
#
# Usage:
# dx init [env] [flags]
#
# Flags:
# --skip-vendors Skip composer install
# --skip-framework-init Skip framework init
# --skip-framework-config Skip framework config generation
# --debug Enable shell trace
#
# ============================================
# Public entrypoint
# ============================================
function cmd::init::on_load() {
flag::register \
--skip-vendors \
--skip-framework-init \
--skip-framework-config \
--skip-proxy \
--debug
}
function cmd::init::run() {
local env=""
local flags=()
for arg in "$@"; do
case "$arg" in
--*) flags+=("$arg") ;;
*) [[ -z "$env" ]] && env="$arg" ;;
esac
done
if [[ ${#flags[@]} -gt 0 ]]; then
if ! flag::parse "${flags[@]}"; then
cmd::init::help
return 1
fi
fi
env="${env:-${ENVIRONMENT:-dev}}"
local framework_env
framework_env="$(app::resolve_env "$env")"
log::env "Initializing environment: ${env} (${framework_env})..."
# ============================================
# Docker
# ============================================
docker::compose::up -d >/dev/null
# ============================================
# Vendors
# ============================================
if ! flag::enabled --skip-vendors; then
app::install_vendors
else
log::fs_warning "$(app::vendor_skip_message)"
fi
# ============================================
# Proxy
# ============================================
if ! flag::enabled --skip-proxy; then
log::run_step network info "Starting proxy..." \
proxy::start
else
log::network_warning "Skipping Proxy initialization... (--skip-proxy)"
fi
# ============================================
# Framework
# ============================================
if ! flag::enabled --skip-framework-init; then
app::init "$env"
else
log::env_warning "$(app::init_skip_message)"
fi
if ! flag::enabled --skip-framework-config; then
app::config
else
log::env_warning "$(app::config_skip_message)"
fi
# ============================================
# Done
# ============================================
log::env_success "Environment '${env}' is ready!"
flag::scaffold_defaults_file
cmd::init::_hint_post_init
}
# ============================================
# Help
# ============================================
function cmd::init::help() {
cat <<EOF
Usage: dx init [env] [flags]
Brings the project to a runnable state for the given environment.
Arguments:
env dev | qly | prd (default: dev)
Flags:
--skip-vendors Skip vendor install
--skip-framework-init Skip framework init
--skip-framework-config Skip framework config generation
--debug Shell trace
EOF
app::post_init_hint
cat <<EOF
Examples:
dx init
dx init qly
dx init --skip-vendors
dx init qly --skip-framework-init --skip-framework-config
EOF
}
# ============================================
# Private
# ============================================
function cmd::init::_hint_post_init() {
echo ""
app::post_init_hint;
echo ""
}