whet 0.0.13 → 0.0.16

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 (38) hide show
  1. package/bin/whet/Source.d.ts +5 -3
  2. package/bin/whet/Source.js +4 -2
  3. package/bin/whet/Stone.d.ts +12 -0
  4. package/bin/whet/Stone.js +21 -0
  5. package/bin/whet/Utils.js +1 -1
  6. package/bin/whet/Whet.js +1 -1
  7. package/bin/whet/extern/Minimatch.d.ts +77 -0
  8. package/bin/whet/magic/MinimatchType.d.ts +5 -0
  9. package/bin/whet/magic/MinimatchType.js +26 -0
  10. package/bin/whet/magic/RoutePathType.d.ts +12 -3
  11. package/bin/whet/magic/RoutePathType.js +87 -23
  12. package/bin/whet/route/Router.d.ts +19 -12
  13. package/bin/whet/route/Router.js +224 -91
  14. package/bin/whet/stones/Files.d.ts +5 -0
  15. package/bin/whet/stones/JsonStone.d.ts +7 -3
  16. package/bin/whet/stones/JsonStone.js +19 -50
  17. package/bin/whet/stones/RemoteFile.d.ts +5 -0
  18. package/bin/whet/stones/Server.d.ts +5 -0
  19. package/bin/whet/stones/Server.js +1 -1
  20. package/bin/whet/stones/Zip.d.ts +5 -0
  21. package/bin/whet/stones/Zip.js +2 -22
  22. package/bin/whet/stones/haxe/HaxeBuild.d.ts +5 -0
  23. package/bin/whet/stones/haxe/HaxeBuild.js +3 -2
  24. package/bin/whet/stones/haxe/Hxml.d.ts +5 -0
  25. package/bin/whet.d.ts +0 -1
  26. package/bin/whet.js +0 -1
  27. package/package.json +4 -2
  28. package/bin/StringBuf.d.ts +0 -13
  29. package/bin/StringBuf.js +0 -25
  30. package/bin/haxe/CallStack.d.ts +0 -41
  31. package/bin/haxe/CallStack.js +0 -96
  32. package/bin/haxe/NativeStackTrace.js +0 -147
  33. package/bin/haxe/io/Path.d.ts +0 -109
  34. package/bin/haxe/io/Path.js +0 -217
  35. package/bin/whet/magic/RouteType.d.ts +0 -13
  36. package/bin/whet/magic/RouteType.js +0 -104
  37. package/bin/whet/route/Route.d.ts +0 -19
  38. package/bin/whet/route/Route.js +0 -121
@@ -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) != "/") {
@@ -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.16", "-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) {
@@ -0,0 +1,77 @@
1
+
2
+ export type IOptions = {
3
+ /**
4
+ Dump a ton of stuff to stderr.
5
+ */
6
+ debug?: null | boolean,
7
+ /**
8
+ Allow patterns to match filenames starting with a period,
9
+ even if the pattern does not explicitly have a period in that spot.
10
+
11
+ Note that by default, `'a/**' + '/b'` will **not** match `a/.d/b`, unless `dot` is set.
12
+ */
13
+ dot?: null | boolean,
14
+ /**
15
+ Returns from negate expressions the same as if they were not negated.
16
+ (Ie, true on a hit, false on a miss.)
17
+ */
18
+ flipNegate?: null | boolean,
19
+ /**
20
+ If set, then patterns without slashes will be matched
21
+ against the basename of the path if it contains slashes. For example,
22
+ `a?b` would match the path `/xyz/123/acb`, but not `/xyz/acb/123`.
23
+ */
24
+ matchBase?: null | boolean,
25
+ /**
26
+ Do not expand `{a,b}` and `{1..3}` brace sets.
27
+ */
28
+ nobrace?: null | boolean,
29
+ /**
30
+ Perform a case-insensitive match.
31
+ */
32
+ nocase?: null | boolean,
33
+ /**
34
+ Suppress the behavior of treating `#` at the start of a pattern as a comment.
35
+ */
36
+ nocomment?: null | boolean,
37
+ /**
38
+ Disable "extglob" style patterns like `+(a|b)`.
39
+ */
40
+ noext?: null | boolean,
41
+ /**
42
+ Disable `**` matching against multiple folder names.
43
+ */
44
+ noglobstar?: null | boolean,
45
+ /**
46
+ Suppress the behavior of treating a leading `!` character as negation.
47
+ */
48
+ nonegate?: null | boolean,
49
+ /**
50
+ When a match is not found by `minimatch.match`,
51
+ return a list containing the pattern itself if this option is set.
52
+ Otherwise, an empty list is returned if there are no matches.
53
+ */
54
+ nonull?: null | boolean,
55
+ /**
56
+ Compare a partial path to a pattern. As long as the parts of the path that
57
+ are present are not contradicted by the pattern, it will be treated as a
58
+ match. This is useful in applications where you're walking through a
59
+ folder structure, and don't yet have the full path, but want to ensure that
60
+ you do not walk down paths that can never be a match.
61
+ */
62
+ partial?: null | boolean,
63
+ /**
64
+ Use `\\` as a path separator _only_, and _never_ as an escape
65
+ character. If set, all `\\` characters are replaced with `/` in
66
+ the pattern. Note that this makes it **impossible** to match
67
+ against paths containing literal glob pattern characters, but
68
+ allows matching with patterns constructed using `path.join()` and
69
+ `path.resolve()` on Windows platforms, mimicking the (buggy!)
70
+ behavior of earlier versions on Windows. Please use with
71
+ caution, and be mindful of the caveat about Windows paths
72
+
73
+ For legacy reasons, this is also set if
74
+ `options.allowWindowsEscape` is set to the exact value `false`.
75
+ */
76
+ windowsPathsNoEscape?: null | boolean
77
+ }
@@ -0,0 +1,5 @@
1
+ import Minimatch from "minimatch"
2
+
3
+ export type MinimatchType = Minimatch | string
4
+
5
+ export const makeMinimatch: (src: MinimatchType) => Minimatch
@@ -0,0 +1,26 @@
1
+ import Minimatch from "minimatch"
2
+ import {Register} from "../../genes/Register.js"
3
+
4
+ const $global = Register.$global
5
+
6
+ export const MinimatchType_Fields_ = Register.global("$hxClasses")["whet.magic._MinimatchType.MinimatchType_Fields_"] =
7
+ class MinimatchType_Fields_ {
8
+ static makeMinimatch(src) {
9
+ if (typeof(src) == "string") {
10
+ return new Minimatch.Minimatch(src, null);
11
+ } else if (src instanceof Minimatch.Minimatch) {
12
+ return src;
13
+ } else {
14
+ throw new Error("Expected a string or Minimatch object.");
15
+ };
16
+ }
17
+ static get __name__() {
18
+ return "whet.magic._MinimatchType.MinimatchType_Fields_"
19
+ }
20
+ get __class__() {
21
+ return MinimatchType_Fields_
22
+ }
23
+ }
24
+
25
+
26
+ export const makeMinimatch = MinimatchType_Fields_.makeMinimatch
@@ -1,9 +1,18 @@
1
1
  import {Router, RoutePath} from "../route/Router"
2
- import {BaseRouteType} from "./RouteType"
2
+ import {MinimatchType} from "./MinimatchType"
3
+ import {AnyStone} from "../Stone"
3
4
 
4
5
  /**
5
- * Anything that can be transformed into `Route`.
6
+ * Anything that can be transformed into `RoutePath`. Can be a Stone or Router.
7
+ * Can also be an array of Stones, Routers, or:
8
+ * - `[routeUnder, Stone|Router]`, where `routeUnder` is a string to serve the results under (directory or filename).
9
+ * - `[routeUnder, Stone|Router, filter]`, where `filter` can be a glob pattern string, or a `Minimatch` object.
10
+ * - `[routeUnder, Stone|Router, filter, extractDirs]`, where `extractDirs` can be a glob pattern,
11
+ * or a `Minimatch` object, and is used to remove the portion of results' directory that matches.
12
+ * Wherever Stone or Router is expected, a string can be used as a shortcut for `new Files({ paths: [<string>] })`.
6
13
  */
7
- export type RoutePathType = Router | BaseRouteType[][]
14
+ export type RoutePathType = BaseRouteType | BaseRouteType[] | BaseRouteType[][]
15
+
16
+ export type BaseRouteType = Router | AnyStone | MinimatchType | string
8
17
 
9
18
  export const makeRoutePath: (routerPathType: RoutePathType) => RoutePath[]
@@ -1,7 +1,9 @@
1
+ import {Files} from "../stones/Files.js"
1
2
  import {Router} from "../route/Router.js"
2
- import {Route} from "../route/Route.js"
3
- import {RouteType_Fields_} from "./RouteType.js"
3
+ import {MinimatchType_Fields_} from "./MinimatchType.js"
4
+ import {Stone} from "../Stone.js"
4
5
  import * as Path from "path"
6
+ import Minimatch from "minimatch"
5
7
  import {Register} from "../../genes/Register.js"
6
8
  import {StringTools} from "../../StringTools.js"
7
9
  import {HxOverrides} from "../../HxOverrides.js"
@@ -11,11 +13,18 @@ const $global = Register.$global
11
13
  export const RoutePathType_Fields_ = Register.global("$hxClasses")["whet.magic._RoutePathType.RoutePathType_Fields_"] =
12
14
  class RoutePathType_Fields_ {
13
15
  static makeRoutePath(routerPathType) {
14
- if (((routerPathType) instanceof Router)) {
15
- return routerPathType.routes;
16
+ if (((routerPathType) instanceof Router) || ((routerPathType) instanceof Stone) || typeof(routerPathType) == "string") {
17
+ var s = "/";
18
+ var str = ("/".length > 1 && HxOverrides.cca("/", 0) == 47) ? "/".substring(1) : "/";
19
+ if (str.length > 0) {
20
+ str = Path.posix.normalize(str);
21
+ str = StringTools.replace(str, "\\", "/");
22
+ };
23
+ s = str;
24
+ return [{"routeUnder": (HxOverrides.cca(s, 0) == 47) ? s : "/" + s, "source": (typeof(routerPathType) == "string") ? new Files({"paths": [routerPathType]}) : routerPathType, "filter": null, "extractDirs": null}];
16
25
  };
17
26
  if (!((routerPathType) instanceof Array)) {
18
- throw new Error("RoutePath should be an array.");
27
+ throw new Error("RoutePath should be a Stone, Router, or an array.");
19
28
  };
20
29
  var _g = [];
21
30
  var _g1 = 0;
@@ -23,25 +32,80 @@ class RoutePathType_Fields_ {
23
32
  while (_g1 < _g2.length) {
24
33
  var item = _g2[_g1];
25
34
  ++_g1;
26
- if (!((item) instanceof Array)) {
27
- throw new Error("RoutePath element should be an array.");
28
- };
29
- if (item.length < 2) {
30
- throw new Error("RoutePath element should have at least 2 entries `[serveId, route]`.");
35
+ if (((item) instanceof Router) || ((item) instanceof Stone) || typeof(item) == "string") {
36
+ var s = "/";
37
+ var str = ("/".length > 1 && HxOverrides.cca("/", 0) == 47) ? "/".substring(1) : "/";
38
+ if (str.length > 0) {
39
+ str = Path.posix.normalize(str);
40
+ str = StringTools.replace(str, "\\", "/");
41
+ };
42
+ s = str;
43
+ _g.push({"routeUnder": (HxOverrides.cca(s, 0) == 47) ? s : "/" + s, "source": (typeof(item) == "string") ? new Files({"paths": [item]}) : item, "filter": null, "extractDirs": null});
44
+ } else if (((item) instanceof Array)) {
45
+ var inner = item;
46
+ if (typeof(inner[0]) != "string") {
47
+ throw new Error("First element of RoutePath array should be `routeUnder` (a string).");
48
+ };
49
+ if (!(((inner[1]) instanceof Router) || ((inner[1]) instanceof Stone) || typeof(inner[1]) == "string")) {
50
+ throw new Error("Second element of RoutePath array should be a Stone or Router.");
51
+ };
52
+ var tmp;
53
+ switch (inner.length) {
54
+ case 2:
55
+ var s1 = inner[0];
56
+ var str1 = (s1.length > 1 && HxOverrides.cca(s1, 0) == 47) ? s1.substring(1) : s1;
57
+ if (str1.length > 0) {
58
+ str1 = Path.posix.normalize(str1);
59
+ str1 = StringTools.replace(str1, "\\", "/");
60
+ };
61
+ s1 = str1;
62
+ var src = inner[1];
63
+ tmp = {"routeUnder": (HxOverrides.cca(s1, 0) == 47) ? s1 : "/" + s1, "source": (typeof(src) == "string") ? new Files({"paths": [src]}) : src, "filter": null, "extractDirs": null};
64
+ break
65
+ case 3:
66
+ var s2 = inner[0];
67
+ var str2 = (s2.length > 1 && HxOverrides.cca(s2, 0) == 47) ? s2.substring(1) : s2;
68
+ if (str2.length > 0) {
69
+ str2 = Path.posix.normalize(str2);
70
+ str2 = StringTools.replace(str2, "\\", "/");
71
+ };
72
+ s2 = str2;
73
+ var tmp1 = (HxOverrides.cca(s2, 0) == 47) ? s2 : "/" + s2;
74
+ var src1 = inner[1];
75
+ var tmp2 = (typeof(src1) == "string") ? new Files({"paths": [src1]}) : src1;
76
+ if (!(typeof(inner[2]) == "string" || inner[2] instanceof Minimatch)) {
77
+ throw new Error("Third" + " element of RoutePath array should be a glob pattern (string or `minimatch` object)");
78
+ };
79
+ tmp = {"routeUnder": tmp1, "source": tmp2, "filter": MinimatchType_Fields_.makeMinimatch(inner[2]), "extractDirs": null};
80
+ break
81
+ case 4:
82
+ var s3 = inner[0];
83
+ var str3 = (s3.length > 1 && HxOverrides.cca(s3, 0) == 47) ? s3.substring(1) : s3;
84
+ if (str3.length > 0) {
85
+ str3 = Path.posix.normalize(str3);
86
+ str3 = StringTools.replace(str3, "\\", "/");
87
+ };
88
+ s3 = str3;
89
+ var tmp3 = (HxOverrides.cca(s3, 0) == 47) ? s3 : "/" + s3;
90
+ var src2 = inner[1];
91
+ var tmp4 = (typeof(src2) == "string") ? new Files({"paths": [src2]}) : src2;
92
+ if (!(typeof(inner[2]) == "string" || inner[2] instanceof Minimatch)) {
93
+ throw new Error("Third" + " element of RoutePath array should be a glob pattern (string or `minimatch` object)");
94
+ };
95
+ var tmp5 = MinimatchType_Fields_.makeMinimatch(inner[2]);
96
+ if (!(typeof(inner[3]) == "string" || inner[3] instanceof Minimatch)) {
97
+ throw new Error("Fourth" + " element of RoutePath array should be a glob pattern (string or `minimatch` object)");
98
+ };
99
+ tmp = {"routeUnder": tmp3, "source": tmp4, "filter": tmp5, "extractDirs": MinimatchType_Fields_.makeMinimatch(inner[3])};
100
+ break
101
+ default:
102
+ throw new Error("Invalid array for a RoutePath element.");
103
+
104
+ };
105
+ _g.push(tmp);
106
+ } else {
107
+ throw new Error("Unexpected RoutePath element.");
31
108
  };
32
- if (item.length > 3) {
33
- throw new Error("RoutePath element should have at most 3 entries `[serveId, route, filter]`.");
34
- };
35
- var s = item[0];
36
- var str = (s.length > 1 && HxOverrides.cca(s, 0) == 47) ? s.substring(1) : s;
37
- if (str.length > 0) {
38
- str = Path.posix.normalize(str);
39
- str = StringTools.replace(str, "\\", "/");
40
- };
41
- s = str;
42
- var tmp = (HxOverrides.cca(s, 0) == 47) ? s : "/" + s;
43
- var _g3 = item.slice(1);
44
- _g.push({"routeUnder": tmp, "route": (_g3.length == 1) ? (((item[1]) instanceof Route)) ? item[1] : RouteType_Fields_.makeRoute([_g3]) : RouteType_Fields_.makeRoute([_g3])});
45
109
  };
46
110
  return _g;
47
111
  }
@@ -1,7 +1,9 @@
1
1
  import {RouteResult} from "./RouteResult"
2
- import {Route} from "./Route"
3
2
  import {RoutePathType} from "../magic/RoutePathType"
3
+ import {MinimatchType} from "../magic/MinimatchType"
4
+ import {AnyStone} from "../Stone"
4
5
  import {SourceHash} from "../SourceHash"
6
+ import Minimatch from "minimatch"
5
7
 
6
8
  export declare class Router {
7
9
  constructor(routes?: null | RoutePathType)
@@ -9,25 +11,30 @@ export declare class Router {
9
11
  route(r: RoutePathType): void
10
12
 
11
13
  /**
12
- * Find data sources routed under `id`. By default only single result is returned if `id`
13
- * is not a directory, all results otherwise. This can be overriden by providing a second argument.
14
+ * Find data sources routed under `pattern`.
15
+ * @param pattern A glob pattern to search for.
14
16
  */
15
- find(id: string, firstOnly?: null | boolean): Promise<RouteResult[]>
17
+ get(pattern?: MinimatchType): Promise<RouteResult[]>
16
18
 
17
19
  /**
18
- * Get combined hash of all sources that would be found under supplied id.
20
+ * Get combined hash of all sources that fit the `pattern`.
19
21
  */
20
- getHash(id: string, firstOnly?: null | boolean): Promise<SourceHash>
21
- getHashOfEverything(): Promise<SourceHash>
22
+ getHash(pattern?: MinimatchType): Promise<SourceHash>
22
23
 
23
24
  /**
24
- * Save files filtered by `searchId` into provided `saveInto` folder.
25
+ * Save files filtered by `pattern` into provided `saveInto` folder.
25
26
  */
26
- saveInto(searchId: string, saveInto: string, clearFirst?: boolean): Promise<any>
27
- listContents(search?: string): Promise<string>
27
+ saveInto(pattern: MinimatchType, saveInto: string, clearFirst?: boolean): Promise<any>
28
+ listContents(pattern?: MinimatchType): Promise<string>
29
+ protected allFromRoute(route: RoutePath): Promise<RouteResult[]>
30
+ protected getServeId(path: string, route: RoutePath): string
28
31
  }
29
32
 
30
33
  export type RoutePath = {
31
- route: Route,
32
- routeUnder: string
34
+ extractDirs: Minimatch,
35
+ filter: Minimatch,
36
+ routeUnder: string,
37
+ source: RouterSource
33
38
  }
39
+
40
+ export type RouterSource = AnyStone | Router