whet 0.0.15 → 0.0.18
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/bin/pino_pretty/PrettyOptions.d.ts +98 -0
- package/bin/pino_pretty/default_/MessageFormatFunc.d.ts +3 -0
- package/bin/whet/Log.d.ts +1 -0
- package/bin/whet/Log.js +3 -2
- package/bin/whet/Stone.js +1 -0
- package/bin/whet/Whet.d.ts +1 -0
- package/bin/whet/Whet.js +20 -3
- package/bin/whet/extern/Minimatch.d.ts +77 -0
- package/bin/whet/magic/MinimatchType.d.ts +5 -0
- package/bin/whet/magic/MinimatchType.js +26 -0
- package/bin/whet/magic/RoutePathType.d.ts +12 -3
- package/bin/whet/magic/RoutePathType.js +87 -23
- package/bin/whet/route/Router.d.ts +19 -12
- package/bin/whet/route/Router.js +224 -91
- package/bin/whet/stones/JsonStone.d.ts +2 -3
- package/bin/whet/stones/JsonStone.js +19 -50
- package/bin/whet/stones/Server.d.ts +1 -0
- package/bin/whet/stones/Server.js +91 -35
- package/bin/whet/stones/Zip.js +2 -22
- package/bin/whet.d.ts +0 -1
- package/bin/whet.js +0 -1
- package/package.json +6 -3
- package/bin/StringBuf.d.ts +0 -13
- package/bin/StringBuf.js +0 -25
- package/bin/haxe/CallStack.d.ts +0 -41
- package/bin/haxe/CallStack.js +0 -96
- package/bin/haxe/NativeStackTrace.js +0 -147
- package/bin/haxe/io/Path.d.ts +0 -109
- package/bin/haxe/io/Path.js +0 -217
- package/bin/whet/magic/RouteType.d.ts +0 -13
- package/bin/whet/magic/RouteType.js +0 -104
- package/bin/whet/route/Route.d.ts +0 -19
- package/bin/whet/route/Route.js +0 -121
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
|
|
2
|
+
export type PrettyOptions = {
|
|
3
|
+
/**
|
|
4
|
+
Opens the file with the 'a' flag.
|
|
5
|
+
*/
|
|
6
|
+
append?: null | boolean,
|
|
7
|
+
/**
|
|
8
|
+
If set to true, will add color information to the formatted output message.
|
|
9
|
+
*/
|
|
10
|
+
colorize?: null | boolean,
|
|
11
|
+
/**
|
|
12
|
+
Appends carriage return and line feed, instead of just a line feed, to the formatted log line.
|
|
13
|
+
*/
|
|
14
|
+
crlf?: null | boolean,
|
|
15
|
+
/**
|
|
16
|
+
Provides the ability to add a custom prettify function for specific log properties.
|
|
17
|
+
`customPrettifiers` is an object, where keys are log properties that will be prettified
|
|
18
|
+
and value is the prettify function itself.
|
|
19
|
+
For example, if a log line contains a query property, you can specify a prettifier for it:
|
|
20
|
+
*/
|
|
21
|
+
customPrettifiers?: null | {
|
|
22
|
+
},
|
|
23
|
+
/**
|
|
24
|
+
The file, file descriptor, or stream to write to. Defaults to 1 (stdout).
|
|
25
|
+
*/
|
|
26
|
+
destination?: null | any,
|
|
27
|
+
/**
|
|
28
|
+
Define the log keys that are associated with error like objects.
|
|
29
|
+
*/
|
|
30
|
+
errorLikeObjectKeys?: null | string[],
|
|
31
|
+
/**
|
|
32
|
+
When formatting an error object, display this list of properties.
|
|
33
|
+
The list should be a comma separated list of properties.
|
|
34
|
+
*/
|
|
35
|
+
errorProps?: null | string,
|
|
36
|
+
/**
|
|
37
|
+
Hide objects from output (but not error object).
|
|
38
|
+
*/
|
|
39
|
+
hideObject?: null | boolean,
|
|
40
|
+
/**
|
|
41
|
+
Ignore one or several keys.
|
|
42
|
+
Will be overridden by the option include if include is presented.
|
|
43
|
+
*/
|
|
44
|
+
ignore?: null | string,
|
|
45
|
+
/**
|
|
46
|
+
Include one or several keys.
|
|
47
|
+
*/
|
|
48
|
+
include?: null | string,
|
|
49
|
+
/**
|
|
50
|
+
If set to true, it will print the name of the log level as the first field in the log line.
|
|
51
|
+
*/
|
|
52
|
+
levelFirst?: null | boolean,
|
|
53
|
+
/**
|
|
54
|
+
Define the key that contains the level of the log.
|
|
55
|
+
*/
|
|
56
|
+
levelKey?: null | string,
|
|
57
|
+
/**
|
|
58
|
+
Output the log level using the specified label.
|
|
59
|
+
*/
|
|
60
|
+
levelLabel?: null | string,
|
|
61
|
+
/**
|
|
62
|
+
Format output of message, e.g. {level} - {pid} will output message: INFO - 1123
|
|
63
|
+
*/
|
|
64
|
+
messageFormat?: null | any,
|
|
65
|
+
/**
|
|
66
|
+
The key in the JSON object to use as the highlighted message.
|
|
67
|
+
*/
|
|
68
|
+
messageKey?: null | string,
|
|
69
|
+
/**
|
|
70
|
+
The minimum log level to include in the output.
|
|
71
|
+
*/
|
|
72
|
+
minimumLevel?: null | any,
|
|
73
|
+
/**
|
|
74
|
+
Ensure directory for destination file exists.
|
|
75
|
+
*/
|
|
76
|
+
mkdir?: null | boolean,
|
|
77
|
+
/**
|
|
78
|
+
Print each log message on a single line (errors will still be multi-line).
|
|
79
|
+
*/
|
|
80
|
+
singleLine?: null | boolean,
|
|
81
|
+
/**
|
|
82
|
+
Makes messaging synchronous.
|
|
83
|
+
*/
|
|
84
|
+
sync?: null | boolean,
|
|
85
|
+
/**
|
|
86
|
+
The key in the JSON object to use for timestamp display.
|
|
87
|
+
*/
|
|
88
|
+
timestampKey?: null | string,
|
|
89
|
+
/**
|
|
90
|
+
Translate the epoch time value into a human readable date and time string. This flag also can set the format
|
|
91
|
+
string to apply when translating the date to human readable format. For a list of available pattern letters
|
|
92
|
+
see the {@link https://www.npmjs.com/package/dateformat|dateformat documentation}.
|
|
93
|
+
- The default format is `yyyy-mm-dd HH:MM:ss.l o` in UTC.
|
|
94
|
+
- Requires a `SYS:` prefix to translate time to the local system's timezone. Use the shortcut `SYS:standard`
|
|
95
|
+
to translate time to `yyyy-mm-dd HH:MM:ss.l o` in system timezone.
|
|
96
|
+
*/
|
|
97
|
+
translateTime?: null | any
|
|
98
|
+
}
|
package/bin/whet/Log.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export declare class Log {
|
|
|
7
7
|
static error(...args: any[]): void
|
|
8
8
|
static fatal(...args: any[]): void
|
|
9
9
|
static logLevel: number
|
|
10
|
+
static stream: IWritable
|
|
10
11
|
protected static log(level: number, ...args: any[]): void
|
|
11
12
|
protected static replacer(key: any, val: any): any
|
|
12
13
|
}
|
package/bin/whet/Log.js
CHANGED
|
@@ -50,12 +50,12 @@ class Log {
|
|
|
50
50
|
};
|
|
51
51
|
};
|
|
52
52
|
};
|
|
53
|
-
|
|
53
|
+
Log.stream.write(JSON.stringify(out, Log.replacer) + "\n");
|
|
54
54
|
};
|
|
55
55
|
}
|
|
56
56
|
static replacer(key, val) {
|
|
57
57
|
if (((val) instanceof Error)) {
|
|
58
|
-
return val.stack;
|
|
58
|
+
return {"type": val.name, "message": val.message, "stack": val.stack};
|
|
59
59
|
};
|
|
60
60
|
if (val != null && typeof(val.toString) == "function" && val.toString != Object.prototype.toString) {
|
|
61
61
|
return val.toString();
|
|
@@ -72,6 +72,7 @@ class Log {
|
|
|
72
72
|
|
|
73
73
|
|
|
74
74
|
Log.logLevel = 30
|
|
75
|
+
Log.stream = process.stdout
|
|
75
76
|
export const LogLevel = Register.global("$hxClasses")["whet._Log.LogLevel"] =
|
|
76
77
|
class LogLevel {
|
|
77
78
|
static fromString(s) {
|
package/bin/whet/Stone.js
CHANGED
|
@@ -161,6 +161,7 @@ class Stone extends Register.inherits() {
|
|
|
161
161
|
* @param err Any error that might have happened during `generateSource`.
|
|
162
162
|
*/
|
|
163
163
|
handleError(err) {
|
|
164
|
+
Log.log(50, ...["Error while generating.", {"stone": this, "err": err}]);
|
|
164
165
|
return Promise.reject(err);
|
|
165
166
|
}
|
|
166
167
|
|
package/bin/whet/Whet.d.ts
CHANGED
package/bin/whet/Whet.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import {Project} from "./Project.js"
|
|
2
2
|
import {LogLevel, Log} from "./Log.js"
|
|
3
3
|
import * as Url from "url"
|
|
4
|
+
import * as PinoPretty from "pino-pretty"
|
|
4
5
|
import {Register} from "../genes/Register.js"
|
|
5
|
-
import {Command} from "commander"
|
|
6
|
+
import {Command, CommanderError} from "commander"
|
|
6
7
|
import {Std} from "../Std.js"
|
|
7
8
|
|
|
8
9
|
const $global = Register.$global
|
|
@@ -10,7 +11,7 @@ const $global = Register.$global
|
|
|
10
11
|
export const Whet_Fields_ = Register.global("$hxClasses")["whet._Whet.Whet_Fields_"] =
|
|
11
12
|
class Whet_Fields_ {
|
|
12
13
|
static main() {
|
|
13
|
-
Whet_Fields_.program.enablePositionalOptions().passThroughOptions().description("Project tooling.").usage("[options] [command] [+ [command]...]").version("0.0.
|
|
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();
|
|
14
15
|
Whet_Fields_.program.parse();
|
|
15
16
|
var options = Whet_Fields_.program.opts();
|
|
16
17
|
if (options.logLevel != null) {
|
|
@@ -24,6 +25,9 @@ class Whet_Fields_ {
|
|
|
24
25
|
Log.logLevel = n;
|
|
25
26
|
};
|
|
26
27
|
};
|
|
28
|
+
if (options.pretty) {
|
|
29
|
+
Log.stream = PinoPretty["default"]();
|
|
30
|
+
};
|
|
27
31
|
global.setImmediate(Whet_Fields_.init, options);
|
|
28
32
|
}
|
|
29
33
|
static init(options) {
|
|
@@ -41,7 +45,10 @@ class Whet_Fields_ {
|
|
|
41
45
|
if (((e) instanceof Error)) {
|
|
42
46
|
Log.log(50, ...[e.stack]);
|
|
43
47
|
};
|
|
44
|
-
|
|
48
|
+
try {
|
|
49
|
+
Whet_Fields_.program.help();
|
|
50
|
+
}catch (_g) {
|
|
51
|
+
};
|
|
45
52
|
});
|
|
46
53
|
};
|
|
47
54
|
}
|
|
@@ -87,12 +94,21 @@ class Whet_Fields_ {
|
|
|
87
94
|
Log.log(10, ...["Executing command.", {"commandArgs": c}]);
|
|
88
95
|
Whet_Fields_.program.parseAsync(c, {"from": "user"}).then(function (_) {
|
|
89
96
|
nextCommand();
|
|
97
|
+
})["catch"](function (err) {
|
|
98
|
+
if (((err) instanceof CommanderError) && err.code == "commander.help") {
|
|
99
|
+
return;
|
|
100
|
+
};
|
|
101
|
+
Log.log(50, ...["Error while executing command.", {"error": err}]);
|
|
90
102
|
});
|
|
91
103
|
};
|
|
92
104
|
initProm.then(function (_) {
|
|
93
105
|
nextCommand();
|
|
94
106
|
});
|
|
95
107
|
}
|
|
108
|
+
static executeCommand(cmd) {
|
|
109
|
+
Log.log(10, ...["Executing command.", {"command": cmd}]);
|
|
110
|
+
return Whet_Fields_.program.parseAsync(cmd, {"from": "user"});
|
|
111
|
+
}
|
|
96
112
|
static getCommands(args) {
|
|
97
113
|
var commands = [];
|
|
98
114
|
var from = 0;
|
|
@@ -119,3 +135,4 @@ class Whet_Fields_ {
|
|
|
119
135
|
Whet_Fields_.program = new Command("whet")
|
|
120
136
|
export const program = Whet_Fields_.program
|
|
121
137
|
export const main = Whet_Fields_.main
|
|
138
|
+
export const executeCommand = Whet_Fields_.executeCommand
|
|
@@ -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,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 {
|
|
2
|
+
import {MinimatchType} from "./MinimatchType"
|
|
3
|
+
import {AnyStone} from "../Stone"
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
|
-
* Anything that can be transformed into `
|
|
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 =
|
|
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 {
|
|
3
|
-
import {
|
|
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
|
-
|
|
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 (
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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 `
|
|
13
|
-
*
|
|
14
|
+
* Find data sources routed under `pattern`.
|
|
15
|
+
* @param pattern A glob pattern to search for.
|
|
14
16
|
*/
|
|
15
|
-
|
|
17
|
+
get(pattern?: MinimatchType): Promise<RouteResult[]>
|
|
16
18
|
|
|
17
19
|
/**
|
|
18
|
-
* Get combined hash of all sources that
|
|
20
|
+
* Get combined hash of all sources that fit the `pattern`.
|
|
19
21
|
*/
|
|
20
|
-
getHash(
|
|
21
|
-
getHashOfEverything(): Promise<SourceHash>
|
|
22
|
+
getHash(pattern?: MinimatchType): Promise<SourceHash>
|
|
22
23
|
|
|
23
24
|
/**
|
|
24
|
-
* Save files filtered by `
|
|
25
|
+
* Save files filtered by `pattern` into provided `saveInto` folder.
|
|
25
26
|
*/
|
|
26
|
-
saveInto(
|
|
27
|
-
listContents(
|
|
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
|
-
|
|
32
|
-
|
|
34
|
+
extractDirs: Minimatch,
|
|
35
|
+
filter: Minimatch,
|
|
36
|
+
routeUnder: string,
|
|
37
|
+
source: RouterSource
|
|
33
38
|
}
|
|
39
|
+
|
|
40
|
+
export type RouterSource = AnyStone | Router
|