@tuya-sat/micro-dev-loader 1.0.2 → 1.0.3
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/codeMaker/base.d.ts +22 -0
- package/dist/codeMaker/base.js +62 -0
- package/dist/codeMaker/index.d.ts +2 -0
- package/dist/codeMaker/index.js +16 -0
- package/dist/codeMaker/mobileCodeMaker.d.ts +10 -0
- package/dist/codeMaker/mobileCodeMaker.js +93 -0
- package/dist/codeMaker/pcCodeMaker.d.ts +13 -0
- package/dist/{transform.js → codeMaker/pcCodeMaker.js} +30 -49
- package/dist/codePiece/permissionComponent.d.ts +2 -0
- package/dist/{manifestDom.js → codePiece/permissionComponent.js} +2 -2
- package/dist/index.js +6 -5
- package/dist/plugins/layoutMock/layout-static/index.html +0 -1
- package/dist/utils/parseManifest.d.ts +1 -0
- package/package.json +1 -1
- package/dist/manifestDom.d.ts +0 -2
- package/dist/transform.d.ts +0 -27
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Manifest } from "../utils/parseManifest";
|
|
2
|
+
export declare type MICRO_FRAMEWORKS_TYPE = "REACT_TS" | "REACT_JS" | "VUE_TS" | "VUE_JS";
|
|
3
|
+
export declare const REACT_TYPES: string[];
|
|
4
|
+
export interface ChangeCodeProps {
|
|
5
|
+
authedCode: string[];
|
|
6
|
+
manifest: Manifest;
|
|
7
|
+
}
|
|
8
|
+
export interface CodeMakerProps {
|
|
9
|
+
sourceCode: string;
|
|
10
|
+
microFramework: MICRO_FRAMEWORKS_TYPE;
|
|
11
|
+
}
|
|
12
|
+
export default class CodeMaker {
|
|
13
|
+
microFramework: MICRO_FRAMEWORKS_TYPE;
|
|
14
|
+
sourceCode: string;
|
|
15
|
+
permissionComponent: string;
|
|
16
|
+
resultCode: string;
|
|
17
|
+
constructor({ sourceCode, microFramework }: CodeMakerProps);
|
|
18
|
+
parse(code: string): import("@babel/core").ParseResult;
|
|
19
|
+
getResultCode(): string;
|
|
20
|
+
vueReRenderTemp(): string;
|
|
21
|
+
reactReRenderTemp(): string;
|
|
22
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
exports.default = exports.REACT_TYPES = void 0;
|
|
6
|
+
var _core = require("@babel/core");
|
|
7
|
+
var _pluginSyntaxTypescript = _interopRequireDefault(require("@babel/plugin-syntax-typescript"));
|
|
8
|
+
var _permissionComponent = _interopRequireDefault(require("../codePiece/permissionComponent"));
|
|
9
|
+
function _interopRequireDefault(obj) {
|
|
10
|
+
return obj && obj.__esModule ? obj : {
|
|
11
|
+
default: obj
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
const VUE_TYPES = [
|
|
15
|
+
"VUE_TS",
|
|
16
|
+
"VUE_JS"
|
|
17
|
+
];
|
|
18
|
+
const REACT_TYPES = [
|
|
19
|
+
"REACT_TS",
|
|
20
|
+
"REACT_JS"
|
|
21
|
+
];
|
|
22
|
+
exports.REACT_TYPES = REACT_TYPES;
|
|
23
|
+
class CodeMaker {
|
|
24
|
+
parse(code) {
|
|
25
|
+
return (0, _core).parse(code, {
|
|
26
|
+
plugins: [
|
|
27
|
+
[
|
|
28
|
+
_pluginSyntaxTypescript.default,
|
|
29
|
+
{
|
|
30
|
+
isTSX: true,
|
|
31
|
+
allExtensions: true
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
]
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
getResultCode() {
|
|
38
|
+
return this.resultCode;
|
|
39
|
+
}
|
|
40
|
+
vueReRenderTemp() {
|
|
41
|
+
return `
|
|
42
|
+
const reRender = () => {
|
|
43
|
+
app.unmount()
|
|
44
|
+
render({})
|
|
45
|
+
}
|
|
46
|
+
`;
|
|
47
|
+
}
|
|
48
|
+
reactReRenderTemp() {
|
|
49
|
+
return `
|
|
50
|
+
const reRender = () => {
|
|
51
|
+
ReactDOM.unmountComponentAtNode(document.querySelector('#root'))
|
|
52
|
+
render({})
|
|
53
|
+
}
|
|
54
|
+
`;
|
|
55
|
+
}
|
|
56
|
+
constructor({ sourceCode , microFramework }){
|
|
57
|
+
this.permissionComponent = _permissionComponent.default;
|
|
58
|
+
this.sourceCode = sourceCode;
|
|
59
|
+
this.microFramework = microFramework;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.default = CodeMaker;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
exports.createCodeMaker = void 0;
|
|
6
|
+
var _mobileCodeMaker = _interopRequireDefault(require("./mobileCodeMaker"));
|
|
7
|
+
var _pcCodeMaker = _interopRequireDefault(require("./pcCodeMaker"));
|
|
8
|
+
function _interopRequireDefault(obj) {
|
|
9
|
+
return obj && obj.__esModule ? obj : {
|
|
10
|
+
default: obj
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
const createCodeMaker = (isMobile)=>{
|
|
14
|
+
return isMobile ? _mobileCodeMaker.default : _pcCodeMaker.default;
|
|
15
|
+
};
|
|
16
|
+
exports.createCodeMaker = createCodeMaker;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Manifest } from "../utils/parseManifest";
|
|
2
|
+
import CodeMaker, { CodeMakerProps, ChangeCodeProps } from "./base";
|
|
3
|
+
export default class MobileCodeMaker extends CodeMaker {
|
|
4
|
+
constructor(props: CodeMakerProps);
|
|
5
|
+
changeCode(props: ChangeCodeProps): void;
|
|
6
|
+
getAuthTemp(props: {
|
|
7
|
+
privileges: Manifest["privileges"];
|
|
8
|
+
authedCode: ChangeCodeProps["authedCode"];
|
|
9
|
+
}): string;
|
|
10
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
exports.default = void 0;
|
|
6
|
+
var _base = _interopRequireWildcard(require("./base"));
|
|
7
|
+
function _interopRequireWildcard(obj) {
|
|
8
|
+
if (obj && obj.__esModule) {
|
|
9
|
+
return obj;
|
|
10
|
+
} else {
|
|
11
|
+
var newObj = {};
|
|
12
|
+
if (obj != null) {
|
|
13
|
+
for(var key in obj){
|
|
14
|
+
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
15
|
+
var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {};
|
|
16
|
+
if (desc.get || desc.set) {
|
|
17
|
+
Object.defineProperty(newObj, key, desc);
|
|
18
|
+
} else {
|
|
19
|
+
newObj[key] = obj[key];
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
newObj.default = obj;
|
|
25
|
+
return newObj;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
class MobileCodeMaker extends _base.default {
|
|
29
|
+
changeCode(props) {
|
|
30
|
+
const { manifest , authedCode } = props;
|
|
31
|
+
const { privileges } = manifest;
|
|
32
|
+
this.resultCode = `${this.getAuthTemp({
|
|
33
|
+
privileges,
|
|
34
|
+
authedCode
|
|
35
|
+
})};${this.sourceCode};${this.permissionComponent}`;
|
|
36
|
+
}
|
|
37
|
+
getAuthTemp(props) {
|
|
38
|
+
const { privileges =[] , authedCode =[] } = props;
|
|
39
|
+
const temp = `
|
|
40
|
+
{
|
|
41
|
+
//重刷函数
|
|
42
|
+
${_base.REACT_TYPES.includes(this.microFramework) ? this.reactReRenderTemp() : this.vueReRenderTemp()}
|
|
43
|
+
//权限点
|
|
44
|
+
window._SDF = {
|
|
45
|
+
permissions:{}
|
|
46
|
+
}
|
|
47
|
+
//用于组件渲染
|
|
48
|
+
window._allCodesStatusMap = new Map()
|
|
49
|
+
//修改权限点的方法
|
|
50
|
+
const changeAuthedMap = (authedCode) => {
|
|
51
|
+
const privileges = ${JSON.stringify(privileges)}
|
|
52
|
+
const allCodesStatus = privileges?.map(
|
|
53
|
+
({ name, code }) => [
|
|
54
|
+
code,
|
|
55
|
+
authedCode.includes(code),
|
|
56
|
+
]
|
|
57
|
+
);
|
|
58
|
+
window._allCodesStatusMap = new Map(allCodesStatus)
|
|
59
|
+
window._SDF.permissions = allCodesStatus.reduce((pre, item) => {
|
|
60
|
+
const [key, value] = item;
|
|
61
|
+
pre[key] = value;
|
|
62
|
+
return pre;
|
|
63
|
+
}, {});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const authedCodeInfo = {
|
|
67
|
+
authedCode:${JSON.stringify(authedCode)}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
changeAuthedMap(authedCodeInfo.authedCode)
|
|
71
|
+
window._authedCodeInfoProxy = new Proxy(authedCodeInfo,{
|
|
72
|
+
get(target,prop){
|
|
73
|
+
return target[prop]
|
|
74
|
+
},
|
|
75
|
+
set(target,prop,value){
|
|
76
|
+
target[prop] = value
|
|
77
|
+
if(prop === 'authedCode') {
|
|
78
|
+
changeAuthedMap(value)
|
|
79
|
+
reRender()
|
|
80
|
+
}
|
|
81
|
+
return true
|
|
82
|
+
}
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
}
|
|
86
|
+
`;
|
|
87
|
+
return temp;
|
|
88
|
+
}
|
|
89
|
+
constructor(props){
|
|
90
|
+
super(props);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
exports.default = MobileCodeMaker;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ParseResult } from "@babel/core";
|
|
2
|
+
import { Manifest } from "../utils/parseManifest";
|
|
3
|
+
import CodeMaker, { CodeMakerProps, ChangeCodeProps } from "./base";
|
|
4
|
+
export default class PcCodeMaker extends CodeMaker {
|
|
5
|
+
ast: ParseResult;
|
|
6
|
+
constructor(props: CodeMakerProps);
|
|
7
|
+
changeCode(props: ChangeCodeProps): void;
|
|
8
|
+
getMenuCode(manifest: Manifest): string;
|
|
9
|
+
getAuthTemp(props: {
|
|
10
|
+
privileges: Manifest["privileges"];
|
|
11
|
+
authedCode: ChangeCodeProps["authedCode"];
|
|
12
|
+
}): string;
|
|
13
|
+
}
|
|
@@ -6,36 +6,36 @@ exports.default = void 0;
|
|
|
6
6
|
var _core = require("@babel/core");
|
|
7
7
|
var _template = _interopRequireDefault(require("@babel/template"));
|
|
8
8
|
var _generator = _interopRequireDefault(require("@babel/generator"));
|
|
9
|
-
var
|
|
10
|
-
var
|
|
9
|
+
var _getFakeMenu = require("../utils/getFakeMenu");
|
|
10
|
+
var _base = _interopRequireWildcard(require("./base"));
|
|
11
11
|
function _interopRequireDefault(obj) {
|
|
12
12
|
return obj && obj.__esModule ? obj : {
|
|
13
13
|
default: obj
|
|
14
14
|
};
|
|
15
15
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
]
|
|
36
|
-
});
|
|
16
|
+
function _interopRequireWildcard(obj) {
|
|
17
|
+
if (obj && obj.__esModule) {
|
|
18
|
+
return obj;
|
|
19
|
+
} else {
|
|
20
|
+
var newObj = {};
|
|
21
|
+
if (obj != null) {
|
|
22
|
+
for(var key in obj){
|
|
23
|
+
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
24
|
+
var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {};
|
|
25
|
+
if (desc.get || desc.set) {
|
|
26
|
+
Object.defineProperty(newObj, key, desc);
|
|
27
|
+
} else {
|
|
28
|
+
newObj[key] = obj[key];
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
newObj.default = obj;
|
|
34
|
+
return newObj;
|
|
37
35
|
}
|
|
38
|
-
|
|
36
|
+
}
|
|
37
|
+
class PcCodeMaker extends _base.default {
|
|
38
|
+
changeCode(props) {
|
|
39
39
|
const { manifest , authedCode } = props;
|
|
40
40
|
const { privileges } = manifest;
|
|
41
41
|
const authTemp = this.getAuthTemp({
|
|
@@ -61,26 +61,7 @@ class CodeMaker {
|
|
|
61
61
|
});
|
|
62
62
|
}
|
|
63
63
|
});
|
|
64
|
-
|
|
65
|
-
gtAst() {
|
|
66
|
-
const { code } = (0, _generator).default(this.ast);
|
|
67
|
-
return code;
|
|
68
|
-
}
|
|
69
|
-
vueReRenderTemp() {
|
|
70
|
-
return `
|
|
71
|
-
const reRender = () => {
|
|
72
|
-
app.unmount()
|
|
73
|
-
render({})
|
|
74
|
-
}
|
|
75
|
-
`;
|
|
76
|
-
}
|
|
77
|
-
reactReRenderTemp() {
|
|
78
|
-
return `
|
|
79
|
-
const reRender = () => {
|
|
80
|
-
ReactDOM.unmountComponentAtNode(document.querySelector('#root'))
|
|
81
|
-
render({})
|
|
82
|
-
}
|
|
83
|
-
`;
|
|
64
|
+
this.resultCode = (0, _generator).default(this.ast).code + ";" + this.permissionComponent;
|
|
84
65
|
}
|
|
85
66
|
getMenuCode(manifest) {
|
|
86
67
|
const temp = `
|
|
@@ -122,7 +103,7 @@ class CodeMaker {
|
|
|
122
103
|
window._allCodesStatusMap = new Map(allCodesStatus)
|
|
123
104
|
}
|
|
124
105
|
|
|
125
|
-
${REACT_TYPES.includes(this.microFramework) ? this.reactReRenderTemp() : this.vueReRenderTemp()}
|
|
106
|
+
${_base.REACT_TYPES.includes(this.microFramework) ? this.reactReRenderTemp() : this.vueReRenderTemp()}
|
|
126
107
|
const authedCodeInfo = {
|
|
127
108
|
authedCode:${JSON.stringify(authedCode)}
|
|
128
109
|
}
|
|
@@ -146,9 +127,9 @@ class CodeMaker {
|
|
|
146
127
|
`;
|
|
147
128
|
return temp;
|
|
148
129
|
}
|
|
149
|
-
constructor(
|
|
150
|
-
|
|
151
|
-
this.
|
|
130
|
+
constructor(props){
|
|
131
|
+
super(props);
|
|
132
|
+
this.ast = this.parse(this.sourceCode);
|
|
152
133
|
}
|
|
153
134
|
}
|
|
154
|
-
exports.default =
|
|
135
|
+
exports.default = PcCodeMaker;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
declare const permissionComponent = "\n(function ExternalRender() {\n const div = document.createElement('div');\n const { insertDom } = require(\"@tuya-sat/micro-dev-component\");\n insertDom(div)\n document.body.appendChild(div);\n})();\n";
|
|
2
|
+
export default permissionComponent;
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
5
|
exports.default = void 0;
|
|
6
|
-
const
|
|
6
|
+
const permissionComponent = `
|
|
7
7
|
(function ExternalRender() {
|
|
8
8
|
const div = document.createElement('div');
|
|
9
9
|
const { insertDom } = require("@tuya-sat/micro-dev-component");
|
|
@@ -11,5 +11,5 @@ const manifestDom = `
|
|
|
11
11
|
document.body.appendChild(div);
|
|
12
12
|
})();
|
|
13
13
|
`;
|
|
14
|
-
var _default =
|
|
14
|
+
var _default = permissionComponent;
|
|
15
15
|
exports.default = _default;
|
package/dist/index.js
CHANGED
|
@@ -10,9 +10,8 @@ Object.defineProperty(exports, "LayoutMockPlugin", {
|
|
|
10
10
|
});
|
|
11
11
|
exports.default = void 0;
|
|
12
12
|
var _loaderUtils = require("loader-utils");
|
|
13
|
-
var
|
|
13
|
+
var _codeMaker = require("./codeMaker");
|
|
14
14
|
var _parseManifest = _interopRequireDefault(require("./utils/parseManifest"));
|
|
15
|
-
var _manifestDom = _interopRequireDefault(require("./manifestDom"));
|
|
16
15
|
var _layoutMock = _interopRequireDefault(require("./plugins/layoutMock"));
|
|
17
16
|
function _interopRequireDefault(obj) {
|
|
18
17
|
return obj && obj.__esModule ? obj : {
|
|
@@ -20,17 +19,19 @@ function _interopRequireDefault(obj) {
|
|
|
20
19
|
};
|
|
21
20
|
}
|
|
22
21
|
const addjsLoader = function(sourceCode) {
|
|
22
|
+
var ref;
|
|
23
23
|
const { authedCode =[] , microFramework } = (0, _loaderUtils).getOptions(this);
|
|
24
24
|
const manifest = (0, _parseManifest).default();
|
|
25
|
-
const
|
|
25
|
+
const isMobile = ((ref = manifest.supportedPlatform) === null || ref === void 0 ? void 0 : ref[0]) === "MOBILE";
|
|
26
|
+
const codeMaker = new ((0, _codeMaker).createCodeMaker(isMobile))({
|
|
26
27
|
sourceCode,
|
|
27
28
|
microFramework
|
|
28
29
|
});
|
|
29
|
-
codeMaker.
|
|
30
|
+
codeMaker.changeCode({
|
|
30
31
|
authedCode,
|
|
31
32
|
manifest
|
|
32
33
|
});
|
|
33
|
-
return codeMaker.
|
|
34
|
+
return codeMaker.getResultCode();
|
|
34
35
|
};
|
|
35
36
|
var _default = addjsLoader;
|
|
36
37
|
exports.default = _default;
|
package/package.json
CHANGED
package/dist/manifestDom.d.ts
DELETED
package/dist/transform.d.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { ParseResult } from "@babel/core";
|
|
2
|
-
import { Manifest } from "./utils/parseManifest";
|
|
3
|
-
export declare type MICRO_FRAMEWORKS_TYPE = "REACT_TS" | "REACT_JS" | "VUE_TS" | "VUE_JS";
|
|
4
|
-
interface ChangeAstProps {
|
|
5
|
-
authedCode: string[];
|
|
6
|
-
manifest: Manifest;
|
|
7
|
-
}
|
|
8
|
-
interface CodeMakerProps {
|
|
9
|
-
sourceCode: string;
|
|
10
|
-
microFramework: MICRO_FRAMEWORKS_TYPE;
|
|
11
|
-
}
|
|
12
|
-
export default class CodeMaker {
|
|
13
|
-
private ast;
|
|
14
|
-
private microFramework;
|
|
15
|
-
constructor({ sourceCode, microFramework }: CodeMakerProps);
|
|
16
|
-
parse(code: string): ParseResult;
|
|
17
|
-
changeAst(props: ChangeAstProps): void;
|
|
18
|
-
gtAst(): string;
|
|
19
|
-
vueReRenderTemp(): string;
|
|
20
|
-
reactReRenderTemp(): string;
|
|
21
|
-
getMenuCode(manifest: Manifest): string;
|
|
22
|
-
getAuthTemp(props: {
|
|
23
|
-
privileges: Manifest["privileges"];
|
|
24
|
-
authedCode: ChangeAstProps["authedCode"];
|
|
25
|
-
}): string;
|
|
26
|
-
}
|
|
27
|
-
export {};
|