if [ "$#" -ne 1 ]; then
echo "Usage: $0 <sourceFileName>"
exit 1
fi
sourceName="$1"
targetDir="/home/build-app-source/src"
appDistDir="/home/app-dist"
# 提取檔名(不帶路徑和副檔名)
sourceBaseName=$(basename "$sourceName")
sourceNameNoExt="${sourceBaseName%.*}"
# 複製檔案到目標目錄並重新命名為App.vue
cp "$sourceName" "${targetDir}/App.vue"
# 切換到構建目錄
cd /home/build-app-source || { echo "Failed to change directory"; exit 1; }
# 執行構建命令
npm run build
# 等待一段時間,確保構建完成
sleep 5 # 等待5秒
# 檢查構建是否成功
if [ $? -eq 0 ]; then
echo "Build succeeded."
# 檢查 dist 資料夾是否存在
if [ ! -d "/home/build-app-source/dist" ]; then
echo "dist folder does not exist. Build might have failed."
exit 1
fi
# 構建成功後重新命名dist資料夾
mv /home/build-app-source/dist "${sourceNameNoExt}-dist"
# 確保目標資料夾存在
if [ ! -d "${appDistDir}" ]; then
mkdir -p "${appDistDir}"
fi
# 移動構建結果到目標位置
mv "${sourceNameNoExt}-dist" "${appDistDir}"
echo "Build and move successful."
else
echo "Build failed."
exit 1
fi