babel-plugin-zova-bean-module 1.0.32 → 1.1.0
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/dist/index.d.ts +1 -2
- package/dist/index.js +63 -46
- package/package.json +19 -22
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,61 +1,78 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const core_1 = require("@babel/core");
|
|
5
|
-
const module_info_1 = require("@cabloy/module-info");
|
|
6
|
-
const __Decorator_Supported = ['Bean', 'Local', 'Scope', 'Store', 'Data', 'Model', 'Style', 'Theme', 'Tool', 'Virtual'];
|
|
7
|
-
function default_1() {
|
|
1
|
+
import { /* template, */ types as t } from '@babel/core';
|
|
2
|
+
import { parseInfoFromPath } from '@cabloy/module-info';
|
|
3
|
+
export default function () {
|
|
8
4
|
const visitor = {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
5
|
+
Program(path, state) {
|
|
6
|
+
const beanInfo = __parseBeanInfo(state);
|
|
7
|
+
if (!beanInfo)
|
|
8
|
+
return;
|
|
9
|
+
// context
|
|
10
|
+
const context = {
|
|
11
|
+
needBeanInfo: false,
|
|
12
|
+
};
|
|
13
|
+
// traverse
|
|
14
|
+
path.traverse(createVisitor(context, beanInfo));
|
|
15
|
+
// insertImport
|
|
16
|
+
if (context.needBeanInfo) {
|
|
17
|
+
insertImport(path);
|
|
22
18
|
}
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
return { visitor };
|
|
22
|
+
}
|
|
23
|
+
function createVisitor(context, beanInfo) {
|
|
24
|
+
return {
|
|
25
|
+
ClassDeclaration(path) {
|
|
23
26
|
const decorators = path.node.decorators;
|
|
24
27
|
if (!decorators || decorators.length === 0)
|
|
25
28
|
return;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const decoratorName = expression.callee.name;
|
|
30
|
-
if (__Decorator_Supported.includes(decoratorName)) {
|
|
31
|
-
const moduleName = getModuleName();
|
|
32
|
-
if (moduleName) {
|
|
33
|
-
__applyDecorator(expression, moduleName);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
29
|
+
const decoratorNode = __createDecoratorNode(beanInfo);
|
|
30
|
+
decorators.push(decoratorNode);
|
|
31
|
+
context.needBeanInfo = true;
|
|
38
32
|
},
|
|
39
33
|
};
|
|
40
|
-
return { visitor };
|
|
41
34
|
}
|
|
42
|
-
function
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
35
|
+
function insertImport(path) {
|
|
36
|
+
const nodeImport = t.importDeclaration([t.importSpecifier(t.identifier('__z_BeanInfo'), t.stringLiteral('BeanInfo'))], t.stringLiteral('zova'));
|
|
37
|
+
path.get('body')[0].insertBefore(nodeImport);
|
|
38
|
+
}
|
|
39
|
+
function __parseBeanInfo(state) {
|
|
40
|
+
const sourceFileName = state.file.opts.sourceFileName || state.file.opts.filename || '';
|
|
41
|
+
const moduleName = __getModuleName(sourceFileName);
|
|
42
|
+
if (!moduleName)
|
|
43
|
+
return;
|
|
44
|
+
return { module: moduleName };
|
|
45
|
+
}
|
|
46
|
+
function __getModuleName(sourceFileName) {
|
|
47
|
+
if (!__checkIfValid(sourceFileName))
|
|
48
|
+
return;
|
|
49
|
+
const moduleInfo = parseInfoFromPath(sourceFileName);
|
|
50
|
+
if (!moduleInfo)
|
|
51
|
+
return;
|
|
52
|
+
return moduleInfo.relativeName;
|
|
53
|
+
}
|
|
54
|
+
function __createDecoratorNode(beanInfo) {
|
|
55
|
+
const propertyNodeModule = t.objectProperty(t.identifier('module'), t.stringLiteral(beanInfo.module));
|
|
56
|
+
const objectExpression = t.objectExpression([propertyNodeModule]);
|
|
57
|
+
const callExpression = t.callExpression(t.identifier('__z_BeanInfo'), [objectExpression]);
|
|
58
|
+
const decoratorNode = t.decorator(callExpression);
|
|
59
|
+
return decoratorNode;
|
|
53
60
|
}
|
|
61
|
+
// function __applyDecorator(expression: t.CallExpression, moduleName: string) {
|
|
62
|
+
// const propertyNode = t.objectProperty(t.identifier('module'), t.stringLiteral(moduleName));
|
|
63
|
+
// const args = expression.arguments;
|
|
64
|
+
// if (args.length === 0) {
|
|
65
|
+
// const objectExpression = t.objectExpression([propertyNode]);
|
|
66
|
+
// args.push(objectExpression);
|
|
67
|
+
// } else {
|
|
68
|
+
// const objectExpression = args[0] as t.ObjectExpression;
|
|
69
|
+
// objectExpression.properties.push(propertyNode);
|
|
70
|
+
// }
|
|
71
|
+
// }
|
|
54
72
|
function __checkIfValid(fileName) {
|
|
55
73
|
if (!fileName)
|
|
56
74
|
return false;
|
|
57
75
|
return !['src/boot/app/', '.zova/app/'].some(item => {
|
|
58
|
-
return fileName.
|
|
76
|
+
return fileName.includes(item);
|
|
59
77
|
});
|
|
60
78
|
}
|
|
61
|
-
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,38 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "babel-plugin-zova-bean-module",
|
|
3
|
-
"
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "1.1.0",
|
|
4
5
|
"description": "babel-plugin-zova-bean-module",
|
|
5
6
|
"publishConfig": {
|
|
6
7
|
"access": "public"
|
|
7
8
|
},
|
|
9
|
+
"author": "zhennann",
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"keywords": [
|
|
12
|
+
"egg",
|
|
13
|
+
"egg-born",
|
|
14
|
+
"framework",
|
|
15
|
+
"zova"
|
|
16
|
+
],
|
|
8
17
|
"exports": {
|
|
9
18
|
".": {
|
|
10
|
-
"types":
|
|
19
|
+
"types": [
|
|
20
|
+
"./src/index.ts",
|
|
21
|
+
"./dist/index.d.ts"
|
|
22
|
+
],
|
|
11
23
|
"default": "./dist/index.js"
|
|
12
24
|
},
|
|
13
|
-
"
|
|
25
|
+
"./package.json": "./package.json"
|
|
14
26
|
},
|
|
15
27
|
"files": [
|
|
16
28
|
"dist"
|
|
17
29
|
],
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"tsc:publish": "npm run clean && tsc -b",
|
|
22
|
-
"prepublishOnly": "npm run tsc:publish"
|
|
23
|
-
},
|
|
24
|
-
"keywords": [
|
|
25
|
-
"egg",
|
|
26
|
-
"egg-born",
|
|
27
|
-
"framework",
|
|
28
|
-
"zova"
|
|
29
|
-
],
|
|
30
|
-
"author": "zhennann",
|
|
31
|
-
"license": "MIT",
|
|
32
|
-
"devDependencies": {
|
|
33
|
-
"@cabloy/module-info": "^1.0.23",
|
|
34
|
-
"@types/babel__core": "^7.20.5",
|
|
35
|
-
"@types/babel__traverse": "^7.20.5"
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@cabloy/module-info": "^1.3.0",
|
|
32
|
+
"@cabloy/word-utils": "^2.0.0"
|
|
36
33
|
},
|
|
37
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "19504afb5d86e9c8a3ab865099813a2cef2493bb"
|
|
38
35
|
}
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4B,KAAK,UAAU,EAAE,MAAM,aAAa,CAAC;AACxE,OAAO,KAAK,EAAY,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAKzD,MAAM,CAAC,OAAO;;EA8Bb"}
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":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