whet 0.0.4 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/StringBuf.d.ts +13 -0
- package/bin/StringBuf.js +25 -0
- package/bin/haxe/CallStack.d.ts +41 -0
- package/bin/haxe/CallStack.js +96 -0
- package/bin/haxe/NativeStackTrace.js +147 -0
- package/bin/whet/Log.js +3 -0
- package/bin/whet/Project.d.ts +5 -2
- package/bin/whet/Project.js +32 -9
- package/bin/whet/Source.d.ts +2 -2
- package/bin/whet/Source.js +21 -5
- package/bin/whet/SourceHash.d.ts +7 -1
- package/bin/whet/SourceHash.js +93 -7
- package/bin/whet/SourceId.d.ts +1 -0
- package/bin/whet/SourceId.js +37 -28
- package/bin/whet/Stone.d.ts +21 -5
- package/bin/whet/Stone.js +63 -18
- package/bin/whet/Utils.d.ts +8 -2
- package/bin/whet/Utils.js +25 -5
- package/bin/whet/Whet.js +4 -1
- package/bin/whet/cache/BaseCache.js +18 -17
- package/bin/whet/cache/CacheManager.d.ts +5 -0
- package/bin/whet/cache/CacheManager.js +21 -12
- package/bin/whet/cache/FileCache.js +83 -43
- package/bin/whet/magic/RoutePathType.js +10 -4
- package/bin/whet/magic/RouteType.d.ts +4 -3
- package/bin/whet/magic/RouteType.js +31 -13
- package/bin/whet/magic/StoneId.d.ts +1 -0
- package/bin/whet/magic/StoneId.js +11 -1
- package/bin/whet/route/Route.d.ts +5 -1
- package/bin/whet/route/Route.js +33 -13
- package/bin/whet/route/Router.js +27 -36
- package/bin/whet/stones/Files.js +25 -16
- package/bin/whet/stones/JsonStone.js +7 -6
- package/bin/whet/stones/RemoteFile.js +5 -7
- package/bin/whet/stones/Server.d.ts +1 -2
- package/bin/whet/stones/Server.js +30 -22
- package/bin/whet/stones/Zip.js +17 -11
- package/bin/whet/stones/haxe/HaxeBuild.d.ts +2 -0
- package/bin/whet/stones/haxe/HaxeBuild.js +44 -63
- package/bin/whet/stones/haxe/Hxml.js +39 -24
- package/bin/whet.d.ts +3 -0
- package/bin/whet.js +3 -0
- package/package.json +1 -1
package/bin/whet/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.length > 1 && SourceId_Fields_.startsWithSlash(s)) ? HxOverrides.substr(s, 1, null) : 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(("/".length > 1 && SourceId_Fields_.startsWithSlash("/")) ? HxOverrides.substr("/", 1, null) : "/");
|
|
31
|
+
s = StringTools.replace(s, "\\", "/");
|
|
32
|
+
if (dir == ((SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s)) {
|
|
33
|
+
var s = this1;
|
|
34
|
+
s = Path.posix.normalize((this1.length > 1 && SourceId_Fields_.startsWithSlash(this1)) ? HxOverrides.substr(this1, 1, null) : 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.length > 1 && SourceId_Fields_.startsWithSlash(s)) ? HxOverrides.substr(s, 1, null) : 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
|
@@ -4,7 +4,6 @@ import {CacheStrategy} from "./cache/Cache"
|
|
|
4
4
|
import {SourceHash} from "./SourceHash"
|
|
5
5
|
import {Source, SourceData} from "./Source"
|
|
6
6
|
import {Project} from "./Project"
|
|
7
|
-
import {Command} from "commander"
|
|
8
7
|
|
|
9
8
|
export declare class Stone<T extends StoneConfig> {
|
|
10
9
|
constructor(config: T)
|
|
@@ -25,12 +24,13 @@ export declare class Stone<T extends StoneConfig> {
|
|
|
25
24
|
protected initConfig(): void
|
|
26
25
|
|
|
27
26
|
/**
|
|
28
|
-
Override this to register commands.
|
|
27
|
+
Override this to register commands via `this.project.addCommand`.
|
|
29
28
|
*/
|
|
30
|
-
protected
|
|
29
|
+
protected addCommands(): void
|
|
31
30
|
|
|
32
31
|
/**
|
|
33
|
-
|
|
32
|
+
* **Do not override.**
|
|
33
|
+
* Get Source for this stone. Goes through the cache.
|
|
34
34
|
*/
|
|
35
35
|
getSource(): Promise<Source>
|
|
36
36
|
|
|
@@ -40,6 +40,7 @@ export declare class Stone<T extends StoneConfig> {
|
|
|
40
40
|
getHash(): Promise<SourceHash>
|
|
41
41
|
|
|
42
42
|
/**
|
|
43
|
+
* **Do not override.**
|
|
43
44
|
* Generates new Source. Used by the cache when needed.
|
|
44
45
|
* Hash passed should be the same as is this stone's current one. Passed in as optimization.
|
|
45
46
|
*/
|
|
@@ -51,6 +52,7 @@ export declare class Stone<T extends StoneConfig> {
|
|
|
51
52
|
protected generateHash(): Promise<SourceHash>
|
|
52
53
|
|
|
53
54
|
/**
|
|
55
|
+
* Abstract method.
|
|
54
56
|
* Function that actually generates the source. Passed hash is only non-null
|
|
55
57
|
* if `generateHash()` is implemented. It can be used for `CacheManager.getDir` and
|
|
56
58
|
* is passed mainly as optimization.
|
|
@@ -67,11 +69,25 @@ export declare class Stone<T extends StoneConfig> {
|
|
|
67
69
|
|
|
68
70
|
/**
|
|
69
71
|
* Caches this resource under supplied `path` as a single copy.
|
|
72
|
+
* @param path
|
|
70
73
|
* If `path` is a directory, stores the file(s) under that path, using their standard names.
|
|
71
74
|
* If `path` is a file and this stone generates only single data source, stores it under the supplied path.
|
|
72
|
-
*
|
|
75
|
+
* @param generate If true (default), the source is exported right away.
|
|
73
76
|
*/
|
|
74
77
|
setAbsolutePath(path: string, generate?: boolean): Promise<Source>
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Stores this resource in the supplied path, without changing cache strategy.
|
|
81
|
+
* @param path Path relative to this stone's project.
|
|
82
|
+
* Can be a directory or a file path (only if this resource generates single source).
|
|
83
|
+
*/
|
|
84
|
+
exportTo(path: string): Promise<any>
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Convenient function to get CWD-relative path from project-relative one.
|
|
88
|
+
* Useful for pure JS stones.
|
|
89
|
+
*/
|
|
90
|
+
cwdPath(path: string): string
|
|
75
91
|
protected get_cache(): CacheManager
|
|
76
92
|
toString(): string
|
|
77
93
|
}
|
package/bin/whet/Stone.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import {StoneId_Fields_} from "./magic/StoneId.js"
|
|
2
2
|
import {CacheStrategy, CacheDurability} from "./cache/Cache.js"
|
|
3
|
+
import {Utils} from "./Utils.js"
|
|
4
|
+
import {SourceId_Fields_, SourceId, RootDir} from "./SourceId.js"
|
|
3
5
|
import {SourceHash} from "./SourceHash.js"
|
|
4
6
|
import {Source} from "./Source.js"
|
|
5
7
|
import {Project} from "./Project.js"
|
|
6
8
|
import {Log} from "./Log.js"
|
|
7
|
-
import
|
|
8
|
-
import {Path} from "../haxe/io/Path.js"
|
|
9
|
+
import * as Path from "path"
|
|
9
10
|
import {Register} from "../genes/Register.js"
|
|
11
|
+
import {StringTools} from "../StringTools.js"
|
|
10
12
|
import {HxOverrides} from "../HxOverrides.js"
|
|
11
13
|
|
|
12
14
|
const $global = Register.$global
|
|
@@ -15,22 +17,20 @@ export const Stone = Register.global("$hxClasses")["whet.Stone"] =
|
|
|
15
17
|
class Stone extends Register.inherits() {
|
|
16
18
|
new(config) {
|
|
17
19
|
this.ignoreFileHash = false;
|
|
18
|
-
|
|
19
|
-
Log.log(10, ...["Instantiating new Stone.", {"type": c.__name__}]);
|
|
20
|
+
Log.log(10, ...["Instantiating new Stone.", {"type": StoneId_Fields_.getTypeName(this)}]);
|
|
20
21
|
if (config == null) {
|
|
21
22
|
throw new Error("Config must be supplied.");
|
|
22
23
|
};
|
|
23
24
|
this.config = config;
|
|
24
|
-
this.initConfig();
|
|
25
|
-
this.id = (config.id != null) ? StoneId_Fields_.makeStoneId(config.id) : StoneId_Fields_.makeStoneId(this);
|
|
26
25
|
this.project = (config.project != null) ? config.project : Project.projects[Project.projects.length - 1];
|
|
27
26
|
if (this.project == null) {
|
|
28
27
|
throw new Error("Did not find a project. Create one before creating stones.");
|
|
29
28
|
};
|
|
29
|
+
this.project.stones.push(this);
|
|
30
|
+
this.initConfig();
|
|
31
|
+
this.id = (config.id != null) ? StoneId_Fields_.makeStoneId(config.id) : StoneId_Fields_.makeStoneId(this);
|
|
30
32
|
this.cacheStrategy = (config.cacheStrategy == null) ? this.project.cache.defaultStrategy : config.cacheStrategy;
|
|
31
|
-
|
|
32
|
-
var _g1 = this.getCommands();
|
|
33
|
-
while (_g < _g1.length) this.project.addCommand(_g1[_g++], this);
|
|
33
|
+
this.addCommands();
|
|
34
34
|
}
|
|
35
35
|
get cache() {
|
|
36
36
|
return this.get_cache()
|
|
@@ -43,14 +43,14 @@ class Stone extends Register.inherits() {
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
/**
|
|
46
|
-
Override this to register commands.
|
|
46
|
+
Override this to register commands via `this.project.addCommand`.
|
|
47
47
|
*/
|
|
48
|
-
|
|
49
|
-
return [];
|
|
48
|
+
addCommands() {
|
|
50
49
|
}
|
|
51
50
|
|
|
52
51
|
/**
|
|
53
|
-
|
|
52
|
+
* **Do not override.**
|
|
53
|
+
* Get Source for this stone. Goes through the cache.
|
|
54
54
|
*/
|
|
55
55
|
getSource() {
|
|
56
56
|
Log.log(20, ...["Getting source.", {"stone": this}]);
|
|
@@ -75,6 +75,7 @@ class Stone extends Register.inherits() {
|
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
/**
|
|
78
|
+
* **Do not override.**
|
|
78
79
|
* Generates new Source. Used by the cache when needed.
|
|
79
80
|
* Hash passed should be the same as is this stone's current one. Passed in as optimization.
|
|
80
81
|
*/
|
|
@@ -130,28 +131,72 @@ class Stone extends Register.inherits() {
|
|
|
130
131
|
|
|
131
132
|
/**
|
|
132
133
|
* Caches this resource under supplied `path` as a single copy.
|
|
134
|
+
* @param path
|
|
133
135
|
* If `path` is a directory, stores the file(s) under that path, using their standard names.
|
|
134
136
|
* If `path` is a file and this stone generates only single data source, stores it under the supplied path.
|
|
135
|
-
*
|
|
137
|
+
* @param generate If true (default), the source is exported right away.
|
|
136
138
|
*/
|
|
137
139
|
setAbsolutePath(path, generate) {
|
|
138
140
|
if (generate == null) {
|
|
139
141
|
generate = true;
|
|
140
142
|
};
|
|
141
|
-
var
|
|
142
|
-
|
|
143
|
+
var s = path;
|
|
144
|
+
s = Path.posix.normalize((path.length > 1 && SourceId_Fields_.startsWithSlash(path)) ? HxOverrides.substr(path, 1, null) : path);
|
|
145
|
+
s = StringTools.replace(s, "\\", "/");
|
|
146
|
+
this.cacheStrategy = CacheStrategy.AbsolutePath((SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s, CacheDurability.LimitCountByAge(1));
|
|
143
147
|
if (generate) {
|
|
144
148
|
return this.getSource();
|
|
145
149
|
} else {
|
|
146
150
|
return Promise.resolve(null);
|
|
147
151
|
};
|
|
148
152
|
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Stores this resource in the supplied path, without changing cache strategy.
|
|
156
|
+
* @param path Path relative to this stone's project.
|
|
157
|
+
* Can be a directory or a file path (only if this resource generates single source).
|
|
158
|
+
*/
|
|
159
|
+
exportTo(path) {
|
|
160
|
+
var _gthis = this;
|
|
161
|
+
Log.log(30, ...["Exporting file(s).", {"path": path, "stone": this}]);
|
|
162
|
+
var s = path;
|
|
163
|
+
s = Path.posix.normalize((path.length > 1 && SourceId_Fields_.startsWithSlash(path)) ? HxOverrides.substr(path, 1, null) : path);
|
|
164
|
+
s = StringTools.replace(s, "\\", "/");
|
|
165
|
+
var pathId = (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
|
|
166
|
+
var isDir = SourceId_Fields_.endsWithSlash(pathId);
|
|
167
|
+
return this.getSource().then(function (src) {
|
|
168
|
+
if (src.data.length > 1 && !isDir) {
|
|
169
|
+
throw new Error("Path is not a directory for multiple source export.");
|
|
170
|
+
};
|
|
171
|
+
var _g = [];
|
|
172
|
+
var _g1 = 0;
|
|
173
|
+
var _g2 = src.data;
|
|
174
|
+
while (_g1 < _g2.length) {
|
|
175
|
+
var data = _g2[_g1];
|
|
176
|
+
++_g1;
|
|
177
|
+
var id = (isDir) ? SourceId.getPutInDir(data.id, pathId) : pathId;
|
|
178
|
+
var root = RootDir.fromProject(_gthis.project);
|
|
179
|
+
if (id.charAt(0) != "/") {
|
|
180
|
+
throw new Error("Badly formed SourceId.");
|
|
181
|
+
};
|
|
182
|
+
_g.push(Utils.saveBytes(Path.posix.join(".", root, ".", id), data.data));
|
|
183
|
+
};
|
|
184
|
+
return Promise.all(_g);
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Convenient function to get CWD-relative path from project-relative one.
|
|
190
|
+
* Useful for pure JS stones.
|
|
191
|
+
*/
|
|
192
|
+
cwdPath(path) {
|
|
193
|
+
return Path.join("./", this.project.rootDir, path);
|
|
194
|
+
}
|
|
149
195
|
get_cache() {
|
|
150
196
|
return this.project.cache;
|
|
151
197
|
}
|
|
152
198
|
toString() {
|
|
153
|
-
|
|
154
|
-
return "" + this.id + ":" + c.__name__;
|
|
199
|
+
return "" + this.id + ":" + StoneId_Fields_.getTypeName(this);
|
|
155
200
|
}
|
|
156
201
|
static get __name__() {
|
|
157
202
|
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,5 +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>
|
|
16
|
-
|
|
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[]>
|
|
17
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,7 +73,14 @@ class Utils {
|
|
|
62
73
|
});
|
|
63
74
|
});
|
|
64
75
|
}
|
|
65
|
-
|
|
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
|
+
};
|
|
66
84
|
return new Promise(function (res, rej) {
|
|
67
85
|
var result = [];
|
|
68
86
|
Fs.readdir(dir, { withFileTypes : true}, function(err,files) {
|
|
@@ -76,7 +94,9 @@ class Utils {
|
|
|
76
94
|
++_g;
|
|
77
95
|
var path = Path.join(dir,file.name);
|
|
78
96
|
if(file.isDirectory()) {
|
|
79
|
-
|
|
97
|
+
if(recursive) {
|
|
98
|
+
otherDirs.push(Utils.listDirectoryFiles(path,true));
|
|
99
|
+
}
|
|
80
100
|
} else {
|
|
81
101
|
result.push(path);
|
|
82
102
|
}
|
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.7", "-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
|
};
|
|
@@ -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;
|
|
@@ -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,15 +84,14 @@ 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) {
|
|
@@ -128,18 +124,23 @@ class BaseCache extends Register.inherits() {
|
|
|
128
124
|
};
|
|
129
125
|
var filenames = this.getExistingDirs(stone);
|
|
130
126
|
var maxNum = (filenames != null) ? Lambda.fold(filenames, function (fn, num) {
|
|
131
|
-
var s =
|
|
132
|
-
|
|
133
|
-
|
|
127
|
+
var s = fn.substring(0, fn.lastIndexOf("/") + 1);
|
|
128
|
+
s = Path.posix.normalize((s.length > 1 && SourceId_Fields_.startsWithSlash(s)) ? HxOverrides.substr(s, 1, null) : s);
|
|
129
|
+
s = StringTools.replace(s, "\\", "/");
|
|
130
|
+
var this1 = (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
|
|
134
131
|
var root = _gthis.rootDir;
|
|
135
|
-
|
|
132
|
+
if (this1.charAt(0) != "/") {
|
|
133
|
+
throw new Error("Badly formed SourceId.");
|
|
134
|
+
};
|
|
135
|
+
var parts = Path.posix.join(".", root, ".", this1).split("/");
|
|
136
136
|
var name = (parts.length > 1) ? parts[parts.length - 2] : "";
|
|
137
137
|
return Math.max(num, (name.charAt(0) == "v") ? Std.parseInt(HxOverrides.substr(name, 1, null)) : 0);
|
|
138
138
|
}, 0) : 0;
|
|
139
139
|
++maxNum;
|
|
140
140
|
var s = "v" + maxNum + "/";
|
|
141
|
-
|
|
142
|
-
|
|
141
|
+
s = Path.posix.normalize((s.length > 1 && SourceId_Fields_.startsWithSlash(s)) ? HxOverrides.substr(s, 1, null) : s);
|
|
142
|
+
s = StringTools.replace(s, "\\", "/");
|
|
143
|
+
return SourceId.getPutInDir((SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s, baseDir);
|
|
143
144
|
}
|
|
144
145
|
checkDurability(stone, values, durability, useIndex, ageIndex) {
|
|
145
146
|
Log.log(20, ...["Checking durability.", {"stone": stone, "durability": Std.string(durability)}]);
|
|
@@ -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
|
/**
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import {MemoryCache} from "./MemoryCache.js"
|
|
2
2
|
import {FileCache} from "./FileCache.js"
|
|
3
|
-
import {CacheStrategy, DurabilityCheck} from "./Cache.js"
|
|
4
|
-
import {RootDir, SourceId} from "../SourceId.js"
|
|
3
|
+
import {CacheStrategy, CacheDurability, DurabilityCheck} from "./Cache.js"
|
|
4
|
+
import {RootDir, SourceId_Fields_, SourceId} from "../SourceId.js"
|
|
5
5
|
import {Log} from "../Log.js"
|
|
6
|
-
import
|
|
6
|
+
import * as Path from "path"
|
|
7
7
|
import {Register} from "../../genes/Register.js"
|
|
8
|
+
import {StringTools} from "../../StringTools.js"
|
|
8
9
|
import {HxOverrides} from "../../HxOverrides.js"
|
|
9
10
|
|
|
10
11
|
const $global = Register.$global
|
|
@@ -12,6 +13,7 @@ const $global = Register.$global
|
|
|
12
13
|
export const CacheManager = Register.global("$hxClasses")["whet.cache.CacheManager"] =
|
|
13
14
|
class CacheManager extends Register.inherits() {
|
|
14
15
|
new(project) {
|
|
16
|
+
this.defaultFileStrategy = CacheStrategy.InFile(CacheDurability.Any([CacheDurability.LimitCountByLastUse(1), CacheDurability.All([CacheDurability.MaxAge(86400), CacheDurability.LimitCountByLastUse(5)])]), DurabilityCheck.AllOnUse);
|
|
15
17
|
this.fileCache = null;
|
|
16
18
|
this.memCache = null;
|
|
17
19
|
this.defaultStrategy = CacheStrategy.None;
|
|
@@ -52,8 +54,9 @@ class CacheManager extends Register.inherits() {
|
|
|
52
54
|
*/
|
|
53
55
|
getDir(stone, hash) {
|
|
54
56
|
var s = stone.id + "/";
|
|
55
|
-
|
|
56
|
-
|
|
57
|
+
s = Path.posix.normalize((s.length > 1 && SourceId_Fields_.startsWithSlash(s)) ? HxOverrides.substr(s, 1, null) : s);
|
|
58
|
+
s = StringTools.replace(s, "\\", "/");
|
|
59
|
+
var baseDir = (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
|
|
57
60
|
var tmp;
|
|
58
61
|
switch (stone.cacheStrategy._hx_index) {
|
|
59
62
|
case 0:
|
|
@@ -67,11 +70,15 @@ class CacheManager extends Register.inherits() {
|
|
|
67
70
|
|
|
68
71
|
};
|
|
69
72
|
if (tmp) {
|
|
70
|
-
var
|
|
71
|
-
|
|
73
|
+
var s = ".temp/";
|
|
74
|
+
s = Path.posix.normalize((".temp/".length > 1 && SourceId_Fields_.startsWithSlash(".temp/")) ? HxOverrides.substr(".temp/", 1, null) : ".temp/");
|
|
75
|
+
s = StringTools.replace(s, "\\", "/");
|
|
76
|
+
baseDir = SourceId.getPutInDir(baseDir, (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s);
|
|
72
77
|
};
|
|
73
|
-
var
|
|
74
|
-
|
|
78
|
+
var s = ".whet/";
|
|
79
|
+
s = Path.posix.normalize((".whet/".length > 1 && SourceId_Fields_.startsWithSlash(".whet/")) ? HxOverrides.substr(".whet/", 1, null) : ".whet/");
|
|
80
|
+
s = StringTools.replace(s, "\\", "/");
|
|
81
|
+
baseDir = SourceId.getPutInDir(baseDir, (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s);
|
|
75
82
|
var id;
|
|
76
83
|
var _g = stone.cacheStrategy;
|
|
77
84
|
switch (_g._hx_index) {
|
|
@@ -85,9 +92,11 @@ class CacheManager extends Register.inherits() {
|
|
|
85
92
|
id = this.fileCache.getUniqueDir(stone, baseDir, hash);
|
|
86
93
|
break
|
|
87
94
|
case 3:
|
|
88
|
-
var
|
|
89
|
-
var
|
|
90
|
-
|
|
95
|
+
var _g1 = _g.path;
|
|
96
|
+
var s = _g1.substring(0, _g1.lastIndexOf("/") + 1);
|
|
97
|
+
s = Path.posix.normalize((s.length > 1 && SourceId_Fields_.startsWithSlash(s)) ? HxOverrides.substr(s, 1, null) : s);
|
|
98
|
+
s = StringTools.replace(s, "\\", "/");
|
|
99
|
+
id = (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
|
|
91
100
|
break
|
|
92
101
|
|
|
93
102
|
};
|