#!/bin/bash set -euo pipefail # Description: Create distribution package with binaries and configs # Arguments: [version] - version string (default: from Cargo.toml) # Returns: 0 on success, 1 on failure # Output: Distribution package path readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" readonly WORKSPACE_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)" readonly DISTRO_DIR="${WORKSPACE_ROOT}/distribution" readonly BUILD_DIR="${WORKSPACE_ROOT}/target/release" # Extract version from Cargo.toml get_version() { grep '^version' "${WORKSPACE_ROOT}/crates/typedialog-core/Cargo.toml" | head -1 | sed 's/.*"\([^"]*\)".*/\1/' } # Function: Print info message log_info() { echo "[INFO] $*" >&2 } # Function: Print error message log_error() { echo "[ERROR] $*" >&2 } # Function: Validate files exist validate_files() { local missing=0 for file in "$@"; do if [[ ! -f "$file" ]]; then log_error "Missing: $file" ((missing++)) fi done return $((missing > 0 ? 1 : 0)) } # Function: Create distribution directory create_distro_structure() { local version="$1" local distro_path="${DISTRO_DIR}/typedialog-${version}" mkdir -p "${distro_path}"/{bin,config,docs,lib} echo "$distro_path" } # Function: Copy binaries copy_binaries() { local distro_path="$1" if [[ -f "${BUILD_DIR}/typedialog" ]]; then cp "${BUILD_DIR}/typedialog" "${distro_path}/bin/" fi if [[ -f "${BUILD_DIR}/typedialog-tui" ]]; then cp "${BUILD_DIR}/typedialog-tui" "${distro_path}/bin/" fi if [[ -f "${BUILD_DIR}/typedialog-web" ]]; then cp "${BUILD_DIR}/typedialog-web" "${distro_path}/bin/" fi } # Function: Copy configurations copy_configs() { local distro_path="$1" cp -r "${WORKSPACE_ROOT}/config"/* "${distro_path}/config/" || { log_error "Failed to copy configurations" return 1 } } # Function: Copy installers copy_installers() { local distro_path="$1" mkdir -p "${distro_path}/installers" if [[ -f "${WORKSPACE_ROOT}/installers/bootstrap/install.sh" ]]; then cp "${WORKSPACE_ROOT}/installers/bootstrap/install.sh" "${distro_path}/installers/" chmod +x "${distro_path}/installers/install.sh" fi if [[ -f "${WORKSPACE_ROOT}/installers/bootstrap/install.ps1" ]]; then cp "${WORKSPACE_ROOT}/installers/bootstrap/install.ps1" "${distro_path}/installers/" fi if [[ -f "${WORKSPACE_ROOT}/installers/bootstrap/README.md" ]]; then cp "${WORKSPACE_ROOT}/installers/bootstrap/README.md" "${distro_path}/installers/" fi } # Function: Create manifest create_manifest() { local distro_path="$1" local version="$2" local manifest="${distro_path}/MANIFEST.json" cat > "$manifest" <