whet 0.0.19 → 0.0.21
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/README.md +9 -6
- package/bin/HxOverrides.d.ts +0 -1
- package/bin/HxOverrides.js +0 -7
- package/bin/whet/Project.js +4 -25
- package/bin/whet/Source.d.ts +3 -2
- package/bin/whet/Source.js +14 -37
- package/bin/whet/SourceId.d.ts +17 -5
- package/bin/whet/SourceId.js +93 -68
- package/bin/whet/Stone.js +14 -26
- package/bin/whet/Whet.js +1 -1
- package/bin/whet/cache/BaseCache.js +6 -23
- package/bin/whet/cache/CacheManager.js +10 -33
- package/bin/whet/cache/FileCache.js +17 -143
- package/bin/whet/magic/MinimatchType.js +1 -11
- package/bin/whet/magic/RoutePathType.js +8 -45
- package/bin/whet/route/Router.d.ts +15 -5
- package/bin/whet/route/Router.js +166 -227
- package/bin/whet/stones/Files.d.ts +6 -0
- package/bin/whet/stones/Files.js +95 -52
- package/bin/whet/stones/JsonStone.d.ts +2 -2
- package/bin/whet/stones/JsonStone.js +6 -13
- package/bin/whet/stones/RemoteFile.js +1 -10
- package/bin/whet/stones/Server.js +9 -33
- package/bin/whet/stones/Zip.d.ts +2 -2
- package/bin/whet/stones/Zip.js +4 -26
- package/bin/whet/stones/haxe/HaxeBuild.js +6 -35
- package/bin/whet/stones/haxe/Hxml.js +21 -67
- package/bin/whet.d.ts +1 -0
- package/bin/whet.js +1 -0
- package/package.json +1 -1
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import {MemoryCache} from "./MemoryCache.js"
|
|
2
2
|
import {FileCache} from "./FileCache.js"
|
|
3
3
|
import {CacheStrategy, CacheDurability, DurabilityCheck} from "./Cache.js"
|
|
4
|
-
import {RootDir
|
|
4
|
+
import {RootDir} from "../SourceId.js"
|
|
5
5
|
import {Log} from "../Log.js"
|
|
6
6
|
import * as Path from "path"
|
|
7
7
|
import {Register} from "../../genes/Register.js"
|
|
8
|
-
import {StringTools} from "../../StringTools.js"
|
|
9
|
-
import {HxOverrides} from "../../HxOverrides.js"
|
|
10
8
|
|
|
11
9
|
const $global = Register.$global
|
|
12
10
|
|
|
@@ -81,14 +79,7 @@ class CacheManager extends Register.inherits() {
|
|
|
81
79
|
* The path is not reserved. Caching depends on stone's `cacheStrategy` and success of source generation.
|
|
82
80
|
*/
|
|
83
81
|
getDir(stone, hash) {
|
|
84
|
-
var
|
|
85
|
-
var str = (s.length > 1 && HxOverrides.cca(s, 0) == 47) ? s.substring(1) : s;
|
|
86
|
-
if (str.length > 0) {
|
|
87
|
-
str = Path.posix.normalize(str);
|
|
88
|
-
str = StringTools.replace(str, "\\", "/");
|
|
89
|
-
};
|
|
90
|
-
s = str;
|
|
91
|
-
var baseDir = (HxOverrides.cca(s, 0) == 47) ? s : "/" + s;
|
|
82
|
+
var baseDir = stone.id + "/";
|
|
92
83
|
var tmp;
|
|
93
84
|
switch (stone.cacheStrategy._hx_index) {
|
|
94
85
|
case 0:
|
|
@@ -102,23 +93,15 @@ class CacheManager extends Register.inherits() {
|
|
|
102
93
|
|
|
103
94
|
};
|
|
104
95
|
if (tmp) {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
if (str.length > 0) {
|
|
108
|
-
str = Path.posix.normalize(str);
|
|
109
|
-
str = StringTools.replace(str, "\\", "/");
|
|
96
|
+
if (!(".temp/".length == 0 || ".temp/".charCodeAt(".temp/".length - 1) == 47)) {
|
|
97
|
+
throw new Error("\"" + ".temp/" + "\" is not a directory.");
|
|
110
98
|
};
|
|
111
|
-
|
|
112
|
-
baseDir = SourceId.getPutInDir(baseDir, (HxOverrides.cca(s, 0) == 47) ? s : "/" + s);
|
|
99
|
+
baseDir = Path.posix.join(".temp/", baseDir);
|
|
113
100
|
};
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
if (str.length > 0) {
|
|
117
|
-
str = Path.posix.normalize(str);
|
|
118
|
-
str = StringTools.replace(str, "\\", "/");
|
|
101
|
+
if (!(".whet/".length == 0 || ".whet/".charCodeAt(".whet/".length - 1) == 47)) {
|
|
102
|
+
throw new Error("\"" + ".whet/" + "\" is not a directory.");
|
|
119
103
|
};
|
|
120
|
-
|
|
121
|
-
baseDir = SourceId.getPutInDir(baseDir, (HxOverrides.cca(s, 0) == 47) ? s : "/" + s);
|
|
104
|
+
baseDir = Path.posix.join(".whet/", baseDir);
|
|
122
105
|
var id;
|
|
123
106
|
var _g = stone.cacheStrategy;
|
|
124
107
|
switch (_g._hx_index) {
|
|
@@ -133,14 +116,8 @@ class CacheManager extends Register.inherits() {
|
|
|
133
116
|
break
|
|
134
117
|
case 3:
|
|
135
118
|
var _g1 = _g.path;
|
|
136
|
-
var
|
|
137
|
-
|
|
138
|
-
if (str.length > 0) {
|
|
139
|
-
str = Path.posix.normalize(str);
|
|
140
|
-
str = StringTools.replace(str, "\\", "/");
|
|
141
|
-
};
|
|
142
|
-
s = str;
|
|
143
|
-
id = (HxOverrides.cca(s, 0) == 47) ? s : "/" + s;
|
|
119
|
+
var dir = _g1.substring(0, _g1.lastIndexOf("/") + 1);
|
|
120
|
+
id = (dir.length == 0) ? "./" : dir;
|
|
144
121
|
break
|
|
145
122
|
|
|
146
123
|
};
|
|
@@ -7,7 +7,6 @@ import * as Path from "path"
|
|
|
7
7
|
import {StringMap} from "../../haxe/ds/StringMap.js"
|
|
8
8
|
import {Register} from "../../genes/Register.js"
|
|
9
9
|
import * as Fs from "fs"
|
|
10
|
-
import {StringTools} from "../../StringTools.js"
|
|
11
10
|
import {Reflect as Reflect__1} from "../../Reflect.js"
|
|
12
11
|
import {Lambda} from "../../Lambda.js"
|
|
13
12
|
import {HxOverrides} from "../../HxOverrides.js"
|
|
@@ -19,18 +18,7 @@ class FileCache extends Register.inherits(BaseCache) {
|
|
|
19
18
|
new(rootDir) {
|
|
20
19
|
this.flushQueued = false;
|
|
21
20
|
super.new(rootDir, new StringMap());
|
|
22
|
-
|
|
23
|
-
var str = (".whet/cache.json".length > 1 && HxOverrides.cca(".whet/cache.json", 0) == 47) ? ".whet/cache.json".substring(1) : ".whet/cache.json";
|
|
24
|
-
if (str.length > 0) {
|
|
25
|
-
str = Path.posix.normalize(str);
|
|
26
|
-
str = StringTools.replace(str, "\\", "/");
|
|
27
|
-
};
|
|
28
|
-
s = str;
|
|
29
|
-
var this1 = (HxOverrides.cca(s, 0) == 47) ? s : "/" + s;
|
|
30
|
-
if (this1.charAt(0) != "/") {
|
|
31
|
-
throw new Error("Badly formed SourceId.");
|
|
32
|
-
};
|
|
33
|
-
this.dbFile = Path.posix.join(".", rootDir, ".", this1);
|
|
21
|
+
this.dbFile = Path.posix.join(".", rootDir, ".", ".whet/cache.json");
|
|
34
22
|
try {
|
|
35
23
|
var db = JSON.parse(Fs.readFileSync(this.dbFile, {"encoding": "utf-8"}));
|
|
36
24
|
var _g_keys = Reflect__1.fields(db);
|
|
@@ -46,39 +34,16 @@ class FileCache extends Register.inherits(BaseCache) {
|
|
|
46
34
|
++_g1;
|
|
47
35
|
var tmp = SourceHash.fromHex(val.hash);
|
|
48
36
|
var val1 = val.ctime;
|
|
49
|
-
var
|
|
50
|
-
var str = (s.length > 1 && HxOverrides.cca(s, 0) == 47) ? s.substring(1) : s;
|
|
51
|
-
if (str.length > 0) {
|
|
52
|
-
str = Path.posix.normalize(str);
|
|
53
|
-
str = StringTools.replace(str, "\\", "/");
|
|
54
|
-
};
|
|
55
|
-
s = str;
|
|
56
|
-
var tmp1 = (HxOverrides.cca(s, 0) == 47) ? s : "/" + s;
|
|
37
|
+
var val2 = val.baseDir;
|
|
57
38
|
var _g2 = [];
|
|
58
39
|
var _g3 = 0;
|
|
59
40
|
var _g4 = val.files;
|
|
60
41
|
while (_g3 < _g4.length) {
|
|
61
42
|
var file = _g4[_g3];
|
|
62
43
|
++_g3;
|
|
63
|
-
|
|
64
|
-
var s1 = file.filePath;
|
|
65
|
-
var str1 = (s1.length > 1 && HxOverrides.cca(s1, 0) == 47) ? s1.substring(1) : s1;
|
|
66
|
-
if (str1.length > 0) {
|
|
67
|
-
str1 = Path.posix.normalize(str1);
|
|
68
|
-
str1 = StringTools.replace(str1, "\\", "/");
|
|
69
|
-
};
|
|
70
|
-
s1 = str1;
|
|
71
|
-
var tmp3 = (HxOverrides.cca(s1, 0) == 47) ? s1 : "/" + s1;
|
|
72
|
-
var s2 = file.id;
|
|
73
|
-
var str2 = (s2.length > 1 && HxOverrides.cca(s2, 0) == 47) ? s2.substring(1) : s2;
|
|
74
|
-
if (str2.length > 0) {
|
|
75
|
-
str2 = Path.posix.normalize(str2);
|
|
76
|
-
str2 = StringTools.replace(str2, "\\", "/");
|
|
77
|
-
};
|
|
78
|
-
s2 = str2;
|
|
79
|
-
_g2.push({"fileHash": tmp2, "filePath": tmp3, "id": (HxOverrides.cca(s2, 0) == 47) ? s2 : "/" + s2});
|
|
44
|
+
_g2.push({"fileHash": SourceHash.fromHex(file.fileHash), "filePath": file.filePath, "id": file.id});
|
|
80
45
|
};
|
|
81
|
-
_g.push({"hash": tmp, "ctime": val1, "baseDir":
|
|
46
|
+
_g.push({"hash": tmp, "ctime": val1, "baseDir": val2, "files": _g2});
|
|
82
47
|
};
|
|
83
48
|
this1.inst.set(key, _g);
|
|
84
49
|
};
|
|
@@ -93,18 +58,7 @@ class FileCache extends Register.inherits(BaseCache) {
|
|
|
93
58
|
var _g = source.origin.cacheStrategy;
|
|
94
59
|
if (_g._hx_index == 3) {
|
|
95
60
|
var _g1 = _g.path;
|
|
96
|
-
|
|
97
|
-
var s = _g1.substring(_g1.lastIndexOf("/"));
|
|
98
|
-
var str = (s.length > 1 && HxOverrides.cca(s, 0) == 47) ? s.substring(1) : s;
|
|
99
|
-
if (str.length > 0) {
|
|
100
|
-
str = Path.posix.normalize(str);
|
|
101
|
-
str = StringTools.replace(str, "\\", "/");
|
|
102
|
-
};
|
|
103
|
-
s = str;
|
|
104
|
-
idOverride = (HxOverrides.cca(s, 0) == 47) ? s : "/" + s;
|
|
105
|
-
} else {
|
|
106
|
-
idOverride = null;
|
|
107
|
-
};
|
|
61
|
+
idOverride = (source.data.length == 1) ? _g1.substring(_g1.lastIndexOf("/") + 1) : null;
|
|
108
62
|
} else {
|
|
109
63
|
idOverride = null;
|
|
110
64
|
};
|
|
@@ -130,18 +84,11 @@ class FileCache extends Register.inherits(BaseCache) {
|
|
|
130
84
|
if (_g._hx_index == 3) {
|
|
131
85
|
var _g1 = _g.path;
|
|
132
86
|
var invalidPath;
|
|
133
|
-
if (value.files.length == 1 &&
|
|
87
|
+
if (value.files.length == 1 && !(_g1.length == 0 || _g1.charCodeAt(_g1.length - 1) == 47)) {
|
|
134
88
|
invalidPath = value.files[0].filePath != _g1;
|
|
135
89
|
} else {
|
|
136
|
-
var
|
|
137
|
-
|
|
138
|
-
var str = (s.length > 1 && HxOverrides.cca(s, 0) == 47) ? s.substring(1) : s;
|
|
139
|
-
if (str.length > 0) {
|
|
140
|
-
str = Path.posix.normalize(str);
|
|
141
|
-
str = StringTools.replace(str, "\\", "/");
|
|
142
|
-
};
|
|
143
|
-
s = str;
|
|
144
|
-
invalidPath = value1 != ((HxOverrides.cca(s, 0) == 47) ? s : "/" + s);
|
|
90
|
+
var dir = _g1.substring(0, _g1.lastIndexOf("/") + 1);
|
|
91
|
+
invalidPath = value.baseDir != ((dir.length == 0) ? "./" : dir);
|
|
145
92
|
};
|
|
146
93
|
if (invalidPath) {
|
|
147
94
|
return Promise.resolve(null);
|
|
@@ -152,12 +99,7 @@ class FileCache extends Register.inherits(BaseCache) {
|
|
|
152
99
|
var _g2 = value.files;
|
|
153
100
|
while (_g1 < _g2.length) _g.push(new Promise((function (file) {
|
|
154
101
|
return function (res, rej) {
|
|
155
|
-
var
|
|
156
|
-
var root = _gthis.rootDir;
|
|
157
|
-
if (this1.charAt(0) != "/") {
|
|
158
|
-
throw new Error("Badly formed SourceId.");
|
|
159
|
-
};
|
|
160
|
-
var path = Path.posix.join(".", root, ".", this1);
|
|
102
|
+
var path = Path.posix.join(".", _gthis.rootDir, ".", file[0].filePath);
|
|
161
103
|
SourceData.fromFile(file[0].id, path, file[0].filePath).then((function (file) {
|
|
162
104
|
return function (sourceData) {
|
|
163
105
|
if (sourceData == null || !stone.ignoreFileHash && !SourceHash.equals(sourceData.hash, file[0].fileHash)) {
|
|
@@ -226,18 +168,8 @@ class FileCache extends Register.inherits(BaseCache) {
|
|
|
226
168
|
var _g2 = value.files;
|
|
227
169
|
while (_g1 < _g2.length) _g.push(new Promise((function (file) {
|
|
228
170
|
return function (res, rej) {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
if (this1.charAt(0) != "/") {
|
|
232
|
-
throw new Error("Badly formed SourceId.");
|
|
233
|
-
};
|
|
234
|
-
Log.log(20, ...["Deleting file.", {"path": Path.posix.join(".", root, ".", this1)}]);
|
|
235
|
-
var this1 = file[0].filePath;
|
|
236
|
-
var root = _gthis.rootDir;
|
|
237
|
-
if (this1.charAt(0) != "/") {
|
|
238
|
-
throw new Error("Badly formed SourceId.");
|
|
239
|
-
};
|
|
240
|
-
Fs.unlink(Path.posix.join(".", root, ".", this1), (function (file) {
|
|
171
|
+
Log.log(20, ...["Deleting file.", {"path": Path.posix.join(".", _gthis.rootDir, ".", file[0].filePath)}]);
|
|
172
|
+
Fs.unlink(Path.posix.join(".", _gthis.rootDir, ".", file[0].filePath), (function (file) {
|
|
241
173
|
return function (err) {
|
|
242
174
|
if (err != null) {
|
|
243
175
|
Log.log(50, ...["Error deleting file.", {"file": file[0], "error": err}]);
|
|
@@ -251,34 +183,14 @@ class FileCache extends Register.inherits(BaseCache) {
|
|
|
251
183
|
};
|
|
252
184
|
}).then(function (_) {
|
|
253
185
|
return new Promise(function (res, rej) {
|
|
254
|
-
|
|
255
|
-
var root = _gthis.rootDir;
|
|
256
|
-
if (this1.charAt(0) != "/") {
|
|
257
|
-
throw new Error("Badly formed SourceId.");
|
|
258
|
-
};
|
|
259
|
-
Fs.readdir(Path.posix.join(".", root, ".", this1), function (err, files) {
|
|
186
|
+
Fs.readdir(Path.posix.join(".", _gthis.rootDir, ".", value.baseDir), function (err, files) {
|
|
260
187
|
if (err != null) {
|
|
261
|
-
|
|
262
|
-
var root = _gthis.rootDir;
|
|
263
|
-
if (this1.charAt(0) != "/") {
|
|
264
|
-
throw new Error("Badly formed SourceId.");
|
|
265
|
-
};
|
|
266
|
-
Log.log(50, ...["Error reading directory", {"dir": Path.posix.join(".", root, ".", this1), "error": err}]);
|
|
188
|
+
Log.log(50, ...["Error reading directory", {"dir": Path.posix.join(".", _gthis.rootDir, ".", value.baseDir), "error": err}]);
|
|
267
189
|
res(null);
|
|
268
190
|
} else if (files.length == 0) {
|
|
269
|
-
|
|
270
|
-
var root = _gthis.rootDir;
|
|
271
|
-
if (this1.charAt(0) != "/") {
|
|
272
|
-
throw new Error("Badly formed SourceId.");
|
|
273
|
-
};
|
|
274
|
-
Fs.rmdir(Path.posix.join(".", root, ".", this1), function (err) {
|
|
191
|
+
Fs.rmdir(Path.posix.join(".", _gthis.rootDir, ".", value.baseDir), function (err) {
|
|
275
192
|
if (err != null) {
|
|
276
|
-
|
|
277
|
-
var root = _gthis.rootDir;
|
|
278
|
-
if (this1.charAt(0) != "/") {
|
|
279
|
-
throw new Error("Badly formed SourceId.");
|
|
280
|
-
};
|
|
281
|
-
Log.log(50, ...["Error removing directory.", {"dir": Path.posix.join(".", root, ".", this1), "error": err}]);
|
|
193
|
+
Log.log(50, ...["Error removing directory.", {"dir": Path.posix.join(".", _gthis.rootDir, ".", value.baseDir), "error": err}]);
|
|
282
194
|
};
|
|
283
195
|
res(null);
|
|
284
196
|
});
|
|
@@ -321,52 +233,14 @@ class FileCache extends Register.inherits(BaseCache) {
|
|
|
321
233
|
var tmp = SourceHash.toHex(val.hash);
|
|
322
234
|
var val1 = val.ctime;
|
|
323
235
|
var tmp1 = HxOverrides.dateStr(new Date(val.ctime * 1000));
|
|
324
|
-
var
|
|
325
|
-
var s = "/";
|
|
326
|
-
var str = ("/".length > 1 && HxOverrides.cca("/", 0) == 47) ? "/".substring(1) : "/";
|
|
327
|
-
if (str.length > 0) {
|
|
328
|
-
str = Path.posix.normalize(str);
|
|
329
|
-
str = StringTools.replace(str, "\\", "/");
|
|
330
|
-
};
|
|
331
|
-
s = str;
|
|
332
|
-
var root = (HxOverrides.cca(s, 0) == 47) ? s : "/" + s;
|
|
333
|
-
if (this2.charAt(0) != "/") {
|
|
334
|
-
throw new Error("Badly formed SourceId.");
|
|
335
|
-
};
|
|
336
|
-
var tmp2 = Path.posix.join(".", root, ".", this2);
|
|
236
|
+
var tmp2 = Path.posix.join(".", "./", ".", val.baseDir);
|
|
337
237
|
var _g2 = [];
|
|
338
238
|
var _g3 = 0;
|
|
339
239
|
var _g4 = val.files;
|
|
340
240
|
while (_g3 < _g4.length) {
|
|
341
241
|
var file = _g4[_g3];
|
|
342
242
|
++_g3;
|
|
343
|
-
|
|
344
|
-
var this3 = file.filePath;
|
|
345
|
-
var s1 = "/";
|
|
346
|
-
var str1 = ("/".length > 1 && HxOverrides.cca("/", 0) == 47) ? "/".substring(1) : "/";
|
|
347
|
-
if (str1.length > 0) {
|
|
348
|
-
str1 = Path.posix.normalize(str1);
|
|
349
|
-
str1 = StringTools.replace(str1, "\\", "/");
|
|
350
|
-
};
|
|
351
|
-
s1 = str1;
|
|
352
|
-
var root1 = (HxOverrides.cca(s1, 0) == 47) ? s1 : "/" + s1;
|
|
353
|
-
if (this3.charAt(0) != "/") {
|
|
354
|
-
throw new Error("Badly formed SourceId.");
|
|
355
|
-
};
|
|
356
|
-
var tmp4 = Path.posix.join(".", root1, ".", this3);
|
|
357
|
-
var this4 = file.id;
|
|
358
|
-
var s2 = "/";
|
|
359
|
-
var str2 = ("/".length > 1 && HxOverrides.cca("/", 0) == 47) ? "/".substring(1) : "/";
|
|
360
|
-
if (str2.length > 0) {
|
|
361
|
-
str2 = Path.posix.normalize(str2);
|
|
362
|
-
str2 = StringTools.replace(str2, "\\", "/");
|
|
363
|
-
};
|
|
364
|
-
s2 = str2;
|
|
365
|
-
var root2 = (HxOverrides.cca(s2, 0) == 47) ? s2 : "/" + s2;
|
|
366
|
-
if (this4.charAt(0) != "/") {
|
|
367
|
-
throw new Error("Badly formed SourceId.");
|
|
368
|
-
};
|
|
369
|
-
_g2.push({"fileHash": tmp3, "filePath": tmp4, "id": Path.posix.join(".", root2, ".", this4)});
|
|
243
|
+
_g2.push({"fileHash": SourceHash.toHex(file.fileHash), "filePath": Path.posix.join(".", "./", ".", file.filePath), "id": Path.posix.join(".", "./", ".", file.id)});
|
|
370
244
|
};
|
|
371
245
|
_g.push({"hash": tmp, "ctime": val1, "ctimePretty": tmp1, "baseDir": tmp2, "files": _g2});
|
|
372
246
|
};
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import * as Path from "path"
|
|
2
1
|
import Minimatch from "minimatch"
|
|
3
2
|
import {Register} from "../../genes/Register.js"
|
|
4
|
-
import {StringTools} from "../../StringTools.js"
|
|
5
|
-
import {HxOverrides} from "../../HxOverrides.js"
|
|
6
3
|
|
|
7
4
|
const $global = Register.$global
|
|
8
5
|
|
|
@@ -10,14 +7,7 @@ export const MinimatchType_Fields_ = Register.global("$hxClasses")["whet.magic._
|
|
|
10
7
|
class MinimatchType_Fields_ {
|
|
11
8
|
static makeMinimatch(src) {
|
|
12
9
|
if (typeof(src) == "string") {
|
|
13
|
-
|
|
14
|
-
var str = (s.length > 1 && HxOverrides.cca(s, 0) == 47) ? s.substring(1) : s;
|
|
15
|
-
if (str.length > 0) {
|
|
16
|
-
str = Path.posix.normalize(str);
|
|
17
|
-
str = StringTools.replace(str, "\\", "/");
|
|
18
|
-
};
|
|
19
|
-
s = str;
|
|
20
|
-
return new Minimatch.Minimatch((HxOverrides.cca(s, 0) == 47) ? s : "/" + s, null);
|
|
10
|
+
return new Minimatch.Minimatch(src, null);
|
|
21
11
|
} else if (src instanceof Minimatch.Minimatch) {
|
|
22
12
|
return src;
|
|
23
13
|
} else {
|
|
@@ -2,11 +2,8 @@ import {Files} from "../stones/Files.js"
|
|
|
2
2
|
import {Router} from "../route/Router.js"
|
|
3
3
|
import {MinimatchType_Fields_} from "./MinimatchType.js"
|
|
4
4
|
import {Stone} from "../Stone.js"
|
|
5
|
-
import * as Path from "path"
|
|
6
5
|
import Minimatch from "minimatch"
|
|
7
6
|
import {Register} from "../../genes/Register.js"
|
|
8
|
-
import {StringTools} from "../../StringTools.js"
|
|
9
|
-
import {HxOverrides} from "../../HxOverrides.js"
|
|
10
7
|
|
|
11
8
|
const $global = Register.$global
|
|
12
9
|
|
|
@@ -14,14 +11,7 @@ export const RoutePathType_Fields_ = Register.global("$hxClasses")["whet.magic._
|
|
|
14
11
|
class RoutePathType_Fields_ {
|
|
15
12
|
static makeRoutePath(routerPathType) {
|
|
16
13
|
if (((routerPathType) instanceof Router) || ((routerPathType) instanceof Stone) || typeof(routerPathType) == "string") {
|
|
17
|
-
|
|
18
|
-
var str = ("/".length > 1 && HxOverrides.cca("/", 0) == 47) ? "/".substring(1) : "/";
|
|
19
|
-
if (str.length > 0) {
|
|
20
|
-
str = Path.posix.normalize(str);
|
|
21
|
-
str = StringTools.replace(str, "\\", "/");
|
|
22
|
-
};
|
|
23
|
-
s = str;
|
|
24
|
-
return [{"routeUnder": (HxOverrides.cca(s, 0) == 47) ? s : "/" + s, "source": (typeof(routerPathType) == "string") ? new Files({"paths": [routerPathType]}) : routerPathType, "filter": null, "extractDirs": null}];
|
|
14
|
+
return [{"routeUnder": "", "source": (typeof(routerPathType) == "string") ? new Files({"paths": [routerPathType]}) : routerPathType, "filter": null, "extractDirs": null}];
|
|
25
15
|
};
|
|
26
16
|
if (!((routerPathType) instanceof Array)) {
|
|
27
17
|
throw new Error("RoutePath should be a Stone, Router, or an array.");
|
|
@@ -33,14 +23,7 @@ class RoutePathType_Fields_ {
|
|
|
33
23
|
var item = _g2[_g1];
|
|
34
24
|
++_g1;
|
|
35
25
|
if (((item) instanceof Router) || ((item) instanceof Stone) || typeof(item) == "string") {
|
|
36
|
-
|
|
37
|
-
var str = ("/".length > 1 && HxOverrides.cca("/", 0) == 47) ? "/".substring(1) : "/";
|
|
38
|
-
if (str.length > 0) {
|
|
39
|
-
str = Path.posix.normalize(str);
|
|
40
|
-
str = StringTools.replace(str, "\\", "/");
|
|
41
|
-
};
|
|
42
|
-
s = str;
|
|
43
|
-
_g.push({"routeUnder": (HxOverrides.cca(s, 0) == 47) ? s : "/" + s, "source": (typeof(item) == "string") ? new Files({"paths": [item]}) : item, "filter": null, "extractDirs": null});
|
|
26
|
+
_g.push({"routeUnder": "", "source": (typeof(item) == "string") ? new Files({"paths": [item]}) : item, "filter": null, "extractDirs": null});
|
|
44
27
|
} else if (((item) instanceof Array)) {
|
|
45
28
|
var inner = item;
|
|
46
29
|
if (typeof(inner[0]) != "string") {
|
|
@@ -52,41 +35,20 @@ class RoutePathType_Fields_ {
|
|
|
52
35
|
var tmp;
|
|
53
36
|
switch (inner.length) {
|
|
54
37
|
case 2:
|
|
55
|
-
var s1 = inner[0];
|
|
56
|
-
var str1 = (s1.length > 1 && HxOverrides.cca(s1, 0) == 47) ? s1.substring(1) : s1;
|
|
57
|
-
if (str1.length > 0) {
|
|
58
|
-
str1 = Path.posix.normalize(str1);
|
|
59
|
-
str1 = StringTools.replace(str1, "\\", "/");
|
|
60
|
-
};
|
|
61
|
-
s1 = str1;
|
|
62
38
|
var src = inner[1];
|
|
63
|
-
|
|
39
|
+
var tmp1 = (typeof(src) == "string") ? new Files({"paths": [src]}) : src;
|
|
40
|
+
tmp = {"routeUnder": inner[0], "source": tmp1, "filter": null, "extractDirs": null};
|
|
64
41
|
break
|
|
65
42
|
case 3:
|
|
66
|
-
var s2 = inner[0];
|
|
67
|
-
var str2 = (s2.length > 1 && HxOverrides.cca(s2, 0) == 47) ? s2.substring(1) : s2;
|
|
68
|
-
if (str2.length > 0) {
|
|
69
|
-
str2 = Path.posix.normalize(str2);
|
|
70
|
-
str2 = StringTools.replace(str2, "\\", "/");
|
|
71
|
-
};
|
|
72
|
-
s2 = str2;
|
|
73
|
-
var tmp1 = (HxOverrides.cca(s2, 0) == 47) ? s2 : "/" + s2;
|
|
74
43
|
var src1 = inner[1];
|
|
75
44
|
var tmp2 = (typeof(src1) == "string") ? new Files({"paths": [src1]}) : src1;
|
|
76
45
|
if (!(typeof(inner[2]) == "string" || inner[2] instanceof Minimatch)) {
|
|
77
46
|
throw new Error("Third" + " element of RoutePath array should be a glob pattern (string or `minimatch` object)");
|
|
78
47
|
};
|
|
79
|
-
|
|
48
|
+
var tmp3 = MinimatchType_Fields_.makeMinimatch(inner[2]);
|
|
49
|
+
tmp = {"routeUnder": inner[0], "source": tmp2, "filter": tmp3, "extractDirs": null};
|
|
80
50
|
break
|
|
81
51
|
case 4:
|
|
82
|
-
var s3 = inner[0];
|
|
83
|
-
var str3 = (s3.length > 1 && HxOverrides.cca(s3, 0) == 47) ? s3.substring(1) : s3;
|
|
84
|
-
if (str3.length > 0) {
|
|
85
|
-
str3 = Path.posix.normalize(str3);
|
|
86
|
-
str3 = StringTools.replace(str3, "\\", "/");
|
|
87
|
-
};
|
|
88
|
-
s3 = str3;
|
|
89
|
-
var tmp3 = (HxOverrides.cca(s3, 0) == 47) ? s3 : "/" + s3;
|
|
90
52
|
var src2 = inner[1];
|
|
91
53
|
var tmp4 = (typeof(src2) == "string") ? new Files({"paths": [src2]}) : src2;
|
|
92
54
|
if (!(typeof(inner[2]) == "string" || inner[2] instanceof Minimatch)) {
|
|
@@ -96,7 +58,8 @@ class RoutePathType_Fields_ {
|
|
|
96
58
|
if (!(typeof(inner[3]) == "string" || inner[3] instanceof Minimatch)) {
|
|
97
59
|
throw new Error("Fourth" + " element of RoutePath array should be a glob pattern (string or `minimatch` object)");
|
|
98
60
|
};
|
|
99
|
-
|
|
61
|
+
var tmp6 = MinimatchType_Fields_.makeMinimatch(inner[3]);
|
|
62
|
+
tmp = {"routeUnder": inner[0], "source": tmp4, "filter": tmp5, "extractDirs": tmp6};
|
|
100
63
|
break
|
|
101
64
|
default:
|
|
102
65
|
throw new Error("Invalid array for a RoutePath element.");
|
|
@@ -14,20 +14,30 @@ export declare class Router {
|
|
|
14
14
|
* Find data sources routed under `pattern`.
|
|
15
15
|
* @param pattern A glob pattern to search for.
|
|
16
16
|
*/
|
|
17
|
-
get(pattern?: MinimatchType): Promise<RouteResult[]>
|
|
17
|
+
get(pattern?: null | MinimatchType): Promise<RouteResult[]>
|
|
18
|
+
protected getResults(mainFilters: Filter[], results: RouteResult[]): Promise<RouteResult[]>
|
|
18
19
|
|
|
19
20
|
/**
|
|
20
21
|
* Get combined hash of all sources that fit the `pattern`.
|
|
21
22
|
*/
|
|
22
|
-
getHash(pattern?: MinimatchType): Promise<SourceHash>
|
|
23
|
+
getHash(pattern?: null | MinimatchType): Promise<SourceHash>
|
|
23
24
|
|
|
24
25
|
/**
|
|
25
26
|
* Save files filtered by `pattern` into provided `saveInto` folder.
|
|
26
27
|
*/
|
|
27
28
|
saveInto(pattern: MinimatchType, saveInto: string, clearFirst?: boolean): Promise<any>
|
|
28
|
-
listContents(pattern?: MinimatchType): Promise<string>
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
listContents(pattern?: null | MinimatchType): Promise<string>
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export type Filter = {
|
|
33
|
+
filter: Minimatch,
|
|
34
|
+
inProgress: boolean,
|
|
35
|
+
pathSoFar: string[],
|
|
36
|
+
remDirs: Minimatch[]
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export declare class Filters {
|
|
40
|
+
protected static isPathPossible($this: Filter[], f: Filter): boolean
|
|
31
41
|
}
|
|
32
42
|
|
|
33
43
|
export type RoutePath = {
|