|
| 1 | +#!/bin/bash |
| 2 | +set -e # Exit immediately if a command exits with a non-zero status. |
| 3 | + |
| 4 | +# --- Configuration --- |
| 5 | +# Attempt to get version from package.json |
| 6 | +PACKAGE_VERSION=$(node -p "require('./package.json').version") |
| 7 | +# Suggest a release version by stripping common pre-release suffixes like -dev.X or -alpha.X etc. |
| 8 | +SUGGESTED_RELEASE_VERSION=$(echo "$PACKAGE_VERSION" | sed -E 's/-(dev|alpha|beta|rc|pre)[-.0-9]*$//') |
| 9 | + |
| 10 | +# --- User Input for Version --- |
| 11 | +echo "Current version in package.json: $PACKAGE_VERSION" |
| 12 | +read -p "Enter release version (default: $SUGGESTED_RELEASE_VERSION): " USER_VERSION |
| 13 | +RELEASE_VERSION=${USER_VERSION:-$SUGGESTED_RELEASE_VERSION} |
| 14 | + |
| 15 | +if [[ -z "$RELEASE_VERSION" ]]; then |
| 16 | + echo "Error: Release version cannot be empty." |
| 17 | + exit 1 |
| 18 | +fi |
| 19 | +echo "Creating release for version: v$RELEASE_VERSION" |
| 20 | + |
| 21 | +# --- Definitions --- |
| 22 | +APP_NAME="pulse" # Or derive from package.json if preferred |
| 23 | +RELEASE_DIR_NAME="${APP_NAME}-v${RELEASE_VERSION}" |
| 24 | +STAGING_PARENT_DIR="pulse-release-staging" # Temporary parent for the release content |
| 25 | +STAGING_FULL_PATH="$STAGING_PARENT_DIR/$RELEASE_DIR_NAME" |
| 26 | +TARBALL_NAME="${RELEASE_DIR_NAME}.tar.gz" |
| 27 | + |
| 28 | +# --- Cleanup Previous Attempts --- |
| 29 | +echo "Cleaning up previous attempts..." |
| 30 | +rm -rf "$STAGING_PARENT_DIR" |
| 31 | +rm -f "$TARBALL_NAME" |
| 32 | +mkdir -p "$STAGING_FULL_PATH" |
| 33 | + |
| 34 | +# --- Build Step --- |
| 35 | +echo "Building CSS..." |
| 36 | +npm run build:css |
| 37 | +if [ ! -f "src/public/output.css" ]; then |
| 38 | + echo "Error: src/public/output.css not found after build. Aborting." |
| 39 | + exit 1 |
| 40 | +fi |
| 41 | + |
| 42 | +# --- Copy Application Files --- |
| 43 | +echo "Copying application files to $STAGING_FULL_PATH..." |
| 44 | + |
| 45 | +# Server files (excluding tests) |
| 46 | +echo "Copying server files..." |
| 47 | +rsync -av --progress server/ "$STAGING_FULL_PATH/server/" --exclude 'tests/' |
| 48 | + |
| 49 | +# Public files (including built CSS and other assets) |
| 50 | +echo "Copying public files..." |
| 51 | +mkdir -p "$STAGING_FULL_PATH/src" # Ensure parent directory exists |
| 52 | +rsync -av --progress src/public/ "$STAGING_FULL_PATH/src/public/" |
| 53 | + |
| 54 | +# Root files |
| 55 | +echo "Copying root files..." |
| 56 | +cp package.json "$STAGING_FULL_PATH/" |
| 57 | +cp package-lock.json "$STAGING_FULL_PATH/" |
| 58 | +cp README.md "$STAGING_FULL_PATH/" |
| 59 | +cp LICENSE "$STAGING_FULL_PATH/" |
| 60 | +cp CHANGELOG.md "$STAGING_FULL_PATH/" |
| 61 | +cp .env.example "$STAGING_FULL_PATH/.env.example" # Essential for user configuration |
| 62 | + |
| 63 | +# Scripts (e.g., install-pulse.sh, if intended for end-user) |
| 64 | +if [ -d "scripts" ]; then |
| 65 | + echo "Copying scripts..." |
| 66 | + mkdir -p "$STAGING_FULL_PATH/scripts/" |
| 67 | + if [ -f "scripts/install-pulse.sh" ]; then |
| 68 | + cp scripts/install-pulse.sh "$STAGING_FULL_PATH/scripts/" |
| 69 | + fi |
| 70 | + # Add other scripts if they are part of the release |
| 71 | +fi |
| 72 | + |
| 73 | +# Docs |
| 74 | +if [ -d "docs" ]; then |
| 75 | + echo "Copying docs..." |
| 76 | + rsync -av --progress docs/ "$STAGING_FULL_PATH/docs/" |
| 77 | +fi |
| 78 | + |
| 79 | +# --- Install Production Dependencies --- |
| 80 | +echo "Installing production dependencies in $STAGING_FULL_PATH..." |
| 81 | +(cd "$STAGING_FULL_PATH" && npm install --omit=dev --ignore-scripts) |
| 82 | +# --ignore-scripts prevents any package's own postinstall scripts from running during this build phase. |
| 83 | +# If your production dependencies have essential postinstall scripts, you might remove --ignore-scripts. |
| 84 | + |
| 85 | +# --- Create Tarball --- |
| 86 | +echo "Creating tarball: $TARBALL_NAME..." |
| 87 | +# Go into the parent of the directory to be tarred to avoid leading paths in tarball |
| 88 | +(cd "$STAGING_PARENT_DIR" && tar -czf "../../$TARBALL_NAME" "$RELEASE_DIR_NAME") |
| 89 | + |
| 90 | +# --- Cleanup --- |
| 91 | +echo "Cleaning up staging directory ($STAGING_PARENT_DIR)..." |
| 92 | +rm -rf "$STAGING_PARENT_DIR" |
| 93 | + |
| 94 | +echo "" |
| 95 | +echo "----------------------------------------------------" |
| 96 | +echo "Release tarball created: $TARBALL_NAME" |
| 97 | +echo "----------------------------------------------------" |
| 98 | +echo "To use the tarball:" |
| 99 | +echo "1. Copy $TARBALL_NAME to the target server." |
| 100 | +echo "2. Extract: tar -xzf $TARBALL_NAME" |
| 101 | +echo "3. Navigate into the directory: cd $RELEASE_DIR_NAME" |
| 102 | +echo "4. Copy .env.example to .env and configure it: cp .env.example .env" |
| 103 | +echo "5. Start the application: npm start (or node server/index.js)" |
| 104 | +echo " (If scripts/install-pulse.sh is provided, consult it for specific setup steps)" |
| 105 | +echo "----------------------------------------------------" |
0 commit comments