107 lines
No EOL
2.5 KiB
Bash
107 lines
No EOL
2.5 KiB
Bash
#!/usr/bin/env bash
|
|
# modules/composer.module.sh
|
|
#
|
|
# Composer wrapper for both in-runtime and bootstrap operations.
|
|
#
|
|
# Two execution modes:
|
|
# composer::run — runs inside the project's runtime
|
|
# (use when the runtime is up)
|
|
# composer::run_isolated — runs in a one-shot Docker container
|
|
# (use for bootstrap before runtime exists)
|
|
|
|
# ============================================
|
|
# Execution modes
|
|
# ============================================
|
|
|
|
# Run composer inside the project's runtime.
|
|
# Requires the runtime to be up.
|
|
function composer::run() {
|
|
runtime::exec composer "$@"
|
|
}
|
|
|
|
# Run composer in a one-shot Docker container.
|
|
# Use for scaffold and other operations that happen before the runtime exists.
|
|
function composer::run_isolated() {
|
|
docker::raw run --rm \
|
|
-v "$(ctx::root):/app" \
|
|
-w /app \
|
|
composer:latest "$@"
|
|
}
|
|
|
|
# ============================================
|
|
# Auth
|
|
# ============================================
|
|
|
|
function composer::config_auth() {
|
|
local mode="cache"
|
|
|
|
if [[ "$1" == "cache" || "$1" == "nocache" ]]; then
|
|
mode="$1"
|
|
shift
|
|
fi
|
|
|
|
local domain="$1"
|
|
local id="$2"
|
|
local pw="$3"
|
|
|
|
if [[ -z "$domain" || -z "$id" || -z "$pw" ]]; then
|
|
log::error "composer::config_auth: domain, id, and password are required"
|
|
return 1
|
|
fi
|
|
|
|
[[ "$mode" == "nocache" ]] && \
|
|
runtime::exec rm -f /root/.composer/auth.json
|
|
|
|
runtime::exec composer config \
|
|
--global \
|
|
--auth "http-basic.${domain}" \
|
|
"$id" \
|
|
"$pw"
|
|
}
|
|
|
|
# ============================================
|
|
# Vendor management
|
|
# ============================================
|
|
|
|
function composer::install() {
|
|
runtime::exec composer install \
|
|
--prefer-dist \
|
|
--no-interaction \
|
|
--no-progress \
|
|
--optimize-autoloader \
|
|
"$@"
|
|
}
|
|
|
|
function composer::update() {
|
|
runtime::exec composer update \
|
|
--prefer-dist \
|
|
--no-interaction \
|
|
--no-progress \
|
|
"$@"
|
|
}
|
|
|
|
function composer::require() {
|
|
runtime::exec composer require \
|
|
--no-interaction \
|
|
--no-progress \
|
|
"$@"
|
|
}
|
|
|
|
function composer::delete_lock() {
|
|
runtime::exec rm -f composer.lock
|
|
}
|
|
|
|
# ============================================
|
|
# Inspection
|
|
# ============================================
|
|
|
|
function composer::version() { runtime::exec composer --version; }
|
|
function composer::validate() { runtime::exec composer validate; }
|
|
|
|
function composer::has_lockfile() {
|
|
[[ -f "$(ctx::root)/composer.lock" ]]
|
|
}
|
|
|
|
function composer::has_manifest() {
|
|
[[ -f "$(ctx::root)/composer.json" ]]
|
|
} |