176 lines
5.4 KiB
Bash
176 lines
5.4 KiB
Bash
#!/usr/bin/env bash
|
|
# framework/yii2-advanced.module.sh
|
|
#
|
|
# Yii2 Advanced framework implementation.
|
|
# Implements the framework:: interface for Yii2 Advanced projects.
|
|
# Owns config generation, init lifecycle, and template handling
|
|
# specific to the advanced template's directory layout.
|
|
|
|
# ============================================
|
|
# Load
|
|
# ============================================
|
|
|
|
function framework::yii2-advanced::on_load() {
|
|
load_module yii
|
|
load_module template
|
|
}
|
|
|
|
# ============================================
|
|
# Skip messages
|
|
# ============================================
|
|
|
|
function framework::yii2-advanced::init_skip_message() { echo "Skipping Yii init (--skip-framework-init)"; }
|
|
function framework::yii2-advanced::config_skip_message() { echo "Skipping Yii config (--skip-framework-config)"; }
|
|
function framework::yii2-advanced::vendor_skip_message() { echo "Skipping Vendors (--skip-vendors)"; }
|
|
|
|
# ============================================
|
|
# Templates
|
|
# ============================================
|
|
|
|
function framework::yii2-advanced::vhost_template_path() { echo "$(ctx::templates)/apache/yii2-advanced/vhosts.conf.template"; }
|
|
|
|
function framework::yii2-advanced::_template_root() { echo "$(ctx::templates)/yii2-advanced"; }
|
|
function framework::yii2-advanced::_components_template_root() { echo "$(framework::yii2-advanced::_template_root)/components"; }
|
|
function framework::yii2-advanced::_config_root() { echo "$(ctx::root)/common/config"; }
|
|
|
|
function framework::yii2-advanced::_template() {
|
|
local templateFile="$1"
|
|
local path="$(framework::yii2-advanced::_template_root)/${templateFile}.php.template"
|
|
|
|
require_file "$path" || {
|
|
log::fs_error "${templateFile}.php.template does not exist!"
|
|
return 1
|
|
}
|
|
|
|
printf "%s" "$path"
|
|
}
|
|
|
|
function framework::yii2-advanced::_template_component() {
|
|
local templateFile="$1"
|
|
local path="$(framework::yii2-advanced::_components_template_root)/${templateFile}.php.template"
|
|
|
|
require_file "$path" || {
|
|
log::fs_error "${templateFile}.php.template does not exist!"
|
|
return 1
|
|
}
|
|
|
|
printf "%s" "$path"
|
|
}
|
|
|
|
function framework::yii2-advanced::_components() {
|
|
printf '%s\n' \
|
|
"db.${DB_ENGINE}" \
|
|
"log"
|
|
}
|
|
|
|
function framework::yii2-advanced::_build_components() {
|
|
local components=()
|
|
|
|
for component in $(framework::yii2-advanced::_components); do
|
|
local comp
|
|
comp=$(envsubst < "$(framework::yii2-advanced::_template_component "$component")")
|
|
|
|
# remove blank lines
|
|
comp=$(printf "%s" "$comp" | sed '/^[[:space:]]*$/d')
|
|
|
|
components+=("$comp")
|
|
done
|
|
|
|
printf "%s\n" "${components[@]}"
|
|
}
|
|
|
|
# ============================================
|
|
# Scaffold
|
|
# ============================================
|
|
|
|
function framework::yii2-advanced::scaffold() {
|
|
local target="$1"
|
|
|
|
log::run_step env "Building Yii2 Advanced application ($target)..." \
|
|
composer::run_isolated create-project yiisoft/yii2-app-advanced "$target" --no-install
|
|
}
|
|
|
|
function framework::yii2-advanced::scaffold() {
|
|
local target="$1"
|
|
local tmp="_scaffold_tmp"
|
|
|
|
log::run_step env "Scaffolding Yii2 Advanced (${target})..." \
|
|
composer::run_isolated sh -c \
|
|
'composer create-project yiisoft/yii2-app-advanced "$1" --no-install && cp -rn "$1/." . && rm -rf "$1"' \
|
|
-- "$tmp"
|
|
}
|
|
|
|
# ============================================
|
|
# Init
|
|
# ============================================
|
|
|
|
function framework::yii2-advanced::init() {
|
|
local env="$1"
|
|
local yii_env
|
|
yii_env="$(yii::resolve_env "$env")"
|
|
|
|
log::run_step env "Initializing Yii2 Advanced (${yii_env})..." \
|
|
runtime::exec php init \
|
|
--env="$yii_env" \
|
|
--overwrite=All \
|
|
--interactive=0
|
|
}
|
|
|
|
# ============================================
|
|
# Config
|
|
# ============================================
|
|
|
|
function framework::yii2-advanced::config() {
|
|
log::run_step env "Generating Yii config..." \
|
|
framework::yii2-advanced::_generate_config main-local.php
|
|
}
|
|
|
|
function framework::yii2-advanced::_generate_config() {
|
|
local output="$(framework::yii2-advanced::_config_root)/$1"
|
|
local components="$(framework::yii2-advanced::_build_components)"
|
|
|
|
# indent components for placement inside the components: array
|
|
local indented_components
|
|
indented_components=$(printf "%s\n" "$components" | sed 's/^/ /')
|
|
|
|
template::render \
|
|
"$(framework::yii2-advanced::_template main-local)" \
|
|
"$output" \
|
|
YII_MAIN_LOCAL_COMPONENTS="$indented_components"
|
|
}
|
|
|
|
# ============================================
|
|
# Console / Env
|
|
# ============================================
|
|
|
|
function framework::yii2-advanced::console_name() { echo "yii"; }
|
|
function framework::yii2-advanced::console() { yii::exec "$@"; }
|
|
function framework::yii2-advanced::resolve_env() { yii::resolve_env "$@"; }
|
|
|
|
# ============================================
|
|
# Vendors
|
|
# ============================================
|
|
|
|
function framework::yii2-advanced::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-advanced::post_init_hint() {
|
|
cat <<EOF
|
|
Next steps (run manually after):
|
|
dx yii migrate
|
|
dx yii gatekeeper/sync-permissions
|
|
EOF
|
|
}
|
|
|
|
# ============================================
|
|
# Private
|
|
# ============================================
|