Quantcast

chore: 🤖 Build scripts

eiymba [11-05-22 - 04:32]
chore: 🤖 Build scripts
Filename
build.ps1
build.sh
diff --git a/build.ps1 b/build.ps1
index 0b20319..59902fb 100644
--- a/build.ps1
+++ b/build.ps1
@@ -1,75 +1,155 @@
 param (

-    [  Bool  ]  $Release = $False, # Build for release. Creates a ./dist folder for distribution.
-    [  Bool  ]  $Clean = $True, # Clean the build directory folder before building.
-    [  Bool  ]  $CopyToWow = $False, # After building, copy and extract the files to directories defined by $WowVersions.
-    [ string ]  $PackageName = "ArcHUD3", # Set the package name. Default: ArcHUD3.
-    [ string ]  $PackageVersion = $(Get-Content -Path .\VERSION.txt), # Set the package version. Defaults to the value in VERSION.txt.
-    [ string ]  $BuildDir = ".\build", # Set the build directory. Default: .\build
-
-    # Set the build destination path.
-    # Defaults to $BuildDir\$PackageName-$PackageVersion.zip.
-    # Overrides package name and version.
-    [ string ]  $DestinationPath = "$BuildDir\$PackageName-$PackageVersion.zip" ,
-
-    # If $CopyToWow is set to true, automatically copy and extract the package to these WoW versions.
-    [ string [] ]  $WowVersions = @(
-        "C:\Program Files (x86)\World of Warcraft\_retail_",
-        "C:\Program Files (x86)\World of Warcraft\_classic_",
-        "C:\Program Files (x86)\World of Warcraft\_classic_era_"
-    )
+    [ Switch ][Alias('h')]  $Help,
+    [ Switch ][Alias('c')]  $Clean,
+    [ Switch ][Alias('r')]  $Release,
+    [ Switch ][Alias('x')]  $CopyToWow,
+    [ string ][Alias('v')]  $Version = $(Get-Content -Path .\VERSION.txt),
+    [ string ][Alias('d')]  $BuildDir = "build",
+    [ string ][Alias('o')]  $OutputDir = "dist",
+    [ string ][Alias('n')]  $Name = "Arcadia",
+    [ string ][Alias('w')]  $WowDir = "C:\Program Files (x86)\World of Warcraft\_retail_",
+    [ string ][Alias('f')]  $TocFile,
+    [ string ][Alias('i')]  $InterfaceVersion = "100000"
+

 )

 #--------------------------------------------------
+# Help
+#--------------------------------------------------
+
+if ( $h -or $Help ) {
+
+    Write-Host "build.ps1 - build the project
+
+    Usage: build.ps1 [options]
+
+    Options:
+        -c, -Clean              clean the project
+        -r, -Release            build the project in release mode
+        -x, -CopyToWow          copy the build to the wow addons folder
+        -n, -Name               the name of the package to build
+        -v, -Version            the version of the package to build
+        -d, -BuildDir           the directory to build the project in
+        -o, -OutputDir          the directory to output the build to
+        -w, -WowDir             copy the build to the specified location
+        -f, -TocFile            the toc file to use
+        -i, -InterfaceVersion   the interface version to use
+    "
+
+    exit
+}
+
+#--------------------------------------------------
 # Create Build Directory
 #--------------------------------------------------

 Write-Debug "Creating build directory: $BuildDir"

 if ($Clean && Test-Path $BuildDir) {
-    Remove-Item -Path $BuildDir -Recurse -Force
+    Remove-Item -Path $BuildDir -Recurse -Force -ErrorAction SilentlyContinue
     New-Item -Path $BuildDir -ItemType Directory | Out-Null
 }

+
+#--------------------------------------------------
+# Parse Toc File
+#--------------------------------------------------
+
+Write-Debug "Parsing toc file: $($TocFile -Or "template.toc" )"
+
+$Toc
+
+if ($TocFile) {
+
+    $Toc = Get-Content -Path $TocFile
+
+}
+else {
+
+    $Toc = Get-Content -Path "template.toc"
+}
+
+
+$Toc = $Toc | ForEach-Object {
+
+    if ( $_ -match "^## Interface: \{\{(.+)\}\}$" ) {
+        $_ = "## Interface: $InterfaceVersion"
+    }
+
+    if ( $_ -match "^## Version: \{\{(.+)\}\}$" ) {
+        $_ = "## Version: $Version"
+    }
+
+    if ( $_ -match "^## Title: \{\{(.+)\}\}$" ) {
+        $_ = "## Title: $Name"
+    }
+
+    if ( $_ -match "^## X-Date: \{\{(.+)\}\}$" ) {
+        $_ = "## Date: $( Get-Date -Format "o" )"
+    }
+
+    $_
+}
+
+if ( $TocFile ) {
+
+    $Toc | Set-Content -Path $TocFile
+
+}
+else {
+
+    $Toc | Set-Content -Path "$BuildDir/$Name.toc"
+}
+
 #--------------------------------------------------
 # Archive Files
 #--------------------------------------------------

-Write-Debug "Archiving files to: $DestinationPath"
+Write-Debug "Archiving files to: $BuildDir\$Name-$Version.zip"
+
+# set $Toc to the contents of a temporary file
+$Toc | Set-Content -Path "$BuildDir\$Name.toc"

 Compress-Archive `
     -Path `
-    .\Docs, `
+    .\docs, `
     .\Icons, `
     .\Libs, `
     .\Locales, `
     .\Rings, `
-    .\ArcHUD3.toc, `
+    "$BuildDir/$Name.toc", `
     .\*.lua, `
     .\*.xml, `
     .\*.txt, `
     .\*.md `
     -DestinationPath `
-    $DestinationPath `
+    "$BuildDir\$Name-$Version.zip" `
     -Force

+# remove the temporary file
+Remove-Item -Path "$BuildDir\$Name.toc"
+
 #--------------------------------------------------
-# Copy To WoW Directory
+# End Build For No Release and No Copy
 #--------------------------------------------------

-if ($CopyToWow) {
-    for ($i = 0; $i -lt $WowVersions.Length; $i++) {
-        $wowVersion = $WowVersions[$i]
-        $wowVersionDir = "$wowVersion\Interface\AddOns\$PackageName"
-        $wowVersionDirExists = Test-Path $wowVersionDir
+if (!$Release -And !$CopyToWow) {
+    Write-Output "Build complete! ✔️"
+    exit
+}
+
+#--------------------------------------------------
+# Copy To WoW Directory
+#--------------------------------------------------

-        if ($wowVersionDirExists) {
-            Write-Debug "Removing existing directory: $wowVersionDir"
-            Remove-Item -Path $wowVersionDir -Recurse -Force
-        }
+if ( $CopyToWow -and !$Release ) {
+    Write-Debug "Copying to WoW directory: $WowDir\Interface\AddOns\$Name"

-        Write-Debug "Extracting package to: $wowVersionDir"
-        Expand-Archive -Path $DestinationPath -DestinationPath $wowVersionDir
+    if (Test-Path "$WowDir\Interface\AddOns\$Name") {
+        Remove-Item -Path "$WowDir\Interface\AddOns\$Name" -Recurse -Force -ErrorAction SilentlyContinue
     }
-}
+
+    Expand-Archive -Path "$BuildDir\$Name-$Version.zip" -DestinationPath "$WowDir\Interface\AddOns\$Name" -Force
+}
\ No newline at end of file
diff --git a/build.sh b/build.sh
new file mode 100644
index 0000000..982d8bd
--- /dev/null
+++ b/build.sh
@@ -0,0 +1,147 @@
+#!/bin/bash
+
+FILE=$(cat << EOF
+build.sh - build the project
+
+build.sh [options]
+
+options:
+    -h, --help                show brief help
+    -c, --clean               clean the project
+    -r, --release             build the project in release mode
+    -x, --copy-to-wow         copy the build to the wow addons folder
+    -n, --name                the name of the package to build
+    -v, --version             the version of the package to build
+    -d, --build-dir           the directory to build the project in
+    -o, --output-dir          the directory to output the build to
+    -w, --wow-dir             copy the build to the specified location
+    -f, --toc-file            the toc file to use
+    -i, --interface-version   the interface version to use
+EOF
+)
+
+# Default flags
+CLEAN=0
+RELEASE=0
+COPY_TO_WOW=0
+NAME="",
+VERSION=$(cat VERSION.txt)
+BUILD_DIR="build"
+OUTPUT_DIR="dist"
+COPY_TO_WOW=0
+WOW_DIR="/Applications/World of Warcraft/_retail_"
+TOC_FILE="template.toc"
+INTERFACE_VERSION="100000"
+
+while test $# -gt 0; do
+    case "$1" in
+        -h|--help)
+            echo "$FILE"
+            exit 0
+            ;;
+        -c|--clean)
+            CLEAN=1
+            ;;
+        -r|--release)
+            RELEASE=1
+            ;;
+        -x|--copy-to-wow)
+            COPY_TO_WOW=1
+            ;;
+        -n|--name)
+            NAME=$2
+            ;;
+        -v|--version)
+            VERSION=$2
+            ;;
+        -d|--build-dir)
+            BUILD_DIR=$2
+            ;;
+        -w|--wow-dir)
+            WOW_DIR=$2
+            ;;
+        -o|--output-dir)
+            OUTPUT_DIR=$2
+            ;;
+        -f|--toc-file)
+            TOC_FILE=$2
+            ;;
+        -i|--interface-version)
+            INTERFACE_VERSION=$2
+            ;;
+        *)
+            break
+            ;;
+    esac
+done
+
+# Create the build directory
+
+echo "Creating build directory: $BUILD_DIR"
+if [ $CLEAN -eq 1 ]; then
+    rm -rf "$BUILD_DIR"
+    mkdir -p "$BUILD_DIR"
+fi
+
+# Parse the toc file
+
+echo "Parsing toc file: $($TOC_FILE || 'template.toc')"
+
+TOC
+
+while IFS= read -r line; do
+    if [[ $line == \#* ]]; then
+        continue
+    fi
+
+    if [[ $line == Interface:* ]]; then
+        INTERFACE_VERSION=$(echo $line | cut -d ':' -f 2)
+        continue
+    fi
+
+    if [[ $line == Title:* ]]; then
+        NAME=$(echo $line | cut -d ':' -f 2)
+        continue
+    fi
+
+    if [[ $line == Version:* ]]; then
+        VERSION=$(echo $line | cut -d ':' -f 2)
+        continue
+    fi
+
+    TOC+="$line"
+done < "$TOC_FILE"
+
+# Archive files
+
+echo "Archiving files to $BUILD_DIR/$ZIP_FILE.zip"
+
+# Set TOC to the contents of a temporary file
+TOC > "$BUILD_DIR/$NAME.toc"
+
+zip -r "$BUILD_DIR/$NAME-$VERSION.zip" . \
+-x "docs" \
+"Icons" \
+"Libs" \
+"Locales" \
+"Rings" \
+"$BUILD_DIR/$NAME.toc" \
+"*.lua" \
+"*.xml" \
+"*.txt" \
+"*.md"
+
+# Exit if we're not copying to wow or release is not set
+
+if [ $COPY_TO_WOW -eq 0 ] || [ $RELEASE -eq 0 ]; then
+    echo "Build complete! ✔️"
+    exit 0
+fi
+
+# Copy to wow
+
+if [ "$COPY_TO_WOW" -eq 1 ] && [ "$RELEASE" -lt 1 ]; then
+    echo "Copying to wow directory: $WOW_DIR/Interface/AddOns/$NAME"
+    rm -rf "$WOW_DIR/Interface/AddOns/$NAME"
+    unzip -o "$BUILD_DIR/$NAME.zip" -d "$WOW_DIR/Interface/AddOns/$NAME"
+fi
\ No newline at end of file