-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.hx
169 lines (85 loc) · 3.37 KB
/
Main.hx
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
package;
import haxe.io.Path;
import sys.FileSystem;
import sys.io.File;
import tools.haxelib.Data;
@:access(tools.haxelib.Main)
class Main {
private static function findUpgrade ():String {
try {
var client = getHaxelibClient (".haxelib");
if (client == null) {
var envPath = Sys.getEnv ("HAXELIB_PATH");
if (envPath != null) {
client = getHaxelibClient (envPath);
} else {
var configFile = "";
if (Sys.systemName () == "Windows") {
var homeDrive = Sys.getEnv ("HOMEDRIVE");
var homePath = Sys.getEnv ("HOMEPATH");
var configFile = null;
if (homeDrive != null && homePath != null) {
configFile = homeDrive + homePath + "/.haxelib";
}
if (configFile != null && FileSystem.exists (configFile) && !FileSystem.isDirectory (configFile)) {
client = getHaxelibClient (File.getContent (configFile));
} else {
var haxePath = Sys.getEnv ("HAXEPATH");
if (haxePath != null) {
client = getHaxelibClient (haxePath + "/lib");
}
}
} else {
var home = Sys.getEnv ("HOME");
var configFile = null;
if (home != null) {
configFile = home + "/.haxelib";
}
if (configFile != null && FileSystem.exists (configFile) && !FileSystem.isDirectory (configFile)) {
client = getHaxelibClient (File.getContent (configFile));
} else if (FileSystem.exists ("/etc/.haxelib")) {
client = getHaxelibClient (File.getContent ("/etc/.haxelib"));
}
}
}
}
return client;
} catch (e:Dynamic) {
return null;
}
}
private static function getHaxelibClient (path:String):String {
try {
path = StringTools.trim (path) + "/haxelib_client";
if (FileSystem.exists (path) && FileSystem.isDirectory (path)) {
if (FileSystem.exists (path + "/.dev")) {
path = StringTools.trim (File.getContent (path + "/.dev"));
} else if (FileSystem.exists (path + "/.current")) {
path += "/" + Data.safe (StringTools.trim (File.getContent (path + "/.current")));
} else {
return null;
}
if (FileSystem.exists (path) && FileSystem.isDirectory (path)) {
return path;
}
}
} catch (e:Dynamic) {}
return null;
}
public static function main () {
var upgradedClient = findUpgrade ();
if (upgradedClient != null) {
var args = Sys.args ();
if (FileSystem.exists (upgradedClient + "/haxelib.n")) {
Sys.exit (Sys.command ("neko", [ upgradedClient + "/haxelib.n" ].concat (args)));
} else if (FileSystem.exists (upgradedClient + "/bin/haxelib.n")) {
Sys.exit (Sys.command ("neko", [ upgradedClient + "/bin/haxelib.n" ].concat (args)));
} else if (FileSystem.exists (upgradedClient + "/tools/haxelib/Main.hx")) {
Sys.exit (Sys.command ("haxe", [ "-cp", upgradedClient, "--run", "tools.haxelib.Main" ].concat (args)));
} else {
Sys.exit (Sys.command ("haxe", [ "-cp", upgradedClient + "/src", "--run", "tools.haxelib.Main" ].concat (args)));
}
}
new tools.haxelib.Main ().process ();
}
}