-
Notifications
You must be signed in to change notification settings - Fork 0
/
Script.hx
62 lines (52 loc) · 1.64 KB
/
Script.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
import haxe.io.Path;
import sys.FileSystem;
import sys.io.File;
using StringTools;
enum abstract Target(String) from String {
var Flash = "flash";
var Html5 = "html5";
}
class Script {
static function main() {
var args = Sys.args();
var target = args[0];
var flixelDemos = args[1];
build(target);
copy(target, flixelDemos);
}
static function build(target:Target) {
var args = ["run", "flixel-tools", "buildprojects", Std.string(target)];
if (target == Html5) {
args = args.concat(["--", "-final"]);
}
runCommand("haxelib", args);
}
static function copy(target:Target, flixelDemos:String) {
FileSystem.createDirectory("bin");
var dir = "bin/" + (if (target == Flash) "swf" else "html5");
runCommand("rm", ["-rf", dir]);
runCommand("mkdir", [dir]);
for (category in FileSystem.readDirectory(flixelDemos)) {
var categoryFullPath = Path.join([flixelDemos, category]);
if (!FileSystem.isDirectory(categoryFullPath) || category.startsWith("."))
continue;
for (demo in FileSystem.readDirectory(categoryFullPath)) {
var demoFullPath = Path.join([categoryFullPath, demo]);
switch (target) {
case Flash:
var swfPath = Path.join([demoFullPath, 'export/flash/bin/$demo.swf']);
if (FileSystem.exists(swfPath))
File.copy(swfPath, '$dir/$demo.swf');
case Html5:
var html5Path = Path.join([demoFullPath, 'export/html5/bin']);
if (FileSystem.exists(html5Path))
runCommand("cp", ["-r", html5Path, '$dir/$demo']);
}
}
}
}
static function runCommand(cmd:String, args:Array<String>):Int {
Sys.println(cmd + " " + args.join(" "));
return Sys.command(cmd, args);
}
}