mirror of
				https://github.com/cmderdev/cmder.git
				synced 2025-11-04 11:22:13 +08:00 
			
		
		
		
	new version handle logic
This commit is contained in:
		@@ -58,14 +58,14 @@ $ScriptRoot = Split-Path -Parent -Path $MyInvocation.MyCommand.Definition
 | 
				
			|||||||
$cmder_root = $ScriptRoot.replace("\scripts","")
 | 
					$cmder_root = $ScriptRoot.replace("\scripts","")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Dot source util functions into this scope
 | 
					# Dot source util functions into this scope
 | 
				
			||||||
. ".\utils.ps1"
 | 
					. "$PSScriptRoot\utils.ps1"
 | 
				
			||||||
$ErrorActionPreference = "Stop"
 | 
					$ErrorActionPreference = "Stop"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Push-Location -Path $saveTo
 | 
					Push-Location -Path $saveTo
 | 
				
			||||||
$sources = Get-Content $sourcesPath | Out-String | Convertfrom-Json
 | 
					$sources = Get-Content $sourcesPath | Out-String | Convertfrom-Json
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Get the version string
 | 
					# Get the version string
 | 
				
			||||||
$Version = Get-VersionStr ($PSScriptRoot + '\..\' + 'CHANGELOG.md')
 | 
					$version = Get-VersionStr
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Check for requirements
 | 
					# Check for requirements
 | 
				
			||||||
Ensure-Exists $sourcesPath
 | 
					Ensure-Exists $sourcesPath
 | 
				
			||||||
@@ -119,13 +119,13 @@ Pop-Location
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
if($Compile) {
 | 
					if($Compile) {
 | 
				
			||||||
    Push-Location -Path $launcher
 | 
					    Push-Location -Path $launcher
 | 
				
			||||||
    Create-RC $Version ($launcher + '\src\version.rc2');
 | 
					    Create-RC $version ($launcher + '\src\version.rc2');
 | 
				
			||||||
    msbuild CmderLauncher.vcxproj /t:Clean,Build /p:configuration=Release
 | 
					    msbuild CmderLauncher.vcxproj /t:Clean,Build /p:configuration=Release
 | 
				
			||||||
    if ($LastExitCode -ne 0) {
 | 
					    if ($LastExitCode -ne 0) {
 | 
				
			||||||
        throw "msbuild failed to build the executable."
 | 
					        throw "msbuild failed to build the executable."
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    else {
 | 
					    else {
 | 
				
			||||||
        Write-Verbose "successfully built Cmder v$Version!"
 | 
					        Write-Verbose "successfully built Cmder v$version!"
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    Pop-Location
 | 
					    Pop-Location
 | 
				
			||||||
} else {
 | 
					} else {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -48,7 +48,7 @@ $targets = @{
 | 
				
			|||||||
Delete-Existing "..\Version*"
 | 
					Delete-Existing "..\Version*"
 | 
				
			||||||
Delete-Existing "..\build\*"
 | 
					Delete-Existing "..\build\*"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$version = Invoke-Expression "git describe --abbrev=0 --tags"
 | 
					$version = Get-VersionStr
 | 
				
			||||||
(New-Item -ItemType file "$cmderRoot\Version $version") | Out-Null
 | 
					(New-Item -ItemType file "$cmderRoot\Version $version") | Out-Null
 | 
				
			||||||
 | 
					
 | 
				
			||||||
foreach ($t in $targets.GetEnumerator()) {
 | 
					foreach ($t in $targets.GetEnumerator()) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -62,7 +62,45 @@ function Digest-Hash($path) {
 | 
				
			|||||||
    return Invoke-Expression "md5sum $path"
 | 
					    return Invoke-Expression "md5sum $path"
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function Get-VersionStr($file) {
 | 
					function Get-VersionStr() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    # Clear existing variable
 | 
				
			||||||
 | 
					    Clear-Variable -name string
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    # Determine if git is available
 | 
				
			||||||
 | 
					    if (Get-Command "git.exe" -ErrorAction SilentlyContinue)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        # Determine if the current diesctory is a git repository
 | 
				
			||||||
 | 
					        $GitPresent = Invoke-Expression "git rev-parse --is-inside-work-tree" -erroraction SilentlyContinue 2>$null
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if ( $GitPresent -eq 'true' )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            $string = Invoke-Expression "git describe --abbrev=0 --tags"
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    # Fallback used when Git is not available
 | 
				
			||||||
 | 
					    if ( -not($string) )
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $string = Parse-Changelog ($PSScriptRoot + '\..\' + 'CHANGELOG.md')
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    # Add build number, if AppVeyor is present
 | 
				
			||||||
 | 
					    if ( $Env:APPVEYOR -eq 'True' )
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $string = $string + '.' + $Env:APPVEYOR_BUILD_NUMBER
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    # Remove starting 'v' characters
 | 
				
			||||||
 | 
					    $string = $string -replace '^v+','' # normalize version string
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return $string
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function Parse-Changelog($file) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	# Define the regular expression to match the version string from changelog
 | 
						# Define the regular expression to match the version string from changelog
 | 
				
			||||||
	[regex]$regex = '^## \[(?<version>[\w\-\.]+)\]\([^\n()]+\)\s+\([^\n()]+\)$';
 | 
						[regex]$regex = '^## \[(?<version>[\w\-\.]+)\]\([^\n()]+\)\s+\([^\n()]+\)$';
 | 
				
			||||||
@@ -75,7 +113,7 @@ function Get-VersionStr($file) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
function Create-RC($string, $path) {
 | 
					function Create-RC($string, $path) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	$version  = $string + '.0.0.0.0' # padding for version string
 | 
					    $version  = $string + '.0.0.0.0' # padding for version string
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if ( !(Test-Path "$path.sample") ) {
 | 
						if ( !(Test-Path "$path.sample") ) {
 | 
				
			||||||
		throw "Invalid path provided for resources file."
 | 
							throw "Invalid path provided for resources file."
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user