-
Notifications
You must be signed in to change notification settings - Fork 0
/
Package.hx
68 lines (61 loc) · 1.68 KB
/
Package.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
import haxe.crypto.Crc32;
import haxe.io.Bytes;
import haxe.zip.Entry;
import haxe.io.Path;
import sys.io.File;
import haxe.zip.Writer;
import sys.FileSystem;
// haxe --main package.hx --interp
class Package {
static final exclude = [
".git",
".gitignore",
"test.bat",
"completion.hxml",
"test",
"Package.hx",
"lib_package.zip"
];
public static function main() {
trace("Zipping files...");
var file = File.write("lib_package.zip", true);
var writer = new Writer(file);
writer.write(getEntries("./"));
file.close();
trace("Done");
Sys.println("Submit to Haxelib? [Y/N]:");
var input = Sys.stdin().readLine().toLowerCase();
if (input == "y") {
trace("Submiting...");
Sys.command("haxelib", ["submit", "lib_package.zip"]);
}
}
static function getEntries(dir:String, entries:List<haxe.zip.Entry> = null, inDir:Null<String> = null) {
if (entries == null)
entries = new List<haxe.zip.Entry>();
if (inDir == null)
inDir = dir;
for (file in FileSystem.readDirectory(dir)) {
var path = Path.join([dir, file]);
if (exclude.contains(path))
continue;
if (sys.FileSystem.isDirectory(path)) {
getEntries(path, entries, inDir);
}
else {
var bytes:Bytes = haxe.io.Bytes.ofData(sys.io.File.getBytes(path).getData());
var entry:Entry = {
fileName: StringTools.replace(path, inDir, ""),
fileSize: bytes.length,
fileTime: Date.now(),
compressed: false,
dataSize: FileSystem.stat(path).size,
data: bytes,
crc32: Crc32.make(bytes)
};
entries.push(entry);
}
}
return entries;
}
}