Debian Codegraph @

extra/haxelib_src/test/Prepare.hx

raw
1 import sys.*;
2 import sys.io.*;
3 import haxe.io.*;
4
5 class Prepare {
6 static function zipDir(dir:String, outPath:String):Void {
7 var entries = new List<haxe.zip.Entry>();
8
9 function add(path:String, target:String) {
10 if (!FileSystem.exists(path))
11 throw 'Invalid path: $path';
12
13 if (FileSystem.isDirectory(path)) {
14 for (item in FileSystem.readDirectory(path))
15 add(path + "/" + item, target == "" ? item : target + "/" + item);
16 } else {
17 var bytes = File.getBytes(path);
18 var entry:haxe.zip.Entry = {
19 fileName: target,
20 fileSize: bytes.length,
21 fileTime: FileSystem.stat(path).mtime,
22 compressed: false,
23 dataSize: 0,
24 data: bytes,
25 crc32: haxe.crypto.Crc32.make(bytes),
26 }
27 haxe.zip.Tools.compress(entry, 9);
28 entries.add(entry);
29 }
30 }
31 add(dir, "");
32
33 var out = File.write(outPath, true);
34 var writer = new haxe.zip.Writer(out);
35 writer.write(entries);
36 out.close();
37 }
38
39 static function main():Void {
40 var system = Sys.systemName();
41 var cwd = Sys.getCwd();
42 /*
43 (re)package the dummy libraries
44 */
45 var libsPath = "test/libraries";
46 for (item in FileSystem.readDirectory(libsPath)) {
47 var path = Path.join([libsPath, item]);
48 if (FileSystem.isDirectory(path)) {
49 switch system {
50 case 'Windows':
51 zipDir(path, 'test/libraries/${item}.zip');
52 case _:
53 Sys.setCwd(path);
54 var exitCode = Sys.command('zip', ['-r', '../${item}.zip', '.']);
55 Sys.setCwd(cwd);
56 if(exitCode != 0) {
57 Sys.stderr().writeString('Failed to zip $item\n');
58 }
59 }
60 }
61 }
62 }
63 }