const fs = require("fs"); const path = require("path"); const dirs = fs.readdirSync(path.resolve(__dirname, "apps")); for (const d of dirs) { const config = require(path.resolve(__dirname, `apps/${d}/deploy.config`)); let content = `#!/bin/bash # # 部署脚本 # set -e # APP_NAME=${config.appName} START_TIME=$(date +%s) DATE=$(date +%m/%d/%y) TIME=$(date +%k:%M:%S) TARGET_VERSION=$(date +%Y%m%d%H%M) # 目录配置 DIST_NAME="dist" BUILD_NAME=${config.buildName} WORK_DIR=${config.workDir} REMOTE_DIR=${config.remoteDir} # SSH配置 REMOTE_USER=${config.remoteUser} REMOTE_IP=${config.remoteIp} PRIVATE_SSH_KEY=${config.privateSSHKey} # workspace cd $WORK_DIR # build echo -e "\\033[34m[INFO]\\033[0m Building $APP_NAME ..." npm run $BUILD_NAME # upload echo -e "\\033[34m[INFO]\\033[0m Uploading $APP_NAME to $REMOTE_IP ..." tar -cf "$DIST_NAME.zip" $DIST_NAME scp -i $PRIVATE_SSH_KEY "$DIST_NAME.zip" "$REMOTE_USER@$REMOTE_IP:$REMOTE_DIR" rm "$DIST_NAME.zip" # publish echo -e "\\033[34m[INFO]\\033[0m Publishing $APP_NAME to $REMOTE_IP ..." ssh -i $PRIVATE_SSH_KEY "$REMOTE_USER@$REMOTE_IP" /bin/bash <