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
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,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.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
|
};
|
|
@@ -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);
|
|
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);
|
|
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,17 +1,18 @@
|
|
|
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 {
|
|
8
|
+
import {StringTools} from "../../StringTools.js"
|
|
9
9
|
|
|
10
10
|
const $global = Register.$global
|
|
11
11
|
|
|
12
12
|
export const CacheManager = Register.global("$hxClasses")["whet.cache.CacheManager"] =
|
|
13
13
|
class CacheManager extends Register.inherits() {
|
|
14
14
|
new(project) {
|
|
15
|
+
this.defaultFileStrategy = CacheStrategy.InFile(CacheDurability.Any([CacheDurability.LimitCountByLastUse(1), CacheDurability.All([CacheDurability.MaxAge(86400), CacheDurability.LimitCountByLastUse(5)])]), DurabilityCheck.AllOnUse);
|
|
15
16
|
this.fileCache = null;
|
|
16
17
|
this.memCache = null;
|
|
17
18
|
this.defaultStrategy = CacheStrategy.None;
|
|
@@ -52,8 +53,9 @@ class CacheManager extends Register.inherits() {
|
|
|
52
53
|
*/
|
|
53
54
|
getDir(stone, hash) {
|
|
54
55
|
var s = stone.id + "/";
|
|
55
|
-
|
|
56
|
-
|
|
56
|
+
s = Path.posix.normalize(s);
|
|
57
|
+
s = StringTools.replace(s, "\\", "/");
|
|
58
|
+
var baseDir = (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
|
|
57
59
|
var tmp;
|
|
58
60
|
switch (stone.cacheStrategy._hx_index) {
|
|
59
61
|
case 0:
|
|
@@ -67,11 +69,15 @@ class CacheManager extends Register.inherits() {
|
|
|
67
69
|
|
|
68
70
|
};
|
|
69
71
|
if (tmp) {
|
|
70
|
-
var
|
|
71
|
-
|
|
72
|
+
var s = ".temp/";
|
|
73
|
+
s = Path.posix.normalize(".temp/");
|
|
74
|
+
s = StringTools.replace(s, "\\", "/");
|
|
75
|
+
baseDir = SourceId.getPutInDir(baseDir, (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s);
|
|
72
76
|
};
|
|
73
|
-
var
|
|
74
|
-
|
|
77
|
+
var s = ".whet/";
|
|
78
|
+
s = Path.posix.normalize(".whet/");
|
|
79
|
+
s = StringTools.replace(s, "\\", "/");
|
|
80
|
+
baseDir = SourceId.getPutInDir(baseDir, (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s);
|
|
75
81
|
var id;
|
|
76
82
|
var _g = stone.cacheStrategy;
|
|
77
83
|
switch (_g._hx_index) {
|
|
@@ -85,9 +91,11 @@ class CacheManager extends Register.inherits() {
|
|
|
85
91
|
id = this.fileCache.getUniqueDir(stone, baseDir, hash);
|
|
86
92
|
break
|
|
87
93
|
case 3:
|
|
88
|
-
var
|
|
89
|
-
var
|
|
90
|
-
|
|
94
|
+
var _g1 = _g.path;
|
|
95
|
+
var s = _g1.substring(0, _g1.lastIndexOf("/") + 1);
|
|
96
|
+
s = Path.posix.normalize(s);
|
|
97
|
+
s = StringTools.replace(s, "\\", "/");
|
|
98
|
+
id = (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
|
|
91
99
|
break
|
|
92
100
|
|
|
93
101
|
};
|