whet 0.0.6 → 0.0.9

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,13 +1,13 @@
1
1
  import {RouteType_Fields_} from "../magic/RouteType.js"
2
2
  import {MaybeArray_Fields_} from "../magic/MaybeArray.js"
3
3
  import {Stone} from "../Stone.js"
4
- import {SourceId_Fields_} from "../SourceId.js"
5
4
  import {SourceHash} from "../SourceHash.js"
6
5
  import {SourceData} from "../Source.js"
7
6
  import * as Path from "path"
8
7
  import {Register} from "../../genes/Register.js"
9
8
  import {StringTools} from "../../StringTools.js"
10
9
  import {Reflect as Reflect__1} from "../../Reflect.js"
10
+ import {HxOverrides} from "../../HxOverrides.js"
11
11
 
12
12
  const $global = Register.$global
13
13
 
@@ -91,9 +91,13 @@ class JsonStone extends Register.inherits(Stone) {
91
91
  }
92
92
  list() {
93
93
  var s = this.config.name;
94
- s = Path.posix.normalize(s);
95
- s = StringTools.replace(s, "\\", "/");
96
- return Promise.resolve([(SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s]);
94
+ var str = (s.length > 1 && HxOverrides.cca(s, 0) == 47) ? s.substring(1) : s;
95
+ if (str.length > 0) {
96
+ str = Path.posix.normalize(str);
97
+ str = StringTools.replace(str, "\\", "/");
98
+ };
99
+ s = str;
100
+ return Promise.resolve([(HxOverrides.cca(s, 0) == 47) ? s : "/" + s]);
97
101
  }
98
102
  initConfig() {
99
103
  if (this.config.name == null) {
@@ -1,6 +1,5 @@
1
1
  import {CacheStrategy, CacheDurability} from "../cache/Cache.js"
2
2
  import {Stone} from "../Stone.js"
3
- import {SourceId_Fields_} from "../SourceId.js"
4
3
  import {SourceHash} from "../SourceHash.js"
5
4
  import {SourceData} from "../Source.js"
6
5
  import {Log} from "../Log.js"
@@ -10,6 +9,7 @@ import * as Https from "https"
10
9
  import {Register} from "../../genes/Register.js"
11
10
  import {Buffer} from "buffer"
12
11
  import {StringTools} from "../../StringTools.js"
12
+ import {HxOverrides} from "../../HxOverrides.js"
13
13
 
14
14
  const $global = Register.$global
15
15
 
@@ -51,9 +51,13 @@ class RemoteFile extends Register.inherits(Stone) {
51
51
  }
52
52
  getId() {
53
53
  var s = Path.basename(new URL(this.config.url).pathname);
54
- s = Path.posix.normalize(s);
55
- s = StringTools.replace(s, "\\", "/");
56
- return (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
54
+ var str = (s.length > 1 && HxOverrides.cca(s, 0) == 47) ? s.substring(1) : s;
55
+ if (str.length > 0) {
56
+ str = Path.posix.normalize(str);
57
+ str = StringTools.replace(str, "\\", "/");
58
+ };
59
+ s = str;
60
+ return (HxOverrides.cca(s, 0) == 47) ? s : "/" + s;
57
61
  }
58
62
  static get __name__() {
59
63
  return "whet.stones.RemoteFile"
@@ -6,7 +6,6 @@ import {SourceHash} from "../SourceHash"
6
6
  import {SourceData} from "../Source"
7
7
  import {Project} from "../Project"
8
8
  import {IncomingMessage, ServerResponse} from "http"
9
- import {Command} from "commander"
10
9
 
11
10
  export declare class Server extends Stone<ServerConfig> {
12
11
  constructor(config: ServerConfig)
@@ -20,7 +19,7 @@ export declare class Server extends Stone<ServerConfig> {
20
19
  */
21
20
  serve(): void
22
21
  protected initConfig(): void
23
- protected getCommands(): Command[]
22
+ protected addCommands(): void
24
23
  protected handler(req: IncomingMessage, res: ServerResponse): void
25
24
  }
26
25
 
@@ -1,13 +1,12 @@
1
1
  import {Stone} from "../Stone.js"
2
- import {SourceId_Fields_} from "../SourceId.js"
3
2
  import {Log} from "../Log.js"
4
3
  import * as Path from "path"
5
4
  import Mime from "mime"
6
5
  import * as Http from "http"
7
6
  import {Register} from "../../genes/Register.js"
8
- import {Command} from "commander"
9
7
  import {StringTools} from "../../StringTools.js"
10
8
  import {Std} from "../../Std.js"
9
+ import {HxOverrides} from "../../HxOverrides.js"
11
10
 
12
11
  const $global = Register.$global
13
12
 
@@ -42,36 +41,61 @@ class Server extends Register.inherits(Stone) {
42
41
  this.config.port = 7000;
43
42
  };
44
43
  }
45
- getCommands() {
44
+ addCommands() {
46
45
  var _gthis = this;
47
- return [new Command("serve").option("-p, --port <port>", "server port", "" + this.config.port).action(function (...args) {
46
+ this.project.addCommand("serve", this).option("-p, --port <port>", "server port", "" + this.config.port).action(function (...args) {
48
47
  if (args[0].port != null) {
49
48
  _gthis.config.port = Std.parseInt(args[0].port);
50
49
  };
51
50
  _gthis.serve();
52
51
  return null;
53
- })];
52
+ });
54
53
  }
55
54
  handler(req, res) {
56
55
  var _gthis = this;
57
56
  Log.log(30, ...["Handling request.", {"url": req.url, "method": req.method}]);
58
- var s = req.url;
59
- s = Path.posix.normalize(s);
60
- s = StringTools.replace(s, "\\", "/");
61
- var id = (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
57
+ var searchIndex = req.url.indexOf("?");
58
+ var id;
59
+ if (searchIndex > 0) {
60
+ var s = req.url.substring(0, searchIndex);
61
+ var str = (s.length > 1 && HxOverrides.cca(s, 0) == 47) ? s.substring(1) : s;
62
+ if (str.length > 0) {
63
+ str = Path.posix.normalize(str);
64
+ str = StringTools.replace(str, "\\", "/");
65
+ };
66
+ s = str;
67
+ id = (HxOverrides.cca(s, 0) == 47) ? s : "/" + s;
68
+ } else {
69
+ var s = req.url;
70
+ var str = (s.length > 1 && HxOverrides.cca(s, 0) == 47) ? s.substring(1) : s;
71
+ if (str.length > 0) {
72
+ str = Path.posix.normalize(str);
73
+ str = StringTools.replace(str, "\\", "/");
74
+ };
75
+ s = str;
76
+ id = (HxOverrides.cca(s, 0) == 47) ? s : "/" + s;
77
+ };
62
78
  if (req.method == "GET") {
63
- if (SourceId_Fields_.endsWithSlash(id)) {
79
+ if (HxOverrides.cca(id, id.length - 1) == 47) {
64
80
  if ("index.html".length > 0) {
65
81
  var s = id.substring(0, id.lastIndexOf("/") + 1);
66
- s = Path.posix.normalize(s);
67
- s = StringTools.replace(s, "\\", "/");
68
- id = ((SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s) + "index.html";
82
+ var str = (s.length > 1 && HxOverrides.cca(s, 0) == 47) ? s.substring(1) : s;
83
+ if (str.length > 0) {
84
+ str = Path.posix.normalize(str);
85
+ str = StringTools.replace(str, "\\", "/");
86
+ };
87
+ s = str;
88
+ id = ((HxOverrides.cca(s, 0) == 47) ? s : "/" + s) + "index.html";
69
89
  };
70
90
  } else if (Path.posix.extname(id) == "") {
71
91
  var s = "" + id + "/index.html";
72
- s = Path.posix.normalize(s);
73
- s = StringTools.replace(s, "\\", "/");
74
- id = (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
92
+ var str = (s.length > 1 && HxOverrides.cca(s, 0) == 47) ? s.substring(1) : s;
93
+ if (str.length > 0) {
94
+ str = Path.posix.normalize(str);
95
+ str = StringTools.replace(str, "\\", "/");
96
+ };
97
+ s = str;
98
+ id = (HxOverrides.cca(s, 0) == 47) ? s : "/" + s;
75
99
  };
76
100
  this.config.router.find(id).then(function (routeResult) {
77
101
  var sourcePromise = (routeResult.length > 0) ? routeResult[0].get() : (_gthis.routeDynamic != null) ? _gthis.routeDynamic(id) : null;
@@ -1,7 +1,6 @@
1
1
  import {Router} from "../route/Router.js"
2
2
  import {CacheStrategy, CacheDurability, DurabilityCheck} from "../cache/Cache.js"
3
3
  import {Stone} from "../Stone.js"
4
- import {SourceId_Fields_} from "../SourceId.js"
5
4
  import {SourceHash} from "../SourceHash.js"
6
5
  import {SourceData} from "../Source.js"
7
6
  import {Log} from "../Log.js"
@@ -15,6 +14,7 @@ import {Register} from "../../genes/Register.js"
15
14
  import {Buffer} from "buffer"
16
15
  import {StringTools} from "../../StringTools.js"
17
16
  import {Lambda} from "../../Lambda.js"
17
+ import {HxOverrides} from "../../HxOverrides.js"
18
18
 
19
19
  const $global = Register.$global
20
20
 
@@ -75,9 +75,13 @@ class ZipStone extends Register.inherits(Stone) {
75
75
  var bytes = Helper.bytesOfBuffer(data.data);
76
76
  var this1 = file[0].serveId;
77
77
  var s = "/";
78
- s = Path.posix.normalize("/");
79
- s = StringTools.replace(s, "\\", "/");
80
- var root = (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
78
+ var str = ("/".length > 1 && HxOverrides.cca("/", 0) == 47) ? "/".substring(1) : "/";
79
+ if (str.length > 0) {
80
+ str = Path.posix.normalize(str);
81
+ str = StringTools.replace(str, "\\", "/");
82
+ };
83
+ s = str;
84
+ var root = (HxOverrides.cca(s, 0) == 47) ? s : "/" + s;
81
85
  if (this1.charAt(0) != "/") {
82
86
  throw new Error("Badly formed SourceId.");
83
87
  };
@@ -99,9 +103,13 @@ class ZipStone extends Register.inherits(Stone) {
99
103
  }
100
104
  list() {
101
105
  var s = this.config.filename;
102
- s = Path.posix.normalize(s);
103
- s = StringTools.replace(s, "\\", "/");
104
- return Promise.resolve([(SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s]);
106
+ var str = (s.length > 1 && HxOverrides.cca(s, 0) == 47) ? s.substring(1) : s;
107
+ if (str.length > 0) {
108
+ str = Path.posix.normalize(str);
109
+ str = StringTools.replace(str, "\\", "/");
110
+ };
111
+ s = str;
112
+ return Promise.resolve([(HxOverrides.cca(s, 0) == 47) ? s : "/" + s]);
105
113
  }
106
114
  static get __name__() {
107
115
  return "whet.stones.ZipStone"
@@ -5,7 +5,6 @@ import {Stone} from "../../Stone"
5
5
  import {SourceHash} from "../../SourceHash"
6
6
  import {SourceData} from "../../Source"
7
7
  import {Project} from "../../Project"
8
- import {Command} from "commander"
9
8
 
10
9
  export declare class HaxeBuild extends Stone<BuildConfig> {
11
10
  constructor(config: BuildConfig)
@@ -16,7 +15,7 @@ export declare class HaxeBuild extends Stone<BuildConfig> {
16
15
  */
17
16
  build(): Promise<any>
18
17
  protected generate(hash: SourceHash): Promise<SourceData[]>
19
- protected getCommands(): Command[]
18
+ protected addCommands(): void
20
19
  list(): Promise<string[]>
21
20
  protected generateHash(): Promise<SourceHash>
22
21
  }
@@ -1,15 +1,15 @@
1
1
  import {MaybeArray_Fields_} from "../../magic/MaybeArray.js"
2
2
  import {Utils} from "../../Utils.js"
3
3
  import {Stone} from "../../Stone.js"
4
- import {SourceId_Fields_, RootDir} from "../../SourceId.js"
4
+ import {RootDir} from "../../SourceId.js"
5
5
  import {SourceHash} from "../../SourceHash.js"
6
6
  import {SourceData} from "../../Source.js"
7
7
  import {Log} from "../../Log.js"
8
8
  import * as Path from "path"
9
9
  import {Register} from "../../../genes/Register.js"
10
- import {Command} from "commander"
11
10
  import * as ChildProcess from "child_process"
12
11
  import {StringTools} from "../../../StringTools.js"
12
+ import {HxOverrides} from "../../../HxOverrides.js"
13
13
 
14
14
  const $global = Register.$global
15
15
 
@@ -34,9 +34,13 @@ class HaxeBuild extends Register.inherits(Stone) {
34
34
  var cwd = process.cwd();
35
35
  var this1 = _gthis.project.rootDir;
36
36
  var s = "/";
37
- s = Path.posix.normalize("/");
38
- s = StringTools.replace(s, "\\", "/");
39
- var root = (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + 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
+ var root = (HxOverrides.cca(s, 0) == 47) ? s : "/" + s;
40
44
  if (this1.charAt(0) != "/") {
41
45
  throw new Error("Badly formed SourceId.");
42
46
  };
@@ -57,8 +61,10 @@ class HaxeBuild extends Register.inherits(Stone) {
57
61
  };
58
62
  ChildProcess.exec(result.join(" "), {"cwd": cwd1, "windowsHide": true}, function (err, stdout, stderr) {
59
63
  if (err != null) {
64
+ Log.log(30, ...["Haxe build failed."]);
60
65
  rej(err);
61
66
  } else {
67
+ Log.log(30, ...["Haxe build successful."]);
62
68
  res(null);
63
69
  };
64
70
  });
@@ -84,11 +90,11 @@ class HaxeBuild extends Register.inherits(Stone) {
84
90
  throw new Error("Cannot get source of a multi-file build. Not implemented yet.");
85
91
  };
86
92
  }
87
- getCommands() {
93
+ addCommands() {
88
94
  var _gthis = this;
89
- return [new Command("build").action(function (..._) {
95
+ this.project.addCommand("build", this).action(function (..._) {
90
96
  return _gthis.build();
91
- })];
97
+ });
92
98
  }
93
99
  list() {
94
100
  if (this.config.hxml.isSingleFile()) {
@@ -105,9 +111,13 @@ class HaxeBuild extends Register.inherits(Stone) {
105
111
  while (_g < _g1) {
106
112
  var i = _g++;
107
113
  var s = _this[i];
108
- s = Path.posix.normalize(s);
109
- s = StringTools.replace(s, "\\", "/");
110
- var this1 = (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
114
+ var str = (s.length > 1 && HxOverrides.cca(s, 0) == 47) ? s.substring(1) : s;
115
+ if (str.length > 0) {
116
+ str = Path.posix.normalize(str);
117
+ str = StringTools.replace(str, "\\", "/");
118
+ };
119
+ s = str;
120
+ var this1 = (HxOverrides.cca(s, 0) == 47) ? s : "/" + s;
111
121
  var root = RootDir.fromProject(this.config.hxml.project);
112
122
  if (this1.charAt(0) != "/") {
113
123
  throw new Error("Badly formed SourceId.");
@@ -3,7 +3,7 @@ import {StoneId_Fields_} from "../../magic/StoneId.js"
3
3
  import {MaybeArray_Fields_} from "../../magic/MaybeArray.js"
4
4
  import {CacheStrategy, CacheDurability} from "../../cache/Cache.js"
5
5
  import {Stone} from "../../Stone.js"
6
- import {SourceId, SourceId_Fields_} from "../../SourceId.js"
6
+ import {SourceId} from "../../SourceId.js"
7
7
  import {SourceHash} from "../../SourceHash.js"
8
8
  import {SourceData} from "../../Source.js"
9
9
  import {Log} from "../../Log.js"
@@ -149,14 +149,22 @@ class Hxml extends Register.inherits(Stone) {
149
149
  var filename;
150
150
  if (this.build.config.filename != null) {
151
151
  var s = this.build.config.filename;
152
- s = Path.posix.normalize(s);
153
- s = StringTools.replace(s, "\\", "/");
154
- filename = (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
152
+ var str = (s.length > 1 && HxOverrides.cca(s, 0) == 47) ? s.substring(1) : s;
153
+ if (str.length > 0) {
154
+ str = Path.posix.normalize(str);
155
+ str = StringTools.replace(str, "\\", "/");
156
+ };
157
+ s = str;
158
+ filename = (HxOverrides.cca(s, 0) == 47) ? s : "/" + s;
155
159
  } else {
156
160
  var s = "build";
157
- s = Path.posix.normalize("build");
158
- s = StringTools.replace(s, "\\", "/");
159
- filename = (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
161
+ var str = ("build".length > 1 && HxOverrides.cca("build", 0) == 47) ? "build".substring(1) : "build";
162
+ if (str.length > 0) {
163
+ str = Path.posix.normalize(str);
164
+ str = StringTools.replace(str, "\\", "/");
165
+ };
166
+ s = str;
167
+ filename = (HxOverrides.cca(s, 0) == 47) ? s : "/" + s;
160
168
  };
161
169
  if (Path.posix.extname(filename) == "") {
162
170
  var v = this.getBuildExtension();
@@ -164,9 +172,13 @@ class Hxml extends Register.inherits(Stone) {
164
172
  v = "." + v;
165
173
  };
166
174
  var s = filename.substring(0, filename.lastIndexOf("/") + 1);
167
- s = Path.posix.normalize(s);
168
- s = StringTools.replace(s, "\\", "/");
169
- filename = ((SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s) + Path.posix.parse(filename.substring(filename.lastIndexOf("/"))).name + v;
175
+ var str = (s.length > 1 && HxOverrides.cca(s, 0) == 47) ? s.substring(1) : s;
176
+ if (str.length > 0) {
177
+ str = Path.posix.normalize(str);
178
+ str = StringTools.replace(str, "\\", "/");
179
+ };
180
+ s = str;
181
+ filename = ((HxOverrides.cca(s, 0) == 47) ? s : "/" + s) + Path.posix.parse(filename.substring(filename.lastIndexOf("/"))).name + v;
170
182
  };
171
183
  return filename;
172
184
  } else {
@@ -176,9 +188,13 @@ class Hxml extends Register.inherits(Stone) {
176
188
  getPlatform() {
177
189
  var this1 = this.getBuildExportPath();
178
190
  var s = "/";
179
- s = Path.posix.normalize("/");
180
- s = StringTools.replace(s, "\\", "/");
181
- var root = (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
191
+ var str = ("/".length > 1 && HxOverrides.cca("/", 0) == 47) ? "/".substring(1) : "/";
192
+ if (str.length > 0) {
193
+ str = Path.posix.normalize(str);
194
+ str = StringTools.replace(str, "\\", "/");
195
+ };
196
+ s = str;
197
+ var root = (HxOverrides.cca(s, 0) == 47) ? s : "/" + s;
182
198
  if (this1.charAt(0) != "/") {
183
199
  throw new Error("Badly formed SourceId.");
184
200
  };
@@ -282,18 +298,26 @@ class Hxml extends Register.inherits(Stone) {
282
298
  }
283
299
  filename() {
284
300
  var s = this.id;
285
- s = Path.posix.normalize(s);
286
- s = StringTools.replace(s, "\\", "/");
287
- var fn = (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
301
+ var str = (s.length > 1 && HxOverrides.cca(s, 0) == 47) ? s.substring(1) : s;
302
+ if (str.length > 0) {
303
+ str = Path.posix.normalize(str);
304
+ str = StringTools.replace(str, "\\", "/");
305
+ };
306
+ s = str;
307
+ var fn = (HxOverrides.cca(s, 0) == 47) ? s : "/" + s;
288
308
  if (Path.posix.extname(fn) == "") {
289
309
  var v = "hxml";
290
310
  if ("hxml".length > 0 && HxOverrides.cca("hxml", 0) != 46) {
291
311
  v = "." + "hxml";
292
312
  };
293
313
  var s = fn.substring(0, fn.lastIndexOf("/") + 1);
294
- s = Path.posix.normalize(s);
295
- s = StringTools.replace(s, "\\", "/");
296
- fn = ((SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s) + Path.posix.parse(fn.substring(fn.lastIndexOf("/"))).name + v;
314
+ var str = (s.length > 1 && HxOverrides.cca(s, 0) == 47) ? s.substring(1) : s;
315
+ if (str.length > 0) {
316
+ str = Path.posix.normalize(str);
317
+ str = StringTools.replace(str, "\\", "/");
318
+ };
319
+ s = str;
320
+ fn = ((HxOverrides.cca(s, 0) == 47) ? s : "/" + s) + Path.posix.parse(fn.substring(fn.lastIndexOf("/"))).name + v;
297
321
  };
298
322
  return fn;
299
323
  }
package/bin/whet.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
 
2
+ export {addOption} from "./whet/Project"
2
3
  export {ZipStone} from "./whet/stones/Zip"
3
4
  export {ZipConfig} from "./whet/stones/Zip"
4
5
  export {Utils} from "./whet/Utils"
package/bin/whet.js CHANGED
@@ -5,6 +5,7 @@ import {Register} from "./genes/Register.js"
5
5
  const $global = Register.$global
6
6
 
7
7
  Whet_Fields_.main()
8
+ export {addOption} from "./whet/Project.js"
8
9
  export {ZipStone} from "./whet/stones/Zip.js"
9
10
  export {Utils} from "./whet/Utils.js"
10
11
  export {Stone} from "./whet/Stone.js"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "whet",
3
- "version": "0.0.6",
3
+ "version": "0.0.9",
4
4
  "description": "NodeJS based assets management and project tooling library.",
5
5
  "scripts": {
6
6
  "devinit": "npx dts2hx commander --modular --noLibWrap",