whet 0.0.5 → 0.0.8

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 +29 -22
  37. package/bin/whet/stones/Zip.js +17 -11
  38. package/bin/whet/stones/haxe/HaxeBuild.d.ts +2 -2
  39. package/bin/whet/stones/haxe/HaxeBuild.js +42 -69
  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
@@ -1,10 +1,11 @@
1
1
  import {MaybeArray_Fields_} from "../magic/MaybeArray.js"
2
2
  import {Stone} from "../Stone.js"
3
- import {RootDir, SourceId} from "../SourceId.js"
3
+ import {SourceId_Fields_, RootDir, SourceId} from "../SourceId.js"
4
4
  import {SourceData} from "../Source.js"
5
- import {Path} from "../../haxe/io/Path.js"
5
+ import * as Path from "path"
6
6
  import {Register} from "../../genes/Register.js"
7
7
  import * as Fs from "fs"
8
+ import {StringTools} from "../../StringTools.js"
8
9
  import {HxOverrides} from "../../HxOverrides.js"
9
10
 
10
11
  const $global = Register.$global
@@ -19,18 +20,19 @@ class Files extends Register.inherits(Stone) {
19
20
  var _g = MaybeArray_Fields_.makeArray(this.config.paths);
20
21
  while (0 < _g.length) {
21
22
  var pathString = _g[0];
22
- var norm = "/" + Path.normalize((pathString.charAt(0) == "/") ? HxOverrides.substr(pathString, 1, null) : pathString);
23
- var path = [(pathString.lastIndexOf("/") == pathString.length - 1) ? Path.addTrailingSlash(norm) : norm];
23
+ var s = pathString;
24
+ s = Path.posix.normalize((pathString.length > 1 && SourceId_Fields_.startsWithSlash(pathString)) ? HxOverrides.substr(pathString, 1, null) : pathString);
25
+ s = StringTools.replace(s, "\\", "/");
26
+ var path = [(SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s];
24
27
  var tmp;
25
- var norm1 = "/" + Path.normalize((path[0].charAt(0) == "/") ? HxOverrides.substr(path[0], 1, null) : path[0]);
26
- var tmp1 = (path[0].lastIndexOf("/") == path[0].length - 1) ? Path.addTrailingSlash(norm1) : norm1;
27
- var s = Path.addTrailingSlash(Path.directory(path[0]));
28
- var norm2 = "/" + Path.normalize((s.charAt(0) == "/") ? HxOverrides.substr(s, 1, null) : s);
29
- if (tmp1 == ((s.lastIndexOf("/") == s.length - 1) ? Path.addTrailingSlash(norm2) : norm2)) {
28
+ if (SourceId_Fields_.endsWithSlash(path[0])) {
30
29
  tmp = new Promise((function (path) {
31
30
  return function (res, rej) {
32
31
  var root = RootDir.fromProject(_gthis.project);
33
- Fs.readdir((root.length == 1) ? path[0].substring(1) : root.substring(1, root.length - 1) + path[0], (function (path) {
32
+ if (path[0].charAt(0) != "/") {
33
+ throw new Error("Badly formed SourceId.");
34
+ };
35
+ Fs.readdir(Path.posix.join(".", root, ".", path[0]), (function (path) {
34
36
  return function (err, files) {
35
37
  if (err != null) {
36
38
  rej(err);
@@ -41,8 +43,10 @@ class Files extends Register.inherits(Stone) {
41
43
  while (_g1 < files.length) {
42
44
  var file = files[_g1];
43
45
  ++_g1;
44
- var norm = "/" + Path.normalize((file.charAt(0) == "/") ? HxOverrides.substr(file, 1, null) : file);
45
- var filepath = SourceId.getPutInDir((file.lastIndexOf("/") == file.length - 1) ? Path.addTrailingSlash(norm) : norm, path[0]);
46
+ var s = file;
47
+ s = Path.posix.normalize((file.length > 1 && SourceId_Fields_.startsWithSlash(file)) ? HxOverrides.substr(file, 1, null) : file);
48
+ s = StringTools.replace(s, "\\", "/");
49
+ var filepath = SourceId.getPutInDir((SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s, path[0]);
46
50
  _g.push({"id": SourceId.relativeTo(filepath, path[0]), "pathId": filepath});
47
51
  };
48
52
  res1(_g);
@@ -52,9 +56,10 @@ class Files extends Register.inherits(Stone) {
52
56
  };
53
57
  })(path));
54
58
  } else {
55
- var s1 = Path.withoutDirectory(path[0]);
56
- var norm3 = "/" + Path.normalize((s1.charAt(0) == "/") ? HxOverrides.substr(s1, 1, null) : s1);
57
- tmp = Promise.resolve([{"id": (s1.lastIndexOf("/") == s1.length - 1) ? Path.addTrailingSlash(norm3) : norm3, "pathId": path[0]}]);
59
+ var s1 = path[0].substring(path[0].lastIndexOf("/"));
60
+ s1 = Path.posix.normalize((s1.length > 1 && SourceId_Fields_.startsWithSlash(s1)) ? HxOverrides.substr(s1, 1, null) : s1);
61
+ s1 = StringTools.replace(s1, "\\", "/");
62
+ tmp = Promise.resolve([{"id": (SourceId_Fields_.startsWithSlash(s1)) ? s1 : "/" + s1, "pathId": path[0]}]);
58
63
  };
59
64
  return tmp.then((function () {
60
65
  return function (files) {
@@ -63,9 +68,13 @@ class Files extends Register.inherits(Stone) {
63
68
  while (_g1 < files.length) {
64
69
  var f = files[_g1];
65
70
  ++_g1;
71
+ var f1 = f.id;
66
72
  var this1 = f.pathId;
67
73
  var root = RootDir.fromProject(_gthis.project);
68
- _g.push(SourceData.fromFile(f.id, (root.length == 1) ? this1.substring(1) : root.substring(1, root.length - 1) + this1, f.pathId));
74
+ if (this1.charAt(0) != "/") {
75
+ throw new Error("Badly formed SourceId.");
76
+ };
77
+ _g.push(SourceData.fromFile(f1, Path.posix.join(".", root, ".", this1), f.pathId));
69
78
  };
70
79
  return Promise.all(_g);
71
80
  };
@@ -1,10 +1,12 @@
1
1
  import {RouteType_Fields_} from "../magic/RouteType.js"
2
2
  import {MaybeArray_Fields_} from "../magic/MaybeArray.js"
3
3
  import {Stone} from "../Stone.js"
4
+ import {SourceId_Fields_} from "../SourceId.js"
4
5
  import {SourceHash} from "../SourceHash.js"
5
6
  import {SourceData} from "../Source.js"
6
- import {Path} from "../../haxe/io/Path.js"
7
+ import * as Path from "path"
7
8
  import {Register} from "../../genes/Register.js"
9
+ import {StringTools} from "../../StringTools.js"
8
10
  import {Reflect as Reflect__1} from "../../Reflect.js"
9
11
  import {HxOverrides} from "../../HxOverrides.js"
10
12
 
@@ -60,9 +62,7 @@ class JsonStone extends Register.inherits(Stone) {
60
62
  };
61
63
  };
62
64
  };
63
- var s = _gthis.config.name;
64
- var norm = "/" + Path.normalize((s.charAt(0) == "/") ? HxOverrides.substr(s, 1, null) : s);
65
- return [SourceData.fromString((s.lastIndexOf("/") == s.length - 1) ? Path.addTrailingSlash(norm) : norm, JSON.stringify(obj, null, " "))];
65
+ return [SourceData.fromString(_gthis.config.name, JSON.stringify(obj, null, " "))];
66
66
  });
67
67
  }
68
68
  generateHash() {
@@ -92,8 +92,9 @@ class JsonStone extends Register.inherits(Stone) {
92
92
  }
93
93
  list() {
94
94
  var s = this.config.name;
95
- var norm = "/" + Path.normalize((s.charAt(0) == "/") ? HxOverrides.substr(s, 1, null) : s);
96
- return Promise.resolve([(s.lastIndexOf("/") == s.length - 1) ? Path.addTrailingSlash(norm) : norm]);
95
+ s = Path.posix.normalize((s.length > 1 && SourceId_Fields_.startsWithSlash(s)) ? HxOverrides.substr(s, 1, null) : s);
96
+ s = StringTools.replace(s, "\\", "/");
97
+ return Promise.resolve([(SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s]);
97
98
  }
98
99
  initConfig() {
99
100
  if (this.config.name == null) {
@@ -1,14 +1,15 @@
1
1
  import {CacheStrategy, CacheDurability} from "../cache/Cache.js"
2
2
  import {Stone} from "../Stone.js"
3
+ import {SourceId_Fields_} from "../SourceId.js"
3
4
  import {SourceHash} from "../SourceHash.js"
4
5
  import {SourceData} from "../Source.js"
5
6
  import {Log} from "../Log.js"
6
7
  import {URL} from "url"
7
8
  import * as Path from "path"
8
9
  import * as Https from "https"
9
- import {Path as Path__1} from "../../haxe/io/Path.js"
10
10
  import {Register} from "../../genes/Register.js"
11
11
  import {Buffer} from "buffer"
12
+ import {StringTools} from "../../StringTools.js"
12
13
  import {HxOverrides} from "../../HxOverrides.js"
13
14
 
14
15
  const $global = Register.$global
@@ -51,12 +52,9 @@ class RemoteFile extends Register.inherits(Stone) {
51
52
  }
52
53
  getId() {
53
54
  var s = Path.basename(new URL(this.config.url).pathname);
54
- var norm = "/" + Path__1.normalize((s.charAt(0) == "/") ? HxOverrides.substr(s, 1, null) : s);
55
- if (s.lastIndexOf("/") == s.length - 1) {
56
- return Path__1.addTrailingSlash(norm);
57
- } else {
58
- return norm;
59
- };
55
+ s = Path.posix.normalize((s.length > 1 && SourceId_Fields_.startsWithSlash(s)) ? HxOverrides.substr(s, 1, null) : s);
56
+ s = StringTools.replace(s, "\\", "/");
57
+ return (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
60
58
  }
61
59
  static get __name__() {
62
60
  return "whet.stones.RemoteFile"
@@ -6,7 +6,6 @@ import {SourceHash} from "../SourceHash"
6
6
  import {SourceData} from "../Source"
7
7
  import {Project} from "../Project"
8
8
  import {IncomingMessage, ServerResponse} from "http"
9
- import {Command} from "commander"
10
9
 
11
10
  export declare class Server extends Stone<ServerConfig> {
12
11
  constructor(config: ServerConfig)
@@ -20,7 +19,7 @@ export declare class Server extends Stone<ServerConfig> {
20
19
  */
21
20
  serve(): void
22
21
  protected initConfig(): void
23
- protected getCommands(): Command[]
22
+ protected addCommands(): void
24
23
  protected handler(req: IncomingMessage, res: ServerResponse): void
25
24
  }
26
25
 
@@ -1,10 +1,11 @@
1
1
  import {Stone} from "../Stone.js"
2
+ import {SourceId_Fields_} from "../SourceId.js"
2
3
  import {Log} from "../Log.js"
4
+ import * as Path from "path"
3
5
  import Mime from "mime"
4
6
  import * as Http from "http"
5
- import {Path} from "../../haxe/io/Path.js"
6
7
  import {Register} from "../../genes/Register.js"
7
- import {Command} from "commander"
8
+ import {StringTools} from "../../StringTools.js"
8
9
  import {Std} from "../../Std.js"
9
10
  import {HxOverrides} from "../../HxOverrides.js"
10
11
 
@@ -41,50 +42,52 @@ class Server extends Register.inherits(Stone) {
41
42
  this.config.port = 7000;
42
43
  };
43
44
  }
44
- getCommands() {
45
+ addCommands() {
45
46
  var _gthis = this;
46
- return [new Command("serve").option("-p, --port <port>", "server port", "" + this.config.port).action(function (...args) {
47
+ this.project.addCommand("serve", this).option("-p, --port <port>", "server port", "" + this.config.port).action(function (...args) {
47
48
  if (args[0].port != null) {
48
49
  _gthis.config.port = Std.parseInt(args[0].port);
49
50
  };
50
51
  _gthis.serve();
51
52
  return null;
52
- })];
53
+ });
53
54
  }
54
55
  handler(req, res) {
55
56
  var _gthis = this;
56
57
  Log.log(30, ...["Handling request.", {"url": req.url, "method": req.method}]);
57
- var id;
58
58
  var s = req.url;
59
- var norm = "/" + Path.normalize((s.charAt(0) == "/") ? HxOverrides.substr(s, 1, null) : s);
60
- id = (s.lastIndexOf("/") == s.length - 1) ? Path.addTrailingSlash(norm) : norm;
59
+ s = Path.posix.normalize((s.length > 1 && SourceId_Fields_.startsWithSlash(s)) ? HxOverrides.substr(s, 1, null) : s);
60
+ s = StringTools.replace(s, "\\", "/");
61
+ var id = (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
61
62
  if (req.method == "GET") {
62
- var norm = "/" + Path.normalize((id.charAt(0) == "/") ? HxOverrides.substr(id, 1, null) : id);
63
- var tmp = (id.lastIndexOf("/") == id.length - 1) ? Path.addTrailingSlash(norm) : norm;
64
- var s = Path.addTrailingSlash(Path.directory(id));
65
- var norm = "/" + Path.normalize((s.charAt(0) == "/") ? HxOverrides.substr(s, 1, null) : s);
66
- if (tmp == ((s.lastIndexOf("/") == s.length - 1) ? Path.addTrailingSlash(norm) : norm)) {
63
+ if (SourceId_Fields_.endsWithSlash(id)) {
67
64
  if ("index.html".length > 0) {
68
- var s = Path.addTrailingSlash(Path.directory(id));
69
- var norm = "/" + Path.normalize((s.charAt(0) == "/") ? HxOverrides.substr(s, 1, null) : s);
70
- id = ((s.lastIndexOf("/") == s.length - 1) ? Path.addTrailingSlash(norm) : norm) + "index.html";
65
+ var s = id.substring(0, id.lastIndexOf("/") + 1);
66
+ s = Path.posix.normalize((s.length > 1 && SourceId_Fields_.startsWithSlash(s)) ? HxOverrides.substr(s, 1, null) : s);
67
+ s = StringTools.replace(s, "\\", "/");
68
+ id = ((SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s) + "index.html";
71
69
  };
72
- } else if (Path.extension(id) == "") {
70
+ } else if (Path.posix.extname(id) == "") {
73
71
  var s = "" + id + "/index.html";
74
- var norm = "/" + Path.normalize((s.charAt(0) == "/") ? HxOverrides.substr(s, 1, null) : s);
75
- id = (s.lastIndexOf("/") == s.length - 1) ? Path.addTrailingSlash(norm) : norm;
72
+ s = Path.posix.normalize((s.length > 1 && SourceId_Fields_.startsWithSlash(s)) ? HxOverrides.substr(s, 1, null) : s);
73
+ s = StringTools.replace(s, "\\", "/");
74
+ id = (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
76
75
  };
77
76
  this.config.router.find(id).then(function (routeResult) {
78
77
  var sourcePromise = (routeResult.length > 0) ? routeResult[0].get() : (_gthis.routeDynamic != null) ? _gthis.routeDynamic(id) : null;
79
78
  if (sourcePromise != null) {
80
79
  sourcePromise.then(function (source) {
81
- res.writeHead(200, {"Content-Type": Mime.getType(Path.extension(id).toLowerCase()), "Last-Modified": new Date(source.source.ctime * 1000).toUTCString(), "Content-Length": Std.string(source.data.length), "Cache-Control": "no-store, no-cache"});
80
+ res.writeHead(200, {"Content-Type": Mime.getType(Path.posix.extname(id).toLowerCase()), "Last-Modified": new Date(source.source.ctime * 1000).toUTCString(), "Content-Length": Std.string(source.data.length), "Cache-Control": "no-store, no-cache"});
82
81
  res.write(source.data, "binary");
83
82
  res.end();
84
83
  })["catch"](function (e) {
85
84
  Log.log(40, ...["Server error.", {"error": e}]);
86
85
  res.writeHead(500, "Error happened.");
87
- res.write(Std.string(e), "utf-8");
86
+ if (((e) instanceof Error)) {
87
+ res.write(e.stack, "utf-8");
88
+ } else {
89
+ res.write(Std.string(e), "utf-8");
90
+ };
88
91
  res.end();
89
92
  });
90
93
  } else {
@@ -94,7 +97,11 @@ class Server extends Register.inherits(Stone) {
94
97
  })["catch"](function (e) {
95
98
  Log.log(40, ...["Server error.", {"error": e}]);
96
99
  res.writeHead(500, "Error happened.");
97
- res.write(Std.string(e), "utf-8");
100
+ if (((e) instanceof Error)) {
101
+ res.write(e.stack, "utf-8");
102
+ } else {
103
+ res.write(Std.string(e), "utf-8");
104
+ };
98
105
  res.end();
99
106
  });
100
107
  } else {
@@ -1,17 +1,19 @@
1
1
  import {Router} from "../route/Router.js"
2
2
  import {CacheStrategy, CacheDurability, DurabilityCheck} from "../cache/Cache.js"
3
3
  import {Stone} from "../Stone.js"
4
+ import {SourceId_Fields_} from "../SourceId.js"
4
5
  import {SourceHash} from "../SourceHash.js"
5
6
  import {SourceData} from "../Source.js"
6
7
  import {Log} from "../Log.js"
8
+ import * as Path from "path"
7
9
  import {Helper} from "../../js/node/buffer/Buffer.js"
8
10
  import {Writer} from "../../haxe/zip/Writer.js"
9
11
  import {Tools} from "../../haxe/zip/Tools.js"
10
- import {Path} from "../../haxe/io/Path.js"
11
12
  import {BytesOutput} from "../../haxe/io/BytesOutput.js"
12
13
  import {Crc32} from "../../haxe/crypto/Crc32.js"
13
14
  import {Register} from "../../genes/Register.js"
14
15
  import {Buffer} from "buffer"
16
+ import {StringTools} from "../../StringTools.js"
15
17
  import {Lambda} from "../../Lambda.js"
16
18
  import {HxOverrides} from "../../HxOverrides.js"
17
19
 
@@ -56,7 +58,7 @@ class ZipStone extends Register.inherits(Stone) {
56
58
  return Promise.all(result).then(function (hashes) {
57
59
  return SourceHash.merge(...hashes);
58
60
  }).then(function (hash) {
59
- return SourceHash.add(SourceHash.fromString(_gthis.config.filename + _gthis.config.level), hash);
61
+ return SourceHash.fromString(_gthis.config.filename + _gthis.config.level).add(hash);
60
62
  });
61
63
  }
62
64
  generate(hash) {
@@ -73,9 +75,14 @@ class ZipStone extends Register.inherits(Stone) {
73
75
  return function (data) {
74
76
  var bytes = Helper.bytesOfBuffer(data.data);
75
77
  var this1 = file[0].serveId;
76
- var norm = "/" + Path.normalize(("/".charAt(0) == "/") ? HxOverrides.substr("/", 1, null) : "/");
77
- var root = ("/".lastIndexOf("/") == "/".length - 1) ? Path.addTrailingSlash(norm) : norm;
78
- var entry = {"fileName": (root.length == 1) ? this1.substring(1) : root.substring(1, root.length - 1) + this1, "fileSize": data.data.length, "fileTime": new Date(data.source.ctime * 1000), "compressed": false, "dataSize": data.data.length, "data": bytes, "crc32": Crc32.make(bytes)};
78
+ var s = "/";
79
+ s = Path.posix.normalize(("/".length > 1 && SourceId_Fields_.startsWithSlash("/")) ? HxOverrides.substr("/", 1, null) : "/");
80
+ s = StringTools.replace(s, "\\", "/");
81
+ var root = (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
82
+ if (this1.charAt(0) != "/") {
83
+ throw new Error("Badly formed SourceId.");
84
+ };
85
+ var entry = {"fileName": Path.posix.join(".", root, ".", this1), "fileSize": data.data.length, "fileTime": new Date(data.source.ctime * 1000), "compressed": false, "dataSize": data.data.length, "data": bytes, "crc32": Crc32.make(bytes)};
79
86
  Tools.compress(entry, level);
80
87
  return entry;
81
88
  };
@@ -84,19 +91,18 @@ class ZipStone extends Register.inherits(Stone) {
84
91
  return Promise.all(_g).then(function (entries) {
85
92
  var out = new BytesOutput();
86
93
  new Writer(out).write(Lambda.list(entries));
87
- var s = _gthis.config.filename;
88
- var norm = "/" + Path.normalize((s.charAt(0) == "/") ? HxOverrides.substr(s, 1, null) : s);
89
- var tmp = (s.lastIndexOf("/") == s.length - 1) ? Path.addTrailingSlash(norm) : norm;
94
+ var _gthis1 = _gthis.config.filename;
90
95
  var b = out.getBytes();
91
96
  var data = b.b;
92
- return [SourceData.fromBytes(tmp, Buffer.from(data.buffer, data.byteOffset, b.length))];
97
+ return [SourceData.fromBytes(_gthis1, Buffer.from(data.buffer, data.byteOffset, b.length))];
93
98
  });
94
99
  });
95
100
  }
96
101
  list() {
97
102
  var s = this.config.filename;
98
- var norm = "/" + Path.normalize((s.charAt(0) == "/") ? HxOverrides.substr(s, 1, null) : s);
99
- return Promise.resolve([(s.lastIndexOf("/") == s.length - 1) ? Path.addTrailingSlash(norm) : norm]);
103
+ s = Path.posix.normalize((s.length > 1 && SourceId_Fields_.startsWithSlash(s)) ? HxOverrides.substr(s, 1, null) : s);
104
+ s = StringTools.replace(s, "\\", "/");
105
+ return Promise.resolve([(SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s]);
100
106
  }
101
107
  static get __name__() {
102
108
  return "whet.stones.ZipStone"
@@ -5,17 +5,17 @@ import {Stone} from "../../Stone"
5
5
  import {SourceHash} from "../../SourceHash"
6
6
  import {SourceData} from "../../Source"
7
7
  import {Project} from "../../Project"
8
- import {Command} from "commander"
9
8
 
10
9
  export declare class HaxeBuild extends Stone<BuildConfig> {
11
10
  constructor(config: BuildConfig)
11
+ protected initConfig(): void
12
12
 
13
13
  /**
14
14
  Build the given hxml.
15
15
  */
16
16
  build(): Promise<any>
17
17
  protected generate(hash: SourceHash): Promise<SourceData[]>
18
- protected getCommands(): Command[]
18
+ protected addCommands(): void
19
19
  list(): Promise<string[]>
20
20
  protected generateHash(): Promise<SourceHash>
21
21
  }
@@ -1,17 +1,14 @@
1
1
  import {MaybeArray_Fields_} from "../../magic/MaybeArray.js"
2
2
  import {Utils} from "../../Utils.js"
3
3
  import {Stone} from "../../Stone.js"
4
- import {RootDir} from "../../SourceId.js"
4
+ import {SourceId_Fields_, RootDir} from "../../SourceId.js"
5
5
  import {SourceHash} from "../../SourceHash.js"
6
6
  import {SourceData} from "../../Source.js"
7
7
  import {Log} from "../../Log.js"
8
- import * as Path__1 from "path"
9
- import {Path, Path as Path__2} from "../../../haxe/io/Path.js"
8
+ import * as Path from "path"
10
9
  import {Register} from "../../../genes/Register.js"
11
- import {Command} from "commander"
12
10
  import * as ChildProcess from "child_process"
13
11
  import {StringTools} from "../../../StringTools.js"
14
- import {Lambda} from "../../../Lambda.js"
15
12
  import {HxOverrides} from "../../../HxOverrides.js"
16
13
 
17
14
  const $global = Register.$global
@@ -21,18 +18,29 @@ class HaxeBuild extends Register.inherits(Stone) {
21
18
  new(config) {
22
19
  super.new(config);
23
20
  }
21
+ initConfig() {
22
+ if (this.config.cacheStrategy == null) {
23
+ this.config.cacheStrategy = this.project.cache.defaultFileStrategy;
24
+ };
25
+ }
24
26
 
25
27
  /**
26
28
  Build the given hxml.
27
29
  */
28
30
  build() {
29
31
  var _gthis = this;
32
+ Log.log(30, ...["Building Haxe project."]);
30
33
  return new Promise(function (res, rej) {
31
34
  var cwd = process.cwd();
32
35
  var this1 = _gthis.project.rootDir;
33
- var norm = "/" + Path.normalize(("/".charAt(0) == "/") ? HxOverrides.substr("/", 1, null) : "/");
34
- var root = ("/".lastIndexOf("/") == "/".length - 1) ? Path.addTrailingSlash(norm) : norm;
35
- var cwd1 = Path__1.join(cwd, (root.length == 1) ? this1.substring(1) : root.substring(1, root.length - 1) + this1);
36
+ var s = "/";
37
+ s = Path.posix.normalize(("/".length > 1 && SourceId_Fields_.startsWithSlash("/")) ? HxOverrides.substr("/", 1, null) : "/");
38
+ s = StringTools.replace(s, "\\", "/");
39
+ var root = (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
40
+ if (this1.charAt(0) != "/") {
41
+ throw new Error("Badly formed SourceId.");
42
+ };
43
+ var cwd1 = Path.join(cwd, Path.posix.join(".", root, ".", this1));
36
44
  var _g = [];
37
45
  var e = Register.iter(_gthis.config.hxml.getBuildArgs());
38
46
  while (e.hasNext()) {
@@ -49,8 +57,10 @@ class HaxeBuild extends Register.inherits(Stone) {
49
57
  };
50
58
  ChildProcess.exec(result.join(" "), {"cwd": cwd1, "windowsHide": true}, function (err, stdout, stderr) {
51
59
  if (err != null) {
60
+ Log.log(30, ...["Haxe build failed."]);
52
61
  rej(err);
53
62
  } else {
63
+ Log.log(30, ...["Haxe build successful."]);
54
64
  res(null);
55
65
  };
56
66
  });
@@ -61,28 +71,26 @@ class HaxeBuild extends Register.inherits(Stone) {
61
71
  if (this.config.hxml.isSingleFile()) {
62
72
  var pathId = this.config.hxml.getBuildExportPath();
63
73
  var root = RootDir.fromProject(this.project);
64
- var path = (root.length == 1) ? pathId.substring(1) : root.substring(1, root.length - 1) + pathId;
74
+ if (pathId.charAt(0) != "/") {
75
+ throw new Error("Badly formed SourceId.");
76
+ };
77
+ var path = Path.posix.join(".", root, ".", pathId);
65
78
  return Utils.deleteAll(path).then(function (_) {
66
79
  return _gthis.build();
67
80
  }).then(function (_) {
68
- var s = Path.withoutDirectory(pathId);
69
- var norm = "/" + Path.normalize((s.charAt(0) == "/") ? HxOverrides.substr(s, 1, null) : s);
70
- return SourceData.fromFile((s.lastIndexOf("/") == s.length - 1) ? Path.addTrailingSlash(norm) : norm, path, pathId).then(function (file) {
81
+ return SourceData.fromFile(pathId.substring(pathId.lastIndexOf("/")), path, pathId).then(function (file) {
71
82
  return [file];
72
83
  });
73
- })["catch"](function (err) {
74
- Log.log(50, ...["Error during Haxe build.", {"error": err}]);
75
- return null;
76
84
  });
77
85
  } else {
78
86
  throw new Error("Cannot get source of a multi-file build. Not implemented yet.");
79
87
  };
80
88
  }
81
- getCommands() {
89
+ addCommands() {
82
90
  var _gthis = this;
83
- return [new Command("build").action(function (..._) {
91
+ this.project.addCommand("build", this).action(function (..._) {
84
92
  return _gthis.build();
85
- })];
93
+ });
86
94
  }
87
95
  list() {
88
96
  if (this.config.hxml.isSingleFile()) {
@@ -92,59 +100,24 @@ class HaxeBuild extends Register.inherits(Stone) {
92
100
  };
93
101
  }
94
102
  generateHash() {
95
- var hxmlHashP = this.config.hxml.generateHash();
96
- var _g = [];
97
- var _g1 = 0;
98
- var _g2 = MaybeArray_Fields_.makeArray(this.config.hxml.config.paths);
99
- while (_g1 < _g2.length) {
100
- var src = _g2[_g1];
101
- ++_g1;
102
- var norm = "/" + Path.normalize((src.charAt(0) == "/") ? HxOverrides.substr(src, 1, null) : src);
103
- var this1 = (src.lastIndexOf("/") == src.length - 1) ? Path.addTrailingSlash(norm) : norm;
103
+ var _this = MaybeArray_Fields_.makeArray(this.config.hxml.config.paths);
104
+ var result = new Array(_this.length);
105
+ var _g = 0;
106
+ var _g1 = _this.length;
107
+ while (_g < _g1) {
108
+ var i = _g++;
109
+ var s = _this[i];
110
+ s = Path.posix.normalize((s.length > 1 && SourceId_Fields_.startsWithSlash(s)) ? HxOverrides.substr(s, 1, null) : s);
111
+ s = StringTools.replace(s, "\\", "/");
112
+ var this1 = (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
104
113
  var root = RootDir.fromProject(this.config.hxml.project);
105
- _g.push(Utils.listDirectoryRecursively((root.length == 1) ? this1.substring(1) : root.substring(1, root.length - 1) + this1));
106
- };
107
- var fileHashesP = Promise.all(_g).then(function (arrFiles) {
108
- var result = new Array(arrFiles.length);
109
- var _g = 0;
110
- var _g1 = arrFiles.length;
111
- while (_g < _g1) {
112
- var i = _g++;
113
- var files = arrFiles[i];
114
- files.sort();
115
- var result1 = new Array(files.length);
116
- var _g2 = 0;
117
- var _g3 = files.length;
118
- while (_g2 < _g3) {
119
- var i1 = _g2++;
120
- result1[i1] = SourceHash.fromFile(files[i1]);
121
- };
122
- result[i] = Promise.all(result1);
123
- };
124
- return result;
125
- }).then(function (proms) {
126
- return Promise.all(proms);
127
- }).then(function (allHashes) {
128
- var _g = [];
129
- var _g_current = 0;
130
- var _g_array = allHashes;
131
- while (_g_current < _g_array.length) {
132
- var e = _g_array[_g_current++];
133
- var x = Register.iter(e);
134
- while (x.hasNext()) {
135
- var x1 = x.next();
136
- _g.push(x1);
137
- };
114
+ if (this1.charAt(0) != "/") {
115
+ throw new Error("Badly formed SourceId.");
138
116
  };
139
- return _g;
140
- });
141
- return Promise.all([hxmlHashP, fileHashesP]).then(function (r) {
142
- var hxmlHash = r[0];
143
- var fileHashes = r[1];
144
- var r = Lambda.fold(fileHashes, function (i, r) {
145
- return SourceHash.add(r, i);
146
- }, hxmlHash);
147
- return r;
117
+ result[i] = Path.posix.join(".", root, ".", this1);
118
+ };
119
+ return Promise.all([this.config.hxml.generateHash(), SourceHash.fromFiles(result)]).then(function (r) {
120
+ return SourceHash.merge(...r);
148
121
  });
149
122
  }
150
123
  static get __name__() {