@tuya-sat/micro-dev-loader 0.0.1-beta.3 → 0.0.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/.swcrc +11 -0
- package/dist/index.js +32 -19
- package/dist/manifestDom.js +7 -10
- package/dist/plugins/layoutMock/index.js +165 -38
- package/dist/plugins/layoutMock/layout-static/index.html +174 -180
- package/dist/transform.js +111 -111
- package/dist/utils/parseManifest.js +14 -10
- package/package.json +15 -5
- package/dist/index.d.ts +0 -4
- package/dist/manifestDom.d.ts +0 -2
- package/dist/plugins/layoutMock/index.d.ts +0 -4
- package/dist/plugins/layoutMock/layout-static/2.c7981cdc.chunk.css +0 -10
- package/dist/plugins/layoutMock/layout-static/main.efdba179.chunk.css +0 -2
- package/dist/transform.d.ts +0 -23
- package/dist/utils/parseManifest.d.ts +0 -22
package/dist/transform.js
CHANGED
|
@@ -1,117 +1,117 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
class
|
|
13
|
-
constructor({ sourceCode, microFramework }) {
|
|
14
|
-
this.ast = this.parse(sourceCode);
|
|
15
|
-
this.microFramework = microFramework;
|
|
16
|
-
}
|
|
17
|
-
parse(code) {
|
|
18
|
-
return (0, core_1.parse)(code, {
|
|
19
|
-
plugins: [
|
|
20
|
-
[
|
|
21
|
-
plugin_syntax_typescript_1.default,
|
|
22
|
-
{
|
|
23
|
-
isTSX: true,
|
|
24
|
-
allExtensions: true,
|
|
25
|
-
},
|
|
26
|
-
],
|
|
27
|
-
],
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
changeAst(props) {
|
|
31
|
-
const temp = this.getTemp(props);
|
|
32
|
-
(0, core_1.traverse)(this.ast, {
|
|
33
|
-
ExportNamedDeclaration(path) {
|
|
34
|
-
let isTarget = false;
|
|
35
|
-
try {
|
|
36
|
-
isTarget =
|
|
37
|
-
path.node.declaration.kind === "let" &&
|
|
38
|
-
path.node.declaration.declarations[0].id.name ===
|
|
39
|
-
"hasPermission";
|
|
40
|
-
}
|
|
41
|
-
catch (_a) { }
|
|
42
|
-
if (!isTarget) {
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
let tempNode = template_1.default.ast(temp);
|
|
46
|
-
path.insertAfter(tempNode);
|
|
47
|
-
},
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
gtAst() {
|
|
51
|
-
const { code } = (0, generator_1.default)(this.ast);
|
|
52
|
-
return code;
|
|
53
|
-
}
|
|
54
|
-
vueReRenderTemp() {
|
|
55
|
-
return `
|
|
56
|
-
const reRender = () => {
|
|
57
|
-
app.unmount()
|
|
58
|
-
render({})
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
exports.default = void 0;
|
|
6
|
+
var _core = require("@babel/core");
|
|
7
|
+
var _template = _interopRequireDefault(require("@babel/template"));
|
|
8
|
+
var _generator = _interopRequireDefault(require("@babel/generator"));
|
|
9
|
+
var _pluginSyntaxTypescript = _interopRequireDefault(require("@babel/plugin-syntax-typescript"));
|
|
10
|
+
function _classCallCheck(instance, Constructor) {
|
|
11
|
+
if (!(instance instanceof Constructor)) {
|
|
12
|
+
throw new TypeError("Cannot call a class as a function");
|
|
59
13
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
14
|
+
}
|
|
15
|
+
function _defineProperties(target, props) {
|
|
16
|
+
for(var i = 0; i < props.length; i++){
|
|
17
|
+
var descriptor = props[i];
|
|
18
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
19
|
+
descriptor.configurable = true;
|
|
20
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
21
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
67
22
|
}
|
|
68
|
-
|
|
23
|
+
}
|
|
24
|
+
function _createClass(Constructor, protoProps, staticProps) {
|
|
25
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
26
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
27
|
+
return Constructor;
|
|
28
|
+
}
|
|
29
|
+
function _interopRequireDefault(obj) {
|
|
30
|
+
return obj && obj.__esModule ? obj : {
|
|
31
|
+
default: obj
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
var VUE_TYPES = [
|
|
35
|
+
"VUE_TS",
|
|
36
|
+
"VUE_JS"
|
|
37
|
+
];
|
|
38
|
+
var REACT_TYPES = [
|
|
39
|
+
"REACT_TS",
|
|
40
|
+
"REACT_JS"
|
|
41
|
+
];
|
|
42
|
+
var CodeMaker = /*#__PURE__*/ function() {
|
|
43
|
+
"use strict";
|
|
44
|
+
function CodeMaker(param) {
|
|
45
|
+
var sourceCode = param.sourceCode, microFramework = param.microFramework;
|
|
46
|
+
_classCallCheck(this, CodeMaker);
|
|
47
|
+
this.ast = this.parse(sourceCode);
|
|
48
|
+
this.microFramework = microFramework;
|
|
69
49
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
]
|
|
86
|
-
);
|
|
87
|
-
window._allCodesStatusMap = new Map(allCodesStatus)
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
${REACT_TYPES.includes(this.microFramework)
|
|
91
|
-
? this.reactReRenderTemp()
|
|
92
|
-
: this.vueReRenderTemp()}
|
|
93
|
-
const authedCodeInfo = {
|
|
94
|
-
authedCode:${JSON.stringify(authedCode)}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
changeAuthedMap(authedCodeInfo.authedCode)
|
|
98
|
-
window._authedCodeInfoProxy = new Proxy(authedCodeInfo,{
|
|
99
|
-
get(target,prop){
|
|
100
|
-
return target[prop]
|
|
101
|
-
},
|
|
102
|
-
set(target,prop,value){
|
|
103
|
-
if(prop === 'authedCode') {
|
|
104
|
-
changeAuthedMap(value)
|
|
105
|
-
reRender()
|
|
50
|
+
_createClass(CodeMaker, [
|
|
51
|
+
{
|
|
52
|
+
key: "parse",
|
|
53
|
+
value: function parse(code) {
|
|
54
|
+
return (0, _core).parse(code, {
|
|
55
|
+
plugins: [
|
|
56
|
+
[
|
|
57
|
+
_pluginSyntaxTypescript.default,
|
|
58
|
+
{
|
|
59
|
+
isTSX: true,
|
|
60
|
+
allExtensions: true
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
]
|
|
64
|
+
});
|
|
106
65
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
key: "changeAst",
|
|
69
|
+
value: function changeAst(props) {
|
|
70
|
+
var temp = this.getTemp(props);
|
|
71
|
+
(0, _core).traverse(this.ast, {
|
|
72
|
+
ExportNamedDeclaration: function ExportNamedDeclaration(path) {
|
|
73
|
+
var isTarget = false;
|
|
74
|
+
try {
|
|
75
|
+
isTarget = path.node.declaration.kind === "let" && path.node.declaration.declarations[0].id.name === "hasPermission";
|
|
76
|
+
} catch (e) {
|
|
77
|
+
}
|
|
78
|
+
if (!isTarget) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
var tempNode = _template.default.ast(temp);
|
|
82
|
+
path.insertAfter(tempNode);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
key: "gtAst",
|
|
89
|
+
value: function gtAst() {
|
|
90
|
+
var code = (0, _generator).default(this.ast).code;
|
|
91
|
+
return code;
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
key: "vueReRenderTemp",
|
|
96
|
+
value: function vueReRenderTemp() {
|
|
97
|
+
return "\n const reRender = () => {\n app.unmount()\n render({})\n }\n ";
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
key: "reactReRenderTemp",
|
|
102
|
+
value: function reactReRenderTemp() {
|
|
103
|
+
return "\n const reRender = () => {\n ReactDOM.unmountComponentAtNode(document.querySelector('#root'))\n render({})\n }\n ";
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
key: "getTemp",
|
|
108
|
+
value: function getTemp(props) {
|
|
109
|
+
var privileges = props.privileges, authedCode = props.authedCode;
|
|
110
|
+
var temp = "\n {\n window._allCodesStatusMap = new Map()\n window._authedCodeInfoProxy = {}\n hasPermission = (code) => {\n return window._allCodesStatusMap.get(code)\n };\n const changeAuthedMap = (authedCode) => {\n const privileges = ".concat(JSON.stringify(privileges), "\n const allCodesStatus = privileges?.map(\n ({ name, code }) => [\n code,\n authedCode.includes(code),\n ]\n );\n window._allCodesStatusMap = new Map(allCodesStatus)\n }\n \n ").concat(REACT_TYPES.includes(this.microFramework) ? this.reactReRenderTemp() : this.vueReRenderTemp(), "\n const authedCodeInfo = {\n authedCode:").concat(JSON.stringify(authedCode), "\n }\n \n changeAuthedMap(authedCodeInfo.authedCode)\n window._authedCodeInfoProxy = new Proxy(authedCodeInfo,{\n get(target,prop){\n return target[prop]\n },\n set(target,prop,value){\n if(prop === 'authedCode') {\n changeAuthedMap(value)\n reRender()\n }\n target[prop] = value\n return true\n }\n })\n\n }\n ");
|
|
111
|
+
return temp;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
]);
|
|
115
|
+
return CodeMaker;
|
|
116
|
+
}();
|
|
117
117
|
exports.default = CodeMaker;
|
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
exports.default = parseManifest;
|
|
6
|
+
var _fsExtra = _interopRequireDefault(require("fs-extra"));
|
|
7
|
+
var _path = _interopRequireDefault(require("path"));
|
|
8
|
+
function _interopRequireDefault(obj) {
|
|
9
|
+
return obj && obj.__esModule ? obj : {
|
|
10
|
+
default: obj
|
|
11
|
+
};
|
|
12
|
+
}
|
|
8
13
|
function parseManifest() {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
14
|
+
var MANIFEST_FILE = "manifest.json";
|
|
15
|
+
var cwd = process.cwd();
|
|
16
|
+
var manifest = _fsExtra.default.readJSONSync(_path.default.resolve(cwd, MANIFEST_FILE), "utf-8");
|
|
12
17
|
return manifest;
|
|
13
18
|
}
|
|
14
|
-
exports.default = parseManifest;
|
package/package.json
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tuya-sat/micro-dev-loader",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"dev": "
|
|
8
|
-
"build": "
|
|
9
|
-
"copyOtherFiles": "cp -R src/plugins/layoutMock/layout-static dist/plugins/layoutMock/layout-static",
|
|
7
|
+
"dev": "swc src -D -w -d dist",
|
|
8
|
+
"build": "swc src -D -d dist",
|
|
10
9
|
"prepublish": "yarn build",
|
|
11
10
|
"test": "jest --verbose ./__tests__"
|
|
12
11
|
},
|
|
@@ -21,9 +20,20 @@
|
|
|
21
20
|
"loader-utils": "^2.0.0"
|
|
22
21
|
},
|
|
23
22
|
"devDependencies": {
|
|
23
|
+
"@swc/cli": "^0.1.52",
|
|
24
|
+
"@swc/core": "^1.2.117",
|
|
24
25
|
"@types/jest": "^26.0.24",
|
|
25
26
|
"jest": "^27.0.6",
|
|
26
27
|
"ts-jest": "^27.0.4",
|
|
27
28
|
"typescript": "^4.4.4"
|
|
28
|
-
}
|
|
29
|
+
},
|
|
30
|
+
"keywords": [
|
|
31
|
+
"saturn-project",
|
|
32
|
+
"micro-frontend",
|
|
33
|
+
"no-code",
|
|
34
|
+
"IoT",
|
|
35
|
+
"saas",
|
|
36
|
+
"cloud",
|
|
37
|
+
"tuya"
|
|
38
|
+
]
|
|
29
39
|
}
|
package/dist/index.d.ts
DELETED
package/dist/manifestDom.d.ts
DELETED