#!/usr/bin/env bash # Resolve paths in projects//conf.json: absolute paths unchanged; others relative to smart_ide monorepo root. # Monorepo root is the directory that contains ./projects/ (conf at .../projects//conf.json) or, when the # file lives under .../ia_dev/projects//conf.json, the parent of ./ia_dev/. # ia_dev_smart_ide_monorepo_root_from_conf ia_dev_smart_ide_monorepo_root_from_conf() { local conf="${1:?}" local c="$conf" if command -v realpath >/dev/null 2>&1; then c="$(realpath "$conf" 2>/dev/null)" || c="$conf" else c="$(readlink -f "$conf" 2>/dev/null)" || c="$conf" fi local d d="$(dirname "$c")" if [[ "$c" == */ia_dev/projects/*/conf.json ]]; then ( cd "$d/../../.." && pwd ) return fi if [[ "$c" == */projects/*/conf.json ]]; then ( cd "$d/../.." && pwd ) return fi ( cd "$d/../.." && pwd ) } # ia_dev_resolve_path_from_conf ia_dev_resolve_path_from_conf() { local conf="${1:?}" local p="${2:-}" p="${p//$'\r'/}" if [[ -z "$p" || "$p" == "null" ]]; then printf '%s\n' "" return 0 fi if [[ "$p" = /* ]]; then printf '%s\n' "$p" return 0 fi local root root="$(ia_dev_smart_ide_monorepo_root_from_conf "$conf")" if ( cd "$root" && realpath -m "$p" >/dev/null 2>&1 ); then ( cd "$root" && realpath -m "$p" ) else printf '%s\n' "$root/$p" fi }