whet 0.0.3 → 0.0.6
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/Log.d.ts +33 -0
- package/bin/haxe/Log.js +61 -0
- package/bin/haxe/NativeStackTrace.js +147 -0
- package/bin/whet/Log.js +3 -0
- package/bin/whet/Project.d.ts +1 -0
- package/bin/whet/Project.js +13 -8
- package/bin/whet/Source.d.ts +2 -2
- package/bin/whet/Source.js +20 -5
- package/bin/whet/SourceHash.d.ts +8 -1
- package/bin/whet/SourceHash.js +105 -7
- package/bin/whet/SourceId.d.ts +1 -0
- package/bin/whet/SourceId.js +37 -28
- package/bin/whet/Stone.d.ts +12 -2
- package/bin/whet/Stone.js +25 -13
- package/bin/whet/Utils.d.ts +8 -1
- package/bin/whet/Utils.js +56 -3
- package/bin/whet/Whet.js +5 -1
- package/bin/whet/cache/BaseCache.js +23 -20
- package/bin/whet/cache/CacheManager.d.ts +5 -0
- package/bin/whet/cache/CacheManager.js +22 -14
- package/bin/whet/cache/FileCache.js +89 -35
- package/bin/whet/magic/RoutePathType.js +10 -5
- package/bin/whet/magic/RouteType.d.ts +2 -2
- package/bin/whet/magic/RouteType.js +28 -14
- 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 -14
- package/bin/whet/route/Router.js +27 -37
- package/bin/whet/stones/Files.js +25 -17
- package/bin/whet/stones/JsonStone.js +7 -7
- package/bin/whet/stones/RemoteFile.js +5 -8
- package/bin/whet/stones/Server.js +28 -19
- package/bin/whet/stones/Zip.js +17 -12
- package/bin/whet/stones/haxe/HaxeBuild.d.ts +3 -0
- package/bin/whet/stones/haxe/HaxeBuild.js +58 -16
- package/bin/whet/stones/haxe/Hxml.js +56 -34
- package/bin/whet.d.ts +2 -0
- package/bin/whet.js +2 -0
- package/package.json +1 -1
package/bin/whet/route/Router.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import {RoutePathType_Fields_} from "../magic/RoutePathType.js"
|
|
2
2
|
import {Utils} from "../Utils.js"
|
|
3
|
-
import {SourceId} from "../SourceId.js"
|
|
3
|
+
import {SourceId_Fields_, SourceId} from "../SourceId.js"
|
|
4
4
|
import {SourceHash} from "../SourceHash.js"
|
|
5
|
-
import * as
|
|
6
|
-
import {Path} from "../../haxe/io/Path.js"
|
|
5
|
+
import * as Path from "path"
|
|
7
6
|
import {Register} from "../../genes/Register.js"
|
|
8
|
-
import {
|
|
7
|
+
import {StringTools} from "../../StringTools.js"
|
|
9
8
|
|
|
10
9
|
const $global = Register.$global
|
|
11
10
|
|
|
@@ -26,16 +25,13 @@ class Router extends Register.inherits() {
|
|
|
26
25
|
*/
|
|
27
26
|
find(id, firstOnly) {
|
|
28
27
|
var _gthis = this;
|
|
29
|
-
var
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
var s = id;
|
|
29
|
+
s = Path.posix.normalize(id);
|
|
30
|
+
s = StringTools.replace(s, "\\", "/");
|
|
31
|
+
var sourceId = (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
|
|
32
32
|
return new Promise(function (res, rej) {
|
|
33
33
|
if (firstOnly == null) {
|
|
34
|
-
|
|
35
|
-
var firstOnly1 = (sourceId.lastIndexOf("/") == sourceId.length - 1) ? Path.addTrailingSlash(norm) : norm;
|
|
36
|
-
var s = Path.addTrailingSlash(Path.directory(sourceId));
|
|
37
|
-
var norm = "/" + Path.normalize((s.charAt(0) == "/") ? HxOverrides.substr(s, 1, null) : s);
|
|
38
|
-
firstOnly = firstOnly1 != ((s.lastIndexOf("/") == s.length - 1) ? Path.addTrailingSlash(norm) : norm);
|
|
34
|
+
firstOnly = !SourceId_Fields_.endsWithSlash(sourceId);
|
|
39
35
|
};
|
|
40
36
|
var result = [];
|
|
41
37
|
var _g = [];
|
|
@@ -46,31 +42,23 @@ class Router extends Register.inherits() {
|
|
|
46
42
|
++_g1;
|
|
47
43
|
_g.push(path[0].route.list().then((function (path) {
|
|
48
44
|
return function (list) {
|
|
49
|
-
|
|
50
|
-
var norm = "/" + Path.normalize((this1.charAt(0) == "/") ? HxOverrides.substr(this1, 1, null) : this1);
|
|
51
|
-
var tmp = (this1.lastIndexOf("/") == this1.length - 1) ? Path.addTrailingSlash(norm) : norm;
|
|
52
|
-
var s = Path.addTrailingSlash(Path.directory(this1));
|
|
53
|
-
var norm = "/" + Path.normalize((s.charAt(0) == "/") ? HxOverrides.substr(s, 1, null) : s);
|
|
54
|
-
if (tmp == ((s.lastIndexOf("/") == s.length - 1) ? Path.addTrailingSlash(norm) : norm)) {
|
|
45
|
+
if (SourceId_Fields_.endsWithSlash(path[0].routeUnder)) {
|
|
55
46
|
var _g = 0;
|
|
56
47
|
while (_g < list.length) {
|
|
57
48
|
var item = list[_g];
|
|
58
49
|
++_g;
|
|
59
50
|
item.serveId = SourceId.getPutInDir(item.serveId, path[0].routeUnder);
|
|
60
|
-
|
|
61
|
-
var tmp = (sourceId.lastIndexOf("/") == sourceId.length - 1) ? Path.addTrailingSlash(norm) : norm;
|
|
62
|
-
var s = Path.addTrailingSlash(Path.directory(sourceId));
|
|
63
|
-
var norm1 = "/" + Path.normalize((s.charAt(0) == "/") ? HxOverrides.substr(s, 1, null) : s);
|
|
64
|
-
if (tmp == ((s.lastIndexOf("/") == s.length - 1) ? Path.addTrailingSlash(norm1) : norm1)) {
|
|
51
|
+
if (SourceId_Fields_.endsWithSlash(sourceId)) {
|
|
65
52
|
var rel = SourceId.relativeTo(item.serveId, sourceId);
|
|
66
53
|
if (rel != null) {
|
|
67
54
|
item.serveId = rel;
|
|
68
55
|
result.push(item);
|
|
69
56
|
};
|
|
70
57
|
} else if (sourceId == item.serveId) {
|
|
71
|
-
var
|
|
72
|
-
|
|
73
|
-
|
|
58
|
+
var s = sourceId.substring(sourceId.lastIndexOf("/"));
|
|
59
|
+
s = Path.posix.normalize(s);
|
|
60
|
+
s = StringTools.replace(s, "\\", "/");
|
|
61
|
+
item.serveId = (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
|
|
74
62
|
result.push(item);
|
|
75
63
|
};
|
|
76
64
|
};
|
|
@@ -80,20 +68,17 @@ class Router extends Register.inherits() {
|
|
|
80
68
|
var item = list[_g];
|
|
81
69
|
++_g;
|
|
82
70
|
item.serveId = path[0].routeUnder;
|
|
83
|
-
|
|
84
|
-
var tmp = (sourceId.lastIndexOf("/") == sourceId.length - 1) ? Path.addTrailingSlash(norm) : norm;
|
|
85
|
-
var s = Path.addTrailingSlash(Path.directory(sourceId));
|
|
86
|
-
var norm1 = "/" + Path.normalize((s.charAt(0) == "/") ? HxOverrides.substr(s, 1, null) : s);
|
|
87
|
-
if (tmp == ((s.lastIndexOf("/") == s.length - 1) ? Path.addTrailingSlash(norm1) : norm1)) {
|
|
71
|
+
if (SourceId_Fields_.endsWithSlash(sourceId)) {
|
|
88
72
|
var rel = SourceId.relativeTo(item.serveId, sourceId);
|
|
89
73
|
if (rel != null) {
|
|
90
74
|
item.serveId = rel;
|
|
91
75
|
result.push(item);
|
|
92
76
|
};
|
|
93
77
|
} else if (sourceId == item.serveId) {
|
|
94
|
-
var
|
|
95
|
-
|
|
96
|
-
|
|
78
|
+
var s = sourceId.substring(sourceId.lastIndexOf("/"));
|
|
79
|
+
s = Path.posix.normalize(s);
|
|
80
|
+
s = StringTools.replace(s, "\\", "/");
|
|
81
|
+
item.serveId = (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
|
|
97
82
|
result.push(item);
|
|
98
83
|
};
|
|
99
84
|
};
|
|
@@ -178,9 +163,14 @@ class Router extends Register.inherits() {
|
|
|
178
163
|
++_g1;
|
|
179
164
|
var saveInto1 = saveInto;
|
|
180
165
|
var this1 = r.serveId;
|
|
181
|
-
var
|
|
182
|
-
|
|
183
|
-
|
|
166
|
+
var s = "/";
|
|
167
|
+
s = Path.posix.normalize("/");
|
|
168
|
+
s = StringTools.replace(s, "\\", "/");
|
|
169
|
+
var root = (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
|
|
170
|
+
if (this1.charAt(0) != "/") {
|
|
171
|
+
throw new Error("Badly formed SourceId.");
|
|
172
|
+
};
|
|
173
|
+
var p = [Path.join(saveInto1, Path.posix.join(".", root, ".", this1))];
|
|
184
174
|
_g.push(r.get().then((function (p) {
|
|
185
175
|
return function (src) {
|
|
186
176
|
return Utils.saveBytes(p[0], src.data);
|
package/bin/whet/stones/Files.js
CHANGED
|
@@ -1,11 +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 {
|
|
8
|
+
import {StringTools} from "../../StringTools.js"
|
|
9
9
|
|
|
10
10
|
const $global = Register.$global
|
|
11
11
|
|
|
@@ -19,18 +19,19 @@ class Files extends Register.inherits(Stone) {
|
|
|
19
19
|
var _g = MaybeArray_Fields_.makeArray(this.config.paths);
|
|
20
20
|
while (0 < _g.length) {
|
|
21
21
|
var pathString = _g[0];
|
|
22
|
-
var
|
|
23
|
-
|
|
22
|
+
var s = pathString;
|
|
23
|
+
s = Path.posix.normalize(pathString);
|
|
24
|
+
s = StringTools.replace(s, "\\", "/");
|
|
25
|
+
var path = [(SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s];
|
|
24
26
|
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)) {
|
|
27
|
+
if (SourceId_Fields_.endsWithSlash(path[0])) {
|
|
30
28
|
tmp = new Promise((function (path) {
|
|
31
29
|
return function (res, rej) {
|
|
32
30
|
var root = RootDir.fromProject(_gthis.project);
|
|
33
|
-
|
|
31
|
+
if (path[0].charAt(0) != "/") {
|
|
32
|
+
throw new Error("Badly formed SourceId.");
|
|
33
|
+
};
|
|
34
|
+
Fs.readdir(Path.posix.join(".", root, ".", path[0]), (function (path) {
|
|
34
35
|
return function (err, files) {
|
|
35
36
|
if (err != null) {
|
|
36
37
|
rej(err);
|
|
@@ -41,8 +42,10 @@ class Files extends Register.inherits(Stone) {
|
|
|
41
42
|
while (_g1 < files.length) {
|
|
42
43
|
var file = files[_g1];
|
|
43
44
|
++_g1;
|
|
44
|
-
var
|
|
45
|
-
|
|
45
|
+
var s = file;
|
|
46
|
+
s = Path.posix.normalize(file);
|
|
47
|
+
s = StringTools.replace(s, "\\", "/");
|
|
48
|
+
var filepath = SourceId.getPutInDir((SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s, path[0]);
|
|
46
49
|
_g.push({"id": SourceId.relativeTo(filepath, path[0]), "pathId": filepath});
|
|
47
50
|
};
|
|
48
51
|
res1(_g);
|
|
@@ -52,9 +55,10 @@ class Files extends Register.inherits(Stone) {
|
|
|
52
55
|
};
|
|
53
56
|
})(path));
|
|
54
57
|
} else {
|
|
55
|
-
var s1 =
|
|
56
|
-
|
|
57
|
-
|
|
58
|
+
var s1 = path[0].substring(path[0].lastIndexOf("/"));
|
|
59
|
+
s1 = Path.posix.normalize(s1);
|
|
60
|
+
s1 = StringTools.replace(s1, "\\", "/");
|
|
61
|
+
tmp = Promise.resolve([{"id": (SourceId_Fields_.startsWithSlash(s1)) ? s1 : "/" + s1, "pathId": path[0]}]);
|
|
58
62
|
};
|
|
59
63
|
return tmp.then((function () {
|
|
60
64
|
return function (files) {
|
|
@@ -63,9 +67,13 @@ class Files extends Register.inherits(Stone) {
|
|
|
63
67
|
while (_g1 < files.length) {
|
|
64
68
|
var f = files[_g1];
|
|
65
69
|
++_g1;
|
|
70
|
+
var f1 = f.id;
|
|
66
71
|
var this1 = f.pathId;
|
|
67
72
|
var root = RootDir.fromProject(_gthis.project);
|
|
68
|
-
|
|
73
|
+
if (this1.charAt(0) != "/") {
|
|
74
|
+
throw new Error("Badly formed SourceId.");
|
|
75
|
+
};
|
|
76
|
+
_g.push(SourceData.fromFile(f1, Path.posix.join(".", root, ".", this1), f.pathId));
|
|
69
77
|
};
|
|
70
78
|
return Promise.all(_g);
|
|
71
79
|
};
|
|
@@ -1,12 +1,13 @@
|
|
|
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
|
-
import {HxOverrides} from "../../HxOverrides.js"
|
|
10
11
|
|
|
11
12
|
const $global = Register.$global
|
|
12
13
|
|
|
@@ -60,9 +61,7 @@ class JsonStone extends Register.inherits(Stone) {
|
|
|
60
61
|
};
|
|
61
62
|
};
|
|
62
63
|
};
|
|
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, " "))];
|
|
64
|
+
return [SourceData.fromString(_gthis.config.name, JSON.stringify(obj, null, " "))];
|
|
66
65
|
});
|
|
67
66
|
}
|
|
68
67
|
generateHash() {
|
|
@@ -92,8 +91,9 @@ class JsonStone extends Register.inherits(Stone) {
|
|
|
92
91
|
}
|
|
93
92
|
list() {
|
|
94
93
|
var s = this.config.name;
|
|
95
|
-
|
|
96
|
-
|
|
94
|
+
s = Path.posix.normalize(s);
|
|
95
|
+
s = StringTools.replace(s, "\\", "/");
|
|
96
|
+
return Promise.resolve([(SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s]);
|
|
97
97
|
}
|
|
98
98
|
initConfig() {
|
|
99
99
|
if (this.config.name == null) {
|
|
@@ -1,15 +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 {
|
|
12
|
+
import {StringTools} from "../../StringTools.js"
|
|
13
13
|
|
|
14
14
|
const $global = Register.$global
|
|
15
15
|
|
|
@@ -51,12 +51,9 @@ class RemoteFile extends Register.inherits(Stone) {
|
|
|
51
51
|
}
|
|
52
52
|
getId() {
|
|
53
53
|
var s = Path.basename(new URL(this.config.url).pathname);
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
} else {
|
|
58
|
-
return norm;
|
|
59
|
-
};
|
|
54
|
+
s = Path.posix.normalize(s);
|
|
55
|
+
s = StringTools.replace(s, "\\", "/");
|
|
56
|
+
return (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
|
|
60
57
|
}
|
|
61
58
|
static get __name__() {
|
|
62
59
|
return "whet.stones.RemoteFile"
|
|
@@ -1,12 +1,13 @@
|
|
|
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
8
|
import {Command} from "commander"
|
|
9
|
+
import {StringTools} from "../../StringTools.js"
|
|
8
10
|
import {Std} from "../../Std.js"
|
|
9
|
-
import {HxOverrides} from "../../HxOverrides.js"
|
|
10
11
|
|
|
11
12
|
const $global = Register.$global
|
|
12
13
|
|
|
@@ -54,36 +55,39 @@ class Server extends Register.inherits(Stone) {
|
|
|
54
55
|
handler(req, res) {
|
|
55
56
|
var _gthis = this;
|
|
56
57
|
Log.log(30, ...["Handling request.", {"url": req.url, "method": req.method}]);
|
|
57
|
-
var id;
|
|
58
58
|
var s = req.url;
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
s = Path.posix.normalize(s);
|
|
60
|
+
s = StringTools.replace(s, "\\", "/");
|
|
61
|
+
var id = (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
|
|
61
62
|
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)) {
|
|
63
|
+
if (SourceId_Fields_.endsWithSlash(id)) {
|
|
67
64
|
if ("index.html".length > 0) {
|
|
68
|
-
var s =
|
|
69
|
-
|
|
70
|
-
|
|
65
|
+
var s = id.substring(0, id.lastIndexOf("/") + 1);
|
|
66
|
+
s = Path.posix.normalize(s);
|
|
67
|
+
s = StringTools.replace(s, "\\", "/");
|
|
68
|
+
id = ((SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s) + "index.html";
|
|
71
69
|
};
|
|
72
|
-
} else if (Path.
|
|
70
|
+
} else if (Path.posix.extname(id) == "") {
|
|
73
71
|
var s = "" + id + "/index.html";
|
|
74
|
-
|
|
75
|
-
|
|
72
|
+
s = Path.posix.normalize(s);
|
|
73
|
+
s = StringTools.replace(s, "\\", "/");
|
|
74
|
+
id = (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
|
|
76
75
|
};
|
|
77
76
|
this.config.router.find(id).then(function (routeResult) {
|
|
78
77
|
var sourcePromise = (routeResult.length > 0) ? routeResult[0].get() : (_gthis.routeDynamic != null) ? _gthis.routeDynamic(id) : null;
|
|
79
78
|
if (sourcePromise != null) {
|
|
80
79
|
sourcePromise.then(function (source) {
|
|
81
|
-
res.writeHead(200, {"Content-Type": Mime.getType(Path.
|
|
80
|
+
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
81
|
res.write(source.data, "binary");
|
|
83
82
|
res.end();
|
|
84
83
|
})["catch"](function (e) {
|
|
84
|
+
Log.log(40, ...["Server error.", {"error": e}]);
|
|
85
85
|
res.writeHead(500, "Error happened.");
|
|
86
|
-
|
|
86
|
+
if (((e) instanceof Error)) {
|
|
87
|
+
res.write(e.stack, "utf-8");
|
|
88
|
+
} else {
|
|
89
|
+
res.write(Std.string(e), "utf-8");
|
|
90
|
+
};
|
|
87
91
|
res.end();
|
|
88
92
|
});
|
|
89
93
|
} else {
|
|
@@ -91,8 +95,13 @@ class Server extends Register.inherits(Stone) {
|
|
|
91
95
|
res.end();
|
|
92
96
|
};
|
|
93
97
|
})["catch"](function (e) {
|
|
98
|
+
Log.log(40, ...["Server error.", {"error": e}]);
|
|
94
99
|
res.writeHead(500, "Error happened.");
|
|
95
|
-
|
|
100
|
+
if (((e) instanceof Error)) {
|
|
101
|
+
res.write(e.stack, "utf-8");
|
|
102
|
+
} else {
|
|
103
|
+
res.write(Std.string(e), "utf-8");
|
|
104
|
+
};
|
|
96
105
|
res.end();
|
|
97
106
|
});
|
|
98
107
|
} else {
|
package/bin/whet/stones/Zip.js
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
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
|
-
import {HxOverrides} from "../../HxOverrides.js"
|
|
17
18
|
|
|
18
19
|
const $global = Register.$global
|
|
19
20
|
|
|
@@ -56,7 +57,7 @@ class ZipStone extends Register.inherits(Stone) {
|
|
|
56
57
|
return Promise.all(result).then(function (hashes) {
|
|
57
58
|
return SourceHash.merge(...hashes);
|
|
58
59
|
}).then(function (hash) {
|
|
59
|
-
return SourceHash.
|
|
60
|
+
return SourceHash.fromString(_gthis.config.filename + _gthis.config.level).add(hash);
|
|
60
61
|
});
|
|
61
62
|
}
|
|
62
63
|
generate(hash) {
|
|
@@ -73,9 +74,14 @@ class ZipStone extends Register.inherits(Stone) {
|
|
|
73
74
|
return function (data) {
|
|
74
75
|
var bytes = Helper.bytesOfBuffer(data.data);
|
|
75
76
|
var this1 = file[0].serveId;
|
|
76
|
-
var
|
|
77
|
-
|
|
78
|
-
|
|
77
|
+
var s = "/";
|
|
78
|
+
s = Path.posix.normalize("/");
|
|
79
|
+
s = StringTools.replace(s, "\\", "/");
|
|
80
|
+
var root = (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
|
|
81
|
+
if (this1.charAt(0) != "/") {
|
|
82
|
+
throw new Error("Badly formed SourceId.");
|
|
83
|
+
};
|
|
84
|
+
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
85
|
Tools.compress(entry, level);
|
|
80
86
|
return entry;
|
|
81
87
|
};
|
|
@@ -84,19 +90,18 @@ class ZipStone extends Register.inherits(Stone) {
|
|
|
84
90
|
return Promise.all(_g).then(function (entries) {
|
|
85
91
|
var out = new BytesOutput();
|
|
86
92
|
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;
|
|
93
|
+
var _gthis1 = _gthis.config.filename;
|
|
90
94
|
var b = out.getBytes();
|
|
91
95
|
var data = b.b;
|
|
92
|
-
return [SourceData.fromBytes(
|
|
96
|
+
return [SourceData.fromBytes(_gthis1, Buffer.from(data.buffer, data.byteOffset, b.length))];
|
|
93
97
|
});
|
|
94
98
|
});
|
|
95
99
|
}
|
|
96
100
|
list() {
|
|
97
101
|
var s = this.config.filename;
|
|
98
|
-
|
|
99
|
-
|
|
102
|
+
s = Path.posix.normalize(s);
|
|
103
|
+
s = StringTools.replace(s, "\\", "/");
|
|
104
|
+
return Promise.resolve([(SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s]);
|
|
100
105
|
}
|
|
101
106
|
static get __name__() {
|
|
102
107
|
return "whet.stones.ZipStone"
|
|
@@ -5,15 +5,18 @@ import {Stone} from "../../Stone"
|
|
|
5
5
|
import {SourceHash} from "../../SourceHash"
|
|
6
6
|
import {SourceData} from "../../Source"
|
|
7
7
|
import {Project} from "../../Project"
|
|
8
|
+
import {Command} from "commander"
|
|
8
9
|
|
|
9
10
|
export declare class HaxeBuild extends Stone<BuildConfig> {
|
|
10
11
|
constructor(config: BuildConfig)
|
|
12
|
+
protected initConfig(): void
|
|
11
13
|
|
|
12
14
|
/**
|
|
13
15
|
Build the given hxml.
|
|
14
16
|
*/
|
|
15
17
|
build(): Promise<any>
|
|
16
18
|
protected generate(hash: SourceHash): Promise<SourceData[]>
|
|
19
|
+
protected getCommands(): Command[]
|
|
17
20
|
list(): Promise<string[]>
|
|
18
21
|
protected generateHash(): Promise<SourceHash>
|
|
19
22
|
}
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
+
import {MaybeArray_Fields_} from "../../magic/MaybeArray.js"
|
|
1
2
|
import {Utils} from "../../Utils.js"
|
|
2
3
|
import {Stone} from "../../Stone.js"
|
|
3
|
-
import {RootDir} from "../../SourceId.js"
|
|
4
|
+
import {SourceId_Fields_, RootDir} from "../../SourceId.js"
|
|
5
|
+
import {SourceHash} from "../../SourceHash.js"
|
|
4
6
|
import {SourceData} from "../../Source.js"
|
|
5
7
|
import {Log} from "../../Log.js"
|
|
6
|
-
import * as
|
|
7
|
-
import {Path, Path as Path__2} from "../../../haxe/io/Path.js"
|
|
8
|
+
import * as Path from "path"
|
|
8
9
|
import {Register} from "../../../genes/Register.js"
|
|
10
|
+
import {Command} from "commander"
|
|
9
11
|
import * as ChildProcess from "child_process"
|
|
10
|
-
import {
|
|
12
|
+
import {StringTools} from "../../../StringTools.js"
|
|
11
13
|
|
|
12
14
|
const $global = Register.$global
|
|
13
15
|
|
|
@@ -16,18 +18,29 @@ class HaxeBuild extends Register.inherits(Stone) {
|
|
|
16
18
|
new(config) {
|
|
17
19
|
super.new(config);
|
|
18
20
|
}
|
|
21
|
+
initConfig() {
|
|
22
|
+
if (this.config.cacheStrategy == null) {
|
|
23
|
+
this.config.cacheStrategy = this.project.cache.defaultFileStrategy;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
19
26
|
|
|
20
27
|
/**
|
|
21
28
|
Build the given hxml.
|
|
22
29
|
*/
|
|
23
30
|
build() {
|
|
24
31
|
var _gthis = this;
|
|
32
|
+
Log.log(30, ...["Building Haxe project."]);
|
|
25
33
|
return new Promise(function (res, rej) {
|
|
26
34
|
var cwd = process.cwd();
|
|
27
35
|
var this1 = _gthis.project.rootDir;
|
|
28
|
-
var
|
|
29
|
-
|
|
30
|
-
|
|
36
|
+
var s = "/";
|
|
37
|
+
s = Path.posix.normalize("/");
|
|
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));
|
|
31
44
|
var _g = [];
|
|
32
45
|
var e = Register.iter(_gthis.config.hxml.getBuildArgs());
|
|
33
46
|
while (e.hasNext()) {
|
|
@@ -35,7 +48,14 @@ class HaxeBuild extends Register.inherits(Stone) {
|
|
|
35
48
|
while (x.hasNext()) _g.push(x.next());
|
|
36
49
|
};
|
|
37
50
|
_g.unshift((_gthis.config.useNpx) ? "npx haxe" : "haxe");
|
|
38
|
-
|
|
51
|
+
var result = new Array(_g.length);
|
|
52
|
+
var _g1 = 0;
|
|
53
|
+
var _g2 = _g.length;
|
|
54
|
+
while (_g1 < _g2) {
|
|
55
|
+
var i = _g1++;
|
|
56
|
+
result[i] = StringTools.replace(_g[i], "\"", "\\\"");
|
|
57
|
+
};
|
|
58
|
+
ChildProcess.exec(result.join(" "), {"cwd": cwd1, "windowsHide": true}, function (err, stdout, stderr) {
|
|
39
59
|
if (err != null) {
|
|
40
60
|
rej(err);
|
|
41
61
|
} else {
|
|
@@ -49,23 +69,27 @@ class HaxeBuild extends Register.inherits(Stone) {
|
|
|
49
69
|
if (this.config.hxml.isSingleFile()) {
|
|
50
70
|
var pathId = this.config.hxml.getBuildExportPath();
|
|
51
71
|
var root = RootDir.fromProject(this.project);
|
|
52
|
-
|
|
72
|
+
if (pathId.charAt(0) != "/") {
|
|
73
|
+
throw new Error("Badly formed SourceId.");
|
|
74
|
+
};
|
|
75
|
+
var path = Path.posix.join(".", root, ".", pathId);
|
|
53
76
|
return Utils.deleteAll(path).then(function (_) {
|
|
54
77
|
return _gthis.build();
|
|
55
78
|
}).then(function (_) {
|
|
56
|
-
|
|
57
|
-
var norm = "/" + Path.normalize((s.charAt(0) == "/") ? HxOverrides.substr(s, 1, null) : s);
|
|
58
|
-
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) {
|
|
59
80
|
return [file];
|
|
60
81
|
});
|
|
61
|
-
})["catch"](function (err) {
|
|
62
|
-
Log.log(50, ...[err]);
|
|
63
|
-
return null;
|
|
64
82
|
});
|
|
65
83
|
} else {
|
|
66
84
|
throw new Error("Cannot get source of a multi-file build. Not implemented yet.");
|
|
67
85
|
};
|
|
68
86
|
}
|
|
87
|
+
getCommands() {
|
|
88
|
+
var _gthis = this;
|
|
89
|
+
return [new Command("build").action(function (..._) {
|
|
90
|
+
return _gthis.build();
|
|
91
|
+
})];
|
|
92
|
+
}
|
|
69
93
|
list() {
|
|
70
94
|
if (this.config.hxml.isSingleFile()) {
|
|
71
95
|
return Promise.resolve([this.config.hxml.getBuildFilename()]);
|
|
@@ -74,7 +98,25 @@ class HaxeBuild extends Register.inherits(Stone) {
|
|
|
74
98
|
};
|
|
75
99
|
}
|
|
76
100
|
generateHash() {
|
|
77
|
-
|
|
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);
|
|
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.");
|
|
114
|
+
};
|
|
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);
|
|
119
|
+
});
|
|
78
120
|
}
|
|
79
121
|
static get __name__() {
|
|
80
122
|
return "whet.stones.haxe.HaxeBuild"
|