TeaSpeak-Client/build_declarations.sh
2019-07-03 14:15:57 +02:00

89 lines
2.6 KiB
Bash
Executable File

#!/usr/bin/env bash
BASEDIR=$(dirname "$0")
cd "${BASEDIR}"
file_paths=(
"$(pwd ~)/../../Web-Client/shared/declarations"
# "$(pwd ~)/TeaSpeak/Web-Client/shared/declarations"
# "$(pwd ~)/../../TeaSpeak/Web-Client/shared/declarations"
"app/dummy-declarations"
#TODO Windows path
)
files=(
"exports.d.ts;imports_shared.d.ts"
# "exports_loader.d.ts;imports_shared_loader.d.ts"
)
path_target="./modules/renderer/imports"
path_found=0
{
mkdir -p "${path_target}"
for path in "${file_paths[@]}"
do
path_found=1
for file_mapping in "${files[@]}"
do
file_mapping=($(echo ${file_mapping} | tr ";" " "))
file=${file_mapping[0]}
if [[ ! -f "${path}/${file}" ]]; then
path_found=0
echo "path test ${path} failed to file ${file}"
break
fi
done
[[ path_found -eq 1 ]] || continue
for file in "${files[@]}"
do
file_mapping=$(echo ${file_mapping} | tr ";" "\n")
src_file=${file_mapping[0]}
dst_file=${file_mapping[1]}
if [[ -e "${path_target}/${dst_file}" ]] || [[ -L "${path_target}/${dst_file}" ]]; then
rm "${path_target}/${dst_file}"
fi
ln -rs "${path}/${src_file}" "${path_target}/${dst_file}"
echo "Linking \"${path_target}/${dst_file}\" to \"${path}/${src_file}\""
cp "${path}/${src_file}" "${path_target}/copy_${dst_file}"
echo "Create copy \"${path}/${src_file}\" to \"${path_target}/copy_${dst_file}\""
done
break
done
}
if [[ ${path_found} -eq 0 ]]; then
echo "Could not import a link to shared imports. Trying copied import."
for file in "${files[@]}"
do
file_mapping=$(echo ${file_mapping} | tr ";" "\n")
dst_file=${file_mapping[1]}
if [[ -e "${path_target}/${dst_file}" ]] || [[ -L "${path_target}/${dst_file}" ]]; then
echo "Hmm target file already exists even thou it hasn't been found yet... Deleting it!"
rm "${path_target}/${dst_file}"
fi
if [[ ! -e "${path_target}/copy_${dst_file}" ]]; then
echo "Missing copy of file ${dst_file} because we cant find any valid link!"
exit 1
fi
ln -rs "${path_target}/copy_${dst_file}" "${path_target}/${dst_file}"
echo "Linking \"${path_target}/${dst_file}\" to \"${path_target}/copy_${dst_file}\""
done
path_found=1
fi
if [[ path_found -eq 0 ]]; then
echo "Failed to find UI imports"
echo "Add your path to 'file_paths' and build the declarations first"
exit 1
fi
exit 1