@@ -14,29 +14,49 @@ enum HaxeRcError {
14
14
ParseError (err : String );
15
15
}
16
16
17
+ typedef HaxeshimConfig = {
18
+ var version (default , null ): String ;
19
+ var resolveLibs (default , null ): String ; // TODO if it becomes relevant
20
+ }
21
+
17
22
class LixTools {
18
23
public static function safeGetRc (): Null <String > {
19
24
return try getRc () catch (_ ) null ;
20
25
}
21
26
22
- public static function getRc (): Null < String > {
27
+ static function getFullRc (): HaxeshimConfig {
23
28
final cwd = Utils .getCallSite ();
24
29
25
30
// TODO (?): check parent directories too
26
31
final rc = Path .join ([cwd , " .haxerc" ]);
27
32
28
33
if (FileSystem .exists (rc )) {
29
- try {
30
- final version = Json .parse (File .getContent (rc )).version ;
31
- return version ;
32
- } catch (e ) {
33
- throw ParseError (Std .string (e ));
34
- }
34
+ try return Json .parse (File .getContent (rc )) catch (e ) throw ParseError (Std .string (e ));
35
35
} else {
36
36
throw NotFound ;
37
37
}
38
38
}
39
39
40
+ public static function getFilename (): String {
41
+ final version = getFullRc ().version ;
42
+ if (version == null ) Utils .failWith (' Invalid .haxerc: missing version' );
43
+
44
+ var filename = HaxeNightlies .resolve (version , true );
45
+ if (filename == null ) Utils .failWith (' Can only get filename for nightlies.' );
46
+ return filename ;
47
+ }
48
+
49
+ static function writeRc (rc : HaxeshimConfig ): Void {
50
+ final cwd = Utils .getCallSite ();
51
+ File .saveContent (Path .join ([cwd , " .haxerc" ]), Json .stringify (rc , ' ' ));
52
+ }
53
+
54
+ public static function getRc (): String {
55
+ final version = getFullRc ().version ;
56
+ if (version == null ) Utils .failWith (' Invalid .haxerc: missing version' );
57
+ return version ;
58
+ }
59
+
40
60
public static function resolveHaxe () {
41
61
try {
42
62
final version = getRc ();
@@ -52,14 +72,27 @@ class LixTools {
52
72
}
53
73
}
54
74
} catch (e : HaxeRcError ) {
55
- switch e {
56
- case NotFound :
57
- Utils .displayError (' Did not find any .haxerc to apply' );
58
- case ParseError (e ):
59
- Utils .displayError (' Could not get Haxe version from .haxerc: $e ' );
60
- }
75
+ Utils .failWith (switch e {
76
+ case NotFound : ' Did not find any .haxerc to apply' ;
77
+ case ParseError (e ): ' Could not parse .haxerc: $e ' ;
78
+ });
79
+ }
80
+ }
81
+
82
+ // TODO: support releases too
83
+ public static function updateHaxeRc () {
84
+ final sha = HaxeNightlies .resolveSha (Utils .getCurrentSha ());
85
+ if (sha == null ) Utils .failWith (' Could not get current Haxe short sha' );
61
86
62
- Sys .exit (1 );
87
+ try {
88
+ final rc = getFullRc ();
89
+ writeRc ({version : sha , resolveLibs : rc .resolveLibs });
90
+ } catch (e : HaxeRcError ) {
91
+ // TODO: factorize with resolveHaxe error handling
92
+ Utils .failWith (switch e {
93
+ case NotFound : ' Did not find any .haxerc to apply' ;
94
+ case ParseError (e ): ' Could not parse .haxerc: $e ' ;
95
+ });
63
96
}
64
97
}
65
98
0 commit comments