whet 0.0.10 → 0.0.11

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,7 +36,9 @@ 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
 
@@ -72,7 +75,8 @@ export declare class Stone<T extends StoneConfig> {
72
75
  * @param path
73
76
  * If `path` is a directory, stores the file(s) under that path, using their standard names.
74
77
  * 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.
78
+ * @param generate If true (default), the source is exported right away. Will not re-save the file, if it already
79
+ * exists under the same path and hash.
76
80
  */
77
81
  setAbsolutePath(path: string, generate?: boolean): Promise<Source>
78
82
 
@@ -95,6 +99,17 @@ export declare class Stone<T extends StoneConfig> {
95
99
  export type StoneConfig = {
96
100
  cacheStrategy?: null | CacheStrategy,
97
101
  /**
102
+ * Registers another stone as dependency of this one. Useful for external processes
103
+ * that use a source of some stone, but don't go via Whet to get it.
104
+ * Use with combination of `setAbsolutePath` on the dependency, so that the external process
105
+ * can rely on fixed path.
106
+ * Will make sure the cached file is up to date when generating this stone.
107
+ * Hash of the dependency is automatically combined with hash generated by this stone. There's no
108
+ * need to add it manually.
109
+ * Do not create cyclic dependencies!
110
+ */
111
+ dependencies?: null | MaybeArray<AnyStone>,
112
+ /**
98
113
  Defaults to the Stone's class name.
99
114
  */
100
115
  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,7 +59,9 @@ 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;
@@ -68,7 +71,17 @@ class Stone extends Register.inherits() {
68
71
  return hash;
69
72
  } else {
70
73
  return _gthis.getSource().then(function (s) {
71
- return s.hash;
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
+ };
72
85
  });
73
86
  };
74
87
  });
@@ -82,24 +95,37 @@ class Stone extends Register.inherits() {
82
95
  generateSource(hash) {
83
96
  var _gthis = this;
84
97
  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
- });
98
+ console.log("src/whet/Stone.hx:74:",this.config.dependencies);
99
+ var init;
100
+ if (this.config.dependencies != null) {
101
+ var _g = [];
102
+ var _g1 = 0;
103
+ var _g2 = MaybeArray_Fields_.makeArray(this.config.dependencies);
104
+ while (_g1 < _g2.length) _g.push(_g2[_g1++].getSource());
105
+ init = Promise.all(_g);
100
106
  } else {
101
- return null;
107
+ init = Promise.resolve(null);
102
108
  };
109
+ return init.then(function (_) {
110
+ var dataPromise = _gthis.generate(hash);
111
+ if (dataPromise != null) {
112
+ return dataPromise.then(function (data) {
113
+ if (hash == null) {
114
+ var result = new Array(data.length);
115
+ var _g = 0;
116
+ var _g1 = data.length;
117
+ while (_g < _g1) {
118
+ var i = _g++;
119
+ result[i] = SourceHash.fromBytes(data[i].data);
120
+ };
121
+ hash = SourceHash.merge(...result);
122
+ };
123
+ return new Source(data, hash, _gthis, Date.now() / 1000);
124
+ });
125
+ } else {
126
+ return null;
127
+ };
128
+ });
103
129
  }
104
130
 
105
131
  /**
@@ -134,7 +160,8 @@ class Stone extends Register.inherits() {
134
160
  * @param path
135
161
  * If `path` is a directory, stores the file(s) under that path, using their standard names.
136
162
  * 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.
163
+ * @param generate If true (default), the source is exported right away. Will not re-save the file, if it already
164
+ * exists under the same path and hash.
138
165
  */
139
166
  setAbsolutePath(path, generate) {
140
167
  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.11", "-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) {
@@ -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.
@@ -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.generateHash().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 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 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 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 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 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 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 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 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 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 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 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 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() {
@@ -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 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 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.11",
4
4
  "description": "NodeJS based assets management and project tooling library.",
5
5
  "scripts": {
6
6
  "devinit": "npx dts2hx commander --modular --noLibWrap",