whet 0.0.4 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/StringBuf.d.ts +13 -0
- package/bin/StringBuf.js +25 -0
- package/bin/haxe/CallStack.d.ts +41 -0
- package/bin/haxe/CallStack.js +96 -0
- package/bin/haxe/NativeStackTrace.js +147 -0
- package/bin/whet/Log.js +3 -0
- package/bin/whet/Project.d.ts +5 -2
- package/bin/whet/Project.js +32 -9
- package/bin/whet/Source.d.ts +2 -2
- package/bin/whet/Source.js +21 -5
- package/bin/whet/SourceHash.d.ts +7 -1
- package/bin/whet/SourceHash.js +93 -7
- package/bin/whet/SourceId.d.ts +1 -0
- package/bin/whet/SourceId.js +37 -28
- package/bin/whet/Stone.d.ts +21 -5
- package/bin/whet/Stone.js +63 -18
- package/bin/whet/Utils.d.ts +8 -2
- package/bin/whet/Utils.js +25 -5
- package/bin/whet/Whet.js +4 -1
- package/bin/whet/cache/BaseCache.js +18 -17
- package/bin/whet/cache/CacheManager.d.ts +5 -0
- package/bin/whet/cache/CacheManager.js +21 -12
- package/bin/whet/cache/FileCache.js +83 -43
- package/bin/whet/magic/RoutePathType.js +10 -4
- package/bin/whet/magic/RouteType.d.ts +4 -3
- package/bin/whet/magic/RouteType.js +31 -13
- package/bin/whet/magic/StoneId.d.ts +1 -0
- package/bin/whet/magic/StoneId.js +11 -1
- package/bin/whet/route/Route.d.ts +5 -1
- package/bin/whet/route/Route.js +33 -13
- package/bin/whet/route/Router.js +27 -36
- package/bin/whet/stones/Files.js +25 -16
- package/bin/whet/stones/JsonStone.js +7 -6
- package/bin/whet/stones/RemoteFile.js +5 -7
- package/bin/whet/stones/Server.d.ts +1 -2
- package/bin/whet/stones/Server.js +30 -22
- package/bin/whet/stones/Zip.js +17 -11
- package/bin/whet/stones/haxe/HaxeBuild.d.ts +2 -0
- package/bin/whet/stones/haxe/HaxeBuild.js +44 -63
- package/bin/whet/stones/haxe/Hxml.js +39 -24
- package/bin/whet.d.ts +3 -0
- package/bin/whet.js +3 -0
- package/package.json +1 -1
package/bin/whet/stones/Files.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import {MaybeArray_Fields_} from "../magic/MaybeArray.js"
|
|
2
2
|
import {Stone} from "../Stone.js"
|
|
3
|
-
import {RootDir, SourceId} from "../SourceId.js"
|
|
3
|
+
import {SourceId_Fields_, RootDir, SourceId} from "../SourceId.js"
|
|
4
4
|
import {SourceData} from "../Source.js"
|
|
5
|
-
import
|
|
5
|
+
import * as Path from "path"
|
|
6
6
|
import {Register} from "../../genes/Register.js"
|
|
7
7
|
import * as Fs from "fs"
|
|
8
|
+
import {StringTools} from "../../StringTools.js"
|
|
8
9
|
import {HxOverrides} from "../../HxOverrides.js"
|
|
9
10
|
|
|
10
11
|
const $global = Register.$global
|
|
@@ -19,18 +20,19 @@ class Files extends Register.inherits(Stone) {
|
|
|
19
20
|
var _g = MaybeArray_Fields_.makeArray(this.config.paths);
|
|
20
21
|
while (0 < _g.length) {
|
|
21
22
|
var pathString = _g[0];
|
|
22
|
-
var
|
|
23
|
-
|
|
23
|
+
var s = pathString;
|
|
24
|
+
s = Path.posix.normalize((pathString.length > 1 && SourceId_Fields_.startsWithSlash(pathString)) ? HxOverrides.substr(pathString, 1, null) : pathString);
|
|
25
|
+
s = StringTools.replace(s, "\\", "/");
|
|
26
|
+
var path = [(SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s];
|
|
24
27
|
var tmp;
|
|
25
|
-
|
|
26
|
-
var tmp1 = (path[0].lastIndexOf("/") == path[0].length - 1) ? Path.addTrailingSlash(norm1) : norm1;
|
|
27
|
-
var s = Path.addTrailingSlash(Path.directory(path[0]));
|
|
28
|
-
var norm2 = "/" + Path.normalize((s.charAt(0) == "/") ? HxOverrides.substr(s, 1, null) : s);
|
|
29
|
-
if (tmp1 == ((s.lastIndexOf("/") == s.length - 1) ? Path.addTrailingSlash(norm2) : norm2)) {
|
|
28
|
+
if (SourceId_Fields_.endsWithSlash(path[0])) {
|
|
30
29
|
tmp = new Promise((function (path) {
|
|
31
30
|
return function (res, rej) {
|
|
32
31
|
var root = RootDir.fromProject(_gthis.project);
|
|
33
|
-
|
|
32
|
+
if (path[0].charAt(0) != "/") {
|
|
33
|
+
throw new Error("Badly formed SourceId.");
|
|
34
|
+
};
|
|
35
|
+
Fs.readdir(Path.posix.join(".", root, ".", path[0]), (function (path) {
|
|
34
36
|
return function (err, files) {
|
|
35
37
|
if (err != null) {
|
|
36
38
|
rej(err);
|
|
@@ -41,8 +43,10 @@ class Files extends Register.inherits(Stone) {
|
|
|
41
43
|
while (_g1 < files.length) {
|
|
42
44
|
var file = files[_g1];
|
|
43
45
|
++_g1;
|
|
44
|
-
var
|
|
45
|
-
|
|
46
|
+
var s = file;
|
|
47
|
+
s = Path.posix.normalize((file.length > 1 && SourceId_Fields_.startsWithSlash(file)) ? HxOverrides.substr(file, 1, null) : file);
|
|
48
|
+
s = StringTools.replace(s, "\\", "/");
|
|
49
|
+
var filepath = SourceId.getPutInDir((SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s, path[0]);
|
|
46
50
|
_g.push({"id": SourceId.relativeTo(filepath, path[0]), "pathId": filepath});
|
|
47
51
|
};
|
|
48
52
|
res1(_g);
|
|
@@ -52,9 +56,10 @@ class Files extends Register.inherits(Stone) {
|
|
|
52
56
|
};
|
|
53
57
|
})(path));
|
|
54
58
|
} else {
|
|
55
|
-
var s1 =
|
|
56
|
-
|
|
57
|
-
|
|
59
|
+
var s1 = path[0].substring(path[0].lastIndexOf("/"));
|
|
60
|
+
s1 = Path.posix.normalize((s1.length > 1 && SourceId_Fields_.startsWithSlash(s1)) ? HxOverrides.substr(s1, 1, null) : s1);
|
|
61
|
+
s1 = StringTools.replace(s1, "\\", "/");
|
|
62
|
+
tmp = Promise.resolve([{"id": (SourceId_Fields_.startsWithSlash(s1)) ? s1 : "/" + s1, "pathId": path[0]}]);
|
|
58
63
|
};
|
|
59
64
|
return tmp.then((function () {
|
|
60
65
|
return function (files) {
|
|
@@ -63,9 +68,13 @@ class Files extends Register.inherits(Stone) {
|
|
|
63
68
|
while (_g1 < files.length) {
|
|
64
69
|
var f = files[_g1];
|
|
65
70
|
++_g1;
|
|
71
|
+
var f1 = f.id;
|
|
66
72
|
var this1 = f.pathId;
|
|
67
73
|
var root = RootDir.fromProject(_gthis.project);
|
|
68
|
-
|
|
74
|
+
if (this1.charAt(0) != "/") {
|
|
75
|
+
throw new Error("Badly formed SourceId.");
|
|
76
|
+
};
|
|
77
|
+
_g.push(SourceData.fromFile(f1, Path.posix.join(".", root, ".", this1), f.pathId));
|
|
69
78
|
};
|
|
70
79
|
return Promise.all(_g);
|
|
71
80
|
};
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import {RouteType_Fields_} from "../magic/RouteType.js"
|
|
2
2
|
import {MaybeArray_Fields_} from "../magic/MaybeArray.js"
|
|
3
3
|
import {Stone} from "../Stone.js"
|
|
4
|
+
import {SourceId_Fields_} from "../SourceId.js"
|
|
4
5
|
import {SourceHash} from "../SourceHash.js"
|
|
5
6
|
import {SourceData} from "../Source.js"
|
|
6
|
-
import
|
|
7
|
+
import * as Path from "path"
|
|
7
8
|
import {Register} from "../../genes/Register.js"
|
|
9
|
+
import {StringTools} from "../../StringTools.js"
|
|
8
10
|
import {Reflect as Reflect__1} from "../../Reflect.js"
|
|
9
11
|
import {HxOverrides} from "../../HxOverrides.js"
|
|
10
12
|
|
|
@@ -60,9 +62,7 @@ class JsonStone extends Register.inherits(Stone) {
|
|
|
60
62
|
};
|
|
61
63
|
};
|
|
62
64
|
};
|
|
63
|
-
|
|
64
|
-
var norm = "/" + Path.normalize((s.charAt(0) == "/") ? HxOverrides.substr(s, 1, null) : s);
|
|
65
|
-
return [SourceData.fromString((s.lastIndexOf("/") == s.length - 1) ? Path.addTrailingSlash(norm) : norm, JSON.stringify(obj, null, " "))];
|
|
65
|
+
return [SourceData.fromString(_gthis.config.name, JSON.stringify(obj, null, " "))];
|
|
66
66
|
});
|
|
67
67
|
}
|
|
68
68
|
generateHash() {
|
|
@@ -92,8 +92,9 @@ class JsonStone extends Register.inherits(Stone) {
|
|
|
92
92
|
}
|
|
93
93
|
list() {
|
|
94
94
|
var s = this.config.name;
|
|
95
|
-
|
|
96
|
-
|
|
95
|
+
s = Path.posix.normalize((s.length > 1 && SourceId_Fields_.startsWithSlash(s)) ? HxOverrides.substr(s, 1, null) : s);
|
|
96
|
+
s = StringTools.replace(s, "\\", "/");
|
|
97
|
+
return Promise.resolve([(SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s]);
|
|
97
98
|
}
|
|
98
99
|
initConfig() {
|
|
99
100
|
if (this.config.name == null) {
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import {CacheStrategy, CacheDurability} from "../cache/Cache.js"
|
|
2
2
|
import {Stone} from "../Stone.js"
|
|
3
|
+
import {SourceId_Fields_} from "../SourceId.js"
|
|
3
4
|
import {SourceHash} from "../SourceHash.js"
|
|
4
5
|
import {SourceData} from "../Source.js"
|
|
5
6
|
import {Log} from "../Log.js"
|
|
6
7
|
import {URL} from "url"
|
|
7
8
|
import * as Path from "path"
|
|
8
9
|
import * as Https from "https"
|
|
9
|
-
import {Path as Path__1} from "../../haxe/io/Path.js"
|
|
10
10
|
import {Register} from "../../genes/Register.js"
|
|
11
11
|
import {Buffer} from "buffer"
|
|
12
|
+
import {StringTools} from "../../StringTools.js"
|
|
12
13
|
import {HxOverrides} from "../../HxOverrides.js"
|
|
13
14
|
|
|
14
15
|
const $global = Register.$global
|
|
@@ -51,12 +52,9 @@ class RemoteFile extends Register.inherits(Stone) {
|
|
|
51
52
|
}
|
|
52
53
|
getId() {
|
|
53
54
|
var s = Path.basename(new URL(this.config.url).pathname);
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
} else {
|
|
58
|
-
return norm;
|
|
59
|
-
};
|
|
55
|
+
s = Path.posix.normalize((s.length > 1 && SourceId_Fields_.startsWithSlash(s)) ? HxOverrides.substr(s, 1, null) : s);
|
|
56
|
+
s = StringTools.replace(s, "\\", "/");
|
|
57
|
+
return (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
|
|
60
58
|
}
|
|
61
59
|
static get __name__() {
|
|
62
60
|
return "whet.stones.RemoteFile"
|
|
@@ -6,7 +6,6 @@ import {SourceHash} from "../SourceHash"
|
|
|
6
6
|
import {SourceData} from "../Source"
|
|
7
7
|
import {Project} from "../Project"
|
|
8
8
|
import {IncomingMessage, ServerResponse} from "http"
|
|
9
|
-
import {Command} from "commander"
|
|
10
9
|
|
|
11
10
|
export declare class Server extends Stone<ServerConfig> {
|
|
12
11
|
constructor(config: ServerConfig)
|
|
@@ -20,7 +19,7 @@ export declare class Server extends Stone<ServerConfig> {
|
|
|
20
19
|
*/
|
|
21
20
|
serve(): void
|
|
22
21
|
protected initConfig(): void
|
|
23
|
-
protected
|
|
22
|
+
protected addCommands(): void
|
|
24
23
|
protected handler(req: IncomingMessage, res: ServerResponse): void
|
|
25
24
|
}
|
|
26
25
|
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import {Stone} from "../Stone.js"
|
|
2
|
+
import {SourceId_Fields_} from "../SourceId.js"
|
|
2
3
|
import {Log} from "../Log.js"
|
|
4
|
+
import * as Path from "path"
|
|
3
5
|
import Mime from "mime"
|
|
4
6
|
import * as Http from "http"
|
|
5
|
-
import {Path} from "../../haxe/io/Path.js"
|
|
6
7
|
import {Register} from "../../genes/Register.js"
|
|
7
|
-
import {
|
|
8
|
+
import {StringTools} from "../../StringTools.js"
|
|
8
9
|
import {Std} from "../../Std.js"
|
|
9
10
|
import {HxOverrides} from "../../HxOverrides.js"
|
|
10
11
|
|
|
@@ -40,51 +41,54 @@ class Server extends Register.inherits(Stone) {
|
|
|
40
41
|
if (this.config.port == null) {
|
|
41
42
|
this.config.port = 7000;
|
|
42
43
|
};
|
|
44
|
+
this.project.addCommand("serve", this);
|
|
43
45
|
}
|
|
44
|
-
|
|
46
|
+
addCommands() {
|
|
45
47
|
var _gthis = this;
|
|
46
|
-
|
|
48
|
+
this.project.addCommand("serve", this).option("-p, --port <port>", "server port", "" + this.config.port).action(function (...args) {
|
|
47
49
|
if (args[0].port != null) {
|
|
48
50
|
_gthis.config.port = Std.parseInt(args[0].port);
|
|
49
51
|
};
|
|
50
52
|
_gthis.serve();
|
|
51
53
|
return null;
|
|
52
|
-
})
|
|
54
|
+
});
|
|
53
55
|
}
|
|
54
56
|
handler(req, res) {
|
|
55
57
|
var _gthis = this;
|
|
56
58
|
Log.log(30, ...["Handling request.", {"url": req.url, "method": req.method}]);
|
|
57
|
-
var id;
|
|
58
59
|
var s = req.url;
|
|
59
|
-
|
|
60
|
-
|
|
60
|
+
s = Path.posix.normalize((s.length > 1 && SourceId_Fields_.startsWithSlash(s)) ? HxOverrides.substr(s, 1, null) : s);
|
|
61
|
+
s = StringTools.replace(s, "\\", "/");
|
|
62
|
+
var id = (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
|
|
61
63
|
if (req.method == "GET") {
|
|
62
|
-
|
|
63
|
-
var tmp = (id.lastIndexOf("/") == id.length - 1) ? Path.addTrailingSlash(norm) : norm;
|
|
64
|
-
var s = Path.addTrailingSlash(Path.directory(id));
|
|
65
|
-
var norm = "/" + Path.normalize((s.charAt(0) == "/") ? HxOverrides.substr(s, 1, null) : s);
|
|
66
|
-
if (tmp == ((s.lastIndexOf("/") == s.length - 1) ? Path.addTrailingSlash(norm) : norm)) {
|
|
64
|
+
if (SourceId_Fields_.endsWithSlash(id)) {
|
|
67
65
|
if ("index.html".length > 0) {
|
|
68
|
-
var s =
|
|
69
|
-
|
|
70
|
-
|
|
66
|
+
var s = id.substring(0, id.lastIndexOf("/") + 1);
|
|
67
|
+
s = Path.posix.normalize((s.length > 1 && SourceId_Fields_.startsWithSlash(s)) ? HxOverrides.substr(s, 1, null) : s);
|
|
68
|
+
s = StringTools.replace(s, "\\", "/");
|
|
69
|
+
id = ((SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s) + "index.html";
|
|
71
70
|
};
|
|
72
|
-
} else if (Path.
|
|
71
|
+
} else if (Path.posix.extname(id) == "") {
|
|
73
72
|
var s = "" + id + "/index.html";
|
|
74
|
-
|
|
75
|
-
|
|
73
|
+
s = Path.posix.normalize((s.length > 1 && SourceId_Fields_.startsWithSlash(s)) ? HxOverrides.substr(s, 1, null) : s);
|
|
74
|
+
s = StringTools.replace(s, "\\", "/");
|
|
75
|
+
id = (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
|
|
76
76
|
};
|
|
77
77
|
this.config.router.find(id).then(function (routeResult) {
|
|
78
78
|
var sourcePromise = (routeResult.length > 0) ? routeResult[0].get() : (_gthis.routeDynamic != null) ? _gthis.routeDynamic(id) : null;
|
|
79
79
|
if (sourcePromise != null) {
|
|
80
80
|
sourcePromise.then(function (source) {
|
|
81
|
-
res.writeHead(200, {"Content-Type": Mime.getType(Path.
|
|
81
|
+
res.writeHead(200, {"Content-Type": Mime.getType(Path.posix.extname(id).toLowerCase()), "Last-Modified": new Date(source.source.ctime * 1000).toUTCString(), "Content-Length": Std.string(source.data.length), "Cache-Control": "no-store, no-cache"});
|
|
82
82
|
res.write(source.data, "binary");
|
|
83
83
|
res.end();
|
|
84
84
|
})["catch"](function (e) {
|
|
85
85
|
Log.log(40, ...["Server error.", {"error": e}]);
|
|
86
86
|
res.writeHead(500, "Error happened.");
|
|
87
|
-
|
|
87
|
+
if (((e) instanceof Error)) {
|
|
88
|
+
res.write(e.stack, "utf-8");
|
|
89
|
+
} else {
|
|
90
|
+
res.write(Std.string(e), "utf-8");
|
|
91
|
+
};
|
|
88
92
|
res.end();
|
|
89
93
|
});
|
|
90
94
|
} else {
|
|
@@ -94,7 +98,11 @@ class Server extends Register.inherits(Stone) {
|
|
|
94
98
|
})["catch"](function (e) {
|
|
95
99
|
Log.log(40, ...["Server error.", {"error": e}]);
|
|
96
100
|
res.writeHead(500, "Error happened.");
|
|
97
|
-
|
|
101
|
+
if (((e) instanceof Error)) {
|
|
102
|
+
res.write(e.stack, "utf-8");
|
|
103
|
+
} else {
|
|
104
|
+
res.write(Std.string(e), "utf-8");
|
|
105
|
+
};
|
|
98
106
|
res.end();
|
|
99
107
|
});
|
|
100
108
|
} else {
|
package/bin/whet/stones/Zip.js
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
import {Router} from "../route/Router.js"
|
|
2
2
|
import {CacheStrategy, CacheDurability, DurabilityCheck} from "../cache/Cache.js"
|
|
3
3
|
import {Stone} from "../Stone.js"
|
|
4
|
+
import {SourceId_Fields_} from "../SourceId.js"
|
|
4
5
|
import {SourceHash} from "../SourceHash.js"
|
|
5
6
|
import {SourceData} from "../Source.js"
|
|
6
7
|
import {Log} from "../Log.js"
|
|
8
|
+
import * as Path from "path"
|
|
7
9
|
import {Helper} from "../../js/node/buffer/Buffer.js"
|
|
8
10
|
import {Writer} from "../../haxe/zip/Writer.js"
|
|
9
11
|
import {Tools} from "../../haxe/zip/Tools.js"
|
|
10
|
-
import {Path} from "../../haxe/io/Path.js"
|
|
11
12
|
import {BytesOutput} from "../../haxe/io/BytesOutput.js"
|
|
12
13
|
import {Crc32} from "../../haxe/crypto/Crc32.js"
|
|
13
14
|
import {Register} from "../../genes/Register.js"
|
|
14
15
|
import {Buffer} from "buffer"
|
|
16
|
+
import {StringTools} from "../../StringTools.js"
|
|
15
17
|
import {Lambda} from "../../Lambda.js"
|
|
16
18
|
import {HxOverrides} from "../../HxOverrides.js"
|
|
17
19
|
|
|
@@ -56,7 +58,7 @@ class ZipStone extends Register.inherits(Stone) {
|
|
|
56
58
|
return Promise.all(result).then(function (hashes) {
|
|
57
59
|
return SourceHash.merge(...hashes);
|
|
58
60
|
}).then(function (hash) {
|
|
59
|
-
return SourceHash.
|
|
61
|
+
return SourceHash.fromString(_gthis.config.filename + _gthis.config.level).add(hash);
|
|
60
62
|
});
|
|
61
63
|
}
|
|
62
64
|
generate(hash) {
|
|
@@ -73,9 +75,14 @@ class ZipStone extends Register.inherits(Stone) {
|
|
|
73
75
|
return function (data) {
|
|
74
76
|
var bytes = Helper.bytesOfBuffer(data.data);
|
|
75
77
|
var this1 = file[0].serveId;
|
|
76
|
-
var
|
|
77
|
-
|
|
78
|
-
|
|
78
|
+
var s = "/";
|
|
79
|
+
s = Path.posix.normalize(("/".length > 1 && SourceId_Fields_.startsWithSlash("/")) ? HxOverrides.substr("/", 1, null) : "/");
|
|
80
|
+
s = StringTools.replace(s, "\\", "/");
|
|
81
|
+
var root = (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
|
|
82
|
+
if (this1.charAt(0) != "/") {
|
|
83
|
+
throw new Error("Badly formed SourceId.");
|
|
84
|
+
};
|
|
85
|
+
var entry = {"fileName": Path.posix.join(".", root, ".", this1), "fileSize": data.data.length, "fileTime": new Date(data.source.ctime * 1000), "compressed": false, "dataSize": data.data.length, "data": bytes, "crc32": Crc32.make(bytes)};
|
|
79
86
|
Tools.compress(entry, level);
|
|
80
87
|
return entry;
|
|
81
88
|
};
|
|
@@ -84,19 +91,18 @@ class ZipStone extends Register.inherits(Stone) {
|
|
|
84
91
|
return Promise.all(_g).then(function (entries) {
|
|
85
92
|
var out = new BytesOutput();
|
|
86
93
|
new Writer(out).write(Lambda.list(entries));
|
|
87
|
-
var
|
|
88
|
-
var norm = "/" + Path.normalize((s.charAt(0) == "/") ? HxOverrides.substr(s, 1, null) : s);
|
|
89
|
-
var tmp = (s.lastIndexOf("/") == s.length - 1) ? Path.addTrailingSlash(norm) : norm;
|
|
94
|
+
var _gthis1 = _gthis.config.filename;
|
|
90
95
|
var b = out.getBytes();
|
|
91
96
|
var data = b.b;
|
|
92
|
-
return [SourceData.fromBytes(
|
|
97
|
+
return [SourceData.fromBytes(_gthis1, Buffer.from(data.buffer, data.byteOffset, b.length))];
|
|
93
98
|
});
|
|
94
99
|
});
|
|
95
100
|
}
|
|
96
101
|
list() {
|
|
97
102
|
var s = this.config.filename;
|
|
98
|
-
|
|
99
|
-
|
|
103
|
+
s = Path.posix.normalize((s.length > 1 && SourceId_Fields_.startsWithSlash(s)) ? HxOverrides.substr(s, 1, null) : s);
|
|
104
|
+
s = StringTools.replace(s, "\\", "/");
|
|
105
|
+
return Promise.resolve([(SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s]);
|
|
100
106
|
}
|
|
101
107
|
static get __name__() {
|
|
102
108
|
return "whet.stones.ZipStone"
|
|
@@ -8,12 +8,14 @@ import {Project} from "../../Project"
|
|
|
8
8
|
|
|
9
9
|
export declare class HaxeBuild extends Stone<BuildConfig> {
|
|
10
10
|
constructor(config: BuildConfig)
|
|
11
|
+
protected initConfig(): void
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
Build the given hxml.
|
|
14
15
|
*/
|
|
15
16
|
build(): Promise<any>
|
|
16
17
|
protected generate(hash: SourceHash): Promise<SourceData[]>
|
|
18
|
+
protected addCommands(): void
|
|
17
19
|
list(): Promise<string[]>
|
|
18
20
|
protected generateHash(): Promise<SourceHash>
|
|
19
21
|
}
|
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
import {MaybeArray_Fields_} from "../../magic/MaybeArray.js"
|
|
2
2
|
import {Utils} from "../../Utils.js"
|
|
3
3
|
import {Stone} from "../../Stone.js"
|
|
4
|
-
import {RootDir} from "../../SourceId.js"
|
|
4
|
+
import {SourceId_Fields_, RootDir} from "../../SourceId.js"
|
|
5
5
|
import {SourceHash} from "../../SourceHash.js"
|
|
6
6
|
import {SourceData} from "../../Source.js"
|
|
7
7
|
import {Log} from "../../Log.js"
|
|
8
|
-
import * as
|
|
9
|
-
import {Path, Path as Path__2} from "../../../haxe/io/Path.js"
|
|
8
|
+
import * as Path from "path"
|
|
10
9
|
import {Register} from "../../../genes/Register.js"
|
|
11
10
|
import * as ChildProcess from "child_process"
|
|
12
11
|
import {StringTools} from "../../../StringTools.js"
|
|
13
|
-
import {Lambda} from "../../../Lambda.js"
|
|
14
12
|
import {HxOverrides} from "../../../HxOverrides.js"
|
|
15
13
|
|
|
16
14
|
const $global = Register.$global
|
|
@@ -20,18 +18,29 @@ class HaxeBuild extends Register.inherits(Stone) {
|
|
|
20
18
|
new(config) {
|
|
21
19
|
super.new(config);
|
|
22
20
|
}
|
|
21
|
+
initConfig() {
|
|
22
|
+
if (this.config.cacheStrategy == null) {
|
|
23
|
+
this.config.cacheStrategy = this.project.cache.defaultFileStrategy;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
23
26
|
|
|
24
27
|
/**
|
|
25
28
|
Build the given hxml.
|
|
26
29
|
*/
|
|
27
30
|
build() {
|
|
28
31
|
var _gthis = this;
|
|
32
|
+
Log.log(30, ...["Building Haxe project."]);
|
|
29
33
|
return new Promise(function (res, rej) {
|
|
30
34
|
var cwd = process.cwd();
|
|
31
35
|
var this1 = _gthis.project.rootDir;
|
|
32
|
-
var
|
|
33
|
-
|
|
34
|
-
|
|
36
|
+
var s = "/";
|
|
37
|
+
s = Path.posix.normalize(("/".length > 1 && SourceId_Fields_.startsWithSlash("/")) ? HxOverrides.substr("/", 1, null) : "/");
|
|
38
|
+
s = StringTools.replace(s, "\\", "/");
|
|
39
|
+
var root = (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
|
|
40
|
+
if (this1.charAt(0) != "/") {
|
|
41
|
+
throw new Error("Badly formed SourceId.");
|
|
42
|
+
};
|
|
43
|
+
var cwd1 = Path.join(cwd, Path.posix.join(".", root, ".", this1));
|
|
35
44
|
var _g = [];
|
|
36
45
|
var e = Register.iter(_gthis.config.hxml.getBuildArgs());
|
|
37
46
|
while (e.hasNext()) {
|
|
@@ -60,23 +69,27 @@ class HaxeBuild extends Register.inherits(Stone) {
|
|
|
60
69
|
if (this.config.hxml.isSingleFile()) {
|
|
61
70
|
var pathId = this.config.hxml.getBuildExportPath();
|
|
62
71
|
var root = RootDir.fromProject(this.project);
|
|
63
|
-
|
|
72
|
+
if (pathId.charAt(0) != "/") {
|
|
73
|
+
throw new Error("Badly formed SourceId.");
|
|
74
|
+
};
|
|
75
|
+
var path = Path.posix.join(".", root, ".", pathId);
|
|
64
76
|
return Utils.deleteAll(path).then(function (_) {
|
|
65
77
|
return _gthis.build();
|
|
66
78
|
}).then(function (_) {
|
|
67
|
-
|
|
68
|
-
var norm = "/" + Path.normalize((s.charAt(0) == "/") ? HxOverrides.substr(s, 1, null) : s);
|
|
69
|
-
return SourceData.fromFile((s.lastIndexOf("/") == s.length - 1) ? Path.addTrailingSlash(norm) : norm, path, pathId).then(function (file) {
|
|
79
|
+
return SourceData.fromFile(pathId.substring(pathId.lastIndexOf("/")), path, pathId).then(function (file) {
|
|
70
80
|
return [file];
|
|
71
81
|
});
|
|
72
|
-
})["catch"](function (err) {
|
|
73
|
-
Log.log(50, ...["Error during Haxe build.", {"error": err}]);
|
|
74
|
-
return null;
|
|
75
82
|
});
|
|
76
83
|
} else {
|
|
77
84
|
throw new Error("Cannot get source of a multi-file build. Not implemented yet.");
|
|
78
85
|
};
|
|
79
86
|
}
|
|
87
|
+
addCommands() {
|
|
88
|
+
var _gthis = this;
|
|
89
|
+
this.project.addCommand("build", this).action(function (..._) {
|
|
90
|
+
return _gthis.build();
|
|
91
|
+
});
|
|
92
|
+
}
|
|
80
93
|
list() {
|
|
81
94
|
if (this.config.hxml.isSingleFile()) {
|
|
82
95
|
return Promise.resolve([this.config.hxml.getBuildFilename()]);
|
|
@@ -85,56 +98,24 @@ class HaxeBuild extends Register.inherits(Stone) {
|
|
|
85
98
|
};
|
|
86
99
|
}
|
|
87
100
|
generateHash() {
|
|
88
|
-
var
|
|
89
|
-
var
|
|
90
|
-
var
|
|
91
|
-
var
|
|
92
|
-
while (
|
|
93
|
-
var
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
var
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
while (_g < _g1) {
|
|
102
|
-
var i = _g++;
|
|
103
|
-
var files = arrFiles[i];
|
|
104
|
-
files.sort();
|
|
105
|
-
var result1 = new Array(files.length);
|
|
106
|
-
var _g2 = 0;
|
|
107
|
-
var _g3 = files.length;
|
|
108
|
-
while (_g2 < _g3) {
|
|
109
|
-
var i1 = _g2++;
|
|
110
|
-
result1[i1] = SourceHash.fromFile(files[i1]);
|
|
111
|
-
};
|
|
112
|
-
result[i] = Promise.all(result1);
|
|
101
|
+
var _this = MaybeArray_Fields_.makeArray(this.config.hxml.config.paths);
|
|
102
|
+
var result = new Array(_this.length);
|
|
103
|
+
var _g = 0;
|
|
104
|
+
var _g1 = _this.length;
|
|
105
|
+
while (_g < _g1) {
|
|
106
|
+
var i = _g++;
|
|
107
|
+
var s = _this[i];
|
|
108
|
+
s = Path.posix.normalize((s.length > 1 && SourceId_Fields_.startsWithSlash(s)) ? HxOverrides.substr(s, 1, null) : s);
|
|
109
|
+
s = StringTools.replace(s, "\\", "/");
|
|
110
|
+
var this1 = (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
|
|
111
|
+
var root = RootDir.fromProject(this.config.hxml.project);
|
|
112
|
+
if (this1.charAt(0) != "/") {
|
|
113
|
+
throw new Error("Badly formed SourceId.");
|
|
113
114
|
};
|
|
114
|
-
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
var _g = [];
|
|
119
|
-
var _g_current = 0;
|
|
120
|
-
var _g_array = allHashes;
|
|
121
|
-
while (_g_current < _g_array.length) {
|
|
122
|
-
var e = _g_array[_g_current++];
|
|
123
|
-
var x = Register.iter(e);
|
|
124
|
-
while (x.hasNext()) {
|
|
125
|
-
var x1 = x.next();
|
|
126
|
-
_g.push(x1);
|
|
127
|
-
};
|
|
128
|
-
};
|
|
129
|
-
return _g;
|
|
130
|
-
});
|
|
131
|
-
return Promise.all([hxmlHashP, fileHashesP]).then(function (r) {
|
|
132
|
-
var hxmlHash = r[0];
|
|
133
|
-
var fileHashes = r[1];
|
|
134
|
-
var r = Lambda.fold(fileHashes, function (i, r) {
|
|
135
|
-
return SourceHash.add(r, i);
|
|
136
|
-
}, hxmlHash);
|
|
137
|
-
return r;
|
|
115
|
+
result[i] = Path.posix.join(".", root, ".", this1);
|
|
116
|
+
};
|
|
117
|
+
return Promise.all([this.config.hxml.generateHash(), SourceHash.fromFiles(result)]).then(function (r) {
|
|
118
|
+
return SourceHash.merge(...r);
|
|
138
119
|
});
|
|
139
120
|
}
|
|
140
121
|
static get __name__() {
|
|
@@ -3,12 +3,13 @@ import {StoneId_Fields_} from "../../magic/StoneId.js"
|
|
|
3
3
|
import {MaybeArray_Fields_} from "../../magic/MaybeArray.js"
|
|
4
4
|
import {CacheStrategy, CacheDurability} from "../../cache/Cache.js"
|
|
5
5
|
import {Stone} from "../../Stone.js"
|
|
6
|
-
import {SourceId} from "../../SourceId.js"
|
|
6
|
+
import {SourceId, SourceId_Fields_} from "../../SourceId.js"
|
|
7
7
|
import {SourceHash} from "../../SourceHash.js"
|
|
8
8
|
import {SourceData} from "../../Source.js"
|
|
9
9
|
import {Log} from "../../Log.js"
|
|
10
|
-
import
|
|
10
|
+
import * as Path from "path"
|
|
11
11
|
import {Register} from "../../../genes/Register.js"
|
|
12
|
+
import {StringTools} from "../../../StringTools.js"
|
|
12
13
|
import {HxOverrides} from "../../../HxOverrides.js"
|
|
13
14
|
|
|
14
15
|
const $global = Register.$global
|
|
@@ -26,7 +27,7 @@ class Hxml extends Register.inherits(Stone) {
|
|
|
26
27
|
}
|
|
27
28
|
clone(id) {
|
|
28
29
|
var configClone = this.cloneConfig(this.config);
|
|
29
|
-
configClone.id = StoneId_Fields_.makeStoneId(id);
|
|
30
|
+
configClone.id = StoneId_Fields_.makeStoneId((id == null) ? this.id : id);
|
|
30
31
|
return new Hxml(configClone);
|
|
31
32
|
}
|
|
32
33
|
mergeConfig(additionalConfig) {
|
|
@@ -148,19 +149,24 @@ class Hxml extends Register.inherits(Stone) {
|
|
|
148
149
|
var filename;
|
|
149
150
|
if (this.build.config.filename != null) {
|
|
150
151
|
var s = this.build.config.filename;
|
|
151
|
-
|
|
152
|
-
|
|
152
|
+
s = Path.posix.normalize((s.length > 1 && SourceId_Fields_.startsWithSlash(s)) ? HxOverrides.substr(s, 1, null) : s);
|
|
153
|
+
s = StringTools.replace(s, "\\", "/");
|
|
154
|
+
filename = (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
|
|
153
155
|
} else {
|
|
154
|
-
var
|
|
155
|
-
|
|
156
|
+
var s = "build";
|
|
157
|
+
s = Path.posix.normalize(("build".length > 1 && SourceId_Fields_.startsWithSlash("build")) ? HxOverrides.substr("build", 1, null) : "build");
|
|
158
|
+
s = StringTools.replace(s, "\\", "/");
|
|
159
|
+
filename = (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
|
|
156
160
|
};
|
|
157
|
-
if (Path.
|
|
161
|
+
if (Path.posix.extname(filename) == "") {
|
|
158
162
|
var v = this.getBuildExtension();
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
var
|
|
163
|
-
|
|
163
|
+
if (v.length > 0 && HxOverrides.cca(v, 0) != 46) {
|
|
164
|
+
v = "." + v;
|
|
165
|
+
};
|
|
166
|
+
var s = filename.substring(0, filename.lastIndexOf("/") + 1);
|
|
167
|
+
s = Path.posix.normalize((s.length > 1 && SourceId_Fields_.startsWithSlash(s)) ? HxOverrides.substr(s, 1, null) : s);
|
|
168
|
+
s = StringTools.replace(s, "\\", "/");
|
|
169
|
+
filename = ((SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s) + Path.posix.parse(filename.substring(filename.lastIndexOf("/"))).name + v;
|
|
164
170
|
};
|
|
165
171
|
return filename;
|
|
166
172
|
} else {
|
|
@@ -169,9 +175,14 @@ class Hxml extends Register.inherits(Stone) {
|
|
|
169
175
|
}
|
|
170
176
|
getPlatform() {
|
|
171
177
|
var this1 = this.getBuildExportPath();
|
|
172
|
-
var
|
|
173
|
-
|
|
174
|
-
|
|
178
|
+
var s = "/";
|
|
179
|
+
s = Path.posix.normalize(("/".length > 1 && SourceId_Fields_.startsWithSlash("/")) ? HxOverrides.substr("/", 1, null) : "/");
|
|
180
|
+
s = StringTools.replace(s, "\\", "/");
|
|
181
|
+
var root = (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
|
|
182
|
+
if (this1.charAt(0) != "/") {
|
|
183
|
+
throw new Error("Badly formed SourceId.");
|
|
184
|
+
};
|
|
185
|
+
var path = Path.posix.join(".", root, ".", this1);
|
|
175
186
|
var _g = this.config.platform;
|
|
176
187
|
if (_g == null) {
|
|
177
188
|
return [];
|
|
@@ -271,14 +282,18 @@ class Hxml extends Register.inherits(Stone) {
|
|
|
271
282
|
}
|
|
272
283
|
filename() {
|
|
273
284
|
var s = this.id;
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
285
|
+
s = Path.posix.normalize((s.length > 1 && SourceId_Fields_.startsWithSlash(s)) ? HxOverrides.substr(s, 1, null) : s);
|
|
286
|
+
s = StringTools.replace(s, "\\", "/");
|
|
287
|
+
var fn = (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
|
|
288
|
+
if (Path.posix.extname(fn) == "") {
|
|
289
|
+
var v = "hxml";
|
|
290
|
+
if ("hxml".length > 0 && HxOverrides.cca("hxml", 0) != 46) {
|
|
291
|
+
v = "." + "hxml";
|
|
292
|
+
};
|
|
293
|
+
var s = fn.substring(0, fn.lastIndexOf("/") + 1);
|
|
294
|
+
s = Path.posix.normalize((s.length > 1 && SourceId_Fields_.startsWithSlash(s)) ? HxOverrides.substr(s, 1, null) : s);
|
|
295
|
+
s = StringTools.replace(s, "\\", "/");
|
|
296
|
+
fn = ((SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s) + Path.posix.parse(fn.substring(fn.lastIndexOf("/"))).name + v;
|
|
282
297
|
};
|
|
283
298
|
return fn;
|
|
284
299
|
}
|