131 lines
No EOL
3.8 KiB
Bash
131 lines
No EOL
3.8 KiB
Bash
#!/usr/bin/env bash
|
|
# modules/framework/yii2-basic.module.sh
|
|
#
|
|
# Yii2 Basic framework implementation.
|
|
|
|
# ============================================
|
|
# Skip messages
|
|
# ============================================
|
|
|
|
function framework::yii2-basic::init_skip_message() { echo "Skipping Yii init (--skip-framework-init)"; }
|
|
function framework::yii2-basic::config_skip_message() { echo "Skipping Yii config (--skip-framework-config)"; }
|
|
function framework::yii2-basic::vendor_skip_message() { echo "Skipping Vendors (--skip-vendors)"; }
|
|
|
|
# ============================================
|
|
# Identity
|
|
# ============================================
|
|
|
|
function framework::yii2-basic::console_name() { echo "yii"; }
|
|
|
|
# ============================================
|
|
# Templates
|
|
# ============================================
|
|
|
|
function framework::yii2-basic::vhost_template_path() {
|
|
echo "$(ctx::templates)/apache/yii2-basic/vhosts.conf.template"
|
|
}
|
|
|
|
function framework::yii2-basic::_template_root() { echo "$(ctx::templates)/yii2-basic"; }
|
|
function framework::yii2-basic::_config_root() { echo "$(ctx::root)/config"; }
|
|
|
|
function framework::yii2-basic::_template() {
|
|
local templateFile="$1"
|
|
local path="$(framework::yii2-basic::_template_root)/${templateFile}.php.template"
|
|
|
|
require_file "$path" || {
|
|
log::fs_error "${templateFile}.php.template does not exist!"
|
|
return 1
|
|
}
|
|
|
|
printf "%s" "$path"
|
|
}
|
|
|
|
# ============================================
|
|
# Scaffold
|
|
# ============================================
|
|
|
|
function framework::yii2-basic::scaffold() {
|
|
local target="$1"
|
|
|
|
log::run_step env "Building Yii2 Basic application (${target})..." \
|
|
composer::run_isolated create-project yiisoft/yii2-app-basic "$target" --no-install
|
|
}
|
|
|
|
# ============================================
|
|
# Init
|
|
# ============================================
|
|
|
|
function framework::yii2-basic::init() {
|
|
local env="$1"
|
|
local yii_env
|
|
yii_env="$(framework::yii2-basic::resolve_env "$env")"
|
|
|
|
log::run_step env "Initializing Yii2 Basic (${yii_env})..." \
|
|
framework::yii2-basic::_ensure_runtime_dirs
|
|
}
|
|
|
|
# ============================================
|
|
# Config
|
|
# ============================================
|
|
|
|
function framework::yii2-basic::config() {
|
|
log::run_step env "Generating Yii config..." \
|
|
framework::yii2-basic::_generate_config db.php
|
|
}
|
|
|
|
function framework::yii2-basic::_generate_config() {
|
|
local output="$(framework::yii2-basic::_config_root)/$1"
|
|
|
|
template::render \
|
|
"$(framework::yii2-basic::_template "db.${DB_ENGINE}")" \
|
|
"$output" \
|
|
DB_NAME="$DB_NAME" \
|
|
DB_USER="$DB_USER" \
|
|
DB_PASS="$DB_PASS"
|
|
}
|
|
|
|
# ============================================
|
|
# Console + env resolution
|
|
# ============================================
|
|
|
|
function framework::yii2-basic::console() { yii::exec "$@"; }
|
|
function framework::yii2-basic::resolve_env() { yii::resolve_env "$@"; }
|
|
|
|
# ============================================
|
|
# Vendors
|
|
# ============================================
|
|
|
|
function framework::yii2-basic::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::yii2-basic::post_init_hint() {
|
|
cat <<EOF
|
|
Next steps (run manually after):
|
|
dx yii migrate
|
|
EOF
|
|
}
|
|
|
|
# ============================================
|
|
# Private
|
|
# ============================================
|
|
|
|
function framework::yii2-basic::_ensure_runtime_dirs() {
|
|
local dirs=(
|
|
"$(ctx::root)/runtime"
|
|
"$(ctx::root)/web/assets"
|
|
)
|
|
|
|
local dir
|
|
for dir in "${dirs[@]}"; do
|
|
[[ -d "$dir" ]] || mkdir -p "$dir"
|
|
done
|
|
} |