jj.js 0.7.1 → 0.7.4
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/lib/controller.js +0 -7
- package/lib/ctx.js +23 -17
- package/lib/loader.js +2 -2
- package/lib/upload.js +1 -1
- package/lib/utils/fs.js +7 -17
- package/package.json +1 -1
package/lib/controller.js
CHANGED
|
@@ -2,13 +2,6 @@ const Middleware = require('./middleware');
|
|
|
2
2
|
|
|
3
3
|
class Controller extends Middleware
|
|
4
4
|
{
|
|
5
|
-
constructor(...args) {
|
|
6
|
-
super(...args);
|
|
7
|
-
if(!this.$view.__node.isClass) {
|
|
8
|
-
this.$view = this.$.view;
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
|
|
12
5
|
// 赋值模版数据
|
|
13
6
|
$assign(name, value) {
|
|
14
7
|
this.$view.assign(name, value);
|
package/lib/ctx.js
CHANGED
|
@@ -3,37 +3,43 @@ const loader = require('./loader');
|
|
|
3
3
|
const Ctx = new Proxy(class {}, {
|
|
4
4
|
construct() {
|
|
5
5
|
return new Proxy({__proto__: arguments[2].prototype}, {
|
|
6
|
-
get: (target, prop) => {
|
|
6
|
+
get: (target, prop, receiver) => {
|
|
7
7
|
if(prop in target || typeof prop == 'symbol' || prop == 'inspect') {
|
|
8
|
-
return target
|
|
8
|
+
return Reflect.get(target, prop, receiver);
|
|
9
9
|
}
|
|
10
10
|
if(prop == '$' || prop == '_') {
|
|
11
11
|
return target.ctx && target.ctx[prop]
|
|
12
12
|
|| prop == '$' && (target.$ || (target.$ = loader('../'))) && target.$
|
|
13
13
|
|| undefined;
|
|
14
14
|
}
|
|
15
|
+
if(prop.slice(0, 1) != '$') {
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
15
18
|
const pp = prop.slice(1);
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
if(_[
|
|
22
|
-
if(_[
|
|
23
|
-
_[
|
|
19
|
+
const ctx = target.ctx;
|
|
20
|
+
if(ctx && ctx._) {
|
|
21
|
+
const _ = ctx._;
|
|
22
|
+
const APP = ctx.APP;
|
|
23
|
+
const COMMON = _.config.app.common_app;
|
|
24
|
+
if(_[APP][prop] === undefined) {
|
|
25
|
+
if(_[APP][pp] && _[COMMON] && _[COMMON][pp]) {
|
|
26
|
+
_[APP][prop] = new Proxy({}, {
|
|
24
27
|
get: (...args) => {
|
|
25
|
-
return _[
|
|
28
|
+
return _[APP][pp][args[1]] || _[COMMON][pp][args[1]];
|
|
26
29
|
}
|
|
27
30
|
});
|
|
28
|
-
} else if(_[
|
|
29
|
-
_[
|
|
30
|
-
} else if(_[
|
|
31
|
-
_[
|
|
31
|
+
} else if(_[APP][pp]) {
|
|
32
|
+
_[APP][prop] = _[APP][pp];
|
|
33
|
+
} else if(_[COMMON] && _[COMMON][pp]) {
|
|
34
|
+
_[APP][prop] = _[COMMON][pp];
|
|
32
35
|
} else {
|
|
33
|
-
_[
|
|
36
|
+
_[APP][prop] = null;
|
|
37
|
+
}
|
|
38
|
+
if(~['view', 'response'].indexOf(pp) && _[APP][prop] && _[APP][prop].__node && !_[APP][prop].__node.isClass && ctx.$ && ctx.$[pp]) {
|
|
39
|
+
_[APP][prop] = ctx.$[pp];
|
|
34
40
|
}
|
|
35
41
|
}
|
|
36
|
-
return _[
|
|
42
|
+
return _[APP][prop] || _[pp] || (ctx.$ && ctx.$[pp]) || undefined;
|
|
37
43
|
} else {
|
|
38
44
|
return (target.$ || (target.$ = loader('../'))) && target.$[pp];
|
|
39
45
|
}
|
package/lib/loader.js
CHANGED
|
@@ -17,9 +17,9 @@ function loader(dir='./', ...args) {
|
|
|
17
17
|
|
|
18
18
|
function creatLoader(node) {
|
|
19
19
|
return new Proxy(node, {
|
|
20
|
-
get: (node, prop) => {
|
|
20
|
+
get: (node, prop, receiver) => {
|
|
21
21
|
if(prop in node || typeof prop == 'symbol' || prop == 'inspect') {
|
|
22
|
-
return node
|
|
22
|
+
return Reflect.get(node, prop, receiver);
|
|
23
23
|
}
|
|
24
24
|
const nodeInfo = info.get(node);
|
|
25
25
|
if(nodeInfo.isClass) {
|
package/lib/upload.js
CHANGED
|
@@ -37,7 +37,7 @@ class Upload extends Context
|
|
|
37
37
|
|
|
38
38
|
try {
|
|
39
39
|
const filePath = pt.join(this.$config.app.base_dir, dir, savename);
|
|
40
|
-
await utils.fs.mkdirs(filePath);
|
|
40
|
+
await utils.fs.mkdirs(pt.dirname(filePath));
|
|
41
41
|
const reader = fs.createReadStream(this._file.path);
|
|
42
42
|
const writer = fs.createWriteStream(filePath);
|
|
43
43
|
reader.pipe(writer);
|
package/lib/utils/fs.js
CHANGED
|
@@ -64,23 +64,13 @@ fsFun.isDirSync = (path) => {return fs.existsSync(path) && fs.statSync(path).isD
|
|
|
64
64
|
});
|
|
65
65
|
|
|
66
66
|
//(多级目录生成)
|
|
67
|
-
fsFun.mkdirs = async function (
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
pathtmp = pt.join(pathtmp, dirname);
|
|
75
|
-
} else {
|
|
76
|
-
pathtmp = dirname;
|
|
77
|
-
}
|
|
78
|
-
if(!await fsFun.isDir(pathtmp)) {
|
|
79
|
-
const result = await fsFun.mkdir(pathtmp)
|
|
80
|
-
if (!result) {
|
|
81
|
-
throw result;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
67
|
+
fsFun.mkdirs = async function (dirname) {
|
|
68
|
+
if(await fsFun.isDir(dirname)) {
|
|
69
|
+
return true;
|
|
70
|
+
} else {
|
|
71
|
+
if(await fsFun.mkdirs(pt.dirname(dirname))) {
|
|
72
|
+
await fsFun.mkdir(dirname);
|
|
73
|
+
return true;
|
|
84
74
|
}
|
|
85
75
|
}
|
|
86
76
|
}
|