Browse Source

Added the `Version.getHaxeVersion()` method

main
Cédric Belin 1 week ago
parent
commit
aaf5b189d1
1 changed files with 9 additions and 4 deletions
  1. +9
    -4
      src/Version.hx

+ 9
- 4
src/Version.hx View File

@@ -1,14 +1,19 @@
import haxe.Json;
import haxe.macro.Context;
import sys.io.File;

/** Provides information about the program version. **/
class Version {

/** Reads the package version from the `haxelib.json` file. **/
public static function getHaxelibVersion(): String
return try Json.parse(File.getContent("haxelib.json")).version catch (e) "0.0.0";
/** Gets the version of the Haxe compiler. **/
macro public static function getHaxeVersion(): ExprOf<String>
return macro $v{Context.definedValue("haxe")};

/** Gets the package version of this program. **/
macro public static function getPackageVersion(): ExprOf<String>
return macro $v{#if display "0.0.0" #else getHaxelibVersion() #end};
return macro $v{#if display "0.0.0" #else getHaxelibFileVersion() #end};

/** Reads the package version from the `haxelib.json` file. **/
static function getHaxelibFileVersion(): String
return try Json.parse(File.getContent("haxelib.json")).version catch (e) "0.0.0";
}

Loading…
Cancel
Save