-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathBuildSamples.hx
79 lines (68 loc) · 2.12 KB
/
BuildSamples.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
package;
import haxe.io.Path;
import sys.FileSystem;
import sys.io.File;
import sys.io.Process;
import Utils.measure;
using StringTools;
/**
* @author Mark Knol
*/
class BuildSamples {
static var GIT_TAG = Sys.getEnv("HEAPS_VER"); // tag name
static var GIT_REPO = "https://github.com/HeapsIO/heaps.git";
static var FOLDER = ".temp/";
static function main() {
var sampleDir = FOLDER + "samples/";
var sampleBuildDir = sampleDir + "/build/";
measure("Download samples from git", function() {
Sys.command('git', ["clone", "--branch", GIT_TAG, "--depth", "1", "--single-branch", GIT_REPO, FOLDER]);
});
measure("Compile samples", function() {
Sys.setCwd(sampleDir);
Sys.command('haxe', ["all.hxml"]);
});
Sys.setCwd("../../");
trace(sampleBuildDir, "assets/includes/samples/");
measure("Copy + minify samples", function() {
copyDirectory(sampleBuildDir, "assets/includes/samples/", true, function(srcPath, dstPath) {
if (new Path(srcPath).file.startsWith(".")) return;
File.copy(srcPath, dstPath);
if (dstPath.endsWith(".js")) {
trace("Minify " + dstPath);
UglifyJS.compileFile(dstPath, dstPath);
}
});
});
measure("Copy sample source files", function() {
copyDirectory(sampleDir, "assets/includes/samples/", false, function(srcPath, dstPath) {
if (dstPath.indexOf(".hx") != -1) {
trace("Copy source file: " + dstPath);
File.copy(srcPath, dstPath);
}
});
});
}
static function runCommand(cmd:String, ?args:Array<String>):String {
var p = new Process(cmd, args);
var out:String = p.stdout.readAll().toString();
p.close();
return out;
}
static function copyDirectory(dir:String, path:String, recursive:Bool, onEachFile:String->String->Void) {
FileSystem.createDirectory(path);
trace("include directory: " + path);
for (file in FileSystem.readDirectory(dir)) {
var srcPath = '$dir/$file';
var dstPath = '$path/$file';
if (FileSystem.isDirectory(srcPath)) {
if (recursive) {
FileSystem.createDirectory(dstPath);
copyDirectory(srcPath, dstPath, recursive, onEachFile);
}
} else {
onEachFile(srcPath, dstPath);
}
}
}
}