summaryrefslogtreecommitdiff
path: root/Pre-Build.ps1
blob: d8705a20be825ebd921f7516d921760d6e18dc71 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# Set current working directory to the script's directory
Set-Location -Path $PSScriptRoot

# Define the path to the target CLI executable
$cliPath = ".\.Temp\Debug\JustEnoughVCS.exe"

# Check if the target CLI file already exists
if (-not (Test-Path $cliPath)) {
    # If the file does not exist, define the relative path to the command-line project directory
    $commandLineDir = ".\..\CommandLine"

    # Check if the command-line project directory exists
    if (-not (Test-Path $commandLineDir)) {
        # If the directory does not exist, output an error and exit the script
        Write-Error "Error: $commandLineDir Not Found!"
        exit 1
    }

    # Define the path to the pre-built CLI executable
    $jvExePath = "$commandLineDir\.temp\deploy\bin\jv.exe"

    # Check if the pre-built CLI file exists
    if (Test-Path $jvExePath) {
        # If the pre-built file exists, ensure the target directory exists
        $null = New-Item -ItemType Directory -Path (Split-Path $cliPath) -Force
        # Copy the pre-built file to the target location
        Copy-Item -Path $jvExePath -Destination $cliPath -Force
        # Output a completion notification
        Write-Host "CLI copied to $cliPath"
    }
    else {
        # If the pre-built file does not exist, define the path to the deployment script
        $deployScriptPath = "$commandLineDir\deploy.ps1"

        # Check if the deployment script exists
        if (-not (Test-Path $deployScriptPath)) {
            # If the deployment script does not exist, output an error and exit
            Write-Error "Error: $deployScriptPath Not Found!"
            exit 1
        }

        # Output a notification that building is starting
        Write-Host "Building CLI from deploy.ps1..."
        # Execute the deployment script to build the CLI
        & $deployScriptPath

        # Check if the CLI file is generated after building
        if (-not (Test-Path $jvExePath)) {
            # If the file still does not exist after building, output an error and exit
            Write-Error "Error: $jvExePath Not Found after deployment!"
            exit 1
        }

        # Ensure the target directory exists
        $null = New-Item -ItemType Directory -Path (Split-Path $cliPath) -Force
        # Copy the newly built file to the target location
        Copy-Item -Path $jvExePath -Destination $cliPath -Force
        # Output a notification that building and copying are complete
        Write-Host "CLI built and copied to $cliPath"
    }
}