whet 0.0.18 → 0.0.20

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.
package/README.md CHANGED
@@ -10,7 +10,7 @@ Project files define a project, its [stones](#Stones). Their content defines wha
10
10
 
11
11
  Stones (named after _whetstone_) are individual building blocks of a project.
12
12
 
13
- They represent a single logical asset (can be multiple files) or functionality (e.g. a dev web server). Stones can use other stones (via routes), to achieve their objective, forming a dependency tree. E.g. a css file could be made by minifying a file generated from scss source, and each step could be individually cached.
13
+ They represent a single logical asset (can be multiple files) or functionality (e.g. a dev web server). Stones can use other stones (via routes), to achieve their objective, forming a dependency tree. E.g. a CSS file could be made by minifying a file generated from SCSS source, and each step could be individually cached.
14
14
 
15
15
  ### Stones Configuration
16
16
 
@@ -30,7 +30,7 @@ Some stones might provide helper methods to modify the configuration after it wa
30
30
 
31
31
  ...
32
32
 
33
- ## Routes And Routers
33
+ ## Routers
34
34
 
35
35
  ...
36
36
 
@@ -40,8 +40,11 @@ Project files should have no side effects, unless some of their commands are exe
40
40
 
41
41
  <!-- TODO: document configuration handlers -->
42
42
 
43
- All paths are in stored as absolute (starting with `/`), but are actually relative to root project directory. Path that is a directory ends with a `/`, otherwise it's considered a file. That means:
43
+ All file paths should use `/` as directory separator, regardless of platform.
44
44
 
45
- - `/assets/` is a **directory** called `assets` that's in the project root.
46
- - `assets/` is a **directory** called `assets` that's relative to the structure within the project (routing/stones).
47
- - `/assets` is a **file** called `assets` in the project root.
45
+ Paths should always be relative, and are considered relative to root project directory, or relative to root of the Router/Stone used. For getting sources from Stones/Routers [minimatch](https://github.com/isaacs/minimatch/) is used.
46
+
47
+ Path that is a directory ends with a `/`, otherwise it's considered a file. That means:
48
+
49
+ - `assets/` is a **directory** called `assets`.
50
+ - `assets` is a **file** called `assets`.
@@ -1,7 +1,6 @@
1
1
 
2
2
  export declare class HxOverrides {
3
3
  protected static dateStr(date: Date): string
4
- protected static cca(s: string, index: number): null | number
5
4
  protected static substr(s: string, pos: number, len?: null | number): string
6
5
  protected static remove<T>(a: T[], obj: T): boolean
7
6
  protected static now(): number
@@ -12,13 +12,6 @@ class HxOverrides {
12
12
  var s = date.getSeconds();
13
13
  return date.getFullYear() + "-" + ((m < 10) ? "0" + m : "" + m) + "-" + ((d < 10) ? "0" + d : "" + d) + " " + ((h < 10) ? "0" + h : "" + h) + ":" + ((mi < 10) ? "0" + mi : "" + mi) + ":" + ((s < 10) ? "0" + s : "" + s);
14
14
  }
15
- static cca(s, index) {
16
- var x = s.charCodeAt(index);
17
- if (x != x) {
18
- return undefined;
19
- };
20
- return x;
21
- }
22
15
  static substr(s, pos, len) {
23
16
  if (len == null) {
24
17
  len = s.length;
@@ -62,5 +62,6 @@ export declare class Exception extends Error {
62
62
  toString(): string
63
63
  protected get_message(): string
64
64
  protected get_native(): any
65
+ protected static caught(value: any): Exception
65
66
  protected static thrown(value: any): any
66
67
  }
@@ -65,6 +65,15 @@ class Exception extends Register.inherits(() => Error, true) {
65
65
  get_native() {
66
66
  return this.__nativeException;
67
67
  }
68
+ static caught(value) {
69
+ if (((value) instanceof Exception)) {
70
+ return value;
71
+ } else if (((value) instanceof Error)) {
72
+ return new Exception(value.message, null, value);
73
+ } else {
74
+ return new ValueException(value, null, value);
75
+ };
76
+ }
68
77
  static thrown(value) {
69
78
  if (((value) instanceof Exception)) {
70
79
  return value.get_native();
@@ -5,7 +5,6 @@ import * as Path from "path"
5
5
  import {Register} from "../genes/Register.js"
6
6
  import {Command, Option} from "commander"
7
7
  import {StringTools} from "../StringTools.js"
8
- import {HxOverrides} from "../HxOverrides.js"
9
8
 
10
9
  const $global = Register.$global
11
10
 
@@ -37,31 +36,11 @@ class Project extends Register.inherits() {
37
36
  Error.prepareStackTrace = oldValue;
38
37
  file = decodeURI(file);
39
38
  file = StringTools.replace(file, "file:///", "");
40
- var s = Path.relative(process.cwd(), file);
41
- var str = (s.length > 1 && HxOverrides.cca(s, 0) == 47) ? s.substring(1) : s;
42
- if (str.length > 0) {
43
- str = Path.posix.normalize(str);
44
- str = StringTools.replace(str, "\\", "/");
45
- };
46
- s = str;
47
- var this1 = (HxOverrides.cca(s, 0) == 47) ? s : "/" + s;
48
- var s = this1.substring(0, this1.lastIndexOf("/") + 1);
49
- var str = (s.length > 1 && HxOverrides.cca(s, 0) == 47) ? s.substring(1) : s;
50
- if (str.length > 0) {
51
- str = Path.posix.normalize(str);
52
- str = StringTools.replace(str, "\\", "/");
53
- };
54
- s = str;
55
- this.rootDir = (HxOverrides.cca(s, 0) == 47) ? s : "/" + s;
39
+ var id = Path.relative(process.cwd(), file);
40
+ var dir = id.substring(0, id.lastIndexOf("/") + 1);
41
+ this.rootDir = (dir.length == 0) ? "./" : dir;
56
42
  } else {
57
- var s = config.rootDir;
58
- var str = (s.length > 1 && HxOverrides.cca(s, 0) == 47) ? s.substring(1) : s;
59
- if (str.length > 0) {
60
- str = Path.posix.normalize(str);
61
- str = StringTools.replace(str, "\\", "/");
62
- };
63
- s = str;
64
- this.rootDir = (HxOverrides.cca(s, 0) == 47) ? s : "/" + s;
43
+ this.rootDir = config.rootDir;
65
44
  };
66
45
  this.cache = (config.cache == null) ? new CacheManager(this) : config.cache;
67
46
  Project.projects.push(this);
@@ -1,3 +1,4 @@
1
+ import {MinimatchType} from "./magic/MinimatchType"
1
2
  import {AnyStone} from "./Stone"
2
3
  import {SourceHash} from "./SourceHash"
3
4
  import {Buffer} from "buffer"
@@ -18,9 +19,9 @@ export declare class Source {
18
19
  getDirPath(): string
19
20
 
20
21
  /**
21
- * Returns first result if `id` is null, or one equals to it.
22
+ * Returns first result if `pattern` is null, or first one it matches.
22
23
  */
23
- get(id?: null | string): SourceData
24
+ get(pattern?: null | MinimatchType): SourceData
24
25
  }
25
26
 
26
27
  export declare class SourceData {
@@ -1,14 +1,13 @@
1
+ import {MinimatchType_Fields_} from "./magic/MinimatchType.js"
1
2
  import {Utils} from "./Utils.js"
2
- import {SourceId, RootDir} from "./SourceId.js"
3
+ import {RootDir} from "./SourceId.js"
3
4
  import {SourceHash} from "./SourceHash.js"
4
5
  import {Log} from "./Log.js"
5
6
  import * as Path from "path"
6
7
  import {Register} from "../genes/Register.js"
7
8
  import * as Fs from "fs"
8
9
  import {Buffer} from "buffer"
9
- import {StringTools} from "../StringTools.js"
10
10
  import {Lambda} from "../Lambda.js"
11
- import {HxOverrides} from "../HxOverrides.js"
12
11
 
13
12
  const $global = Register.$global
14
13
 
@@ -39,22 +38,15 @@ class Source extends Register.inherits() {
39
38
  }
40
39
 
41
40
  /**
42
- * Returns first result if `id` is null, or one equals to it.
41
+ * Returns first result if `pattern` is null, or first one it matches.
43
42
  */
44
- get(id) {
45
- if (id == null) {
43
+ get(pattern) {
44
+ if (pattern == null) {
46
45
  return this.data[0];
47
46
  } else {
48
- var s = id;
49
- var str = (id.length > 1 && HxOverrides.cca(id, 0) == 47) ? id.substring(1) : id;
50
- if (str.length > 0) {
51
- str = Path.posix.normalize(str);
52
- str = StringTools.replace(str, "\\", "/");
53
- };
54
- s = str;
55
- var sid = (HxOverrides.cca(s, 0) == 47) ? s : "/" + s;
47
+ var filter = MinimatchType_Fields_.makeMinimatch(pattern);
56
48
  return Lambda.find(this.data, function (entry) {
57
- return entry.id == sid;
49
+ return filter.match(entry.id);
58
50
  });
59
51
  };
60
52
  }
@@ -103,13 +95,12 @@ class SourceData extends Register.inherits() {
103
95
  new Error("Data without source.");
104
96
  };
105
97
  var dir = this.source.getDirPath();
106
- this.filePathId = SourceId.getPutInDir((idOverride != null && HxOverrides.cca(idOverride, idOverride.length - 1) != 47) ? idOverride : this.id, dir);
107
- var this1 = this.filePathId;
108
- var root = RootDir.fromProject(this.source.origin.project);
109
- if (this1.charAt(0) != "/") {
110
- throw new Error("Badly formed SourceId.");
98
+ var name = (idOverride != null && !(idOverride.length == 0 || idOverride.charCodeAt(idOverride.length - 1) == 47)) ? idOverride : this.id;
99
+ if (!(dir.length == 0 || dir.charCodeAt(dir.length - 1) == 47)) {
100
+ throw new Error("\"" + dir + "\" is not a directory.");
111
101
  };
112
- this.filePath = Path.posix.join(".", root, ".", this1);
102
+ this.filePathId = Path.posix.join(dir, name);
103
+ this.filePath = Path.posix.join(".", RootDir.fromProject(this.source.origin.project), ".", this.filePathId);
113
104
  return Utils.saveBytes(this.filePath, this.data).then(function (_) {
114
105
  return _gthis.filePath;
115
106
  });
@@ -129,18 +120,11 @@ class SourceData extends Register.inherits() {
129
120
  Fs.readFile(path, function (err, buffer) {
130
121
  if (err != null) {
131
122
  Log.log(50, ...["File does not exist.", {"id": id, "path": path}]);
132
- res(null);
123
+ rej(err);
133
124
  } else {
134
125
  var source = SourceData.fromBytes(id, buffer);
135
126
  source.filePath = path;
136
- var s = pathId;
137
- var str = (s.length > 1 && HxOverrides.cca(s, 0) == 47) ? s.substring(1) : s;
138
- if (str.length > 0) {
139
- str = Path.posix.normalize(str);
140
- str = StringTools.replace(str, "\\", "/");
141
- };
142
- s = str;
143
- source.filePathId = (HxOverrides.cca(s, 0) == 47) ? s : "/" + s;
127
+ source.filePathId = pathId;
144
128
  res(source);
145
129
  };
146
130
  });
@@ -150,14 +134,7 @@ class SourceData extends Register.inherits() {
150
134
  return SourceData.fromBytes(id, Buffer.from(s, "utf-8"));
151
135
  }
152
136
  static fromBytes(id, data) {
153
- var s = id;
154
- var str = (id.length > 1 && HxOverrides.cca(id, 0) == 47) ? id.substring(1) : id;
155
- if (str.length > 0) {
156
- str = Path.posix.normalize(str);
157
- str = StringTools.replace(str, "\\", "/");
158
- };
159
- s = str;
160
- return new SourceData((HxOverrides.cca(s, 0) == 47) ? s : "/" + s, data);
137
+ return new SourceData(id, data);
161
138
  }
162
139
  static get __name__() {
163
140
  return "whet.SourceData"
@@ -1,12 +1,24 @@
1
1
  import {Project} from "./Project"
2
2
 
3
- export declare class SourceId {
4
- static relativeTo($this: string, directory: string): string
5
- static getPutInDir($this: string, dir: string): string
3
+ export declare class IdUtils {
4
+ static toCwdPath(id: string, root: string): string
5
+ static isDir(id: string): boolean
6
+ static isInDir(id: string, directory: string, nested?: boolean): boolean
7
+ static getRelativeTo(id: string, directory: string): string
8
+ static getPutInDir(id: string, dir: string): string
9
+ static compare(a: string, b: string): number
10
+ static assertDir(directory: string): void
11
+ static getWithExt(id: string): string
12
+ static setWithExt(id: string, name: string): string
13
+ static getExt(id: string): string
14
+ static setExt(id: string, ext: string): string
15
+ static getWithoutExt(id: string): string
16
+ static setWithoutExt(id: string, name: string): string
17
+ static getDir(id: string): string
18
+ static setDir(id: string, dir: string): string
19
+ static fromCwdPath(s: string, root: string): string
6
20
  }
7
21
 
8
22
  export declare class RootDir {
9
23
  static fromProject(p: Project): string
10
24
  }
11
-
12
- export const fromCwdPath: (s: string, root: string) => string
@@ -1,67 +1,120 @@
1
1
  import * as Path from "path"
2
2
  import {Register} from "../genes/Register.js"
3
3
  import {StringTools} from "../StringTools.js"
4
- import {HxOverrides} from "../HxOverrides.js"
5
4
 
6
5
  const $global = Register.$global
7
6
 
8
- export const SourceId = Register.global("$hxClasses")["whet._SourceId.SourceId"] =
9
- class SourceId {
10
- static relativeTo(this1, directory) {
11
- if (HxOverrides.cca(directory, directory.length - 1) != 47) {
7
+ export const IdUtils = Register.global("$hxClasses")["whet.IdUtils"] =
8
+ class IdUtils {
9
+ static toCwdPath(id, root) {
10
+ return Path.posix.join(".", root, ".", id);
11
+ }
12
+ static isDir(id) {
13
+ if (id.length != 0) {
14
+ return id.charCodeAt(id.length - 1) == 47;
15
+ } else {
16
+ return true;
17
+ };
18
+ }
19
+ static isInDir(id, directory, nested) {
20
+ if (nested == null) {
21
+ nested = false;
22
+ };
23
+ if (!(directory.length == 0 || directory.charCodeAt(directory.length - 1) == 47)) {
12
24
  throw new Error("\"" + directory + "\" is not a directory.");
13
25
  };
14
- var tmp;
15
- var s = this1.substring(0, this1.lastIndexOf("/") + 1);
16
- var str = (s.length > 1 && HxOverrides.cca(s, 0) == 47) ? s.substring(1) : s;
17
- if (str.length > 0) {
18
- str = Path.posix.normalize(str);
19
- str = StringTools.replace(str, "\\", "/");
26
+ if (nested) {
27
+ var dir = id.substring(0, id.lastIndexOf("/") + 1);
28
+ return ((dir.length == 0) ? "./" : dir).indexOf(directory) == 0;
29
+ } else {
30
+ var dir = id.substring(0, id.lastIndexOf("/") + 1);
31
+ return ((dir.length == 0) ? "./" : dir) == directory;
32
+ };
33
+ }
34
+ static getRelativeTo(id, directory) {
35
+ if (!(directory.length == 0 || directory.charCodeAt(directory.length - 1) == 47)) {
36
+ throw new Error("\"" + directory + "\" is not a directory.");
20
37
  };
21
- s = str;
22
- tmp = ((HxOverrides.cca(s, 0) == 47) ? s : "/" + s).indexOf(directory) == 0;
38
+ var tmp;
39
+ var dir = id.substring(0, id.lastIndexOf("/") + 1);
40
+ tmp = ((dir.length == 0) ? "./" : dir).indexOf(directory) == 0;
23
41
  if (tmp) {
24
- return this1.substring(directory.length - 1);
42
+ return id.substring(directory.length);
25
43
  } else {
26
44
  return null;
27
45
  };
28
46
  }
29
- static getPutInDir(this1, dir) {
30
- if (HxOverrides.cca(dir, dir.length - 1) != 47) {
47
+ static getPutInDir(id, dir) {
48
+ if (!(dir.length == 0 || dir.charCodeAt(dir.length - 1) == 47)) {
31
49
  throw new Error("\"" + dir + "\" is not a directory.");
32
50
  };
33
- var s = "/";
34
- var str = ("/".length > 1 && HxOverrides.cca("/", 0) == 47) ? "/".substring(1) : "/";
51
+ return Path.posix.join(dir, id);
52
+ }
53
+ static compare(a, b) {
54
+ if (a < b) {
55
+ return -1;
56
+ } else if (a > b) {
57
+ return 1;
58
+ } else {
59
+ return 0;
60
+ };
61
+ }
62
+ static assertDir(directory) {
63
+ if (!(directory.length == 0 || directory.charCodeAt(directory.length - 1) == 47)) {
64
+ throw new Error("\"" + directory + "\" is not a directory.");
65
+ };
66
+ }
67
+ static getWithExt(id) {
68
+ return id.substring(id.lastIndexOf("/") + 1);
69
+ }
70
+ static setWithExt(id, name) {
71
+ var dir = id.substring(0, id.lastIndexOf("/") + 1);
72
+ return Path.posix.join((dir.length == 0) ? "./" : dir, name);
73
+ }
74
+ static getExt(id) {
75
+ return Path.posix.extname(id);
76
+ }
77
+ static setExt(id, ext) {
78
+ if (ext.length > 0 && ext.charCodeAt(0) != 46) {
79
+ ext = "." + ext;
80
+ };
81
+ var dir = id.substring(0, id.lastIndexOf("/") + 1);
82
+ return Path.posix.join((dir.length == 0) ? "./" : dir, Path.posix.parse(id).name) + ext;
83
+ }
84
+ static getWithoutExt(id) {
85
+ return Path.posix.parse(id).name;
86
+ }
87
+ static setWithoutExt(id, name) {
88
+ var dir = id.substring(0, id.lastIndexOf("/") + 1);
89
+ return Path.posix.join((dir.length == 0) ? "./" : dir, name) + Path.posix.extname(id);
90
+ }
91
+ static getDir(id) {
92
+ var dir = id.substring(0, id.lastIndexOf("/") + 1);
93
+ if (dir.length == 0) {
94
+ return "./";
95
+ } else {
96
+ return dir;
97
+ };
98
+ }
99
+ static setDir(id, dir) {
100
+ return Path.posix.join(dir, id.substring(id.lastIndexOf("/") + 1));
101
+ }
102
+ static fromCwdPath(s, root) {
103
+ var absPath = Path.posix;
104
+ var str = s;
35
105
  if (str.length > 0) {
36
106
  str = Path.posix.normalize(str);
37
107
  str = StringTools.replace(str, "\\", "/");
38
108
  };
39
- s = str;
40
- if (dir == ((HxOverrides.cca(s, 0) == 47) ? s : "/" + s)) {
41
- var s = this1;
42
- var str = (this1.length > 1 && HxOverrides.cca(this1, 0) == 47) ? this1.substring(1) : this1;
43
- if (str.length > 0) {
44
- str = Path.posix.normalize(str);
45
- str = StringTools.replace(str, "\\", "/");
46
- };
47
- s = str;
48
- return (HxOverrides.cca(s, 0) == 47) ? s : "/" + s;
49
- } else {
50
- var s = dir + this1;
51
- var str = (s.length > 1 && HxOverrides.cca(s, 0) == 47) ? s.substring(1) : s;
52
- if (str.length > 0) {
53
- str = Path.posix.normalize(str);
54
- str = StringTools.replace(str, "\\", "/");
55
- };
56
- s = str;
57
- return (HxOverrides.cca(s, 0) == 47) ? s : "/" + s;
58
- };
109
+ var absPath1 = absPath.resolve(str);
110
+ var rootStr = Path.posix.resolve(root);
111
+ return Path.posix.relative(rootStr, absPath1);
59
112
  }
60
113
  static get __name__() {
61
- return "whet._SourceId.SourceId_Impl_"
114
+ return "whet.IdUtils"
62
115
  }
63
116
  get __class__() {
64
- return SourceId
117
+ return IdUtils
65
118
  }
66
119
  }
67
120
 
@@ -79,31 +132,3 @@ class RootDir {
79
132
  }
80
133
  }
81
134
 
82
-
83
- export const SourceId_Fields_ = Register.global("$hxClasses")["whet._SourceId.SourceId_Fields_"] =
84
- class SourceId_Fields_ {
85
- static fromCwdPath(s, root) {
86
- var s1 = Path.posix;
87
- var str = s;
88
- if (str.length > 0) {
89
- str = Path.posix.normalize(str);
90
- str = StringTools.replace(str, "\\", "/");
91
- };
92
- s = s1.resolve(str);
93
- var rootStr = root;
94
- if (HxOverrides.cca(rootStr, 0) == 47) {
95
- rootStr = rootStr.substring(1);
96
- };
97
- rootStr = Path.posix.resolve(rootStr);
98
- return Path.posix.relative(rootStr, s);
99
- }
100
- static get __name__() {
101
- return "whet._SourceId.SourceId_Fields_"
102
- }
103
- get __class__() {
104
- return SourceId_Fields_
105
- }
106
- }
107
-
108
-
109
- export const fromCwdPath = SourceId_Fields_.fromCwdPath
@@ -18,6 +18,12 @@ export declare class Stone<T extends StoneConfig> {
18
18
  cacheStrategy: CacheStrategy
19
19
  readonly cache: CacheManager
20
20
  project: Project
21
+ protected lockQueue: {
22
+ rej: (arg0: any) => void,
23
+ res: (arg0: any) => void,
24
+ run: () => Promise<any>
25
+ }[]
26
+ protected locked: boolean
21
27
 
22
28
  /**
23
29
  Override this to set config defaults.
@@ -29,6 +35,11 @@ export declare class Stone<T extends StoneConfig> {
29
35
  */
30
36
  protected addCommands(): void
31
37
 
38
+ /**
39
+ * Locks this stone for generating. Used to prevent parallel generation of the same sources.
40
+ */
41
+ protected acquire<T>(run: (() => Promise<T>)): Promise<T>
42
+
32
43
  /**
33
44
  * **Do not override.**
34
45
  * Get Source for this stone. Goes through the cache.
package/bin/whet/Stone.js CHANGED
@@ -2,21 +2,21 @@ import {StoneId_Fields_} from "./magic/StoneId.js"
2
2
  import {MaybeArray_Fields_} from "./magic/MaybeArray.js"
3
3
  import {CacheStrategy, CacheDurability} from "./cache/Cache.js"
4
4
  import {Utils} from "./Utils.js"
5
- import {SourceId, RootDir} from "./SourceId.js"
5
+ import {RootDir} from "./SourceId.js"
6
6
  import {SourceHash} from "./SourceHash.js"
7
7
  import {Source} from "./Source.js"
8
8
  import {Project} from "./Project.js"
9
9
  import {Log} from "./Log.js"
10
10
  import * as Path from "path"
11
11
  import {Register} from "../genes/Register.js"
12
- import {StringTools} from "../StringTools.js"
13
- import {HxOverrides} from "../HxOverrides.js"
14
12
 
15
13
  const $global = Register.$global
16
14
 
17
15
  export const Stone = Register.global("$hxClasses")["whet.Stone"] =
18
16
  class Stone extends Register.inherits() {
19
17
  new(config) {
18
+ this.locked = false;
19
+ this.lockQueue = [];
20
20
  this.ignoreFileHash = false;
21
21
  Log.log(10, ...["Instantiating new Stone.", {"type": StoneId_Fields_.getTypeName(this)}]);
22
22
  if (config == null) {
@@ -49,6 +49,39 @@ class Stone extends Register.inherits() {
49
49
  addCommands() {
50
50
  }
51
51
 
52
+ /**
53
+ * Locks this stone for generating. Used to prevent parallel generation of the same sources.
54
+ */
55
+ acquire(run) {
56
+ var _gthis = this;
57
+ Log.log(10, ...["Acquiring lock on a stone.", {"stone": this}]);
58
+ if (this.locked) {
59
+ Log.log(20, ...["Stone is locked, waiting.", {"stone": this}]);
60
+ var deferredRes;
61
+ var deferredRej;
62
+ var deferred = new Promise(function (res, rej) {
63
+ deferredRes = res;
64
+ deferredRej = rej;
65
+ });
66
+ this.lockQueue.push({"run": run, "res": deferredRes, "rej": deferredRej});
67
+ return deferred;
68
+ } else {
69
+ this.locked = true;
70
+ var runNext = null;
71
+ runNext = function () {
72
+ if (_gthis.lockQueue.length > 0) {
73
+ Log.log(20, ...["Running next queued-up lock acquire function.", {"stone": _gthis}]);
74
+ var queued = _gthis.lockQueue.shift();
75
+ queued.run().then(queued.res)["catch"](queued.rej)["finally"](runNext);
76
+ } else {
77
+ _gthis.locked = false;
78
+ Log.log(10, ...["No function in lock queue. Stone is now unlocked.", {"stone": _gthis}]);
79
+ };
80
+ };
81
+ return run()["finally"](runNext);
82
+ };
83
+ }
84
+
52
85
  /**
53
86
  * **Do not override.**
54
87
  * Get Source for this stone. Goes through the cache.
@@ -104,6 +137,9 @@ class Stone extends Register.inherits() {
104
137
  */
105
138
  generateSource(hash) {
106
139
  var _gthis = this;
140
+ if (!this.locked) {
141
+ throw new Error("Acquire a lock before generating.");
142
+ };
107
143
  Log.log(20, ...["Generating source.", {"stone": this, "hash": hash}]);
108
144
  var init;
109
145
  if (this.config.dependencies != null) {
@@ -217,14 +253,7 @@ class Stone extends Register.inherits() {
217
253
  if (generate == null) {
218
254
  generate = true;
219
255
  };
220
- var s = path;
221
- var str = (path.length > 1 && HxOverrides.cca(path, 0) == 47) ? path.substring(1) : path;
222
- if (str.length > 0) {
223
- str = Path.posix.normalize(str);
224
- str = StringTools.replace(str, "\\", "/");
225
- };
226
- s = str;
227
- this.cacheStrategy = CacheStrategy.AbsolutePath((HxOverrides.cca(s, 0) == 47) ? s : "/" + s, CacheDurability.LimitCountByAge(1));
256
+ this.cacheStrategy = CacheStrategy.AbsolutePath(path, CacheDurability.LimitCountByAge(1));
228
257
  if (generate) {
229
258
  return this.getSource();
230
259
  } else {
@@ -240,15 +269,7 @@ class Stone extends Register.inherits() {
240
269
  exportTo(path) {
241
270
  var _gthis = this;
242
271
  Log.log(30, ...["Exporting file(s).", {"path": path, "stone": this}]);
243
- var s = path;
244
- var str = (path.length > 1 && HxOverrides.cca(path, 0) == 47) ? path.substring(1) : path;
245
- if (str.length > 0) {
246
- str = Path.posix.normalize(str);
247
- str = StringTools.replace(str, "\\", "/");
248
- };
249
- s = str;
250
- var pathId = (HxOverrides.cca(s, 0) == 47) ? s : "/" + s;
251
- var isDir = HxOverrides.cca(pathId, pathId.length - 1) == 47;
272
+ var isDir = path.length == 0 || path.charCodeAt(path.length - 1) == 47;
252
273
  return this.getSource().then(function (src) {
253
274
  if (src.data.length > 1 && !isDir) {
254
275
  throw new Error("Path is not a directory for multiple source export.");
@@ -259,12 +280,17 @@ class Stone extends Register.inherits() {
259
280
  while (_g1 < _g2.length) {
260
281
  var data = _g2[_g1];
261
282
  ++_g1;
262
- var id = (isDir) ? SourceId.getPutInDir(data.id, pathId) : pathId;
263
- var root = RootDir.fromProject(_gthis.project);
264
- if (id.charAt(0) != "/") {
265
- throw new Error("Badly formed SourceId.");
283
+ var id;
284
+ if (isDir) {
285
+ var id1 = data.id;
286
+ if (!(path.length == 0 || path.charCodeAt(path.length - 1) == 47)) {
287
+ throw new Error("\"" + path + "\" is not a directory.");
288
+ };
289
+ id = Path.posix.join(path, id1);
290
+ } else {
291
+ id = path;
266
292
  };
267
- _g.push(Utils.saveBytes(Path.posix.join(".", root, ".", id), data.data));
293
+ _g.push(Utils.saveBytes(Path.posix.join(".", RootDir.fromProject(_gthis.project), ".", id), data.data));
268
294
  };
269
295
  return Promise.all(_g);
270
296
  });
@@ -275,7 +301,7 @@ class Stone extends Register.inherits() {
275
301
  * Useful for pure JS stones.
276
302
  */
277
303
  cwdPath(path) {
278
- return Path.join("./", this.project.rootDir, path);
304
+ return Path.posix.join(".", RootDir.fromProject(this.project), ".", path);
279
305
  }
280
306
  get_cache() {
281
307
  return this.project.cache;
package/bin/whet/Whet.js CHANGED
@@ -2,6 +2,7 @@ import {Project} from "./Project.js"
2
2
  import {LogLevel, Log} from "./Log.js"
3
3
  import * as Url from "url"
4
4
  import * as PinoPretty from "pino-pretty"
5
+ import {Exception} from "../haxe/Exception.js"
5
6
  import {Register} from "../genes/Register.js"
6
7
  import {Command, CommanderError} from "commander"
7
8
  import {Std} from "../Std.js"
@@ -11,8 +12,17 @@ const $global = Register.$global
11
12
  export const Whet_Fields_ = Register.global("$hxClasses")["whet._Whet.Whet_Fields_"] =
12
13
  class Whet_Fields_ {
13
14
  static main() {
14
- Whet_Fields_.program.enablePositionalOptions().passThroughOptions().description("Project tooling.").usage("[options] [command] [+ [command]...]").version("0.0.18", "-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").option("--no-pretty", "disable pretty logging").exitOverride();
15
- Whet_Fields_.program.parse();
15
+ Whet_Fields_.program.enablePositionalOptions().passThroughOptions().description("Project tooling.").usage("[options] [command] [+ [command]...]").version("0.0.20", "-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").option("--no-pretty", "disable pretty logging").exitOverride();
16
+ try {
17
+ Whet_Fields_.program.parse();
18
+ }catch (_g) {
19
+ var _g1 = Exception.caught(_g);
20
+ if (((_g1.get_native()) instanceof CommanderError) && _g1.get_native().code == "commander.version") {
21
+ process.exit();
22
+ } else {
23
+ throw Exception.thrown(_g1);
24
+ };
25
+ };
16
26
  var options = Whet_Fields_.program.opts();
17
27
  if (options.logLevel != null) {
18
28
  var n = Std.parseInt(options.logLevel);