whet 0.0.5 → 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/NativeStackTrace.js +147 -0
- package/bin/whet/Log.js +3 -0
- package/bin/whet/Project.d.ts +1 -0
- package/bin/whet/Project.js +12 -8
- package/bin/whet/Source.d.ts +2 -2
- package/bin/whet/Source.js +20 -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 +12 -2
- package/bin/whet/Stone.js +25 -13
- 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 -13
- package/bin/whet/cache/FileCache.js +83 -43
- 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 +26 -19
- package/bin/whet/stones/Zip.js +17 -12
- package/bin/whet/stones/haxe/HaxeBuild.d.ts +1 -0
- package/bin/whet/stones/haxe/HaxeBuild.js +37 -66
- package/bin/whet/stones/haxe/Hxml.js +39 -24
- package/bin/whet.d.ts +2 -0
- package/bin/whet.js +2 -0
- package/package.json +1 -1
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import {BaseCache} from "./BaseCache.js"
|
|
2
2
|
import {Utils} from "../Utils.js"
|
|
3
|
+
import {SourceId_Fields_} from "../SourceId.js"
|
|
3
4
|
import {SourceHash} from "../SourceHash.js"
|
|
4
5
|
import {SourceData, Source} from "../Source.js"
|
|
5
6
|
import {Log} from "../Log.js"
|
|
6
|
-
import
|
|
7
|
+
import * as Path from "path"
|
|
7
8
|
import {StringMap} from "../../haxe/ds/StringMap.js"
|
|
8
9
|
import {Register} from "../../genes/Register.js"
|
|
9
10
|
import * as Fs from "fs"
|
|
11
|
+
import {StringTools} from "../../StringTools.js"
|
|
10
12
|
import {Reflect as Reflect__1} from "../../Reflect.js"
|
|
11
13
|
import {Lambda} from "../../Lambda.js"
|
|
12
14
|
import {HxOverrides} from "../../HxOverrides.js"
|
|
@@ -18,9 +20,14 @@ class FileCache extends Register.inherits(BaseCache) {
|
|
|
18
20
|
new(rootDir) {
|
|
19
21
|
this.flushQueued = false;
|
|
20
22
|
super.new(rootDir, new StringMap());
|
|
21
|
-
var
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
var s = ".whet/cache.json";
|
|
24
|
+
s = Path.posix.normalize(".whet/cache.json");
|
|
25
|
+
s = StringTools.replace(s, "\\", "/");
|
|
26
|
+
var this1 = (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
|
|
27
|
+
if (this1.charAt(0) != "/") {
|
|
28
|
+
throw new Error("Badly formed SourceId.");
|
|
29
|
+
};
|
|
30
|
+
this.dbFile = Path.posix.join(".", rootDir, ".", this1);
|
|
24
31
|
try {
|
|
25
32
|
var db = JSON.parse(Fs.readFileSync(this.dbFile, {"encoding": "utf-8"}));
|
|
26
33
|
var _g_keys = Reflect__1.fields(db);
|
|
@@ -37,8 +44,9 @@ class FileCache extends Register.inherits(BaseCache) {
|
|
|
37
44
|
var tmp = SourceHash.fromHex(val.hash);
|
|
38
45
|
var val1 = val.ctime;
|
|
39
46
|
var s = val.baseDir;
|
|
40
|
-
|
|
41
|
-
|
|
47
|
+
s = Path.posix.normalize(s);
|
|
48
|
+
s = StringTools.replace(s, "\\", "/");
|
|
49
|
+
var tmp1 = (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
|
|
42
50
|
var _g2 = [];
|
|
43
51
|
var _g3 = 0;
|
|
44
52
|
var _g4 = val.files;
|
|
@@ -47,11 +55,13 @@ class FileCache extends Register.inherits(BaseCache) {
|
|
|
47
55
|
++_g3;
|
|
48
56
|
var tmp2 = SourceHash.fromHex(file.fileHash);
|
|
49
57
|
var s1 = file.filePath;
|
|
50
|
-
|
|
51
|
-
|
|
58
|
+
s1 = Path.posix.normalize(s1);
|
|
59
|
+
s1 = StringTools.replace(s1, "\\", "/");
|
|
60
|
+
var tmp3 = (SourceId_Fields_.startsWithSlash(s1)) ? s1 : "/" + s1;
|
|
52
61
|
var s2 = file.id;
|
|
53
|
-
|
|
54
|
-
|
|
62
|
+
s2 = Path.posix.normalize(s2);
|
|
63
|
+
s2 = StringTools.replace(s2, "\\", "/");
|
|
64
|
+
_g2.push({"fileHash": tmp2, "filePath": tmp3, "id": (SourceId_Fields_.startsWithSlash(s2)) ? s2 : "/" + s2});
|
|
55
65
|
};
|
|
56
66
|
_g.push({"hash": tmp, "ctime": val1, "baseDir": tmp1, "files": _g2});
|
|
57
67
|
};
|
|
@@ -67,10 +77,12 @@ class FileCache extends Register.inherits(BaseCache) {
|
|
|
67
77
|
var idOverride;
|
|
68
78
|
var _g = source.origin.cacheStrategy;
|
|
69
79
|
if (_g._hx_index == 3) {
|
|
80
|
+
var _g1 = _g.path;
|
|
70
81
|
if (source.data.length == 1) {
|
|
71
|
-
var s =
|
|
72
|
-
|
|
73
|
-
|
|
82
|
+
var s = _g1.substring(_g1.lastIndexOf("/"));
|
|
83
|
+
s = Path.posix.normalize(s);
|
|
84
|
+
s = StringTools.replace(s, "\\", "/");
|
|
85
|
+
idOverride = (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
|
|
74
86
|
} else {
|
|
75
87
|
idOverride = null;
|
|
76
88
|
};
|
|
@@ -99,23 +111,14 @@ class FileCache extends Register.inherits(BaseCache) {
|
|
|
99
111
|
if (_g._hx_index == 3) {
|
|
100
112
|
var _g1 = _g.path;
|
|
101
113
|
var invalidPath;
|
|
102
|
-
|
|
103
|
-
if (value.files.length == 1) {
|
|
104
|
-
var norm = "/" + Path.normalize((_g1.charAt(0) == "/") ? HxOverrides.substr(_g1, 1, null) : _g1);
|
|
105
|
-
var invalidPath2 = (_g1.lastIndexOf("/") == _g1.length - 1) ? Path.addTrailingSlash(norm) : norm;
|
|
106
|
-
var s = Path.addTrailingSlash(Path.directory(_g1));
|
|
107
|
-
var norm = "/" + Path.normalize((s.charAt(0) == "/") ? HxOverrides.substr(s, 1, null) : s);
|
|
108
|
-
invalidPath1 = invalidPath2 != ((s.lastIndexOf("/") == s.length - 1) ? Path.addTrailingSlash(norm) : norm);
|
|
109
|
-
} else {
|
|
110
|
-
invalidPath1 = false;
|
|
111
|
-
};
|
|
112
|
-
if (invalidPath1) {
|
|
114
|
+
if (value.files.length == 1 && !SourceId_Fields_.endsWithSlash(_g1)) {
|
|
113
115
|
invalidPath = value.files[0].filePath != _g1;
|
|
114
116
|
} else {
|
|
115
117
|
var value1 = value.baseDir;
|
|
116
|
-
var s =
|
|
117
|
-
|
|
118
|
-
|
|
118
|
+
var s = _g1.substring(0, _g1.lastIndexOf("/") + 1);
|
|
119
|
+
s = Path.posix.normalize(s);
|
|
120
|
+
s = StringTools.replace(s, "\\", "/");
|
|
121
|
+
invalidPath = value1 != ((SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s);
|
|
119
122
|
};
|
|
120
123
|
if (invalidPath) {
|
|
121
124
|
return Promise.resolve(null);
|
|
@@ -128,7 +131,11 @@ class FileCache extends Register.inherits(BaseCache) {
|
|
|
128
131
|
return function (res, rej) {
|
|
129
132
|
var this1 = file[0].filePath;
|
|
130
133
|
var root = _gthis.rootDir;
|
|
131
|
-
|
|
134
|
+
if (this1.charAt(0) != "/") {
|
|
135
|
+
throw new Error("Badly formed SourceId.");
|
|
136
|
+
};
|
|
137
|
+
var path = Path.posix.join(".", root, ".", this1);
|
|
138
|
+
SourceData.fromFile(file[0].id, path, file[0].filePath).then((function (file) {
|
|
132
139
|
return function (sourceData) {
|
|
133
140
|
if (sourceData == null || !stone.ignoreFileHash && !SourceHash.equals(sourceData.hash, file[0].fileHash)) {
|
|
134
141
|
rej("Wrong hash.");
|
|
@@ -190,10 +197,16 @@ class FileCache extends Register.inherits(BaseCache) {
|
|
|
190
197
|
return function (res, rej) {
|
|
191
198
|
var this1 = file[0].filePath;
|
|
192
199
|
var root = _gthis.rootDir;
|
|
193
|
-
|
|
200
|
+
if (this1.charAt(0) != "/") {
|
|
201
|
+
throw new Error("Badly formed SourceId.");
|
|
202
|
+
};
|
|
203
|
+
Log.log(20, ...["Deleting file.", {"path": Path.posix.join(".", root, ".", this1)}]);
|
|
194
204
|
var this1 = file[0].filePath;
|
|
195
205
|
var root = _gthis.rootDir;
|
|
196
|
-
|
|
206
|
+
if (this1.charAt(0) != "/") {
|
|
207
|
+
throw new Error("Badly formed SourceId.");
|
|
208
|
+
};
|
|
209
|
+
Fs.unlink(Path.posix.join(".", root, ".", this1), (function (file) {
|
|
197
210
|
return function (err) {
|
|
198
211
|
if (err != null) {
|
|
199
212
|
Log.log(50, ...["Error deleting file.", {"file": file[0], "error": err}]);
|
|
@@ -209,20 +222,32 @@ class FileCache extends Register.inherits(BaseCache) {
|
|
|
209
222
|
return new Promise(function (res, rej) {
|
|
210
223
|
var this1 = value.baseDir;
|
|
211
224
|
var root = _gthis.rootDir;
|
|
212
|
-
|
|
225
|
+
if (this1.charAt(0) != "/") {
|
|
226
|
+
throw new Error("Badly formed SourceId.");
|
|
227
|
+
};
|
|
228
|
+
Fs.readdir(Path.posix.join(".", root, ".", this1), function (err, files) {
|
|
213
229
|
if (err != null) {
|
|
214
230
|
var this1 = value.baseDir;
|
|
215
231
|
var root = _gthis.rootDir;
|
|
216
|
-
|
|
232
|
+
if (this1.charAt(0) != "/") {
|
|
233
|
+
throw new Error("Badly formed SourceId.");
|
|
234
|
+
};
|
|
235
|
+
Log.log(50, ...["Error reading directory", {"dir": Path.posix.join(".", root, ".", this1), "error": err}]);
|
|
217
236
|
res(null);
|
|
218
237
|
} else if (files.length == 0) {
|
|
219
238
|
var this1 = value.baseDir;
|
|
220
239
|
var root = _gthis.rootDir;
|
|
221
|
-
|
|
240
|
+
if (this1.charAt(0) != "/") {
|
|
241
|
+
throw new Error("Badly formed SourceId.");
|
|
242
|
+
};
|
|
243
|
+
Fs.rmdir(Path.posix.join(".", root, ".", this1), function (err) {
|
|
222
244
|
if (err != null) {
|
|
223
245
|
var this1 = value.baseDir;
|
|
224
246
|
var root = _gthis.rootDir;
|
|
225
|
-
|
|
247
|
+
if (this1.charAt(0) != "/") {
|
|
248
|
+
throw new Error("Badly formed SourceId.");
|
|
249
|
+
};
|
|
250
|
+
Log.log(50, ...["Error removing directory.", {"dir": Path.posix.join(".", root, ".", this1), "error": err}]);
|
|
226
251
|
};
|
|
227
252
|
res(null);
|
|
228
253
|
});
|
|
@@ -266,9 +291,14 @@ class FileCache extends Register.inherits(BaseCache) {
|
|
|
266
291
|
var val1 = val.ctime;
|
|
267
292
|
var tmp1 = HxOverrides.dateStr(new Date(val.ctime * 1000));
|
|
268
293
|
var this2 = val.baseDir;
|
|
269
|
-
var
|
|
270
|
-
|
|
271
|
-
|
|
294
|
+
var s = "/";
|
|
295
|
+
s = Path.posix.normalize("/");
|
|
296
|
+
s = StringTools.replace(s, "\\", "/");
|
|
297
|
+
var root = (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
|
|
298
|
+
if (this2.charAt(0) != "/") {
|
|
299
|
+
throw new Error("Badly formed SourceId.");
|
|
300
|
+
};
|
|
301
|
+
var tmp2 = Path.posix.join(".", root, ".", this2);
|
|
272
302
|
var _g2 = [];
|
|
273
303
|
var _g3 = 0;
|
|
274
304
|
var _g4 = val.files;
|
|
@@ -277,13 +307,23 @@ class FileCache extends Register.inherits(BaseCache) {
|
|
|
277
307
|
++_g3;
|
|
278
308
|
var tmp3 = SourceHash.toHex(file.fileHash);
|
|
279
309
|
var this3 = file.filePath;
|
|
280
|
-
var
|
|
281
|
-
|
|
282
|
-
|
|
310
|
+
var s1 = "/";
|
|
311
|
+
s1 = Path.posix.normalize("/");
|
|
312
|
+
s1 = StringTools.replace(s1, "\\", "/");
|
|
313
|
+
var root1 = (SourceId_Fields_.startsWithSlash(s1)) ? s1 : "/" + s1;
|
|
314
|
+
if (this3.charAt(0) != "/") {
|
|
315
|
+
throw new Error("Badly formed SourceId.");
|
|
316
|
+
};
|
|
317
|
+
var tmp4 = Path.posix.join(".", root1, ".", this3);
|
|
283
318
|
var this4 = file.id;
|
|
284
|
-
var
|
|
285
|
-
|
|
286
|
-
|
|
319
|
+
var s2 = "/";
|
|
320
|
+
s2 = Path.posix.normalize("/");
|
|
321
|
+
s2 = StringTools.replace(s2, "\\", "/");
|
|
322
|
+
var root2 = (SourceId_Fields_.startsWithSlash(s2)) ? s2 : "/" + s2;
|
|
323
|
+
if (this4.charAt(0) != "/") {
|
|
324
|
+
throw new Error("Badly formed SourceId.");
|
|
325
|
+
};
|
|
326
|
+
_g2.push({"fileHash": tmp3, "filePath": tmp4, "id": Path.posix.join(".", root2, ".", this4)});
|
|
287
327
|
};
|
|
288
328
|
_g.push({"hash": tmp, "ctime": val1, "ctimePretty": tmp1, "baseDir": tmp2, "files": _g2});
|
|
289
329
|
};
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import {Router} from "../route/Router.js"
|
|
2
|
+
import {Route} from "../route/Route.js"
|
|
2
3
|
import {RouteType_Fields_} from "./RouteType.js"
|
|
3
|
-
import {
|
|
4
|
+
import {SourceId_Fields_} from "../SourceId.js"
|
|
5
|
+
import * as Path from "path"
|
|
4
6
|
import {Register} from "../../genes/Register.js"
|
|
5
|
-
import {
|
|
7
|
+
import {StringTools} from "../../StringTools.js"
|
|
6
8
|
|
|
7
9
|
const $global = Register.$global
|
|
8
10
|
|
|
@@ -28,11 +30,14 @@ class RoutePathType_Fields_ {
|
|
|
28
30
|
throw new Error("RoutePath element should have at least 2 entries `[serveId, route]`.");
|
|
29
31
|
};
|
|
30
32
|
if (item.length > 3) {
|
|
31
|
-
throw new Error("RoutePath element should have at most 3 entries `[serveId, route,
|
|
33
|
+
throw new Error("RoutePath element should have at most 3 entries `[serveId, route, filter]`.");
|
|
32
34
|
};
|
|
33
35
|
var s = item[0];
|
|
34
|
-
|
|
35
|
-
|
|
36
|
+
s = Path.posix.normalize(s);
|
|
37
|
+
s = StringTools.replace(s, "\\", "/");
|
|
38
|
+
var tmp = (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
|
|
39
|
+
var _g3 = item.slice(1);
|
|
40
|
+
_g.push({"routeUnder": tmp, "route": (_g3.length == 1) ? (((item[1]) instanceof Route)) ? item[1] : RouteType_Fields_.makeRoute([_g3]) : RouteType_Fields_.makeRoute([_g3])});
|
|
36
41
|
};
|
|
37
42
|
return _g;
|
|
38
43
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {Route} from "../route/Route"
|
|
1
|
+
import {Route, RouteData} from "../route/Route"
|
|
2
2
|
import {MaybeArray} from "./MaybeArray"
|
|
3
3
|
import {AnyStone} from "../Stone"
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Anything that can be transformed into `Route`.
|
|
7
7
|
*/
|
|
8
|
-
export type RouteType = MaybeArray<MaybeArray<BaseRouteType>>
|
|
8
|
+
export type RouteType = Route | MaybeArray<MaybeArray<BaseRouteType>>
|
|
9
9
|
|
|
10
10
|
export type BaseRouteType = string | AnyStone
|
|
11
11
|
|
|
@@ -2,16 +2,24 @@ import {Files} from "../stones/Files.js"
|
|
|
2
2
|
import {Route} from "../route/Route.js"
|
|
3
3
|
import {MaybeArray_Fields_} from "./MaybeArray.js"
|
|
4
4
|
import {Stone} from "../Stone.js"
|
|
5
|
-
import {SourceId} from "../SourceId.js"
|
|
6
|
-
import
|
|
5
|
+
import {SourceId_Fields_, SourceId} from "../SourceId.js"
|
|
6
|
+
import * as Path from "path"
|
|
7
7
|
import {Register} from "../../genes/Register.js"
|
|
8
|
-
import {
|
|
8
|
+
import {StringTools} from "../../StringTools.js"
|
|
9
|
+
import {Std} from "../../Std.js"
|
|
9
10
|
|
|
10
11
|
const $global = Register.$global
|
|
11
12
|
|
|
12
13
|
export const RouteType_Fields_ = Register.global("$hxClasses")["whet.magic._RouteType.RouteType_Fields_"] =
|
|
13
14
|
class RouteType_Fields_ {
|
|
14
15
|
static makeRoute(routeType) {
|
|
16
|
+
if (((routeType) instanceof Route)) {
|
|
17
|
+
return routeType;
|
|
18
|
+
} else {
|
|
19
|
+
return new Route(routeType);
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
static makeRouteRoutes(routeType) {
|
|
15
23
|
var _g = [];
|
|
16
24
|
var _g1 = 0;
|
|
17
25
|
var _g2 = MaybeArray_Fields_.makeArray(routeType);
|
|
@@ -25,11 +33,12 @@ class RouteType_Fields_ {
|
|
|
25
33
|
};
|
|
26
34
|
var tinner1 = tinner[0];
|
|
27
35
|
var s = tinner[1];
|
|
28
|
-
|
|
29
|
-
|
|
36
|
+
s = Path.posix.normalize(s);
|
|
37
|
+
s = StringTools.replace(s, "\\", "/");
|
|
38
|
+
_g.push(RouteType_Fields_.getRoute(tinner1, (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s));
|
|
30
39
|
};
|
|
31
40
|
};
|
|
32
|
-
return
|
|
41
|
+
return _g;
|
|
33
42
|
}
|
|
34
43
|
static getRoute(t, path) {
|
|
35
44
|
if (typeof(t) == "string") {
|
|
@@ -38,11 +47,14 @@ class RouteType_Fields_ {
|
|
|
38
47
|
if (path != null) {
|
|
39
48
|
tmp1 = path;
|
|
40
49
|
} else {
|
|
41
|
-
var
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
var
|
|
45
|
-
|
|
50
|
+
var s = t;
|
|
51
|
+
s = Path.posix.normalize(s);
|
|
52
|
+
s = StringTools.replace(s, "\\", "/");
|
|
53
|
+
var p = (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
|
|
54
|
+
var s = p.substring(0, p.lastIndexOf("/") + 1);
|
|
55
|
+
s = Path.posix.normalize(s);
|
|
56
|
+
s = StringTools.replace(s, "\\", "/");
|
|
57
|
+
tmp1 = SourceId.relativeTo(p, (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s);
|
|
46
58
|
};
|
|
47
59
|
return {"stone": tmp, "path": tmp1};
|
|
48
60
|
} else if (((t) instanceof Stone)) {
|
|
@@ -50,12 +62,14 @@ class RouteType_Fields_ {
|
|
|
50
62
|
if (path != null) {
|
|
51
63
|
tmp = path;
|
|
52
64
|
} else {
|
|
53
|
-
var
|
|
54
|
-
|
|
65
|
+
var s = "/";
|
|
66
|
+
s = Path.posix.normalize("/");
|
|
67
|
+
s = StringTools.replace(s, "\\", "/");
|
|
68
|
+
tmp = (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
|
|
55
69
|
};
|
|
56
70
|
return {"stone": t, "path": tmp};
|
|
57
71
|
} else {
|
|
58
|
-
throw new Error("Unsupported type for Route.");
|
|
72
|
+
throw new Error("Unsupported type for Route. Expected String or Stone, but got " + Std.string(t.constructor?.name) + ".");
|
|
59
73
|
};
|
|
60
74
|
}
|
|
61
75
|
static get __name__() {
|
|
@@ -12,7 +12,7 @@ class StoneId_Fields_ {
|
|
|
12
12
|
} else if (Boot.__instanceof(id, "$hxCoreType__Class")) {
|
|
13
13
|
return StoneId_Fields_.makeStoneIdFromClass(id);
|
|
14
14
|
} else if (((id) instanceof Stone)) {
|
|
15
|
-
return
|
|
15
|
+
return id.constructor.name;
|
|
16
16
|
} else {
|
|
17
17
|
throw new Error("Unsupported type for StoneId.");
|
|
18
18
|
};
|
|
@@ -20,6 +20,15 @@ class StoneId_Fields_ {
|
|
|
20
20
|
static makeStoneIdFromClass(c) {
|
|
21
21
|
return c.__name__.split(".").pop();
|
|
22
22
|
}
|
|
23
|
+
static getTypeName(stone) {
|
|
24
|
+
var c = Boot.getClass(stone);
|
|
25
|
+
var name = c.__name__;
|
|
26
|
+
if (name != "whet.Stone") {
|
|
27
|
+
return name;
|
|
28
|
+
} else {
|
|
29
|
+
return stone.constructor.name;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
23
32
|
static get __name__() {
|
|
24
33
|
return "whet.magic._StoneId.StoneId_Fields_"
|
|
25
34
|
}
|
|
@@ -30,3 +39,4 @@ class StoneId_Fields_ {
|
|
|
30
39
|
|
|
31
40
|
|
|
32
41
|
export const makeStoneId = StoneId_Fields_.makeStoneId
|
|
42
|
+
export const getTypeName = StoneId_Fields_.getTypeName
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import {RouteResult} from "./RouteResult"
|
|
2
|
+
import {RouteType} from "../magic/RouteType"
|
|
2
3
|
import {AnyStone} from "../Stone"
|
|
4
|
+
import {SourceHash} from "../SourceHash"
|
|
3
5
|
import {SourceData} from "../Source"
|
|
4
6
|
|
|
5
7
|
export declare class Route {
|
|
6
|
-
constructor(
|
|
8
|
+
constructor(route: RouteType)
|
|
7
9
|
protected routes: RouteData[]
|
|
10
|
+
add(r: RouteType): Route
|
|
11
|
+
getHash(): Promise<SourceHash>
|
|
8
12
|
list(): Promise<RouteResult[]>
|
|
9
13
|
getData(): Promise<SourceData[]>
|
|
10
14
|
}
|
package/bin/whet/route/Route.js
CHANGED
|
@@ -1,14 +1,36 @@
|
|
|
1
1
|
import {RouteResult} from "./RouteResult.js"
|
|
2
|
-
import {
|
|
2
|
+
import {RouteType_Fields_} from "../magic/RouteType.js"
|
|
3
|
+
import {SourceId_Fields_, SourceId} from "../SourceId.js"
|
|
4
|
+
import {SourceHash} from "../SourceHash.js"
|
|
5
|
+
import * as Path from "path"
|
|
3
6
|
import {Register} from "../../genes/Register.js"
|
|
4
|
-
import {
|
|
7
|
+
import {StringTools} from "../../StringTools.js"
|
|
5
8
|
|
|
6
9
|
const $global = Register.$global
|
|
7
10
|
|
|
8
11
|
export const Route = Register.global("$hxClasses")["whet.route.Route"] =
|
|
9
12
|
class Route extends Register.inherits() {
|
|
10
|
-
new(
|
|
11
|
-
this.routes = routes;
|
|
13
|
+
new(route) {
|
|
14
|
+
this.routes = (((route) instanceof Route)) ? route.routes.slice() : RouteType_Fields_.makeRouteRoutes(route);
|
|
15
|
+
}
|
|
16
|
+
add(r) {
|
|
17
|
+
var _g = 0;
|
|
18
|
+
var _g1 = RouteType_Fields_.makeRoute(r).routes;
|
|
19
|
+
while (_g < _g1.length) this.routes.push(_g1[_g++]);
|
|
20
|
+
return this;
|
|
21
|
+
}
|
|
22
|
+
getHash() {
|
|
23
|
+
var _this = this.routes;
|
|
24
|
+
var result = new Array(_this.length);
|
|
25
|
+
var _g = 0;
|
|
26
|
+
var _g1 = _this.length;
|
|
27
|
+
while (_g < _g1) {
|
|
28
|
+
var i = _g++;
|
|
29
|
+
result[i] = _this[i].stone.getHash();
|
|
30
|
+
};
|
|
31
|
+
return Promise.all(result).then(function (hashes) {
|
|
32
|
+
return SourceHash.merge(...hashes);
|
|
33
|
+
});
|
|
12
34
|
}
|
|
13
35
|
list() {
|
|
14
36
|
var _g = [];
|
|
@@ -20,17 +42,13 @@ class Route extends Register.inherits() {
|
|
|
20
42
|
_g.push(r[0].stone.list().then((function (r) {
|
|
21
43
|
return function (list) {
|
|
22
44
|
var arr = [];
|
|
23
|
-
|
|
24
|
-
var norm = "/" + Path.normalize((this1.charAt(0) == "/") ? HxOverrides.substr(this1, 1, null) : this1);
|
|
25
|
-
var tmp = (this1.lastIndexOf("/") == this1.length - 1) ? Path.addTrailingSlash(norm) : norm;
|
|
26
|
-
var s = Path.addTrailingSlash(Path.directory(this1));
|
|
27
|
-
var norm = "/" + Path.normalize((s.charAt(0) == "/") ? HxOverrides.substr(s, 1, null) : s);
|
|
28
|
-
if (tmp == ((s.lastIndexOf("/") == s.length - 1) ? Path.addTrailingSlash(norm) : norm)) {
|
|
45
|
+
if (SourceId_Fields_.endsWithSlash(r[0].path)) {
|
|
29
46
|
var _g = 0;
|
|
30
47
|
while (_g < list.length) {
|
|
31
48
|
var path = list[_g];
|
|
32
49
|
++_g;
|
|
33
|
-
|
|
50
|
+
var _g1 = r[0].stone;
|
|
51
|
+
arr.push(new RouteResult(SourceId.relativeTo(path, r[0].path), path, _g1));
|
|
34
52
|
};
|
|
35
53
|
} else {
|
|
36
54
|
var _g = 0;
|
|
@@ -39,9 +57,10 @@ class Route extends Register.inherits() {
|
|
|
39
57
|
++_g;
|
|
40
58
|
if (path == r[0].path) {
|
|
41
59
|
var _g1 = r[0].stone;
|
|
42
|
-
var s =
|
|
43
|
-
|
|
44
|
-
|
|
60
|
+
var s = path.substring(path.lastIndexOf("/"));
|
|
61
|
+
s = Path.posix.normalize(s);
|
|
62
|
+
s = StringTools.replace(s, "\\", "/");
|
|
63
|
+
arr.push(new RouteResult((SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s, path, _g1));
|
|
45
64
|
};
|
|
46
65
|
};
|
|
47
66
|
};
|
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);
|