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/SourceHash.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
import {MaybeArray_Fields_} from "./magic/MaybeArray.js"
|
|
2
|
+
import {Utils} from "./Utils.js"
|
|
1
3
|
import {Register} from "../genes/Register.js"
|
|
4
|
+
import * as Fs from "fs"
|
|
2
5
|
import * as Crypto from "crypto"
|
|
3
6
|
import {Buffer} from "buffer"
|
|
4
7
|
|
|
@@ -9,21 +12,116 @@ class SourceHash extends Register.inherits() {
|
|
|
9
12
|
new(bytes) {
|
|
10
13
|
this.bytes = bytes;
|
|
11
14
|
}
|
|
15
|
+
add(hash) {
|
|
16
|
+
var data = Buffer.alloc(64);
|
|
17
|
+
this.bytes.copy(data, 0, 0, 32);
|
|
18
|
+
hash.bytes.copy(data, 32, 0, 32);
|
|
19
|
+
return SourceHash.fromBytes(data);
|
|
20
|
+
}
|
|
12
21
|
toString() {
|
|
13
22
|
return this.bytes.toString("hex");
|
|
14
23
|
}
|
|
24
|
+
static fromFile(path) {
|
|
25
|
+
return new Promise(function (res, rej) {
|
|
26
|
+
Fs.readFile(path, function (err, bytes) {
|
|
27
|
+
if (err != null) {
|
|
28
|
+
rej(err);
|
|
29
|
+
} else {
|
|
30
|
+
res(SourceHash.fromBytes(bytes));
|
|
31
|
+
};
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Creates hashes of all files and or content of directories, optionally recursive.
|
|
38
|
+
*/
|
|
39
|
+
static fromFiles(paths, filter, recursive) {
|
|
40
|
+
if (recursive == null) {
|
|
41
|
+
recursive = true;
|
|
42
|
+
};
|
|
43
|
+
var _g = [];
|
|
44
|
+
var _g1 = 0;
|
|
45
|
+
var _g2 = MaybeArray_Fields_.makeArray(paths);
|
|
46
|
+
while (_g1 < _g2.length) {
|
|
47
|
+
var src = [_g2[_g1]];
|
|
48
|
+
++_g1;
|
|
49
|
+
_g.push(new Promise((function (src) {
|
|
50
|
+
return function (res, rej) {
|
|
51
|
+
Fs.stat(src[0], (function (src) {
|
|
52
|
+
return function (err, stats) {
|
|
53
|
+
if (err != null) {
|
|
54
|
+
rej(err);
|
|
55
|
+
} else if (stats.isDirectory()) {
|
|
56
|
+
Utils.listDirectoryFiles(src[0], recursive).then((function () {
|
|
57
|
+
return function (files) {
|
|
58
|
+
res(files);
|
|
59
|
+
};
|
|
60
|
+
})());
|
|
61
|
+
} else {
|
|
62
|
+
res([src[0]]);
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
})(src));
|
|
66
|
+
};
|
|
67
|
+
})(src)));
|
|
68
|
+
};
|
|
69
|
+
var allFilesProm = _g;
|
|
70
|
+
return Promise.all(allFilesProm).then(function (arrFiles) {
|
|
71
|
+
var result = new Array(arrFiles.length);
|
|
72
|
+
var _g = 0;
|
|
73
|
+
var _g1 = arrFiles.length;
|
|
74
|
+
while (_g < _g1) {
|
|
75
|
+
var i = _g++;
|
|
76
|
+
var files = arrFiles[i];
|
|
77
|
+
if (filter != null) {
|
|
78
|
+
var _g2 = [];
|
|
79
|
+
var _g3 = 0;
|
|
80
|
+
var _g4 = files;
|
|
81
|
+
while (_g3 < _g4.length) {
|
|
82
|
+
var v = _g4[_g3];
|
|
83
|
+
++_g3;
|
|
84
|
+
if (filter(v)) {
|
|
85
|
+
_g2.push(v);
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
files = _g2;
|
|
89
|
+
};
|
|
90
|
+
files.sort();
|
|
91
|
+
var result1 = new Array(files.length);
|
|
92
|
+
var _g5 = 0;
|
|
93
|
+
var _g6 = files.length;
|
|
94
|
+
while (_g5 < _g6) {
|
|
95
|
+
var i1 = _g5++;
|
|
96
|
+
result1[i1] = SourceHash.fromFile(files[i1]);
|
|
97
|
+
};
|
|
98
|
+
result[i] = Promise.all(result1);
|
|
99
|
+
};
|
|
100
|
+
return result;
|
|
101
|
+
}).then(function (proms) {
|
|
102
|
+
return Promise.all(proms);
|
|
103
|
+
}).then(function (allHashes) {
|
|
104
|
+
var _g = [];
|
|
105
|
+
var _g_current = 0;
|
|
106
|
+
var _g_array = allHashes;
|
|
107
|
+
while (_g_current < _g_array.length) {
|
|
108
|
+
var e = _g_array[_g_current++];
|
|
109
|
+
var x = Register.iter(e);
|
|
110
|
+
while (x.hasNext()) {
|
|
111
|
+
var x1 = x.next();
|
|
112
|
+
_g.push(x1);
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
var this1 = _g;
|
|
116
|
+
return SourceHash.merge(...this1);
|
|
117
|
+
});
|
|
118
|
+
}
|
|
15
119
|
static fromBytes(data) {
|
|
16
120
|
return new SourceHash(Crypto.createHash("sha256").update(data).digest());
|
|
17
121
|
}
|
|
18
122
|
static fromString(data) {
|
|
19
123
|
return SourceHash.fromBytes(Buffer.from(data));
|
|
20
124
|
}
|
|
21
|
-
static add(a, b) {
|
|
22
|
-
var data = Buffer.alloc(64);
|
|
23
|
-
a.bytes.copy(data, 0, 0, 32);
|
|
24
|
-
b.bytes.copy(data, 32, 0, 32);
|
|
25
|
-
return SourceHash.fromBytes(data);
|
|
26
|
-
}
|
|
27
125
|
static equals(a, b) {
|
|
28
126
|
if (a != null && b != null) {
|
|
29
127
|
return a.bytes.compare(b.bytes) == 0;
|
|
@@ -53,7 +151,7 @@ class SourceHash extends Register.inherits() {
|
|
|
53
151
|
var h = hash[0];
|
|
54
152
|
var _g = 1;
|
|
55
153
|
var _g1 = hash.length;
|
|
56
|
-
while (_g < _g1) h =
|
|
154
|
+
while (_g < _g1) h = h.add(hash[_g++]);
|
|
57
155
|
return h;
|
|
58
156
|
}
|
|
59
157
|
static get __name__() {
|
package/bin/whet/SourceId.d.ts
CHANGED
package/bin/whet/SourceId.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as Path from "path"
|
|
2
2
|
import {Register} from "../genes/Register.js"
|
|
3
|
+
import {StringTools} from "../StringTools.js"
|
|
3
4
|
import {HxOverrides} from "../HxOverrides.js"
|
|
4
5
|
|
|
5
6
|
const $global = Register.$global
|
|
@@ -7,17 +8,14 @@ const $global = Register.$global
|
|
|
7
8
|
export const SourceId = Register.global("$hxClasses")["whet._SourceId.SourceId"] =
|
|
8
9
|
class SourceId {
|
|
9
10
|
static relativeTo(this1, directory) {
|
|
10
|
-
|
|
11
|
-
var tmp = (directory.lastIndexOf("/") == directory.length - 1) ? Path.addTrailingSlash(norm) : norm;
|
|
12
|
-
var s = Path.addTrailingSlash(Path.directory(directory));
|
|
13
|
-
var norm = "/" + Path.normalize((s.charAt(0) == "/") ? HxOverrides.substr(s, 1, null) : s);
|
|
14
|
-
if (tmp != ((s.lastIndexOf("/") == s.length - 1) ? Path.addTrailingSlash(norm) : norm)) {
|
|
11
|
+
if (!SourceId_Fields_.endsWithSlash(directory)) {
|
|
15
12
|
throw new Error("\"" + directory + "\" is not a directory.");
|
|
16
13
|
};
|
|
17
14
|
var tmp;
|
|
18
|
-
var s =
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
var s = this1.substring(0, this1.lastIndexOf("/") + 1);
|
|
16
|
+
s = Path.posix.normalize(s);
|
|
17
|
+
s = StringTools.replace(s, "\\", "/");
|
|
18
|
+
tmp = ((SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s).indexOf(directory) == 0;
|
|
21
19
|
if (tmp) {
|
|
22
20
|
return HxOverrides.substr(this1, directory.length - 1, null);
|
|
23
21
|
} else {
|
|
@@ -25,29 +23,22 @@ class SourceId {
|
|
|
25
23
|
};
|
|
26
24
|
}
|
|
27
25
|
static getPutInDir(this1, dir) {
|
|
28
|
-
|
|
29
|
-
var tmp = (dir.lastIndexOf("/") == dir.length - 1) ? Path.addTrailingSlash(norm) : norm;
|
|
30
|
-
var s = Path.addTrailingSlash(Path.directory(dir));
|
|
31
|
-
var norm = "/" + Path.normalize((s.charAt(0) == "/") ? HxOverrides.substr(s, 1, null) : s);
|
|
32
|
-
if (tmp != ((s.lastIndexOf("/") == s.length - 1) ? Path.addTrailingSlash(norm) : norm)) {
|
|
26
|
+
if (!SourceId_Fields_.endsWithSlash(dir)) {
|
|
33
27
|
throw new Error("\"" + dir + "\" is not a directory.");
|
|
34
28
|
};
|
|
35
|
-
var
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
29
|
+
var s = "/";
|
|
30
|
+
s = Path.posix.normalize("/");
|
|
31
|
+
s = StringTools.replace(s, "\\", "/");
|
|
32
|
+
if (dir == ((SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s)) {
|
|
33
|
+
var s = this1;
|
|
34
|
+
s = Path.posix.normalize(this1);
|
|
35
|
+
s = StringTools.replace(s, "\\", "/");
|
|
36
|
+
return (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
|
|
43
37
|
} else {
|
|
44
38
|
var s = dir + this1;
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
} else {
|
|
49
|
-
return norm;
|
|
50
|
-
};
|
|
39
|
+
s = Path.posix.normalize(s);
|
|
40
|
+
s = StringTools.replace(s, "\\", "/");
|
|
41
|
+
return (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
|
|
51
42
|
};
|
|
52
43
|
}
|
|
53
44
|
static get __name__() {
|
|
@@ -72,3 +63,21 @@ class RootDir {
|
|
|
72
63
|
}
|
|
73
64
|
}
|
|
74
65
|
|
|
66
|
+
|
|
67
|
+
export const SourceId_Fields_ = Register.global("$hxClasses")["whet._SourceId.SourceId_Fields_"] =
|
|
68
|
+
class SourceId_Fields_ {
|
|
69
|
+
static startsWithSlash(str) {
|
|
70
|
+
return HxOverrides.cca(str, 0) == 47;
|
|
71
|
+
}
|
|
72
|
+
static endsWithSlash(str) {
|
|
73
|
+
return HxOverrides.cca(str, str.length - 1) == 47;
|
|
74
|
+
}
|
|
75
|
+
static get __name__() {
|
|
76
|
+
return "whet._SourceId.SourceId_Fields_"
|
|
77
|
+
}
|
|
78
|
+
get __class__() {
|
|
79
|
+
return SourceId_Fields_
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
|
package/bin/whet/Stone.d.ts
CHANGED
|
@@ -30,7 +30,8 @@ export declare class Stone<T extends StoneConfig> {
|
|
|
30
30
|
protected getCommands(): Command[]
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
|
-
|
|
33
|
+
* **Do not override.**
|
|
34
|
+
* Get Source for this stone. Goes through the cache.
|
|
34
35
|
*/
|
|
35
36
|
getSource(): Promise<Source>
|
|
36
37
|
|
|
@@ -40,6 +41,7 @@ export declare class Stone<T extends StoneConfig> {
|
|
|
40
41
|
getHash(): Promise<SourceHash>
|
|
41
42
|
|
|
42
43
|
/**
|
|
44
|
+
* **Do not override.**
|
|
43
45
|
* Generates new Source. Used by the cache when needed.
|
|
44
46
|
* Hash passed should be the same as is this stone's current one. Passed in as optimization.
|
|
45
47
|
*/
|
|
@@ -51,6 +53,7 @@ export declare class Stone<T extends StoneConfig> {
|
|
|
51
53
|
protected generateHash(): Promise<SourceHash>
|
|
52
54
|
|
|
53
55
|
/**
|
|
56
|
+
* Abstract method.
|
|
54
57
|
* Function that actually generates the source. Passed hash is only non-null
|
|
55
58
|
* if `generateHash()` is implemented. It can be used for `CacheManager.getDir` and
|
|
56
59
|
* is passed mainly as optimization.
|
|
@@ -67,11 +70,18 @@ export declare class Stone<T extends StoneConfig> {
|
|
|
67
70
|
|
|
68
71
|
/**
|
|
69
72
|
* Caches this resource under supplied `path` as a single copy.
|
|
73
|
+
* @param path
|
|
70
74
|
* If `path` is a directory, stores the file(s) under that path, using their standard names.
|
|
71
75
|
* If `path` is a file and this stone generates only single data source, stores it under the supplied path.
|
|
72
|
-
*
|
|
76
|
+
* @param generate If true (default), the source is exported right away.
|
|
73
77
|
*/
|
|
74
78
|
setAbsolutePath(path: string, generate?: boolean): Promise<Source>
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Convenient function to get CWD-relative path from project-relative one.
|
|
82
|
+
* Useful for pure JS stones.
|
|
83
|
+
*/
|
|
84
|
+
cwdPath(path: string): string
|
|
75
85
|
protected get_cache(): CacheManager
|
|
76
86
|
toString(): string
|
|
77
87
|
}
|
package/bin/whet/Stone.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {StoneId_Fields_} from "./magic/StoneId.js"
|
|
2
2
|
import {CacheStrategy, CacheDurability} from "./cache/Cache.js"
|
|
3
|
+
import {SourceId_Fields_} from "./SourceId.js"
|
|
3
4
|
import {SourceHash} from "./SourceHash.js"
|
|
4
5
|
import {Source} from "./Source.js"
|
|
5
6
|
import {Project} from "./Project.js"
|
|
6
7
|
import {Log} from "./Log.js"
|
|
7
|
-
import
|
|
8
|
-
import {Path} from "../haxe/io/Path.js"
|
|
8
|
+
import * as Path from "path"
|
|
9
9
|
import {Register} from "../genes/Register.js"
|
|
10
|
-
import {
|
|
10
|
+
import {StringTools} from "../StringTools.js"
|
|
11
11
|
|
|
12
12
|
const $global = Register.$global
|
|
13
13
|
|
|
@@ -15,18 +15,18 @@ export const Stone = Register.global("$hxClasses")["whet.Stone"] =
|
|
|
15
15
|
class Stone extends Register.inherits() {
|
|
16
16
|
new(config) {
|
|
17
17
|
this.ignoreFileHash = false;
|
|
18
|
-
|
|
19
|
-
Log.log(10, ...["Instantiating new Stone.", {"type": c.__name__}]);
|
|
18
|
+
Log.log(10, ...["Instantiating new Stone.", {"type": StoneId_Fields_.getTypeName(this)}]);
|
|
20
19
|
if (config == null) {
|
|
21
20
|
throw new Error("Config must be supplied.");
|
|
22
21
|
};
|
|
23
22
|
this.config = config;
|
|
24
|
-
this.initConfig();
|
|
25
|
-
this.id = (config.id != null) ? StoneId_Fields_.makeStoneId(config.id) : StoneId_Fields_.makeStoneId(this);
|
|
26
23
|
this.project = (config.project != null) ? config.project : Project.projects[Project.projects.length - 1];
|
|
27
24
|
if (this.project == null) {
|
|
28
25
|
throw new Error("Did not find a project. Create one before creating stones.");
|
|
29
26
|
};
|
|
27
|
+
this.project.stones.push(this);
|
|
28
|
+
this.initConfig();
|
|
29
|
+
this.id = (config.id != null) ? StoneId_Fields_.makeStoneId(config.id) : StoneId_Fields_.makeStoneId(this);
|
|
30
30
|
this.cacheStrategy = (config.cacheStrategy == null) ? this.project.cache.defaultStrategy : config.cacheStrategy;
|
|
31
31
|
var _g = 0;
|
|
32
32
|
var _g1 = this.getCommands();
|
|
@@ -50,7 +50,8 @@ class Stone extends Register.inherits() {
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
/**
|
|
53
|
-
|
|
53
|
+
* **Do not override.**
|
|
54
|
+
* Get Source for this stone. Goes through the cache.
|
|
54
55
|
*/
|
|
55
56
|
getSource() {
|
|
56
57
|
Log.log(20, ...["Getting source.", {"stone": this}]);
|
|
@@ -75,6 +76,7 @@ class Stone extends Register.inherits() {
|
|
|
75
76
|
}
|
|
76
77
|
|
|
77
78
|
/**
|
|
79
|
+
* **Do not override.**
|
|
78
80
|
* Generates new Source. Used by the cache when needed.
|
|
79
81
|
* Hash passed should be the same as is this stone's current one. Passed in as optimization.
|
|
80
82
|
*/
|
|
@@ -130,28 +132,38 @@ class Stone extends Register.inherits() {
|
|
|
130
132
|
|
|
131
133
|
/**
|
|
132
134
|
* Caches this resource under supplied `path` as a single copy.
|
|
135
|
+
* @param path
|
|
133
136
|
* If `path` is a directory, stores the file(s) under that path, using their standard names.
|
|
134
137
|
* If `path` is a file and this stone generates only single data source, stores it under the supplied path.
|
|
135
|
-
*
|
|
138
|
+
* @param generate If true (default), the source is exported right away.
|
|
136
139
|
*/
|
|
137
140
|
setAbsolutePath(path, generate) {
|
|
138
141
|
if (generate == null) {
|
|
139
142
|
generate = true;
|
|
140
143
|
};
|
|
141
|
-
var
|
|
142
|
-
|
|
144
|
+
var s = path;
|
|
145
|
+
s = Path.posix.normalize(path);
|
|
146
|
+
s = StringTools.replace(s, "\\", "/");
|
|
147
|
+
this.cacheStrategy = CacheStrategy.AbsolutePath((SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s, CacheDurability.LimitCountByAge(1));
|
|
143
148
|
if (generate) {
|
|
144
149
|
return this.getSource();
|
|
145
150
|
} else {
|
|
146
151
|
return Promise.resolve(null);
|
|
147
152
|
};
|
|
148
153
|
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Convenient function to get CWD-relative path from project-relative one.
|
|
157
|
+
* Useful for pure JS stones.
|
|
158
|
+
*/
|
|
159
|
+
cwdPath(path) {
|
|
160
|
+
return Path.join("./", this.project.rootDir, path);
|
|
161
|
+
}
|
|
149
162
|
get_cache() {
|
|
150
163
|
return this.project.cache;
|
|
151
164
|
}
|
|
152
165
|
toString() {
|
|
153
|
-
|
|
154
|
-
return "" + this.id + ":" + c.__name__;
|
|
166
|
+
return "" + this.id + ":" + StoneId_Fields_.getTypeName(this);
|
|
155
167
|
}
|
|
156
168
|
static get __name__() {
|
|
157
169
|
return "whet.Stone"
|
package/bin/whet/Utils.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import {Buffer} from "buffer"
|
|
2
2
|
|
|
3
3
|
export declare class Utils {
|
|
4
|
-
static
|
|
4
|
+
static makeUnique<T>(val: T, isNotUnique: ((arg0: T) => boolean), modify: ((val: T, variant: number) => T)): T
|
|
5
|
+
static makeUniqueString(s: string, isNotUnique: ((arg0: string) => boolean)): string
|
|
6
|
+
static ensureDirExist(dir: string): Promise<any>
|
|
5
7
|
|
|
6
8
|
/**
|
|
7
9
|
Saves string as UTF-8, creates missing directories if needed.
|
|
@@ -13,4 +15,9 @@ export declare class Utils {
|
|
|
13
15
|
*/
|
|
14
16
|
static saveBytes(path: string, bytes: Buffer): Promise<any>
|
|
15
17
|
static deleteAll(path: string): Promise<any>
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Returns a list of all files in the directory. Doesn't include inner directories in non-recursive mode.
|
|
21
|
+
*/
|
|
22
|
+
static listDirectoryFiles(dir: string, recursive?: boolean): Promise<string[]>
|
|
16
23
|
}
|
package/bin/whet/Utils.js
CHANGED
|
@@ -8,8 +8,19 @@ const $global = Register.$global
|
|
|
8
8
|
|
|
9
9
|
export const Utils = Register.global("$hxClasses")["whet.Utils"] =
|
|
10
10
|
class Utils {
|
|
11
|
-
static
|
|
12
|
-
var
|
|
11
|
+
static makeUnique(val, isNotUnique, modify) {
|
|
12
|
+
var unique = val;
|
|
13
|
+
var counter = 0;
|
|
14
|
+
while (isNotUnique(unique)) unique = modify(val, ++counter);
|
|
15
|
+
return unique;
|
|
16
|
+
}
|
|
17
|
+
static makeUniqueString(s, isNotUnique) {
|
|
18
|
+
var unique = s;
|
|
19
|
+
var counter = 0;
|
|
20
|
+
while (isNotUnique(unique)) unique = s + ++counter;
|
|
21
|
+
return unique;
|
|
22
|
+
}
|
|
23
|
+
static ensureDirExist(dir) {
|
|
13
24
|
var this1 = ["Ensuring directory " + dir + " exists."];
|
|
14
25
|
Log.log(10, ...this1);
|
|
15
26
|
return new Promise(function (res, rej) {
|
|
@@ -43,7 +54,7 @@ class Utils {
|
|
|
43
54
|
*/
|
|
44
55
|
static saveBytes(path, bytes) {
|
|
45
56
|
Log.log(10, ...["Writing bytes to " + path + "."]);
|
|
46
|
-
return Utils.ensureDirExist(path).then(function (_) {
|
|
57
|
+
return Utils.ensureDirExist(Path.dirname(path)).then(function (_) {
|
|
47
58
|
return new Promise(function (res, rej) {
|
|
48
59
|
Fs.writeFile(path, bytes, function (err) {
|
|
49
60
|
if (err != null) {
|
|
@@ -62,6 +73,48 @@ class Utils {
|
|
|
62
73
|
});
|
|
63
74
|
});
|
|
64
75
|
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Returns a list of all files in the directory. Doesn't include inner directories in non-recursive mode.
|
|
79
|
+
*/
|
|
80
|
+
static listDirectoryFiles(dir, recursive) {
|
|
81
|
+
if (recursive == null) {
|
|
82
|
+
recursive = true;
|
|
83
|
+
};
|
|
84
|
+
return new Promise(function (res, rej) {
|
|
85
|
+
var result = [];
|
|
86
|
+
Fs.readdir(dir, { withFileTypes : true}, function(err,files) {
|
|
87
|
+
if(err != null) {
|
|
88
|
+
rej(err);
|
|
89
|
+
} else {
|
|
90
|
+
var otherDirs = [];
|
|
91
|
+
var _g = 0;
|
|
92
|
+
while(_g < files.length) {
|
|
93
|
+
var file = files[_g];
|
|
94
|
+
++_g;
|
|
95
|
+
var path = Path.join(dir,file.name);
|
|
96
|
+
if(file.isDirectory()) {
|
|
97
|
+
if(recursive) {
|
|
98
|
+
otherDirs.push(Utils.listDirectoryFiles(path,true));
|
|
99
|
+
}
|
|
100
|
+
} else {
|
|
101
|
+
result.push(path);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
Promise.all(otherDirs).then(function(arr) {
|
|
105
|
+
var _g = 0;
|
|
106
|
+
while(_g < arr.length) {
|
|
107
|
+
var a = arr[_g];
|
|
108
|
+
++_g;
|
|
109
|
+
var _g1 = 0;
|
|
110
|
+
while(_g1 < a.length) result.push(a[_g1++]);
|
|
111
|
+
}
|
|
112
|
+
res(result);
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
}
|
|
65
118
|
static get __name__() {
|
|
66
119
|
return "whet.Utils"
|
|
67
120
|
}
|
package/bin/whet/Whet.js
CHANGED
|
@@ -10,7 +10,7 @@ const $global = Register.$global
|
|
|
10
10
|
export const Whet_Fields_ = Register.global("$hxClasses")["whet._Whet.Whet_Fields_"] =
|
|
11
11
|
class Whet_Fields_ {
|
|
12
12
|
static main() {
|
|
13
|
-
Whet_Fields_.program.enablePositionalOptions().passThroughOptions().description("Project tooling.").usage("[options] [command] [+ [command]...]").version("0.0.
|
|
13
|
+
Whet_Fields_.program.enablePositionalOptions().passThroughOptions().description("Project tooling.").usage("[options] [command] [+ [command]...]").version("0.0.6", "-v, --version").allowUnknownOption(true).showSuggestionAfterError(true).option("-p, --project <file>", "project to run", "Project.mjs").option("-l, --log-level <level>", "log level, a string/number", "info");
|
|
14
14
|
Whet_Fields_.program.parse();
|
|
15
15
|
var options = Whet_Fields_.program.opts();
|
|
16
16
|
if (options.logLevel != null) {
|
|
@@ -38,6 +38,9 @@ class Whet_Fields_ {
|
|
|
38
38
|
Whet_Fields_.initProjects();
|
|
39
39
|
})["catch"](function (e) {
|
|
40
40
|
Log.log(50, ...["Error loading project.", {"error": e}]);
|
|
41
|
+
if (((e) instanceof Error)) {
|
|
42
|
+
Log.log(50, ...[e.stack]);
|
|
43
|
+
};
|
|
41
44
|
return Whet_Fields_.program.help();
|
|
42
45
|
});
|
|
43
46
|
};
|
|
@@ -64,6 +67,7 @@ class Whet_Fields_ {
|
|
|
64
67
|
var p = _g1[_g];
|
|
65
68
|
++_g;
|
|
66
69
|
if (p.onInit != null) {
|
|
70
|
+
Log.log(10, ...["Initializing project.", {"project": p.id}]);
|
|
67
71
|
var prom = p.onInit(Whet_Fields_.program.opts());
|
|
68
72
|
if (prom != null) {
|
|
69
73
|
promises.push(prom);
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import {Cache} from "./Cache.js"
|
|
2
|
-
import {SourceId} from "../SourceId.js"
|
|
2
|
+
import {SourceId_Fields_, SourceId} from "../SourceId.js"
|
|
3
3
|
import {SourceHash} from "../SourceHash.js"
|
|
4
4
|
import {Log} from "../Log.js"
|
|
5
|
+
import * as Path from "path"
|
|
5
6
|
import {Boot} from "../../js/Boot.js"
|
|
6
|
-
import {Path} from "../../haxe/io/Path.js"
|
|
7
7
|
import {Register} from "../../genes/Register.js"
|
|
8
|
+
import {StringTools} from "../../StringTools.js"
|
|
8
9
|
import {Std} from "../../Std.js"
|
|
9
10
|
import {Lambda} from "../../Lambda.js"
|
|
10
11
|
import {HxOverrides} from "../../HxOverrides.js"
|
|
@@ -14,11 +15,7 @@ const $global = Register.$global
|
|
|
14
15
|
export const BaseCache = Register.global("$hxClasses")["whet.cache.BaseCache"] =
|
|
15
16
|
class BaseCache extends Register.inherits() {
|
|
16
17
|
new(rootDir, cache) {
|
|
17
|
-
|
|
18
|
-
var tmp = (rootDir.lastIndexOf("/") == rootDir.length - 1) ? Path.addTrailingSlash(norm) : norm;
|
|
19
|
-
var s = Path.addTrailingSlash(Path.directory(rootDir));
|
|
20
|
-
var norm = "/" + Path.normalize((s.charAt(0) == "/") ? HxOverrides.substr(s, 1, null) : s);
|
|
21
|
-
if (tmp != ((s.lastIndexOf("/") == s.length - 1) ? Path.addTrailingSlash(norm) : norm)) {
|
|
18
|
+
if (!SourceId_Fields_.endsWithSlash(rootDir)) {
|
|
22
19
|
throw new Error("Root dir is a not a dir.");
|
|
23
20
|
};
|
|
24
21
|
this.rootDir = rootDir;
|
|
@@ -26,16 +23,16 @@ class BaseCache extends Register.inherits() {
|
|
|
26
23
|
}
|
|
27
24
|
get(stone, durability, check) {
|
|
28
25
|
var _gthis = this;
|
|
29
|
-
Log.log(20, ...["Looking for cached source.", {"stone": stone, "cache": this}]);
|
|
30
26
|
return stone.generateHash().then(function (hash) {
|
|
31
27
|
if (hash == null) {
|
|
32
|
-
Log.log(
|
|
28
|
+
Log.log(20, ...["Generating source, because it does not supply a hash.", {"stone": stone, "cache": _gthis}]);
|
|
33
29
|
};
|
|
34
30
|
if (hash == null) {
|
|
35
31
|
return stone.generateSource(null).then(function (generatedSource) {
|
|
36
32
|
return {"generatedSource": generatedSource, "hash": generatedSource.hash};
|
|
37
33
|
});
|
|
38
34
|
} else {
|
|
35
|
+
Log.log(20, ...["Stone provided hash.", {"stone": stone, "hash": SourceHash.toHex(hash)}]);
|
|
39
36
|
return Promise.resolve({"generatedSource": null, "hash": hash});
|
|
40
37
|
};
|
|
41
38
|
}).then(function (data) {
|
|
@@ -66,7 +63,7 @@ class BaseCache extends Register.inherits() {
|
|
|
66
63
|
_gthis.setRecentUseOrder(values, value);
|
|
67
64
|
};
|
|
68
65
|
};
|
|
69
|
-
|
|
66
|
+
return ((value != null) ? _gthis.source(stone, value) : Promise.resolve(null)).then(function (src) {
|
|
70
67
|
if (src == null) {
|
|
71
68
|
Log.log(10, ...["Not cached.", {"stone": stone, "cache": _gthis}]);
|
|
72
69
|
return ((value != null) ? _gthis.remove(stone, value) : Promise.resolve(null)).then(function (_) {
|
|
@@ -87,19 +84,19 @@ class BaseCache extends Register.inherits() {
|
|
|
87
84
|
Log.log(10, ...["Found in cache", {"stone": stone, "cache": _gthis}]);
|
|
88
85
|
return Promise.resolve(src);
|
|
89
86
|
};
|
|
90
|
-
})
|
|
91
|
-
srcPromise.then(function (_) {
|
|
87
|
+
}).then(function (src) {
|
|
92
88
|
if ((check == null) ? true : check._hx_index == 0) {
|
|
93
89
|
_gthis.checkDurability(stone, values, durability, function (v) {
|
|
94
90
|
return values.indexOf(v);
|
|
95
91
|
}, ageCount);
|
|
96
92
|
};
|
|
93
|
+
return src;
|
|
97
94
|
});
|
|
98
|
-
return srcPromise;
|
|
99
95
|
});
|
|
100
96
|
}
|
|
101
97
|
set(source) {
|
|
102
98
|
var _gthis = this;
|
|
99
|
+
Log.log(10, ...["Setting source in cache.", {"source": source}]);
|
|
103
100
|
var k = this.key(source.origin);
|
|
104
101
|
if (!this.cache.exists(k)) {
|
|
105
102
|
this.cache.set(k, []);
|
|
@@ -127,21 +124,26 @@ class BaseCache extends Register.inherits() {
|
|
|
127
124
|
};
|
|
128
125
|
var filenames = this.getExistingDirs(stone);
|
|
129
126
|
var maxNum = (filenames != null) ? Lambda.fold(filenames, function (fn, num) {
|
|
130
|
-
var s =
|
|
131
|
-
|
|
132
|
-
|
|
127
|
+
var s = fn.substring(0, fn.lastIndexOf("/") + 1);
|
|
128
|
+
s = Path.posix.normalize(s);
|
|
129
|
+
s = StringTools.replace(s, "\\", "/");
|
|
130
|
+
var this1 = (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
|
|
133
131
|
var root = _gthis.rootDir;
|
|
134
|
-
|
|
132
|
+
if (this1.charAt(0) != "/") {
|
|
133
|
+
throw new Error("Badly formed SourceId.");
|
|
134
|
+
};
|
|
135
|
+
var parts = Path.posix.join(".", root, ".", this1).split("/");
|
|
135
136
|
var name = (parts.length > 1) ? parts[parts.length - 2] : "";
|
|
136
137
|
return Math.max(num, (name.charAt(0) == "v") ? Std.parseInt(HxOverrides.substr(name, 1, null)) : 0);
|
|
137
138
|
}, 0) : 0;
|
|
138
139
|
++maxNum;
|
|
139
140
|
var s = "v" + maxNum + "/";
|
|
140
|
-
|
|
141
|
-
|
|
141
|
+
s = Path.posix.normalize(s);
|
|
142
|
+
s = StringTools.replace(s, "\\", "/");
|
|
143
|
+
return SourceId.getPutInDir((SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s, baseDir);
|
|
142
144
|
}
|
|
143
145
|
checkDurability(stone, values, durability, useIndex, ageIndex) {
|
|
144
|
-
Log.log(
|
|
146
|
+
Log.log(20, ...["Checking durability.", {"stone": stone, "durability": Std.string(durability)}]);
|
|
145
147
|
if (values == null || values.length == 0) {
|
|
146
148
|
return;
|
|
147
149
|
};
|
|
@@ -190,6 +192,7 @@ class BaseCache extends Register.inherits() {
|
|
|
190
192
|
return true;
|
|
191
193
|
}
|
|
192
194
|
remove(stone, value) {
|
|
195
|
+
Log.log(20, ...["Removing cached value.", {"stone": stone, "valueHash": SourceHash.toHex(value.hash)}]);
|
|
193
196
|
HxOverrides.remove(this.cache.get(this.key(stone)), value);
|
|
194
197
|
return Promise.resolve(null);
|
|
195
198
|
}
|
|
@@ -12,6 +12,11 @@ export declare class CacheManager {
|
|
|
12
12
|
defaultStrategy: CacheStrategy
|
|
13
13
|
protected memCache: MemoryCache
|
|
14
14
|
protected fileCache: FileCache
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
Keep last used 5 for a day and last used 1 indefinitely.
|
|
18
|
+
*/
|
|
19
|
+
defaultFileStrategy: CacheStrategy
|
|
15
20
|
getSource(stone: AnyStone): Promise<Source>
|
|
16
21
|
|
|
17
22
|
/**
|