whet 0.0.10 → 0.0.13

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,4 +1,5 @@
1
1
  import {StoneIdType} from "./magic/StoneId"
2
+ import {MaybeArray} from "./magic/MaybeArray"
2
3
  import {CacheManager} from "./cache/CacheManager"
3
4
  import {CacheStrategy} from "./cache/Cache"
4
5
  import {SourceHash} from "./SourceHash"
@@ -35,22 +36,40 @@ export declare class Stone<T extends StoneConfig> {
35
36
  getSource(): Promise<Source>
36
37
 
37
38
  /**
38
- Hash of this stone with its current config. Defaults to hash of generated source.
39
+ * **Do not override.**
40
+ * Hash of this stone with its current config. Defaults to hash of generated source.
41
+ * Hashes of dependency stones (see `config.dependencies`) will be added to the hash.
39
42
  */
40
43
  getHash(): Promise<SourceHash>
41
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
+
42
53
  /**
43
54
  * **Do not override.**
44
55
  * Generates new Source. Used by the cache when needed.
45
56
  * Hash passed should be the same as is this stone's current one. Passed in as optimization.
46
57
  */
47
- protected generateSource(hash: SourceHash): Promise<Source>
58
+ protected generateSource(hash: null | SourceHash): Promise<Source>
48
59
 
49
60
  /**
50
61
  * Optionally overridable hash generation as optimization.
62
+ * Do not use directly. Use `getHash` instead.
51
63
  */
52
64
  protected generateHash(): Promise<SourceHash>
53
65
 
66
+ /**
67
+ * **Do not override.**
68
+ * Used by cache. Returns either null, or result of `generateHash` finalized by adding
69
+ * dependencies.
70
+ */
71
+ protected finalMaybeHash(): Promise<null | SourceHash>
72
+
54
73
  /**
55
74
  * Abstract method.
56
75
  * Function that actually generates the source. Passed hash is only non-null
@@ -72,7 +91,8 @@ export declare class Stone<T extends StoneConfig> {
72
91
  * @param path
73
92
  * If `path` is a directory, stores the file(s) under that path, using their standard names.
74
93
  * If `path` is a file and this stone generates only single data source, stores it under the supplied path.
75
- * @param generate If true (default), the source is exported right away.
94
+ * @param generate If true (default), the source is exported right away. Will not re-save the file, if it already
95
+ * exists under the same path and hash.
76
96
  */
77
97
  setAbsolutePath(path: string, generate?: boolean): Promise<Source>
78
98
 
@@ -95,6 +115,17 @@ export declare class Stone<T extends StoneConfig> {
95
115
  export type StoneConfig = {
96
116
  cacheStrategy?: null | CacheStrategy,
97
117
  /**
118
+ * Registers another stone(s) as dependency of this one. Useful for external processes
119
+ * that use a source of some stone, but don't go via Whet to get it.
120
+ * Use with combination of `setAbsolutePath` on the dependency, so that the external process
121
+ * can rely on a fixed path.
122
+ * Will make sure the cached file is up to date when generating this stone.
123
+ * Hash of the dependency is automatically combined with hash generated by this stone. There's no
124
+ * need to add it manually.
125
+ * Do not create cyclic dependencies!
126
+ */
127
+ dependencies?: null | MaybeArray<AnyStone>,
128
+ /**
98
129
  Defaults to the Stone's class name.
99
130
  */
100
131
  id?: null | StoneIdType,
package/bin/whet/Stone.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import {StoneId_Fields_} from "./magic/StoneId.js"
2
+ import {MaybeArray_Fields_} from "./magic/MaybeArray.js"
2
3
  import {CacheStrategy, CacheDurability} from "./cache/Cache.js"
3
4
  import {Utils} from "./Utils.js"
4
5
  import {SourceId, RootDir} from "./SourceId.js"
@@ -58,12 +59,14 @@ class Stone extends Register.inherits() {
58
59
  }
59
60
 
60
61
  /**
61
- Hash of this stone with its current config. Defaults to hash of generated source.
62
+ * **Do not override.**
63
+ * Hash of this stone with its current config. Defaults to hash of generated source.
64
+ * Hashes of dependency stones (see `config.dependencies`) will be added to the hash.
62
65
  */
63
66
  getHash() {
64
67
  var _gthis = this;
65
68
  Log.log(20, ...["Generating hash.", {"stone": this}]);
66
- return this.generateHash().then(function (hash) {
69
+ return this.finalMaybeHash().then(function (hash) {
67
70
  if (hash != null) {
68
71
  return hash;
69
72
  } else {
@@ -74,6 +77,26 @@ class Stone extends Register.inherits() {
74
77
  });
75
78
  }
76
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
+
77
100
  /**
78
101
  * **Do not override.**
79
102
  * Generates new Source. Used by the cache when needed.
@@ -82,33 +105,64 @@ class Stone extends Register.inherits() {
82
105
  generateSource(hash) {
83
106
  var _gthis = this;
84
107
  Log.log(20, ...["Generating source.", {"stone": this, "hash": hash}]);
85
- var dataPromise = this.generate(hash);
86
- if (dataPromise != null) {
87
- return dataPromise.then(function (data) {
88
- if (hash == null) {
89
- var result = new Array(data.length);
90
- var _g = 0;
91
- var _g1 = data.length;
92
- while (_g < _g1) {
93
- var i = _g++;
94
- result[i] = SourceHash.fromBytes(data[i].data);
95
- };
96
- hash = SourceHash.merge(...result);
97
- };
98
- return new Source(data, hash, _gthis, Date.now() / 1000);
99
- });
108
+ var init;
109
+ if (this.config.dependencies != null) {
110
+ var _g = [];
111
+ var _g1 = 0;
112
+ var _g2 = MaybeArray_Fields_.makeArray(this.config.dependencies);
113
+ while (_g1 < _g2.length) _g.push(_g2[_g1++].getSource());
114
+ init = Promise.all(_g);
100
115
  } else {
101
- return null;
116
+ init = Promise.resolve(null);
102
117
  };
118
+ return init.then(function (_) {
119
+ var dataPromise = _gthis.generate(hash);
120
+ if (dataPromise != null) {
121
+ return dataPromise.then(function (data) {
122
+ var finalHash;
123
+ if (hash != null) {
124
+ finalHash = Promise.resolve(hash);
125
+ } else {
126
+ var _gthis1 = _gthis;
127
+ var result = new Array(data.length);
128
+ var _g = 0;
129
+ var _g1 = data.length;
130
+ while (_g < _g1) {
131
+ var i = _g++;
132
+ result[i] = SourceHash.fromBytes(data[i].data);
133
+ };
134
+ finalHash = _gthis1.finalizeHash(SourceHash.merge(...result));
135
+ };
136
+ return finalHash.then(function (hash) {
137
+ return new Source(data, hash, _gthis, Date.now() / 1000);
138
+ });
139
+ });
140
+ } else {
141
+ return null;
142
+ };
143
+ });
103
144
  }
104
145
 
105
146
  /**
106
147
  * Optionally overridable hash generation as optimization.
148
+ * Do not use directly. Use `getHash` instead.
107
149
  */
108
150
  generateHash() {
109
151
  return Promise.resolve(null);
110
152
  }
111
153
 
154
+ /**
155
+ * **Do not override.**
156
+ * Used by cache. Returns either null, or result of `generateHash` finalized by adding
157
+ * dependencies.
158
+ */
159
+ finalMaybeHash() {
160
+ var _gthis = this;
161
+ return this.generateHash().then(function (hash) {
162
+ return _gthis.finalizeHash(hash);
163
+ });
164
+ }
165
+
112
166
  /**
113
167
  * Returns a list of sources that this stone generates.
114
168
  * Used by Router for finding the correct asset.
@@ -134,7 +188,8 @@ class Stone extends Register.inherits() {
134
188
  * @param path
135
189
  * If `path` is a directory, stores the file(s) under that path, using their standard names.
136
190
  * If `path` is a file and this stone generates only single data source, stores it under the supplied path.
137
- * @param generate If true (default), the source is exported right away.
191
+ * @param generate If true (default), the source is exported right away. Will not re-save the file, if it already
192
+ * exists under the same path and hash.
138
193
  */
139
194
  setAbsolutePath(path, generate) {
140
195
  if (generate == null) {
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.10", "-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.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");
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
  };
@@ -19,6 +19,11 @@ export declare class CacheManager {
19
19
  defaultFileStrategy: CacheStrategy
20
20
  getSource(stone: AnyStone): Promise<Source>
21
21
 
22
+ /**
23
+ * Re-generates source even if the currently cached value is valid.
24
+ */
25
+ refreshSource(stone: AnyStone): Promise<Source>
26
+
22
27
  /**
23
28
  * Get valid directory to generate files in. The path is unique per stone based on caching rules.
24
29
  * If hash is supplied, and a path was already assigned, the same path is returned, assuring consistency.
@@ -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
@@ -47,6 +47,30 @@ class CacheManager extends Register.inherits() {
47
47
  };
48
48
  }
49
49
 
50
+ /**
51
+ * Re-generates source even if the currently cached value is valid.
52
+ */
53
+ refreshSource(stone) {
54
+ Log.log(10, ...["Re-generating cached stone.", {"stone": stone}]);
55
+ switch (stone.cacheStrategy._hx_index) {
56
+ case 0:
57
+ return stone.finalMaybeHash().then(function (hash) {
58
+ return stone.generateSource(hash);
59
+ });
60
+ break
61
+ case 1:
62
+ return this.memCache.get(stone, CacheDurability.MaxAge(-1), DurabilityCheck.SingleOnGet);
63
+ break
64
+ case 2:
65
+ return this.fileCache.get(stone, CacheDurability.MaxAge(-1), DurabilityCheck.SingleOnGet);
66
+ break
67
+ case 3:
68
+ return this.fileCache.get(stone, CacheDurability.MaxAge(-1), DurabilityCheck.SingleOnGet);
69
+ break
70
+
71
+ };
72
+ }
73
+
50
74
  /**
51
75
  * Get valid directory to generate files in. The path is unique per stone based on caching rules.
52
76
  * If hash is supplied, and a path was already assigned, the same path is returned, assuring consistency.
@@ -1,7 +1,7 @@
1
1
  import {StoneIdType} from "../magic/StoneId"
2
2
  import {MaybeArray} from "../magic/MaybeArray"
3
3
  import {CacheStrategy} from "../cache/Cache"
4
- import {Stone} from "../Stone"
4
+ import {Stone, AnyStone} from "../Stone"
5
5
  import {SourceHash} from "../SourceHash"
6
6
  import {SourceData} from "../Source"
7
7
  import {Project} from "../Project"
@@ -15,6 +15,17 @@ export declare class Files extends Stone<FilesConfig> {
15
15
  export type FilesConfig = {
16
16
  cacheStrategy?: null | CacheStrategy,
17
17
  /**
18
+ * Registers another stone(s) as dependency of this one. Useful for external processes
19
+ * that use a source of some stone, but don't go via Whet to get it.
20
+ * Use with combination of `setAbsolutePath` on the dependency, so that the external process
21
+ * can rely on a fixed path.
22
+ * Will make sure the cached file is up to date when generating this stone.
23
+ * Hash of the dependency is automatically combined with hash generated by this stone. There's no
24
+ * need to add it manually.
25
+ * Do not create cyclic dependencies!
26
+ */
27
+ dependencies?: null | MaybeArray<AnyStone>,
28
+ /**
18
29
  Defaults to the Stone's class name.
19
30
  */
20
31
  id?: null | StoneIdType,
@@ -2,7 +2,7 @@ import {StoneIdType} from "../magic/StoneId"
2
2
  import {RouteType} from "../magic/RouteType"
3
3
  import {MaybeArray} from "../magic/MaybeArray"
4
4
  import {CacheStrategy} from "../cache/Cache"
5
- import {Stone} from "../Stone"
5
+ import {Stone, AnyStone} from "../Stone"
6
6
  import {SourceHash} from "../SourceHash"
7
7
  import {SourceData} from "../Source"
8
8
  import {Project} from "../Project"
@@ -21,6 +21,17 @@ export declare class JsonStone extends Stone<JsonStoneConfig> {
21
21
  export type JsonStoneConfig = {
22
22
  cacheStrategy?: null | CacheStrategy,
23
23
  /**
24
+ * Registers another stone(s) as dependency of this one. Useful for external processes
25
+ * that use a source of some stone, but don't go via Whet to get it.
26
+ * Use with combination of `setAbsolutePath` on the dependency, so that the external process
27
+ * can rely on a fixed path.
28
+ * Will make sure the cached file is up to date when generating this stone.
29
+ * Hash of the dependency is automatically combined with hash generated by this stone. There's no
30
+ * need to add it manually.
31
+ * Do not create cyclic dependencies!
32
+ */
33
+ dependencies?: null | MaybeArray<AnyStone>,
34
+ /**
24
35
  Defaults to the Stone's class name.
25
36
  */
26
37
  id?: null | StoneIdType,
@@ -1,6 +1,7 @@
1
1
  import {StoneIdType} from "../magic/StoneId"
2
+ import {MaybeArray} from "../magic/MaybeArray"
2
3
  import {CacheStrategy} from "../cache/Cache"
3
- import {Stone} from "../Stone"
4
+ import {Stone, AnyStone} from "../Stone"
4
5
  import {SourceHash} from "../SourceHash"
5
6
  import {SourceData} from "../Source"
6
7
  import {Project} from "../Project"
@@ -17,6 +18,17 @@ export declare class RemoteFile extends Stone<RemoteFileConfig> {
17
18
  export type RemoteFileConfig = {
18
19
  cacheStrategy?: null | CacheStrategy,
19
20
  /**
21
+ * Registers another stone(s) as dependency of this one. Useful for external processes
22
+ * that use a source of some stone, but don't go via Whet to get it.
23
+ * Use with combination of `setAbsolutePath` on the dependency, so that the external process
24
+ * can rely on a fixed path.
25
+ * Will make sure the cached file is up to date when generating this stone.
26
+ * Hash of the dependency is automatically combined with hash generated by this stone. There's no
27
+ * need to add it manually.
28
+ * Do not create cyclic dependencies!
29
+ */
30
+ dependencies?: null | MaybeArray<AnyStone>,
31
+ /**
20
32
  Defaults to the Stone's class name.
21
33
  */
22
34
  id?: null | StoneIdType,
@@ -1,7 +1,8 @@
1
1
  import {Router} from "../route/Router"
2
2
  import {StoneIdType} from "../magic/StoneId"
3
+ import {MaybeArray} from "../magic/MaybeArray"
3
4
  import {CacheStrategy} from "../cache/Cache"
4
- import {Stone} from "../Stone"
5
+ import {Stone, AnyStone} from "../Stone"
5
6
  import {SourceHash} from "../SourceHash"
6
7
  import {SourceData} from "../Source"
7
8
  import {Project} from "../Project"
@@ -26,6 +27,17 @@ export declare class Server extends Stone<ServerConfig> {
26
27
  export type ServerConfig = {
27
28
  cacheStrategy?: null | CacheStrategy,
28
29
  /**
30
+ * Registers another stone(s) as dependency of this one. Useful for external processes
31
+ * that use a source of some stone, but don't go via Whet to get it.
32
+ * Use with combination of `setAbsolutePath` on the dependency, so that the external process
33
+ * can rely on a fixed path.
34
+ * Will make sure the cached file is up to date when generating this stone.
35
+ * Hash of the dependency is automatically combined with hash generated by this stone. There's no
36
+ * need to add it manually.
37
+ * Do not create cyclic dependencies!
38
+ */
39
+ dependencies?: null | MaybeArray<AnyStone>,
40
+ /**
29
41
  Defaults to the Stone's class name.
30
42
  */
31
43
  id?: null | StoneIdType,
@@ -1,7 +1,8 @@
1
1
  import {StoneIdType} from "../magic/StoneId"
2
2
  import {RoutePathType} from "../magic/RoutePathType"
3
+ import {MaybeArray} from "../magic/MaybeArray"
3
4
  import {CacheStrategy} from "../cache/Cache"
4
- import {Stone} from "../Stone"
5
+ import {Stone, AnyStone} from "../Stone"
5
6
  import {SourceHash} from "../SourceHash"
6
7
  import {SourceData} from "../Source"
7
8
  import {Project} from "../Project"
@@ -16,6 +17,17 @@ export declare class ZipStone extends Stone<ZipConfig> {
16
17
 
17
18
  export type ZipConfig = {
18
19
  cacheStrategy?: null | CacheStrategy,
20
+ /**
21
+ * Registers another stone(s) as dependency of this one. Useful for external processes
22
+ * that use a source of some stone, but don't go via Whet to get it.
23
+ * Use with combination of `setAbsolutePath` on the dependency, so that the external process
24
+ * can rely on a fixed path.
25
+ * Will make sure the cached file is up to date when generating this stone.
26
+ * Hash of the dependency is automatically combined with hash generated by this stone. There's no
27
+ * need to add it manually.
28
+ * Do not create cyclic dependencies!
29
+ */
30
+ dependencies?: null | MaybeArray<AnyStone>,
19
31
  filename?: null | string,
20
32
  /**
21
33
  Defaults to the Stone's class name.
@@ -1,7 +1,8 @@
1
1
  import {Hxml} from "./Hxml"
2
2
  import {StoneIdType} from "../../magic/StoneId"
3
+ import {MaybeArray} from "../../magic/MaybeArray"
3
4
  import {CacheStrategy} from "../../cache/Cache"
4
- import {Stone} from "../../Stone"
5
+ import {Stone, AnyStone} from "../../Stone"
5
6
  import {SourceHash} from "../../SourceHash"
6
7
  import {SourceData} from "../../Source"
7
8
  import {Project} from "../../Project"
@@ -22,6 +23,17 @@ export declare class HaxeBuild extends Stone<BuildConfig> {
22
23
 
23
24
  export type BuildConfig = {
24
25
  cacheStrategy?: null | CacheStrategy,
26
+ /**
27
+ * Registers another stone(s) as dependency of this one. Useful for external processes
28
+ * that use a source of some stone, but don't go via Whet to get it.
29
+ * Use with combination of `setAbsolutePath` on the dependency, so that the external process
30
+ * can rely on a fixed path.
31
+ * Will make sure the cached file is up to date when generating this stone.
32
+ * Hash of the dependency is automatically combined with hash generated by this stone. There's no
33
+ * need to add it manually.
34
+ * Do not create cyclic dependencies!
35
+ */
36
+ dependencies?: null | MaybeArray<AnyStone>,
25
37
  filename?: null | string,
26
38
  hxml: Hxml,
27
39
  /**
@@ -93,7 +93,7 @@ class HaxeBuild extends Register.inherits(Stone) {
93
93
  addCommands() {
94
94
  var _gthis = this;
95
95
  this.project.addCommand("build", this).action(function (..._) {
96
- return _gthis.build();
96
+ return _gthis.project.cache.refreshSource(_gthis);
97
97
  });
98
98
  }
99
99
  list() {
@@ -124,7 +124,7 @@ class HaxeBuild extends Register.inherits(Stone) {
124
124
  };
125
125
  result[i] = Path.posix.join(".", root, ".", this1);
126
126
  };
127
- return Promise.all([this.config.hxml.generateHash(), SourceHash.fromFiles(result)]).then(function (r) {
127
+ return Promise.all([this.config.hxml.getHash(), SourceHash.fromFiles(result)]).then(function (r) {
128
128
  return SourceHash.merge(...r);
129
129
  });
130
130
  }
@@ -2,7 +2,7 @@ import {HaxeBuild} from "./HaxeBuild"
2
2
  import {StoneIdType} from "../../magic/StoneId"
3
3
  import {MaybeArray} from "../../magic/MaybeArray"
4
4
  import {CacheStrategy} from "../../cache/Cache"
5
- import {Stone} from "../../Stone"
5
+ import {Stone, AnyStone} from "../../Stone"
6
6
  import {SourceHash} from "../../SourceHash"
7
7
  import {SourceData} from "../../Source"
8
8
  import {Project} from "../../Project"
@@ -34,6 +34,17 @@ export type HxmlConfig = {
34
34
  dce?: null | DCE,
35
35
  debug?: null | boolean,
36
36
  defines?: null | MaybeArray<string>,
37
+ /**
38
+ * Registers another stone(s) as dependency of this one. Useful for external processes
39
+ * that use a source of some stone, but don't go via Whet to get it.
40
+ * Use with combination of `setAbsolutePath` on the dependency, so that the external process
41
+ * can rely on a fixed path.
42
+ * Will make sure the cached file is up to date when generating this stone.
43
+ * Hash of the dependency is automatically combined with hash generated by this stone. There's no
44
+ * need to add it manually.
45
+ * Do not create cyclic dependencies!
46
+ */
47
+ dependencies?: null | MaybeArray<AnyStone>,
37
48
  flags?: null | MaybeArray<MaybeArray<string>>,
38
49
  /**
39
50
  Defaults to the Stone's class name.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "whet",
3
- "version": "0.0.10",
3
+ "version": "0.0.13",
4
4
  "description": "NodeJS based assets management and project tooling library.",
5
5
  "scripts": {
6
6
  "devinit": "npx dts2hx commander --modular --noLibWrap",