whet 0.0.1

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.
Files changed (177) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +47 -0
  3. package/bin/HxOverrides.d.ts +8 -0
  4. package/bin/HxOverrides.js +54 -0
  5. package/bin/Lambda.d.ts +86 -0
  6. package/bin/Lambda.js +141 -0
  7. package/bin/Map.d.ts +5 -0
  8. package/bin/Reflect.d.ts +19 -0
  9. package/bin/Reflect.js +41 -0
  10. package/bin/Std.d.ts +49 -0
  11. package/bin/Std.js +96 -0
  12. package/bin/StdTypes.d.ts +57 -0
  13. package/bin/StringTools.d.ts +23 -0
  14. package/bin/StringTools.js +36 -0
  15. package/bin/commander/AddHelpTextContext.d.ts +6 -0
  16. package/bin/commander/AddHelpTextPosition.d.ts +2 -0
  17. package/bin/commander/CommandOptions.d.ts +6 -0
  18. package/bin/commander/ErrorOptions.d.ts +11 -0
  19. package/bin/commander/ExecutableCommandOptions.d.ts +7 -0
  20. package/bin/commander/HelpContext.d.ts +4 -0
  21. package/bin/commander/HookEvent.d.ts +2 -0
  22. package/bin/commander/OptionValueSource.d.ts +2 -0
  23. package/bin/commander/OutputConfiguration.d.ts +8 -0
  24. package/bin/commander/ParseOptions.d.ts +4 -0
  25. package/bin/commander/ParseOptionsResult.d.ts +5 -0
  26. package/bin/genes/Register.d.ts +15 -0
  27. package/bin/genes/Register.js +107 -0
  28. package/bin/genes/util/EsMap.d.ts +12 -0
  29. package/bin/genes/util/EsMap.js +51 -0
  30. package/bin/haxe/Constraints.d.ts +8 -0
  31. package/bin/haxe/Constraints.js +5 -0
  32. package/bin/haxe/Exception.d.ts +66 -0
  33. package/bin/haxe/Exception.js +88 -0
  34. package/bin/haxe/NativeStackTrace.d.ts +7 -0
  35. package/bin/haxe/PosInfos.d.ts +19 -0
  36. package/bin/haxe/Rest.d.ts +2 -0
  37. package/bin/haxe/ValueException.d.ts +24 -0
  38. package/bin/haxe/ValueException.js +36 -0
  39. package/bin/haxe/crypto/Crc32.d.ts +12 -0
  40. package/bin/haxe/crypto/Crc32.js +40 -0
  41. package/bin/haxe/ds/List.d.ts +31 -0
  42. package/bin/haxe/ds/List.js +55 -0
  43. package/bin/haxe/ds/ObjectMap.d.ts +7 -0
  44. package/bin/haxe/ds/ObjectMap.js +25 -0
  45. package/bin/haxe/ds/StringMap.d.ts +6 -0
  46. package/bin/haxe/ds/StringMap.js +25 -0
  47. package/bin/haxe/exceptions/NotImplementedException.d.ts +10 -0
  48. package/bin/haxe/exceptions/NotImplementedException.js +27 -0
  49. package/bin/haxe/exceptions/PosException.d.ts +19 -0
  50. package/bin/haxe/exceptions/PosException.js +36 -0
  51. package/bin/haxe/extern/Rest.d.ts +11 -0
  52. package/bin/haxe/io/ArrayBufferView.d.ts +2 -0
  53. package/bin/haxe/io/Bytes.d.ts +19 -0
  54. package/bin/haxe/io/Bytes.js +78 -0
  55. package/bin/haxe/io/BytesBuffer.d.ts +19 -0
  56. package/bin/haxe/io/BytesBuffer.js +67 -0
  57. package/bin/haxe/io/BytesData.d.ts +2 -0
  58. package/bin/haxe/io/BytesOutput.d.ts +18 -0
  59. package/bin/haxe/io/BytesOutput.js +39 -0
  60. package/bin/haxe/io/Encoding.d.ts +20 -0
  61. package/bin/haxe/io/Encoding.js +20 -0
  62. package/bin/haxe/io/Error.d.ts +35 -0
  63. package/bin/haxe/io/Error.js +31 -0
  64. package/bin/haxe/io/Output.d.ts +63 -0
  65. package/bin/haxe/io/Output.js +126 -0
  66. package/bin/haxe/io/Path.d.ts +109 -0
  67. package/bin/haxe/io/Path.js +217 -0
  68. package/bin/haxe/io/UInt8Array.d.ts +2 -0
  69. package/bin/haxe/iterators/ArrayIterator.d.ts +19 -0
  70. package/bin/haxe/iterators/ArrayIterator.js +35 -0
  71. package/bin/haxe/macro/Expr.d.ts +331 -0
  72. package/bin/haxe/macro/Type.d.ts +609 -0
  73. package/bin/haxe/zip/Compress.d.ts +5 -0
  74. package/bin/haxe/zip/Compress.js +21 -0
  75. package/bin/haxe/zip/Entry.d.ts +27 -0
  76. package/bin/haxe/zip/Entry.js +15 -0
  77. package/bin/haxe/zip/Tools.d.ts +5 -0
  78. package/bin/haxe/zip/Tools.js +24 -0
  79. package/bin/haxe/zip/Writer.d.ts +22 -0
  80. package/bin/haxe/zip/Writer.js +149 -0
  81. package/bin/js/Boot.d.ts +18 -0
  82. package/bin/js/Boot.js +225 -0
  83. package/bin/js/Node.d.ts +6 -0
  84. package/bin/js/lib/ArrayBuffer.d.ts +4 -0
  85. package/bin/js/lib/ArrayBuffer.js +24 -0
  86. package/bin/js/lib/Iterator.d.ts +23 -0
  87. package/bin/js/lib/Map.d.ts +2 -0
  88. package/bin/js/lib/Object.d.ts +82 -0
  89. package/bin/js/lib/Promise.d.ts +10 -0
  90. package/bin/js/lib/intl/NumberFormat.d.ts +114 -0
  91. package/bin/js/node/Buffer.d.ts +3 -0
  92. package/bin/js/node/ChildProcess.d.ts +424 -0
  93. package/bin/js/node/Crypto.d.ts +21 -0
  94. package/bin/js/node/Dns.d.ts +57 -0
  95. package/bin/js/node/Fs.d.ts +308 -0
  96. package/bin/js/node/Http.d.ts +114 -0
  97. package/bin/js/node/Https.d.ts +330 -0
  98. package/bin/js/node/Iterator.d.ts +5 -0
  99. package/bin/js/node/Path.d.ts +44 -0
  100. package/bin/js/node/Process.d.ts +6 -0
  101. package/bin/js/node/Tls.d.ts +304 -0
  102. package/bin/js/node/Url.d.ts +126 -0
  103. package/bin/js/node/Util.d.ts +115 -0
  104. package/bin/js/node/Zlib.d.ts +29 -0
  105. package/bin/js/node/buffer/Buffer.d.ts +23 -0
  106. package/bin/js/node/buffer/Buffer.js +24 -0
  107. package/bin/js/node/child_process/ChildProcess.d.ts +11 -0
  108. package/bin/js/node/console/Console.d.ts +26 -0
  109. package/bin/js/node/http/Agent.d.ts +40 -0
  110. package/bin/js/node/http/ClientRequest.d.ts +10 -0
  111. package/bin/js/node/https/Agent.d.ts +50 -0
  112. package/bin/js/node/net/Server.d.ts +22 -0
  113. package/bin/js/node/net/Socket.d.ts +101 -0
  114. package/bin/js/node/stream/Duplex.d.ts +86 -0
  115. package/bin/js/node/stream/Readable.d.ts +41 -0
  116. package/bin/js/node/stream/Transform.d.ts +92 -0
  117. package/bin/js/node/stream/Writable.d.ts +57 -0
  118. package/bin/js/node/tls/SecureContext.d.ts +74 -0
  119. package/bin/js/node/tls/TLSSocket.d.ts +47 -0
  120. package/bin/ts/Undefined.d.ts +5 -0
  121. package/bin/whet/Log.d.ts +16 -0
  122. package/bin/whet/Log.js +106 -0
  123. package/bin/whet/Project.d.ts +33 -0
  124. package/bin/whet/Project.js +71 -0
  125. package/bin/whet/Source.d.ts +51 -0
  126. package/bin/whet/Source.js +136 -0
  127. package/bin/whet/SourceHash.d.ts +15 -0
  128. package/bin/whet/SourceHash.js +68 -0
  129. package/bin/whet/SourceId.d.ts +10 -0
  130. package/bin/whet/SourceId.js +74 -0
  131. package/bin/whet/Stone.d.ts +88 -0
  132. package/bin/whet/Stone.js +157 -0
  133. package/bin/whet/Utils.d.ts +16 -0
  134. package/bin/whet/Utils.js +72 -0
  135. package/bin/whet/Whet.d.ts +4 -0
  136. package/bin/whet/Whet.js +117 -0
  137. package/bin/whet/cache/BaseCache.d.ts +27 -0
  138. package/bin/whet/cache/BaseCache.js +210 -0
  139. package/bin/whet/cache/Cache.d.ts +72 -0
  140. package/bin/whet/cache/Cache.js +57 -0
  141. package/bin/whet/cache/CacheManager.d.ts +23 -0
  142. package/bin/whet/cache/CacheManager.js +103 -0
  143. package/bin/whet/cache/FileCache.d.ts +35 -0
  144. package/bin/whet/cache/FileCache.js +295 -0
  145. package/bin/whet/cache/MemoryCache.d.ts +12 -0
  146. package/bin/whet/cache/MemoryCache.js +58 -0
  147. package/bin/whet/magic/MaybeArray.d.ts +4 -0
  148. package/bin/whet/magic/MaybeArray.js +25 -0
  149. package/bin/whet/magic/RoutePathType.d.ts +9 -0
  150. package/bin/whet/magic/RoutePathType.js +48 -0
  151. package/bin/whet/magic/RouteType.d.ts +12 -0
  152. package/bin/whet/magic/RouteType.js +70 -0
  153. package/bin/whet/magic/StoneId.d.ts +5 -0
  154. package/bin/whet/magic/StoneId.js +32 -0
  155. package/bin/whet/route/Route.d.ts +15 -0
  156. package/bin/whet/route/Route.js +81 -0
  157. package/bin/whet/route/RouteResult.d.ts +22 -0
  158. package/bin/whet/route/RouteResult.js +25 -0
  159. package/bin/whet/route/Router.d.ts +33 -0
  160. package/bin/whet/route/Router.js +224 -0
  161. package/bin/whet/stones/Files.d.ts +28 -0
  162. package/bin/whet/stones/Files.js +86 -0
  163. package/bin/whet/stones/JsonStone.d.ts +33 -0
  164. package/bin/whet/stones/JsonStone.js +117 -0
  165. package/bin/whet/stones/RemoteFile.d.ts +28 -0
  166. package/bin/whet/stones/RemoteFile.js +71 -0
  167. package/bin/whet/stones/Server.d.ts +42 -0
  168. package/bin/whet/stones/Server.js +113 -0
  169. package/bin/whet/stones/Zip.d.ts +30 -0
  170. package/bin/whet/stones/Zip.js +111 -0
  171. package/bin/whet/stones/haxe/HaxeBuild.d.ts +34 -0
  172. package/bin/whet/stones/haxe/HaxeBuild.js +89 -0
  173. package/bin/whet/stones/haxe/Hxml.d.ts +102 -0
  174. package/bin/whet/stones/haxe/Hxml.js +348 -0
  175. package/bin/whet.d.ts +20 -0
  176. package/bin/whet.js +18 -0
  177. package/package.json +32 -0
@@ -0,0 +1,136 @@
1
+ import {Utils} from "./Utils.js"
2
+ import {SourceId, RootDir} from "./SourceId.js"
3
+ import {SourceHash} from "./SourceHash.js"
4
+ import {Log} from "./Log.js"
5
+ import {Register} from "../genes/Register.js"
6
+ import * as Fs from "fs"
7
+ import {Buffer} from "buffer"
8
+ import {Lambda} from "../Lambda.js"
9
+
10
+ const $global = Register.$global
11
+
12
+ export const Source = Register.global("$hxClasses")["whet.Source"] =
13
+ class Source extends Register.inherits() {
14
+ new(data, hash, origin, ctime) {
15
+ this.dirPath = null;
16
+ this.data = data;
17
+ this.hash = hash;
18
+ this.origin = origin;
19
+ this.ctime = ctime;
20
+ var _g = 0;
21
+ while (_g < data.length) data[_g++].source = this;
22
+ }
23
+ tryDirPath() {
24
+ return this.dirPath;
25
+ }
26
+
27
+ /**
28
+ * Returns a directory path where this source data is stored.
29
+ * If none exists yet, generates a usable path through cache.
30
+ */
31
+ getDirPath() {
32
+ if (this.dirPath == null) {
33
+ this.dirPath = this.origin.project.cache.getDir(this.origin, this.hash);
34
+ };
35
+ return this.dirPath;
36
+ }
37
+
38
+ /**
39
+ * Returns first result if `id` is null, or one equals to it.
40
+ */
41
+ get(id) {
42
+ if (id == null) {
43
+ return this.data[0];
44
+ } else {
45
+ return Lambda.find(this.data, function (entry) {
46
+ return entry.id == id;
47
+ });
48
+ };
49
+ }
50
+ static get __name__() {
51
+ return "whet.Source"
52
+ }
53
+ get __class__() {
54
+ return Source
55
+ }
56
+ }
57
+
58
+
59
+ export const SourceData = Register.global("$hxClasses")["whet.SourceData"] =
60
+ class SourceData extends Register.inherits() {
61
+ new(id, data) {
62
+ this.filePath = null;
63
+ this.filePathId = null;
64
+ this.data = data;
65
+ this.id = id;
66
+ this.hash = SourceHash.fromBytes(data);
67
+ }
68
+
69
+ /**
70
+ Same as `getFilePath` but relative to project, not CWD.
71
+ */
72
+ getFilePathId(idOverride) {
73
+ var _gthis = this;
74
+ if (this.filePathId == null) {
75
+ return this.getFilePath(idOverride).then(function (_) {
76
+ return _gthis.filePathId;
77
+ });
78
+ } else {
79
+ return Promise.resolve(this.filePathId);
80
+ };
81
+ }
82
+
83
+ /**
84
+ Path to a file for this source, relative to CWD.
85
+ */
86
+ getFilePath(idOverride) {
87
+ var _gthis = this;
88
+ if (this.filePath == null) {
89
+ if (this.source == null) {
90
+ new Error("Data without source.");
91
+ };
92
+ var dir = this.source.getDirPath();
93
+ this.filePathId = SourceId.getPutInDir((idOverride != null) ? idOverride : this.id, dir);
94
+ var this1 = this.filePathId;
95
+ var root = RootDir.fromProject(this.source.origin.project);
96
+ this.filePath = (root.length == 1) ? this1.substring(1) : root.substring(1, root.length - 1) + this1;
97
+ return Utils.saveBytes(this.filePath, this.data).then(function (_) {
98
+ return _gthis.filePath;
99
+ });
100
+ } else {
101
+ return Promise.resolve(this.filePath);
102
+ };
103
+ }
104
+
105
+ /**
106
+ * `path` is the actual cwd-relative path. `pathId` is the project-relative source Id.
107
+ */
108
+ static fromFile(id, path, pathId) {
109
+ return new Promise(function (res, rej) {
110
+ Fs.readFile(path, function (err, buffer) {
111
+ if (err != null) {
112
+ Log.log(50, ...["File does not exist.", {"id": id, "path": path}]);
113
+ res(null);
114
+ } else {
115
+ var source = SourceData.fromBytes(id, buffer);
116
+ source.filePath = path;
117
+ source.filePathId = pathId;
118
+ res(source);
119
+ };
120
+ });
121
+ });
122
+ }
123
+ static fromString(id, s) {
124
+ return SourceData.fromBytes(id, Buffer.from(s, "utf-8"));
125
+ }
126
+ static fromBytes(id, data) {
127
+ return new SourceData(id, data);
128
+ }
129
+ static get __name__() {
130
+ return "whet.SourceData"
131
+ }
132
+ get __class__() {
133
+ return SourceData
134
+ }
135
+ }
136
+
@@ -0,0 +1,15 @@
1
+ import {Buffer} from "buffer"
2
+
3
+ export declare class SourceHash {
4
+ protected constructor(bytes: Buffer)
5
+ protected bytes: Buffer
6
+ toString(): string
7
+ static EMPTY: SourceHash
8
+ static fromBytes(data: Buffer): SourceHash
9
+ static fromString(data: string): SourceHash
10
+ static add(a: SourceHash, b: SourceHash): SourceHash
11
+ static equals(a: SourceHash, b: SourceHash): boolean
12
+ static toHex(hash: SourceHash): string
13
+ static fromHex(hex: string): SourceHash
14
+ static merge(...hash: SourceHash[]): SourceHash
15
+ }
@@ -0,0 +1,68 @@
1
+ import {Register} from "../genes/Register.js"
2
+ import * as Crypto from "crypto"
3
+ import {Buffer} from "buffer"
4
+
5
+ const $global = Register.$global
6
+
7
+ export const SourceHash = Register.global("$hxClasses")["whet.SourceHash"] =
8
+ class SourceHash extends Register.inherits() {
9
+ new(bytes) {
10
+ this.bytes = bytes;
11
+ }
12
+ toString() {
13
+ return this.bytes.toString("hex");
14
+ }
15
+ static fromBytes(data) {
16
+ return new SourceHash(Crypto.createHash("sha256").update(data).digest());
17
+ }
18
+ static fromString(data) {
19
+ return SourceHash.fromBytes(Buffer.from(data));
20
+ }
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
+ static equals(a, b) {
28
+ if (a != null && b != null) {
29
+ return a.bytes.compare(b.bytes) == 0;
30
+ } else {
31
+ return false;
32
+ };
33
+ }
34
+ static toHex(hash) {
35
+ if (hash == null) {
36
+ return "";
37
+ } else {
38
+ return hash.toString();
39
+ };
40
+ }
41
+ static fromHex(hex) {
42
+ var hash = Buffer.from(hex, "hex");
43
+ if (hash.length != 32) {
44
+ return null;
45
+ } else {
46
+ return new SourceHash(hash);
47
+ };
48
+ }
49
+ static merge(...hash) {
50
+ if (hash.length == 0) {
51
+ return SourceHash.EMPTY;
52
+ };
53
+ var h = hash[0];
54
+ var _g = 1;
55
+ var _g1 = hash.length;
56
+ while (_g < _g1) h = SourceHash.add(h, hash[_g++]);
57
+ return h;
58
+ }
59
+ static get __name__() {
60
+ return "whet.SourceHash"
61
+ }
62
+ get __class__() {
63
+ return SourceHash
64
+ }
65
+ }
66
+
67
+
68
+ SourceHash.EMPTY = new SourceHash(Buffer.alloc(32))
@@ -0,0 +1,10 @@
1
+ import {Project} from "./Project"
2
+
3
+ export declare class SourceId {
4
+ static relativeTo($this: string, directory: string): string
5
+ static getPutInDir($this: string, dir: string): string
6
+ }
7
+
8
+ export declare class RootDir {
9
+ static fromProject(p: Project): string
10
+ }
@@ -0,0 +1,74 @@
1
+ import {Path} from "../haxe/io/Path.js"
2
+ import {Register} from "../genes/Register.js"
3
+ import {HxOverrides} from "../HxOverrides.js"
4
+
5
+ const $global = Register.$global
6
+
7
+ export const SourceId = Register.global("$hxClasses")["whet._SourceId.SourceId"] =
8
+ class SourceId {
9
+ static relativeTo(this1, directory) {
10
+ var norm = "/" + Path.normalize((directory.charAt(0) == "/") ? HxOverrides.substr(directory, 1, null) : directory);
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)) {
15
+ throw new Error("\"" + directory + "\" is not a directory.");
16
+ };
17
+ var tmp;
18
+ var s = Path.addTrailingSlash(Path.directory(this1));
19
+ var norm = "/" + Path.normalize((s.charAt(0) == "/") ? HxOverrides.substr(s, 1, null) : s);
20
+ tmp = ((s.lastIndexOf("/") == s.length - 1) ? Path.addTrailingSlash(norm) : norm).indexOf(directory) == 0;
21
+ if (tmp) {
22
+ return HxOverrides.substr(this1, directory.length - 1, null);
23
+ } else {
24
+ return null;
25
+ };
26
+ }
27
+ static getPutInDir(this1, dir) {
28
+ var norm = "/" + Path.normalize((dir.charAt(0) == "/") ? HxOverrides.substr(dir, 1, null) : dir);
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)) {
33
+ throw new Error("\"" + dir + "\" is not a directory.");
34
+ };
35
+ var norm = "/" + Path.normalize(("/".charAt(0) == "/") ? HxOverrides.substr("/", 1, null) : "/");
36
+ if (dir == (("/".lastIndexOf("/") == "/".length - 1) ? Path.addTrailingSlash(norm) : norm)) {
37
+ var norm = "/" + Path.normalize((this1.charAt(0) == "/") ? HxOverrides.substr(this1, 1, null) : this1);
38
+ if (this1.lastIndexOf("/") == this1.length - 1) {
39
+ return Path.addTrailingSlash(norm);
40
+ } else {
41
+ return norm;
42
+ };
43
+ } else {
44
+ var s = dir + this1;
45
+ var norm = "/" + Path.normalize((s.charAt(0) == "/") ? HxOverrides.substr(s, 1, null) : s);
46
+ if (s.lastIndexOf("/") == s.length - 1) {
47
+ return Path.addTrailingSlash(norm);
48
+ } else {
49
+ return norm;
50
+ };
51
+ };
52
+ }
53
+ static get __name__() {
54
+ return "whet._SourceId.SourceId_Impl_"
55
+ }
56
+ get __class__() {
57
+ return SourceId
58
+ }
59
+ }
60
+
61
+
62
+ export const RootDir = Register.global("$hxClasses")["whet._SourceId.RootDir"] =
63
+ class RootDir {
64
+ static fromProject(p) {
65
+ return p.rootDir;
66
+ }
67
+ static get __name__() {
68
+ return "whet._SourceId.RootDir_Impl_"
69
+ }
70
+ get __class__() {
71
+ return RootDir
72
+ }
73
+ }
74
+
@@ -0,0 +1,88 @@
1
+ import {StoneIdType} from "./magic/StoneId"
2
+ import {CacheStrategy} from "./cache/Cache"
3
+ import {SourceHash} from "./SourceHash"
4
+ import {Source, SourceData} from "./Source"
5
+ import {Project} from "./Project"
6
+ import {Command} from "commander"
7
+
8
+ export declare class Stone<T extends StoneConfig> {
9
+ constructor(config: T)
10
+ config: T
11
+
12
+ /**
13
+ If true, hash of a cached file (not `stone.getHash()` but actual file contents) won't be checked.
14
+ */
15
+ ignoreFileHash: boolean
16
+ id: string
17
+ cacheStrategy: CacheStrategy
18
+ project: Project
19
+
20
+ /**
21
+ Override this to set config defaults.
22
+ */
23
+ protected initConfig(): void
24
+
25
+ /**
26
+ Override this to register commands.
27
+ */
28
+ protected getCommands(): Command[]
29
+
30
+ /**
31
+ Get Source for this stone. Goes through the cache.
32
+ */
33
+ getSource(): Promise<Source>
34
+
35
+ /**
36
+ Hash of this stone with its current config. Defaults to hash of generated source.
37
+ */
38
+ getHash(): Promise<SourceHash>
39
+
40
+ /**
41
+ * Generates new Source. Used by the cache when needed.
42
+ * Hash passed should be the same as is this stone's current one. Passed in as optimization.
43
+ */
44
+ protected generateSource(hash: SourceHash): Promise<Source>
45
+
46
+ /**
47
+ * Optionally overridable hash generation as optimization.
48
+ */
49
+ protected generateHash(): Promise<SourceHash>
50
+
51
+ /**
52
+ * Function that actually generates the source. Passed hash is only non-null
53
+ * if `generateHash()` is implemented. It can be used for `CacheManager.getDir` and
54
+ * is passed mainly as optimization.
55
+ */
56
+ protected generate(hash: SourceHash): Promise<SourceData[]>
57
+
58
+ /**
59
+ * Returns a list of sources that this stone generates.
60
+ * Used by Router for finding the correct asset.
61
+ * Default implementation generates the sources to find their ids, but can be overriden
62
+ * to provide optimized implementation that would avoid generating assets we might not need.
63
+ */
64
+ list(): Promise<string[]>
65
+
66
+ /**
67
+ * Caches this resource under supplied `path` as a single copy.
68
+ * If `path` is a directory, stores the file(s) under that path, using their standard names.
69
+ * If `path` is a file and this stone generates only single data source, stores it under the supplied path.
70
+ * If `generate` is true, the source is exported right away.
71
+ */
72
+ setAbsolutePath(path: string, generate?: boolean): Promise<Source>
73
+ toString(): string
74
+ }
75
+
76
+ export type StoneConfig = {
77
+ cacheStrategy?: null | CacheStrategy,
78
+ /**
79
+ Defaults to the Stone's class name.
80
+ */
81
+ id?: null | StoneIdType,
82
+ /**
83
+ Defaults to the last instanced project.
84
+ */
85
+ project?: null | Project
86
+ }
87
+
88
+ export type AnyStone = Stone<any>
@@ -0,0 +1,157 @@
1
+ import {StoneId_Fields_} from "./magic/StoneId.js"
2
+ import {CacheStrategy, CacheDurability} from "./cache/Cache.js"
3
+ import {SourceHash} from "./SourceHash.js"
4
+ import {Source} from "./Source.js"
5
+ import {Project} from "./Project.js"
6
+ import {Log} from "./Log.js"
7
+ import {Boot} from "../js/Boot.js"
8
+ import {Path} from "../haxe/io/Path.js"
9
+ import {Register} from "../genes/Register.js"
10
+ import {HxOverrides} from "../HxOverrides.js"
11
+
12
+ const $global = Register.$global
13
+
14
+ export const Stone = Register.global("$hxClasses")["whet.Stone"] =
15
+ class Stone extends Register.inherits() {
16
+ new(config) {
17
+ this.ignoreFileHash = false;
18
+ var c = Boot.getClass(this);
19
+ Log.log(10, ...["Instantiating new Stone.", {"type": c.__name__}]);
20
+ if (config == null) {
21
+ throw new Error("Config must be supplied.");
22
+ };
23
+ this.config = config;
24
+ this.initConfig();
25
+ this.id = (config.id != null) ? StoneId_Fields_.makeStoneId(config.id) : StoneId_Fields_.makeStoneId(this);
26
+ this.project = (config.project != null) ? config.project : Project.projects[Project.projects.length - 1];
27
+ if (this.project == null) {
28
+ throw new Error("Did not find a project. Create one before creating stones.");
29
+ };
30
+ this.cacheStrategy = (config.cacheStrategy == null) ? this.project.cache.defaultStrategy : config.cacheStrategy;
31
+ var _g = 0;
32
+ var _g1 = this.getCommands();
33
+ while (_g < _g1.length) this.project.addCommand(_g1[_g++], this);
34
+ }
35
+
36
+ /**
37
+ Override this to set config defaults.
38
+ */
39
+ initConfig() {
40
+ }
41
+
42
+ /**
43
+ Override this to register commands.
44
+ */
45
+ getCommands() {
46
+ return [];
47
+ }
48
+
49
+ /**
50
+ Get Source for this stone. Goes through the cache.
51
+ */
52
+ getSource() {
53
+ Log.log(20, ...["Getting source.", {"stone": this}]);
54
+ return this.project.cache.getSource(this);
55
+ }
56
+
57
+ /**
58
+ Hash of this stone with its current config. Defaults to hash of generated source.
59
+ */
60
+ getHash() {
61
+ var _gthis = this;
62
+ Log.log(20, ...["Generating hash.", {"stone": this}]);
63
+ return this.generateHash().then(function (hash) {
64
+ if (hash != null) {
65
+ return hash;
66
+ } else {
67
+ return _gthis.getSource().then(function (s) {
68
+ return s.hash;
69
+ });
70
+ };
71
+ });
72
+ }
73
+
74
+ /**
75
+ * Generates new Source. Used by the cache when needed.
76
+ * Hash passed should be the same as is this stone's current one. Passed in as optimization.
77
+ */
78
+ generateSource(hash) {
79
+ var _gthis = this;
80
+ Log.log(20, ...["Generating source.", {"stone": this, "hash": hash}]);
81
+ var dataPromise = this.generate(hash);
82
+ if (dataPromise != null) {
83
+ return dataPromise.then(function (data) {
84
+ if (hash == null) {
85
+ var result = new Array(data.length);
86
+ var _g = 0;
87
+ var _g1 = data.length;
88
+ while (_g < _g1) {
89
+ var i = _g++;
90
+ result[i] = SourceHash.fromBytes(data[i].data);
91
+ };
92
+ hash = SourceHash.merge(...result);
93
+ };
94
+ return new Source(data, hash, _gthis, Date.now() / 1000);
95
+ });
96
+ } else {
97
+ return null;
98
+ };
99
+ }
100
+
101
+ /**
102
+ * Optionally overridable hash generation as optimization.
103
+ */
104
+ generateHash() {
105
+ return Promise.resolve(null);
106
+ }
107
+
108
+ /**
109
+ * Returns a list of sources that this stone generates.
110
+ * Used by Router for finding the correct asset.
111
+ * Default implementation generates the sources to find their ids, but can be overriden
112
+ * to provide optimized implementation that would avoid generating assets we might not need.
113
+ */
114
+ list() {
115
+ return this.getSource().then(function (source) {
116
+ var _this = source.data;
117
+ var result = new Array(_this.length);
118
+ var _g = 0;
119
+ var _g1 = _this.length;
120
+ while (_g < _g1) {
121
+ var i = _g++;
122
+ result[i] = _this[i].id;
123
+ };
124
+ return result;
125
+ });
126
+ }
127
+
128
+ /**
129
+ * Caches this resource under supplied `path` as a single copy.
130
+ * If `path` is a directory, stores the file(s) under that path, using their standard names.
131
+ * If `path` is a file and this stone generates only single data source, stores it under the supplied path.
132
+ * If `generate` is true, the source is exported right away.
133
+ */
134
+ setAbsolutePath(path, generate) {
135
+ if (generate == null) {
136
+ generate = true;
137
+ };
138
+ var norm = "/" + Path.normalize((path.charAt(0) == "/") ? HxOverrides.substr(path, 1, null) : path);
139
+ this.cacheStrategy = CacheStrategy.AbsolutePath((path.lastIndexOf("/") == path.length - 1) ? Path.addTrailingSlash(norm) : norm, CacheDurability.LimitCountByAge(1));
140
+ if (generate) {
141
+ return this.getSource();
142
+ } else {
143
+ return Promise.resolve(null);
144
+ };
145
+ }
146
+ toString() {
147
+ var c = Boot.getClass(this);
148
+ return "" + this.id + ":" + c.__name__;
149
+ }
150
+ static get __name__() {
151
+ return "whet.Stone"
152
+ }
153
+ get __class__() {
154
+ return Stone
155
+ }
156
+ }
157
+
@@ -0,0 +1,16 @@
1
+ import {Buffer} from "buffer"
2
+
3
+ export declare class Utils {
4
+ static ensureDirExist(path: string): Promise<any>
5
+
6
+ /**
7
+ Saves string as UTF-8, creates missing directories if needed.
8
+ */
9
+ static saveContent(path: string, content: string): Promise<any>
10
+
11
+ /**
12
+ Saves bytes Buffer, creates missing directories if needed.
13
+ */
14
+ static saveBytes(path: string, bytes: Buffer): Promise<any>
15
+ static deleteAll(path: string): Promise<any>
16
+ }
@@ -0,0 +1,72 @@
1
+ import {Log} from "./Log.js"
2
+ import * as Path from "path"
3
+ import {Register} from "../genes/Register.js"
4
+ import * as Fs from "fs"
5
+ import {Buffer} from "buffer"
6
+
7
+ const $global = Register.$global
8
+
9
+ export const Utils = Register.global("$hxClasses")["whet.Utils"] =
10
+ class Utils {
11
+ static ensureDirExist(path) {
12
+ var dir = Path.dirname(path);
13
+ var this1 = ["Ensuring directory " + dir + " exists."];
14
+ Log.log(10, ...this1);
15
+ return new Promise(function (res, rej) {
16
+ Fs.stat(dir, function (err, stats) {
17
+ if (err != null) {
18
+ Fs.mkdir(dir, {"recursive": true}, function (err) {
19
+ if (err != null) {
20
+ rej(err);
21
+ } else {
22
+ res(null);
23
+ };
24
+ });
25
+ } else if (!stats.isDirectory()) {
26
+ rej(new Error("Path exists, but is not a directory."));
27
+ } else {
28
+ res(null);
29
+ };
30
+ });
31
+ });
32
+ }
33
+
34
+ /**
35
+ Saves string as UTF-8, creates missing directories if needed.
36
+ */
37
+ static saveContent(path, content) {
38
+ return Utils.saveBytes(path, Buffer.from(content, "utf-8"));
39
+ }
40
+
41
+ /**
42
+ Saves bytes Buffer, creates missing directories if needed.
43
+ */
44
+ static saveBytes(path, bytes) {
45
+ Log.log(10, ...["Writing bytes to " + path + "."]);
46
+ return Utils.ensureDirExist(path).then(function (_) {
47
+ return new Promise(function (res, rej) {
48
+ Fs.writeFile(path, bytes, function (err) {
49
+ if (err != null) {
50
+ rej(err);
51
+ } else {
52
+ res(null);
53
+ };
54
+ });
55
+ });
56
+ });
57
+ }
58
+ static deleteAll(path) {
59
+ return new Promise(function (res, rej) {
60
+ Fs.rm(path, { recursive : true, force : true}, function(_) {
61
+ res(null);
62
+ });
63
+ });
64
+ }
65
+ static get __name__() {
66
+ return "whet.Utils"
67
+ }
68
+ get __class__() {
69
+ return Utils
70
+ }
71
+ }
72
+
@@ -0,0 +1,4 @@
1
+ import {Command} from "commander"
2
+
3
+ export const program: Command
4
+ export const main: () => void