whet 0.0.12 → 0.0.15

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.
@@ -39,12 +39,14 @@ export declare class SourceData {
39
39
  /**
40
40
  Same as `getFilePath` but relative to project, not CWD.
41
41
  */
42
- protected getFilePathId(idOverride?: null | string): Promise<string>
42
+ getFilePathId(idOverride?: null | string): Promise<string>
43
43
 
44
44
  /**
45
- Path to a file for this source, relative to CWD.
45
+ * Path to a file for this source, relative to CWD.
46
+ * Useful for working with sources outside of Whet ecosystem.
47
+ * @param [idOverride] Use to change the name/directory of the file. Ignored if source already has a filepath.
46
48
  */
47
- protected getFilePath(idOverride?: null | string): Promise<string>
49
+ getFilePath(idOverride?: null | string): Promise<string>
48
50
 
49
51
  /**
50
52
  * @param id Path id relative to stone that generates it.
@@ -92,7 +92,9 @@ class SourceData extends Register.inherits() {
92
92
  }
93
93
 
94
94
  /**
95
- Path to a file for this source, relative to CWD.
95
+ * Path to a file for this source, relative to CWD.
96
+ * Useful for working with sources outside of Whet ecosystem.
97
+ * @param [idOverride] Use to change the name/directory of the file. Ignored if source already has a filepath.
96
98
  */
97
99
  getFilePath(idOverride) {
98
100
  var _gthis = this;
@@ -101,7 +103,7 @@ 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) != "/") {
@@ -42,18 +42,41 @@ export declare class Stone<T extends StoneConfig> {
42
42
  */
43
43
  getHash(): Promise<SourceHash>
44
44
 
45
+ /**
46
+ * **Do not override.**
47
+ * Should only be used internally.
48
+ * Used to finalize a hash in `getHash` or in `generateSource` if `getHash` isn't implemented.
49
+ * Also used by the cache for the same purpose.
50
+ */
51
+ protected finalizeHash(hash: SourceHash): Promise<null | SourceHash>
52
+
45
53
  /**
46
54
  * **Do not override.**
47
55
  * Generates new Source. Used by the cache when needed.
48
56
  * Hash passed should be the same as is this stone's current one. Passed in as optimization.
49
57
  */
50
- protected generateSource(hash: SourceHash): Promise<Source>
58
+ protected generateSource(hash: null | SourceHash): Promise<Source>
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[]>
51
66
 
52
67
  /**
53
68
  * Optionally overridable hash generation as optimization.
69
+ * Do not use directly. Use `getHash` instead.
54
70
  */
55
71
  protected generateHash(): Promise<SourceHash>
56
72
 
73
+ /**
74
+ * **Do not override.**
75
+ * Used by cache. Returns either null, or result of `generateHash` finalized by adding
76
+ * dependencies.
77
+ */
78
+ protected finalMaybeHash(): Promise<null | SourceHash>
79
+
57
80
  /**
58
81
  * Abstract method.
59
82
  * Function that actually generates the source. Passed hash is only non-null
@@ -97,6 +120,11 @@ export declare class Stone<T extends StoneConfig> {
97
120
  }
98
121
 
99
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
+ */
100
128
  cacheStrategy?: null | CacheStrategy,
101
129
  /**
102
130
  * Registers another stone(s) as dependency of this one. Useful for external processes
package/bin/whet/Stone.js CHANGED
@@ -66,27 +66,37 @@ class Stone extends Register.inherits() {
66
66
  getHash() {
67
67
  var _gthis = this;
68
68
  Log.log(20, ...["Generating hash.", {"stone": this}]);
69
- return this.generateHash().then(function (hash) {
69
+ return this.finalMaybeHash().then(function (hash) {
70
70
  if (hash != null) {
71
71
  return hash;
72
72
  } else {
73
73
  return _gthis.getSource().then(function (s) {
74
- if (_gthis.config.dependencies != null) {
75
- var _g = [];
76
- var _g1 = 0;
77
- var _g2 = MaybeArray_Fields_.makeArray(_gthis.config.dependencies);
78
- while (_g1 < _g2.length) _g.push(_g2[_g1++].getHash());
79
- return Promise.all(_g).then(function (hashes) {
80
- return s.hash.add(SourceHash.merge(...hashes));
81
- });
82
- } else {
83
- return Promise.resolve(s.hash);
84
- };
74
+ return s.hash;
85
75
  });
86
76
  };
87
77
  });
88
78
  }
89
79
 
80
+ /**
81
+ * **Do not override.**
82
+ * Should only be used internally.
83
+ * Used to finalize a hash in `getHash` or in `generateSource` if `getHash` isn't implemented.
84
+ * Also used by the cache for the same purpose.
85
+ */
86
+ finalizeHash(hash) {
87
+ if (hash == null || this.config.dependencies == null) {
88
+ return Promise.resolve(hash);
89
+ } else {
90
+ var _g = [];
91
+ var _g1 = 0;
92
+ var _g2 = MaybeArray_Fields_.makeArray(this.config.dependencies);
93
+ while (_g1 < _g2.length) _g.push(_g2[_g1++].getHash());
94
+ return Promise.all(_g).then(function (hashes) {
95
+ return hash.add(SourceHash.merge(...hashes));
96
+ });
97
+ };
98
+ }
99
+
90
100
  /**
91
101
  * **Do not override.**
92
102
  * Generates new Source. Used by the cache when needed.
@@ -109,7 +119,11 @@ class Stone extends Register.inherits() {
109
119
  var dataPromise = _gthis.generate(hash);
110
120
  if (dataPromise != null) {
111
121
  return dataPromise.then(function (data) {
112
- if (hash == null) {
122
+ var finalHash;
123
+ if (hash != null) {
124
+ finalHash = Promise.resolve(hash);
125
+ } else {
126
+ var _gthis1 = _gthis;
113
127
  var result = new Array(data.length);
114
128
  var _g = 0;
115
129
  var _g1 = data.length;
@@ -117,23 +131,59 @@ class Stone extends Register.inherits() {
117
131
  var i = _g++;
118
132
  result[i] = SourceHash.fromBytes(data[i].data);
119
133
  };
120
- hash = SourceHash.merge(...result);
134
+ finalHash = _gthis1.finalizeHash(SourceHash.merge(...result));
121
135
  };
122
- return new Source(data, hash, _gthis, Date.now() / 1000);
136
+ return finalHash.then(function (hash) {
137
+ return new Source(data, hash, _gthis, Date.now() / 1000);
138
+ });
123
139
  });
124
140
  } else {
125
141
  return null;
126
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
+ });
127
155
  });
128
156
  }
129
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
+
130
167
  /**
131
168
  * Optionally overridable hash generation as optimization.
169
+ * Do not use directly. Use `getHash` instead.
132
170
  */
133
171
  generateHash() {
134
172
  return Promise.resolve(null);
135
173
  }
136
174
 
175
+ /**
176
+ * **Do not override.**
177
+ * Used by cache. Returns either null, or result of `generateHash` finalized by adding
178
+ * dependencies.
179
+ */
180
+ finalMaybeHash() {
181
+ var _gthis = this;
182
+ return this.generateHash().then(function (hash) {
183
+ return _gthis.finalizeHash(hash);
184
+ });
185
+ }
186
+
137
187
  /**
138
188
  * Returns a list of sources that this stone generates.
139
189
  * Used by Router for finding the correct asset.
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.12", "-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.15", "-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) {
@@ -23,7 +23,7 @@ class BaseCache extends Register.inherits() {
23
23
  }
24
24
  get(stone, durability, check) {
25
25
  var _gthis = this;
26
- return stone.generateHash().then(function (hash) {
26
+ return stone.finalMaybeHash().then(function (hash) {
27
27
  if (hash == null) {
28
28
  Log.log(20, ...["Generating source, because it does not supply a hash.", {"stone": stone, "cache": _gthis}]);
29
29
  };
@@ -27,7 +27,7 @@ class CacheManager extends Register.inherits() {
27
27
  var _g = stone.cacheStrategy;
28
28
  switch (_g._hx_index) {
29
29
  case 0:
30
- return stone.generateHash().then(function (hash) {
30
+ return stone.finalMaybeHash().then(function (hash) {
31
31
  return stone.generateSource(hash);
32
32
  });
33
33
  break
@@ -54,7 +54,7 @@ class CacheManager extends Register.inherits() {
54
54
  Log.log(10, ...["Re-generating cached stone.", {"stone": stone}]);
55
55
  switch (stone.cacheStrategy._hx_index) {
56
56
  case 0:
57
- return stone.generateHash().then(function (hash) {
57
+ return stone.finalMaybeHash().then(function (hash) {
58
58
  return stone.generateSource(hash);
59
59
  });
60
60
  break
@@ -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
@@ -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);
@@ -124,7 +125,7 @@ class HaxeBuild extends Register.inherits(Stone) {
124
125
  };
125
126
  result[i] = Path.posix.join(".", root, ".", this1);
126
127
  };
127
- return Promise.all([this.config.hxml.generateHash(), SourceHash.fromFiles(result)]).then(function (r) {
128
+ return Promise.all([this.config.hxml.getHash(), SourceHash.fromFiles(result)]).then(function (r) {
128
129
  return SourceHash.merge(...r);
129
130
  });
130
131
  }
@@ -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.12",
3
+ "version": "0.0.15",
4
4
  "description": "NodeJS based assets management and project tooling library.",
5
5
  "scripts": {
6
6
  "devinit": "npx dts2hx commander --modular --noLibWrap",