@makano/rew 1.2.65 → 1.2.67
Sign up to get free protection for your applications and to get access to all the features.
package/lib/rew/const/usage.js
CHANGED
@@ -12,4 +12,18 @@ module.exports.USING_DEFAULT = {
|
|
12
12
|
DECORATORS: {
|
13
13
|
use: (options) => options.decorators = true
|
14
14
|
}
|
15
|
+
}
|
16
|
+
|
17
|
+
module.exports.Usage = class Usage {
|
18
|
+
name = "null";
|
19
|
+
trigger = () => {}
|
20
|
+
|
21
|
+
constructor(name, trigger){
|
22
|
+
this.name = name;
|
23
|
+
this.trigger = trigger;
|
24
|
+
}
|
25
|
+
|
26
|
+
create(name, trigger){
|
27
|
+
return new Usage(name, trigger);
|
28
|
+
}
|
15
29
|
}
|
@@ -2,6 +2,8 @@ const SerializableData = ['string', 'number', 'boolean'];
|
|
2
2
|
|
3
3
|
const isRegExp = (obj) => Object.prototype.toString.call(obj) === '[object RegExp]';
|
4
4
|
|
5
|
+
const AnySymbol = Symbol('any');
|
6
|
+
|
5
7
|
module.exports.match = function match(value, templates, props) {
|
6
8
|
const matchProps = (pattern, value) => {
|
7
9
|
if (!props) return false;
|
@@ -23,6 +25,8 @@ module.exports.match = function match(value, templates, props) {
|
|
23
25
|
|
24
26
|
const entries = templates instanceof Map ? templates.entries() : Array.isArray(templates) ? templates : Object.entries(templates);
|
25
27
|
|
28
|
+
let any;
|
29
|
+
|
26
30
|
for (const [pattern, callback] of entries) {
|
27
31
|
if (
|
28
32
|
isRegExp(pattern)
|
@@ -36,8 +40,17 @@ module.exports.match = function match(value, templates, props) {
|
|
36
40
|
: matchProps(pattern, value)
|
37
41
|
) {
|
38
42
|
return callback(...(isRegExp(pattern) ? pattern.exec(value) : [value]));
|
43
|
+
} else if(pattern == AnySymbol){
|
44
|
+
any = callback;
|
39
45
|
}
|
40
46
|
}
|
41
47
|
|
48
|
+
if(any){
|
49
|
+
return any(value);
|
50
|
+
}
|
51
|
+
|
42
52
|
return null;
|
43
53
|
};
|
54
|
+
|
55
|
+
|
56
|
+
module.exports.match.any = AnySymbol;
|
package/lib/rew/models/struct.js
CHANGED
@@ -9,14 +9,17 @@ module.exports.struct = function struct(template) {
|
|
9
9
|
types[key] = typeof value;
|
10
10
|
}
|
11
11
|
|
12
|
-
const fun = function (properties = {}) {
|
12
|
+
const fun = function (properties = {}, extra) {
|
13
13
|
var defaultValue, instance;
|
14
14
|
instance = {};
|
15
15
|
for (key in template) {
|
16
16
|
defaultValue = template[key];
|
17
|
-
if
|
17
|
+
if(key.startsWith('@') && typeof template[key] == "function"){
|
18
|
+
const realname = key.slice(1);
|
19
|
+
instance[realname] = defaultValue(properties[realname]);
|
20
|
+
} else if (key in properties) {
|
18
21
|
value = properties[key];
|
19
|
-
if (defaultValue != '!any' && typeof value !== types[key]) {
|
22
|
+
if (defaultValue != '!any' && typeof value !== types[key] && types[key] !== '!any') {
|
20
23
|
throw new Error(`Type error: Expected ${types[key]} for ${key}, got ${typeof value}`);
|
21
24
|
}
|
22
25
|
instance[key] = value;
|
@@ -24,10 +27,17 @@ module.exports.struct = function struct(template) {
|
|
24
27
|
instance[key] = defaultValue == '!any' ? null : defaultValue;
|
25
28
|
}
|
26
29
|
}
|
30
|
+
if(typeof extra == "object"){
|
31
|
+
for(let i in extra){
|
32
|
+
instance[i] = extra[i];
|
33
|
+
}
|
34
|
+
}
|
27
35
|
instance.__proto__ = { '@instance': fun };
|
28
36
|
return instance;
|
29
37
|
};
|
30
38
|
|
39
|
+
fun.extends = (stuff) => struct({ ...template, ...stuff });
|
40
|
+
|
31
41
|
return fun;
|
32
42
|
};
|
33
43
|
|
@@ -5,9 +5,10 @@ const { imp } = require("../functions/import");
|
|
5
5
|
const { customRequire } = require("../functions/require");
|
6
6
|
const fsLib = require("../functions/fs");
|
7
7
|
const pathLib = require("../functions/path");
|
8
|
+
const path = require("path");
|
8
9
|
const execLib = require("../functions/exec");
|
9
10
|
const { findAppInfo } = require("../misc/findAppInfo");
|
10
|
-
const { USING_DEFAULT } = require("../const/usage");
|
11
|
+
const { USING_DEFAULT, Usage } = require("../const/usage");
|
11
12
|
|
12
13
|
let mainFile = "";
|
13
14
|
const isMainFile = (filepath) => filepath == mainFile;
|
@@ -45,6 +46,7 @@ module.exports.prepareContext = function (
|
|
45
46
|
...pathLib(filepath),
|
46
47
|
...execLib(filepath),
|
47
48
|
...custom_context,
|
49
|
+
Usage
|
48
50
|
};
|
49
51
|
}
|
50
52
|
if (!context.process)
|
@@ -59,6 +61,7 @@ module.exports.prepareContext = function (
|
|
59
61
|
env: process.env,
|
60
62
|
cwd: () => process.cwd(),
|
61
63
|
arch: process.arch,
|
64
|
+
pid: process.pid
|
62
65
|
};
|
63
66
|
|
64
67
|
context.global = context;
|
@@ -98,11 +101,21 @@ module.exports.prepareContext = function (
|
|
98
101
|
if(USING_DEFAULT[name].param) {
|
99
102
|
context.__using__[name] = USING_DEFAULT[name].param(...params);
|
100
103
|
}
|
104
|
+
} else if(name instanceof Usage) {
|
105
|
+
context.__using__[name.name] = name.trigger(...params) || true;
|
101
106
|
} else {
|
102
107
|
context.__using__[name] = params.length ? params.length > 1 ? [...params] : params : true;
|
103
108
|
}
|
104
109
|
};
|
105
110
|
|
111
|
+
if(context.app?.config?.exec?.['auto import']){
|
112
|
+
const autoipath = path.join(context.app.path, context.app.config?.exec?.['auto import']);
|
113
|
+
if(autoipath !== filepath){
|
114
|
+
const all = context.imp(path.relative(path.dirname(filepath), autoipath));
|
115
|
+
for(let i in all) context[i] = all[i];
|
116
|
+
}
|
117
|
+
}
|
118
|
+
|
106
119
|
if (
|
107
120
|
context.module.main ||
|
108
121
|
(options.fromMain == true && options.as == "main")
|