whet 0.0.13 → 0.0.14

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.
@@ -1,8 +1,9 @@
1
1
  import {Utils} from "./Utils.js"
2
2
  import {SourceId, RootDir} from "./SourceId.js"
3
3
  import {SourceHash} from "./SourceHash.js"
4
- import {Log} from "./Log.js"
4
+ import {Log as Log__1} from "./Log.js"
5
5
  import * as Path from "path"
6
+ import {Log} from "../haxe/Log.js"
6
7
  import {Register} from "../genes/Register.js"
7
8
  import * as Fs from "fs"
8
9
  import {Buffer} from "buffer"
@@ -82,6 +83,7 @@ class SourceData extends Register.inherits() {
82
83
  */
83
84
  getFilePathId(idOverride) {
84
85
  var _gthis = this;
86
+ Log.trace(this.filePath, {"fileName": "src/whet/Source.hx", "lineNumber": 106, "className": "whet.SourceData", "methodName": "getFilePathId", "customParams": [this.filePathId, idOverride]});
85
87
  if (this.filePathId == null) {
86
88
  return this.getFilePath(idOverride).then(function (_) {
87
89
  return _gthis.filePathId;
@@ -101,13 +103,14 @@ class SourceData extends Register.inherits() {
101
103
  new Error("Data without source.");
102
104
  };
103
105
  var dir = this.source.getDirPath();
104
- this.filePathId = SourceId.getPutInDir((idOverride != null) ? idOverride : this.id, dir);
106
+ this.filePathId = SourceId.getPutInDir((idOverride != null && HxOverrides.cca(idOverride, idOverride.length - 1) != 47) ? idOverride : this.id, dir);
105
107
  var this1 = this.filePathId;
106
108
  var root = RootDir.fromProject(this.source.origin.project);
107
109
  if (this1.charAt(0) != "/") {
108
110
  throw new Error("Badly formed SourceId.");
109
111
  };
110
112
  this.filePath = Path.posix.join(".", root, ".", this1);
113
+ Log.trace(dir, {"fileName": "src/whet/Source.hx", "lineNumber": 121, "className": "whet.SourceData", "methodName": "getFilePath", "customParams": [this.filePath, this.filePathId]});
111
114
  return Utils.saveBytes(this.filePath, this.data).then(function (_) {
112
115
  return _gthis.filePath;
113
116
  });
@@ -126,7 +129,7 @@ class SourceData extends Register.inherits() {
126
129
  return new Promise(function (res, rej) {
127
130
  Fs.readFile(path, function (err, buffer) {
128
131
  if (err != null) {
129
- Log.log(50, ...["File does not exist.", {"id": id, "path": path}]);
132
+ Log__1.log(50, ...["File does not exist.", {"id": id, "path": path}]);
130
133
  res(null);
131
134
  } else {
132
135
  var source = SourceData.fromBytes(id, buffer);
@@ -57,6 +57,13 @@ export declare class Stone<T extends StoneConfig> {
57
57
  */
58
58
  protected generateSource(hash: null | SourceHash): Promise<Source>
59
59
 
60
+ /**
61
+ * To be used externally (i.e. `myStone.handleError = err => ...`) for providing a fallback value
62
+ * where it might make sense.
63
+ * @param err Any error that might have happened during `generateSource`.
64
+ */
65
+ handleError(err: any): Promise<SourceData[]>
66
+
60
67
  /**
61
68
  * Optionally overridable hash generation as optimization.
62
69
  * Do not use directly. Use `getHash` instead.
@@ -113,6 +120,11 @@ export declare class Stone<T extends StoneConfig> {
113
120
  }
114
121
 
115
122
  export type StoneConfig = {
123
+ /**
124
+ * Defaults to `project.cache.defaultStrategy`.
125
+ * **Do not modify after initialization – it is ignored.**
126
+ * After stone is initialized, change `stone.cacheStrategy` directly.
127
+ */
116
128
  cacheStrategy?: null | CacheStrategy,
117
129
  /**
118
130
  * Registers another stone(s) as dependency of this one. Useful for external processes
package/bin/whet/Stone.js CHANGED
@@ -140,9 +140,30 @@ class Stone extends Register.inherits() {
140
140
  } else {
141
141
  return null;
142
142
  };
143
+ })["catch"](function (e) {
144
+ return _gthis.handleError(e).then(function (data) {
145
+ Log.log(40, ...["Error happened and was handled by `handleError`.", {"stone": _gthis, "error": e}]);
146
+ var result = new Array(data.length);
147
+ var _g = 0;
148
+ var _g1 = data.length;
149
+ while (_g < _g1) {
150
+ var i = _g++;
151
+ result[i] = SourceHash.fromBytes(data[i].data);
152
+ };
153
+ return new Source(data, SourceHash.merge(...result), _gthis, Date.now() / 1000);
154
+ });
143
155
  });
144
156
  }
145
157
 
158
+ /**
159
+ * To be used externally (i.e. `myStone.handleError = err => ...`) for providing a fallback value
160
+ * where it might make sense.
161
+ * @param err Any error that might have happened during `generateSource`.
162
+ */
163
+ handleError(err) {
164
+ return Promise.reject(err);
165
+ }
166
+
146
167
  /**
147
168
  * Optionally overridable hash generation as optimization.
148
169
  * Do not use directly. Use `getHash` instead.
package/bin/whet/Utils.js CHANGED
@@ -53,7 +53,7 @@ class Utils {
53
53
  Saves bytes Buffer, creates missing directories if needed.
54
54
  */
55
55
  static saveBytes(path, bytes) {
56
- Log.log(10, ...["Writing bytes to " + path + "."]);
56
+ Log.log(10, ...["Writing bytes to \"" + path + "\"."]);
57
57
  return Utils.ensureDirExist(Path.dirname(path)).then(function (_) {
58
58
  return new Promise(function (res, rej) {
59
59
  Fs.writeFile(path, bytes, function (err) {
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", "-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");
13
+ Whet_Fields_.program.enablePositionalOptions().passThroughOptions().description("Project tooling.").usage("[options] [command] [+ [command]...]").version("0.0.14", "-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) {
@@ -94,6 +94,7 @@ class FileCache extends Register.inherits(BaseCache) {
94
94
  if (_g._hx_index == 3) {
95
95
  var _g1 = _g.path;
96
96
  if (source.data.length == 1) {
97
+ console.log("src/whet/cache/FileCache.hx:46:",_g1);
97
98
  var s = _g1.substring(_g1.lastIndexOf("/"));
98
99
  var str = (s.length > 1 && HxOverrides.cca(s, 0) == 47) ? s.substring(1) : s;
99
100
  if (str.length > 0) {
@@ -108,6 +109,7 @@ class FileCache extends Register.inherits(BaseCache) {
108
109
  } else {
109
110
  idOverride = null;
110
111
  };
112
+ console.log("src/whet/cache/FileCache.hx:50:",idOverride);
111
113
  var _g = [];
112
114
  var _g1 = 0;
113
115
  var _g2 = source.data;
@@ -116,7 +118,9 @@ class FileCache extends Register.inherits(BaseCache) {
116
118
  ++_g1;
117
119
  _g.push(data[0].getFilePathId(idOverride).then((function (data) {
118
120
  return function (filePath) {
119
- return {"fileHash": SourceHash.fromBytes(data[0].data), "filePath": filePath, "id": data[0].id};
121
+ var tmp = SourceHash.fromBytes(data[0].data);
122
+ console.log("src/whet/cache/FileCache.hx:53:",filePath);
123
+ return {"fileHash": tmp, "filePath": filePath, "id": data[0].id};
120
124
  };
121
125
  })(data)));
122
126
  };
@@ -1,3 +1,4 @@
1
+ import {Log} from "../../haxe/Log.js"
1
2
  import {Register} from "../../genes/Register.js"
2
3
 
3
4
  const $global = Register.$global
@@ -12,6 +13,16 @@ class RouteResult extends Register.inherits() {
12
13
  get() {
13
14
  var _gthis = this;
14
15
  return this.source.getSource().then(function (data) {
16
+ Log.trace("getting ", {"fileName": "src/whet/route/RouteResult.hx", "lineNumber": 17, "className": "whet.route.RouteResult", "methodName": "get", "customParams": [_gthis.sourceId, "has data:"]});
17
+ var _this = data.data;
18
+ var result = new Array(_this.length);
19
+ var _g = 0;
20
+ var _g1 = _this.length;
21
+ while (_g < _g1) {
22
+ var i = _g++;
23
+ result[i] = _this[i].id;
24
+ };
25
+ console.log("src/whet/route/RouteResult.hx:18:",result);
15
26
  return data.get(_gthis.sourceId);
16
27
  });
17
28
  }
@@ -13,6 +13,11 @@ export declare class Files extends Stone<FilesConfig> {
13
13
  }
14
14
 
15
15
  export type FilesConfig = {
16
+ /**
17
+ * Defaults to `project.cache.defaultStrategy`.
18
+ * **Do not modify after initialization – it is ignored.**
19
+ * After stone is initialized, change `stone.cacheStrategy` directly.
20
+ */
16
21
  cacheStrategy?: null | CacheStrategy,
17
22
  /**
18
23
  * Registers another stone(s) as dependency of this one. Useful for external processes
@@ -19,6 +19,11 @@ export declare class JsonStone extends Stone<JsonStoneConfig> {
19
19
  }
20
20
 
21
21
  export type JsonStoneConfig = {
22
+ /**
23
+ * Defaults to `project.cache.defaultStrategy`.
24
+ * **Do not modify after initialization – it is ignored.**
25
+ * After stone is initialized, change `stone.cacheStrategy` directly.
26
+ */
22
27
  cacheStrategy?: null | CacheStrategy,
23
28
  /**
24
29
  * Registers another stone(s) as dependency of this one. Useful for external processes
@@ -16,6 +16,11 @@ export declare class RemoteFile extends Stone<RemoteFileConfig> {
16
16
  }
17
17
 
18
18
  export type RemoteFileConfig = {
19
+ /**
20
+ * Defaults to `project.cache.defaultStrategy`.
21
+ * **Do not modify after initialization – it is ignored.**
22
+ * After stone is initialized, change `stone.cacheStrategy` directly.
23
+ */
19
24
  cacheStrategy?: null | CacheStrategy,
20
25
  /**
21
26
  * Registers another stone(s) as dependency of this one. Useful for external processes
@@ -25,6 +25,11 @@ export declare class Server extends Stone<ServerConfig> {
25
25
  }
26
26
 
27
27
  export type ServerConfig = {
28
+ /**
29
+ * Defaults to `project.cache.defaultStrategy`.
30
+ * **Do not modify after initialization – it is ignored.**
31
+ * After stone is initialized, change `stone.cacheStrategy` directly.
32
+ */
28
33
  cacheStrategy?: null | CacheStrategy,
29
34
  /**
30
35
  * Registers another stone(s) as dependency of this one. Useful for external processes
@@ -1,8 +1,9 @@
1
1
  import {Stone} from "../Stone.js"
2
- import {Log} from "../Log.js"
2
+ import {Log, Log as Log__2} from "../Log.js"
3
3
  import * as Path from "path"
4
4
  import Mime from "mime"
5
5
  import * as Http from "http"
6
+ import {Log as Log__1} from "../../haxe/Log.js"
6
7
  import {Register} from "../../genes/Register.js"
7
8
  import {StringTools} from "../../StringTools.js"
8
9
  import {Std} from "../../Std.js"
@@ -98,7 +99,11 @@ class Server extends Register.inherits(Stone) {
98
99
  id = (HxOverrides.cca(s, 0) == 47) ? s : "/" + s;
99
100
  };
100
101
  this.config.router.find(id).then(function (routeResult) {
102
+ Log__1.trace("result for ", {"fileName": "src/whet/stones/Server.hx", "lineNumber": 60, "className": "whet.stones.Server", "methodName": "handler", "customParams": [id]});
103
+ console.log("src/whet/stones/Server.hx:61:",routeResult);
101
104
  return ((routeResult.length > 0) ? routeResult[0].get() : (_gthis.routeDynamic != null) ? _gthis.routeDynamic(id) : Promise.resolve(null)).then(function (source) {
105
+ Log__1.trace("Source for ", {"fileName": "src/whet/stones/Server.hx", "lineNumber": 66, "className": "whet.stones.Server", "methodName": "handler", "customParams": [id]});
106
+ console.log("src/whet/stones/Server.hx:67:",source);
102
107
  if (source == null) {
103
108
  res.writeHead(404, "File not found.");
104
109
  res.end();
@@ -16,6 +16,11 @@ export declare class ZipStone extends Stone<ZipConfig> {
16
16
  }
17
17
 
18
18
  export type ZipConfig = {
19
+ /**
20
+ * Defaults to `project.cache.defaultStrategy`.
21
+ * **Do not modify after initialization – it is ignored.**
22
+ * After stone is initialized, change `stone.cacheStrategy` directly.
23
+ */
19
24
  cacheStrategy?: null | CacheStrategy,
20
25
  /**
21
26
  * Registers another stone(s) as dependency of this one. Useful for external processes
@@ -22,6 +22,11 @@ export declare class HaxeBuild extends Stone<BuildConfig> {
22
22
  }
23
23
 
24
24
  export type BuildConfig = {
25
+ /**
26
+ * Defaults to `project.cache.defaultStrategy`.
27
+ * **Do not modify after initialization – it is ignored.**
28
+ * After stone is initialized, change `stone.cacheStrategy` directly.
29
+ */
25
30
  cacheStrategy?: null | CacheStrategy,
26
31
  /**
27
32
  * Registers another stone(s) as dependency of this one. Useful for external processes
@@ -61,8 +61,9 @@ class HaxeBuild extends Register.inherits(Stone) {
61
61
  };
62
62
  ChildProcess.exec(result.join(" "), {"cwd": cwd1, "windowsHide": true}, function (err, stdout, stderr) {
63
63
  if (err != null) {
64
- Log.log(30, ...["Haxe build failed."]);
65
- rej(err);
64
+ var haxeError = new Error(stderr);
65
+ haxeError.name = "Haxe Build Error";
66
+ rej(haxeError);
66
67
  } else {
67
68
  Log.log(30, ...["Haxe build successful."]);
68
69
  res(null);
@@ -30,6 +30,11 @@ export declare class Hxml extends Stone<HxmlConfig> {
30
30
  }
31
31
 
32
32
  export type HxmlConfig = {
33
+ /**
34
+ * Defaults to `project.cache.defaultStrategy`.
35
+ * **Do not modify after initialization – it is ignored.**
36
+ * After stone is initialized, change `stone.cacheStrategy` directly.
37
+ */
33
38
  cacheStrategy?: null | CacheStrategy,
34
39
  dce?: null | DCE,
35
40
  debug?: null | boolean,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "whet",
3
- "version": "0.0.13",
3
+ "version": "0.0.14",
4
4
  "description": "NodeJS based assets management and project tooling library.",
5
5
  "scripts": {
6
6
  "devinit": "npx dts2hx commander --modular --noLibWrap",