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.
Files changed (43) hide show
  1. package/bin/StringBuf.d.ts +13 -0
  2. package/bin/StringBuf.js +25 -0
  3. package/bin/haxe/CallStack.d.ts +41 -0
  4. package/bin/haxe/CallStack.js +96 -0
  5. package/bin/haxe/NativeStackTrace.js +147 -0
  6. package/bin/whet/Log.js +3 -0
  7. package/bin/whet/Project.d.ts +5 -2
  8. package/bin/whet/Project.js +32 -9
  9. package/bin/whet/Source.d.ts +2 -2
  10. package/bin/whet/Source.js +21 -5
  11. package/bin/whet/SourceHash.d.ts +7 -1
  12. package/bin/whet/SourceHash.js +93 -7
  13. package/bin/whet/SourceId.d.ts +1 -0
  14. package/bin/whet/SourceId.js +37 -28
  15. package/bin/whet/Stone.d.ts +21 -5
  16. package/bin/whet/Stone.js +63 -18
  17. package/bin/whet/Utils.d.ts +8 -2
  18. package/bin/whet/Utils.js +25 -5
  19. package/bin/whet/Whet.js +4 -1
  20. package/bin/whet/cache/BaseCache.js +18 -17
  21. package/bin/whet/cache/CacheManager.d.ts +5 -0
  22. package/bin/whet/cache/CacheManager.js +21 -12
  23. package/bin/whet/cache/FileCache.js +83 -43
  24. package/bin/whet/magic/RoutePathType.js +10 -4
  25. package/bin/whet/magic/RouteType.d.ts +4 -3
  26. package/bin/whet/magic/RouteType.js +31 -13
  27. package/bin/whet/magic/StoneId.d.ts +1 -0
  28. package/bin/whet/magic/StoneId.js +11 -1
  29. package/bin/whet/route/Route.d.ts +5 -1
  30. package/bin/whet/route/Route.js +33 -13
  31. package/bin/whet/route/Router.js +27 -36
  32. package/bin/whet/stones/Files.js +25 -16
  33. package/bin/whet/stones/JsonStone.js +7 -6
  34. package/bin/whet/stones/RemoteFile.js +5 -7
  35. package/bin/whet/stones/Server.d.ts +1 -2
  36. package/bin/whet/stones/Server.js +30 -22
  37. package/bin/whet/stones/Zip.js +17 -11
  38. package/bin/whet/stones/haxe/HaxeBuild.d.ts +2 -0
  39. package/bin/whet/stones/haxe/HaxeBuild.js +44 -63
  40. package/bin/whet/stones/haxe/Hxml.js +39 -24
  41. package/bin/whet.d.ts +3 -0
  42. package/bin/whet.js +3 -0
  43. package/package.json +1 -1
@@ -0,0 +1,13 @@
1
+
2
+ /**
3
+ A String buffer is an efficient way to build a big string by appending small
4
+ elements together.
5
+
6
+ Unlike String, an instance of StringBuf is not immutable in the sense that
7
+ it can be passed as argument to functions which modify it by appending more
8
+ values.
9
+ */
10
+ export declare class StringBuf {
11
+ constructor()
12
+ protected b: string
13
+ }
@@ -0,0 +1,25 @@
1
+ import {Register} from "./genes/Register.js"
2
+
3
+ const $global = Register.$global
4
+
5
+ /**
6
+ A String buffer is an efficient way to build a big string by appending small
7
+ elements together.
8
+
9
+ Unlike String, an instance of StringBuf is not immutable in the sense that
10
+ it can be passed as argument to functions which modify it by appending more
11
+ values.
12
+ */
13
+ export const StringBuf = Register.global("$hxClasses")["StringBuf"] =
14
+ class StringBuf extends Register.inherits() {
15
+ new() {
16
+ this.b = "";
17
+ }
18
+ static get __name__() {
19
+ return "StringBuf"
20
+ }
21
+ get __class__() {
22
+ return StringBuf
23
+ }
24
+ }
25
+
@@ -0,0 +1,41 @@
1
+ import {StringBuf} from "../StringBuf"
2
+
3
+ /**
4
+ Elements return by `CallStack` methods.
5
+ */
6
+ export declare namespace StackItem {
7
+ export type Module = {_hx_index: 1, m: string, __enum__: "haxe.StackItem"}
8
+ export const Module: (m: string) => StackItem
9
+ export type Method = {_hx_index: 3, classname: null | string, method: string, __enum__: "haxe.StackItem"}
10
+ export const Method: (classname: null | string, method: string) => StackItem
11
+ export type LocalFunction = {_hx_index: 4, v: null | number, __enum__: "haxe.StackItem"}
12
+ export const LocalFunction: (v: null | number) => StackItem
13
+ export type FilePos = {_hx_index: 2, s: null | StackItem, file: string, line: number, column: null | number, __enum__: "haxe.StackItem"}
14
+ export const FilePos: (s: null | StackItem, file: string, line: number, column: null | number) => StackItem
15
+ export type CFunction = {_hx_index: 0, __enum__: "haxe.StackItem"}
16
+ export const CFunction: CFunction
17
+ }
18
+
19
+ /**
20
+ Elements return by `CallStack` methods.
21
+ */
22
+ export declare type StackItem =
23
+ | StackItem.Module
24
+ | StackItem.Method
25
+ | StackItem.LocalFunction
26
+ | StackItem.FilePos
27
+ | StackItem.CFunction
28
+
29
+ export declare class CallStack {
30
+
31
+ /**
32
+ Return the call stack elements, or an empty array if not available.
33
+ */
34
+ static callStack(): StackItem[]
35
+
36
+ /**
37
+ Returns a representation of the stack as a printable string.
38
+ */
39
+ static toString(stack: StackItem[]): string
40
+ protected static itemToString(b: StringBuf, s: StackItem): void
41
+ }
@@ -0,0 +1,96 @@
1
+ import {NativeStackTrace} from "./NativeStackTrace.js"
2
+ import {Register} from "../genes/Register.js"
3
+ import {StringBuf} from "../StringBuf.js"
4
+ import {Std} from "../Std.js"
5
+
6
+ const $global = Register.$global
7
+
8
+ /**
9
+ Elements return by `CallStack` methods.
10
+ */
11
+ export const StackItem =
12
+ Register.global("$hxEnums")["haxe.StackItem"] =
13
+ {
14
+ __ename__: "haxe.StackItem",
15
+
16
+ CFunction: {_hx_name: "CFunction", _hx_index: 0, __enum__: "haxe.StackItem"},
17
+ Module: Object.assign((m) => ({_hx_index: 1, __enum__: "haxe.StackItem", "m": m}), {_hx_name: "Module", __params__: ["m"]}),
18
+ FilePos: Object.assign((s, file, line, column) => ({_hx_index: 2, __enum__: "haxe.StackItem", "s": s, "file": file, "line": line, "column": column}), {_hx_name: "FilePos", __params__: ["s", "file", "line", "column"]}),
19
+ Method: Object.assign((classname, method) => ({_hx_index: 3, __enum__: "haxe.StackItem", "classname": classname, "method": method}), {_hx_name: "Method", __params__: ["classname", "method"]}),
20
+ LocalFunction: Object.assign((v) => ({_hx_index: 4, __enum__: "haxe.StackItem", "v": v}), {_hx_name: "LocalFunction", __params__: ["v"]})
21
+ }
22
+ StackItem.__constructs__ = [StackItem.CFunction, StackItem.Module, StackItem.FilePos, StackItem.Method, StackItem.LocalFunction]
23
+ StackItem.__empty_constructs__ = [StackItem.CFunction]
24
+
25
+ export const CallStack = Register.global("$hxClasses")["haxe._CallStack.CallStack"] =
26
+ class CallStack {
27
+
28
+ /**
29
+ Return the call stack elements, or an empty array if not available.
30
+ */
31
+ static callStack() {
32
+ return NativeStackTrace.toHaxe(NativeStackTrace.callStack());
33
+ }
34
+
35
+ /**
36
+ Returns a representation of the stack as a printable string.
37
+ */
38
+ static toString(stack) {
39
+ var b = new StringBuf();
40
+ var _g = 0;
41
+ var _g1 = stack;
42
+ while (_g < _g1.length) {
43
+ var s = _g1[_g++];
44
+ b.b += "\nCalled from ";
45
+ CallStack.itemToString(b, s);
46
+ };
47
+ return b.b;
48
+ }
49
+ static itemToString(b, s) {
50
+ switch (s._hx_index) {
51
+ case 0:
52
+ b.b += "a C function";
53
+ break
54
+ case 1:
55
+ var _g = s.m;
56
+ b.b = (b.b += "module ") + ((_g == null) ? "null" : "" + _g);
57
+ break
58
+ case 2:
59
+ var _g = s.s;
60
+ var _g1 = s.file;
61
+ var _g2 = s.line;
62
+ var _g3 = s.column;
63
+ if (_g != null) {
64
+ CallStack.itemToString(b, _g);
65
+ b.b += " (";
66
+ };
67
+ b.b = (b.b += (_g1 == null) ? "null" : "" + _g1) + " line ";
68
+ b.b += (_g2 == null) ? "null" : "" + _g2;
69
+ if (_g3 != null) {
70
+ b.b = (b.b += " column ") + ((_g3 == null) ? "null" : "" + _g3);
71
+ };
72
+ if (_g != null) {
73
+ b.b += ")";
74
+ };
75
+ break
76
+ case 3:
77
+ var _g = s.classname;
78
+ var _g1 = s.method;
79
+ b.b = (b.b += Std.string((_g == null) ? "<unknown>" : _g)) + ".";
80
+ b.b += (_g1 == null) ? "null" : "" + _g1;
81
+ break
82
+ case 4:
83
+ var _g = s.v;
84
+ b.b = (b.b += "local function #") + ((_g == null) ? "null" : "" + _g);
85
+ break
86
+
87
+ };
88
+ }
89
+ static get __name__() {
90
+ return "haxe._CallStack.CallStack_Impl_"
91
+ }
92
+ get __class__() {
93
+ return CallStack
94
+ }
95
+ }
96
+
@@ -0,0 +1,147 @@
1
+ import {StackItem} from "./CallStack.js"
2
+ import {Register} from "../genes/Register.js"
3
+ import {StringTools} from "../StringTools.js"
4
+ import {Std} from "../Std.js"
5
+
6
+ const $global = Register.$global
7
+
8
+ /**
9
+ Do not use manually.
10
+ */
11
+ export const NativeStackTrace = Register.global("$hxClasses")["haxe.NativeStackTrace"] =
12
+ class NativeStackTrace {
13
+ static callStack() {
14
+ var e = new Error("");
15
+ var stack = NativeStackTrace.tryHaxeStack(e);
16
+ if (typeof(stack) == "undefined") {
17
+ try {
18
+ throw e;
19
+ }catch (_g) {
20
+ };
21
+ stack = e.stack;
22
+ };
23
+ return NativeStackTrace.normalize(stack, 2);
24
+ }
25
+ static toHaxe(s, skip) {
26
+ if (skip == null) {
27
+ skip = 0;
28
+ };
29
+ if (s == null) {
30
+ return [];
31
+ } else if (typeof(s) == "string") {
32
+ var stack = s.split("\n");
33
+ if (stack[0] == "Error") {
34
+ stack.shift();
35
+ };
36
+ var m = [];
37
+ var _g = 0;
38
+ var _g1 = stack.length;
39
+ while (_g < _g1) {
40
+ var i = _g++;
41
+ if (skip > i) {
42
+ continue;
43
+ };
44
+ var line = stack[i];
45
+ var matched = line.match(/^ at ([A-Za-z0-9_. ]+) \(([^)]+):([0-9]+):([0-9]+)\)$/);
46
+ if (matched != null) {
47
+ var path = matched[1].split(".");
48
+ if (path[0] == "$hxClasses") {
49
+ path.shift();
50
+ };
51
+ var meth = path.pop();
52
+ var file = matched[2];
53
+ var line1 = Std.parseInt(matched[3]);
54
+ var column = Std.parseInt(matched[4]);
55
+ m.push(StackItem.FilePos((meth == "Anonymous function") ? StackItem.LocalFunction() : (meth == "Global code") ? null : StackItem.Method(path.join("."), meth), file, line1, column));
56
+ } else {
57
+ m.push(StackItem.Module(StringTools.trim(line)));
58
+ };
59
+ };
60
+ return m;
61
+ } else if (skip > 0 && Array.isArray(s)) {
62
+ return s.slice(skip);
63
+ } else {
64
+ return s;
65
+ };
66
+ }
67
+ static tryHaxeStack(e) {
68
+ if (e == null) {
69
+ return [];
70
+ };
71
+ var oldValue = Error.prepareStackTrace;
72
+ Error.prepareStackTrace = NativeStackTrace.prepareHxStackTrace;
73
+ Error.prepareStackTrace = oldValue;
74
+ return e.stack;
75
+ }
76
+ static prepareHxStackTrace(e, callsites) {
77
+ var stack = [];
78
+ var _g = 0;
79
+ while (_g < callsites.length) {
80
+ var site = callsites[_g];
81
+ ++_g;
82
+ if (NativeStackTrace.wrapCallSite != null) {
83
+ site = NativeStackTrace.wrapCallSite(site);
84
+ };
85
+ var method = null;
86
+ var fullName = site.getFunctionName();
87
+ if (fullName != null) {
88
+ var idx = fullName.lastIndexOf(".");
89
+ if (idx >= 0) {
90
+ method = StackItem.Method(fullName.substring(0, idx), fullName.substring(idx + 1));
91
+ } else {
92
+ method = StackItem.Method(null, fullName);
93
+ };
94
+ };
95
+ var fileName = site.getFileName();
96
+ var fileAddr = (fileName == null) ? -1 : fileName.indexOf("file:");
97
+ if (NativeStackTrace.wrapCallSite != null && fileAddr > 0) {
98
+ fileName = fileName.substring(fileAddr + 6);
99
+ };
100
+ stack.push(StackItem.FilePos(method, fileName, site.getLineNumber(), site.getColumnNumber()));
101
+ };
102
+ return stack;
103
+ }
104
+ static normalize(stack, skipItems) {
105
+ if (skipItems == null) {
106
+ skipItems = 0;
107
+ };
108
+ if (Array.isArray(stack) && skipItems > 0) {
109
+ return stack.slice(skipItems);
110
+ } else if (typeof(stack) == "string") {
111
+ switch (stack.substring(0, 6)) {
112
+ case "Error\n":case "Error:":
113
+ ++skipItems;
114
+ break
115
+ default:
116
+
117
+ };
118
+ return NativeStackTrace.skipLines(stack, skipItems);
119
+ } else {
120
+ return stack;
121
+ };
122
+ }
123
+ static skipLines(stack, skip, pos) {
124
+ if (pos == null) {
125
+ pos = 0;
126
+ };
127
+ while (true) if (skip > 0) {
128
+ pos = stack.indexOf("\n", pos);
129
+ if (pos < 0) {
130
+ return "";
131
+ } else {
132
+ skip = --skip;
133
+ pos += 1;
134
+ continue;
135
+ };
136
+ } else {
137
+ return stack.substring(pos);
138
+ };
139
+ }
140
+ static get __name__() {
141
+ return "haxe.NativeStackTrace"
142
+ }
143
+ get __class__() {
144
+ return NativeStackTrace
145
+ }
146
+ }
147
+
package/bin/whet/Log.js CHANGED
@@ -54,6 +54,9 @@ class Log {
54
54
  };
55
55
  }
56
56
  static replacer(key, val) {
57
+ if (((val) instanceof Error)) {
58
+ return val.stack;
59
+ };
57
60
  if (val != null && typeof(val.toString) == "function" && val.toString != Object.prototype.toString) {
58
61
  return val.toString();
59
62
  };
@@ -9,9 +9,10 @@ export declare class Project {
9
9
  description: string
10
10
  rootDir: string
11
11
  cache: CacheManager
12
+ stones: AnyStone[]
12
13
  onInit: (config: any) => Promise<any>
13
14
  protected options: Option[]
14
- addCommand(cmd: Command, stone?: null | AnyStone): void
15
+ addCommand(name: string, stone?: null | AnyStone): Command
15
16
  toString(): string
16
17
  protected static projects: Project[]
17
18
  }
@@ -26,8 +27,10 @@ export type ProjectConfig = {
26
27
  */
27
28
  onInit?: null | ((config: any) => Promise<any>),
28
29
  /**
29
- * Array of Commander.js options this project supports.
30
+ * Array of Commander.js options this project supports. Use `addOption` to get Option instance.
30
31
  */
31
32
  options?: null | Option[],
32
33
  rootDir?: null | string
33
34
  }
35
+
36
+ export const addOption: (flags: string, description: null | string) => Option
@@ -1,9 +1,10 @@
1
1
  import {CacheManager} from "./cache/CacheManager.js"
2
2
  import {Whet_Fields_} from "./Whet.js"
3
+ import {SourceId_Fields_} from "./SourceId.js"
3
4
  import {Log} from "./Log.js"
4
5
  import * as Path from "path"
5
- import {Path as Path__1} from "../haxe/io/Path.js"
6
6
  import {Register} from "../genes/Register.js"
7
+ import {Command, Option} from "commander"
7
8
  import {StringTools} from "../StringTools.js"
8
9
  import {HxOverrides} from "../HxOverrides.js"
9
10
 
@@ -12,6 +13,7 @@ const $global = Register.$global
12
13
  export const Project = Register.global("$hxClasses")["whet.Project"] =
13
14
  class Project extends Register.inherits() {
14
15
  new(config) {
16
+ this.stones = [];
15
17
  this.cache = null;
16
18
  var this1 = ["Instantiating new Project."];
17
19
  Log.log(20, ...this1);
@@ -37,25 +39,31 @@ class Project extends Register.inherits() {
37
39
  file = decodeURI(file);
38
40
  file = StringTools.replace(file, "file:///", "");
39
41
  var s = Path.relative(process.cwd(), file);
40
- var norm = "/" + Path__1.normalize((s.charAt(0) == "/") ? HxOverrides.substr(s, 1, null) : s);
41
- var s1 = Path__1.addTrailingSlash(Path__1.directory((s.lastIndexOf("/") == s.length - 1) ? Path__1.addTrailingSlash(norm) : norm));
42
- var norm = "/" + Path__1.normalize((s1.charAt(0) == "/") ? HxOverrides.substr(s1, 1, null) : s1);
43
- this.rootDir = (s1.lastIndexOf("/") == s1.length - 1) ? Path__1.addTrailingSlash(norm) : norm;
42
+ s = Path.posix.normalize((s.length > 1 && SourceId_Fields_.startsWithSlash(s)) ? HxOverrides.substr(s, 1, null) : s);
43
+ s = StringTools.replace(s, "\\", "/");
44
+ var this1 = (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
45
+ var s = this1.substring(0, this1.lastIndexOf("/") + 1);
46
+ s = Path.posix.normalize((s.length > 1 && SourceId_Fields_.startsWithSlash(s)) ? HxOverrides.substr(s, 1, null) : s);
47
+ s = StringTools.replace(s, "\\", "/");
48
+ this.rootDir = (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
44
49
  } else {
45
50
  var s = config.rootDir;
46
- var norm = "/" + Path__1.normalize((s.charAt(0) == "/") ? HxOverrides.substr(s, 1, null) : s);
47
- this.rootDir = (s.lastIndexOf("/") == s.length - 1) ? Path__1.addTrailingSlash(norm) : norm;
51
+ s = Path.posix.normalize((s.length > 1 && SourceId_Fields_.startsWithSlash(s)) ? HxOverrides.substr(s, 1, null) : s);
52
+ s = StringTools.replace(s, "\\", "/");
53
+ this.rootDir = (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
48
54
  };
49
55
  this.cache = (config.cache == null) ? new CacheManager(this) : config.cache;
50
56
  Project.projects.push(this);
51
57
  var this1 = ["New project created.", {"project": this, "projectCount": Project.projects.length}];
52
58
  Log.log(30, ...this1);
53
59
  }
54
- addCommand(cmd, stone) {
60
+ addCommand(name, stone) {
61
+ var cmd = new Command(name);
55
62
  if (stone != null) {
56
63
  cmd.alias(stone.id + "." + cmd.name());
57
64
  };
58
65
  Whet_Fields_.program.addCommand(cmd);
66
+ return cmd;
59
67
  }
60
68
  toString() {
61
69
  return "" + this.name + "@" + this.rootDir;
@@ -69,4 +77,19 @@ class Project extends Register.inherits() {
69
77
  }
70
78
 
71
79
 
72
- Project.projects = []
80
+ Project.projects = []
81
+ export const Project_Fields_ = Register.global("$hxClasses")["whet._Project.Project_Fields_"] =
82
+ class Project_Fields_ {
83
+ static get __name__() {
84
+ return "whet._Project.Project_Fields_"
85
+ }
86
+ get __class__() {
87
+ return Project_Fields_
88
+ }
89
+ }
90
+
91
+
92
+ Project_Fields_.addOption = function (flags, description) {
93
+ return new Option(flags, description);
94
+ }
95
+ export const addOption = Project_Fields_.addOption
@@ -35,12 +35,12 @@ export declare class SourceData {
35
35
  /**
36
36
  Same as `getFilePath` but relative to project, not CWD.
37
37
  */
38
- getFilePathId(idOverride?: null | string): Promise<string>
38
+ protected getFilePathId(idOverride?: null | string): Promise<string>
39
39
 
40
40
  /**
41
41
  Path to a file for this source, relative to CWD.
42
42
  */
43
- getFilePath(idOverride?: null | string): Promise<string>
43
+ protected getFilePath(idOverride?: null | string): Promise<string>
44
44
 
45
45
  /**
46
46
  * `path` is the actual cwd-relative path. `pathId` is the project-relative source Id.
@@ -1,11 +1,14 @@
1
1
  import {Utils} from "./Utils.js"
2
- import {SourceId, RootDir} from "./SourceId.js"
2
+ import {SourceId_Fields_, SourceId, RootDir} 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 {Register} from "../genes/Register.js"
6
7
  import * as Fs from "fs"
7
8
  import {Buffer} from "buffer"
9
+ import {StringTools} from "../StringTools.js"
8
10
  import {Lambda} from "../Lambda.js"
11
+ import {HxOverrides} from "../HxOverrides.js"
9
12
 
10
13
  const $global = Register.$global
11
14
 
@@ -42,8 +45,12 @@ class Source extends Register.inherits() {
42
45
  if (id == null) {
43
46
  return this.data[0];
44
47
  } else {
48
+ var s = id;
49
+ s = Path.posix.normalize((id.length > 1 && SourceId_Fields_.startsWithSlash(id)) ? HxOverrides.substr(id, 1, null) : id);
50
+ s = StringTools.replace(s, "\\", "/");
51
+ var sid = (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
45
52
  return Lambda.find(this.data, function (entry) {
46
- return entry.id == id;
53
+ return entry.id == sid;
47
54
  });
48
55
  };
49
56
  }
@@ -93,7 +100,10 @@ class SourceData extends Register.inherits() {
93
100
  this.filePathId = SourceId.getPutInDir((idOverride != null) ? idOverride : this.id, dir);
94
101
  var this1 = this.filePathId;
95
102
  var root = RootDir.fromProject(this.source.origin.project);
96
- this.filePath = (root.length == 1) ? this1.substring(1) : root.substring(1, root.length - 1) + this1;
103
+ if (this1.charAt(0) != "/") {
104
+ throw new Error("Badly formed SourceId.");
105
+ };
106
+ this.filePath = Path.posix.join(".", root, ".", this1);
97
107
  return Utils.saveBytes(this.filePath, this.data).then(function (_) {
98
108
  return _gthis.filePath;
99
109
  });
@@ -114,7 +124,10 @@ class SourceData extends Register.inherits() {
114
124
  } else {
115
125
  var source = SourceData.fromBytes(id, buffer);
116
126
  source.filePath = path;
117
- source.filePathId = pathId;
127
+ var s = pathId;
128
+ s = Path.posix.normalize((s.length > 1 && SourceId_Fields_.startsWithSlash(s)) ? HxOverrides.substr(s, 1, null) : s);
129
+ s = StringTools.replace(s, "\\", "/");
130
+ source.filePathId = (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
118
131
  res(source);
119
132
  };
120
133
  });
@@ -124,7 +137,10 @@ class SourceData extends Register.inherits() {
124
137
  return SourceData.fromBytes(id, Buffer.from(s, "utf-8"));
125
138
  }
126
139
  static fromBytes(id, data) {
127
- return new SourceData(id, data);
140
+ var s = id;
141
+ s = Path.posix.normalize((id.length > 1 && SourceId_Fields_.startsWithSlash(id)) ? HxOverrides.substr(id, 1, null) : id);
142
+ s = StringTools.replace(s, "\\", "/");
143
+ return new SourceData((SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s, data);
128
144
  }
129
145
  static get __name__() {
130
146
  return "whet.SourceData"
@@ -1,14 +1,20 @@
1
+ import {MaybeArray} from "./magic/MaybeArray"
1
2
  import {Buffer} from "buffer"
2
3
 
3
4
  export declare class SourceHash {
4
5
  protected constructor(bytes: Buffer)
5
6
  protected bytes: Buffer
7
+ add(hash: SourceHash): SourceHash
6
8
  toString(): string
7
9
  static EMPTY: SourceHash
8
10
  static fromFile(path: string): Promise<SourceHash>
11
+
12
+ /**
13
+ * Creates hashes of all files and or content of directories, optionally recursive.
14
+ */
15
+ static fromFiles(paths: MaybeArray<string>, filter?: null | ((arg0: string) => boolean), recursive?: boolean): Promise<SourceHash>
9
16
  static fromBytes(data: Buffer): SourceHash
10
17
  static fromString(data: string): SourceHash
11
- static add(a: SourceHash, b: SourceHash): SourceHash
12
18
  static equals(a: SourceHash, b: SourceHash): boolean
13
19
  static toHex(hash: SourceHash): string
14
20
  static fromHex(hex: string): SourceHash
@@ -1,3 +1,5 @@
1
+ import {MaybeArray_Fields_} from "./magic/MaybeArray.js"
2
+ import {Utils} from "./Utils.js"
1
3
  import {Register} from "../genes/Register.js"
2
4
  import * as Fs from "fs"
3
5
  import * as Crypto from "crypto"
@@ -10,6 +12,12 @@ class SourceHash extends Register.inherits() {
10
12
  new(bytes) {
11
13
  this.bytes = bytes;
12
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
+ }
13
21
  toString() {
14
22
  return this.bytes.toString("hex");
15
23
  }
@@ -24,18 +32,96 @@ class SourceHash extends Register.inherits() {
24
32
  });
25
33
  });
26
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
+ }
27
119
  static fromBytes(data) {
28
120
  return new SourceHash(Crypto.createHash("sha256").update(data).digest());
29
121
  }
30
122
  static fromString(data) {
31
123
  return SourceHash.fromBytes(Buffer.from(data));
32
124
  }
33
- static add(a, b) {
34
- var data = Buffer.alloc(64);
35
- a.bytes.copy(data, 0, 0, 32);
36
- b.bytes.copy(data, 32, 0, 32);
37
- return SourceHash.fromBytes(data);
38
- }
39
125
  static equals(a, b) {
40
126
  if (a != null && b != null) {
41
127
  return a.bytes.compare(b.bytes) == 0;
@@ -65,7 +151,7 @@ class SourceHash extends Register.inherits() {
65
151
  var h = hash[0];
66
152
  var _g = 1;
67
153
  var _g1 = hash.length;
68
- while (_g < _g1) h = SourceHash.add(h, hash[_g++]);
154
+ while (_g < _g1) h = h.add(hash[_g++]);
69
155
  return h;
70
156
  }
71
157
  static get __name__() {
@@ -8,3 +8,4 @@ export declare class SourceId {
8
8
  export declare class RootDir {
9
9
  static fromProject(p: Project): string
10
10
  }
11
+