@tuya-sat/micro-dev-loader 1.0.3 → 1.0.7
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 -22
- package/dist/codeMaker/base.js +50 -55
- package/dist/codeMaker/index.d.ts +2 -2
- package/dist/codeMaker/index.js +10 -14
- package/dist/codeMaker/mobileCodeMaker.d.ts +12 -10
- package/dist/codeMaker/mobileCodeMaker.js +43 -45
- package/dist/codeMaker/pcCodeMaker.d.ts +13 -13
- package/dist/codeMaker/pcCodeMaker.js +60 -81
- package/dist/codePiece/permissionComponent.d.ts +2 -2
- package/dist/codePiece/permissionComponent.js +6 -7
- package/dist/index.d.ts +4 -4
- package/dist/index.js +26 -36
- package/dist/plugins/layoutMock/index.d.ts +4 -4
- package/dist/plugins/layoutMock/index.js +46 -47
- package/package.json +13 -6
- package/.swcrc +0 -11
- package/dist/utils/getFakeMenu.d.ts +0 -10
- package/dist/utils/getFakeMenu.js +0 -71
- package/dist/utils/getLang.d.ts +0 -1
- package/dist/utils/getLang.js +0 -22
- package/dist/utils/parseManifest.d.ts +0 -22
- package/dist/utils/parseManifest.js +0 -18
package/dist/codeMaker/base.d.ts
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import { Manifest } from "
|
|
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
|
-
}
|
|
1
|
+
import { Manifest } from "@tuya-sat/micro-utils";
|
|
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
|
+
}
|
package/dist/codeMaker/base.js
CHANGED
|
@@ -1,62 +1,57 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
function
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
getResultCode() {
|
|
38
|
-
return this.resultCode;
|
|
39
|
-
}
|
|
40
|
-
vueReRenderTemp() {
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var core = require('@babel/core');
|
|
6
|
+
var syntaxTs = require('@babel/plugin-syntax-typescript');
|
|
7
|
+
var permissionComponent = require('../codePiece/permissionComponent.js');
|
|
8
|
+
|
|
9
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
10
|
+
|
|
11
|
+
var syntaxTs__default = /*#__PURE__*/_interopDefaultLegacy(syntaxTs);
|
|
12
|
+
|
|
13
|
+
const REACT_TYPES = ["REACT_TS", "REACT_JS"];
|
|
14
|
+
class CodeMaker {
|
|
15
|
+
constructor({ sourceCode, microFramework }) {
|
|
16
|
+
this.permissionComponent = permissionComponent["default"];
|
|
17
|
+
this.sourceCode = sourceCode;
|
|
18
|
+
this.microFramework = microFramework;
|
|
19
|
+
}
|
|
20
|
+
parse(code) {
|
|
21
|
+
return core.parse(code, {
|
|
22
|
+
plugins: [
|
|
23
|
+
[
|
|
24
|
+
syntaxTs__default["default"],
|
|
25
|
+
{
|
|
26
|
+
isTSX: true,
|
|
27
|
+
allExtensions: true,
|
|
28
|
+
},
|
|
29
|
+
],
|
|
30
|
+
],
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
getResultCode() {
|
|
34
|
+
return this.resultCode;
|
|
35
|
+
}
|
|
36
|
+
vueReRenderTemp() {
|
|
41
37
|
return `
|
|
42
38
|
const reRender = () => {
|
|
43
|
-
app.unmount()
|
|
44
|
-
|
|
39
|
+
app.unmount();
|
|
40
|
+
message.destroy();
|
|
41
|
+
render({});
|
|
45
42
|
}
|
|
46
|
-
`;
|
|
47
|
-
}
|
|
48
|
-
reactReRenderTemp() {
|
|
43
|
+
`;
|
|
44
|
+
}
|
|
45
|
+
reactReRenderTemp() {
|
|
49
46
|
return `
|
|
50
47
|
const reRender = () => {
|
|
51
|
-
ReactDOM.unmountComponentAtNode(document.querySelector('#root'))
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
`;
|
|
55
|
-
}
|
|
56
|
-
constructor({ sourceCode , microFramework }){
|
|
57
|
-
this.permissionComponent = _permissionComponent.default;
|
|
58
|
-
this.sourceCode = sourceCode;
|
|
59
|
-
this.microFramework = microFramework;
|
|
48
|
+
ReactDOM.unmountComponentAtNode(document.querySelector('#root'));
|
|
49
|
+
message.destroy();
|
|
50
|
+
render({});
|
|
60
51
|
}
|
|
52
|
+
`;
|
|
53
|
+
}
|
|
61
54
|
}
|
|
62
|
-
|
|
55
|
+
|
|
56
|
+
exports.REACT_TYPES = REACT_TYPES;
|
|
57
|
+
exports["default"] = CodeMaker;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import MobileCodeMaker from "./mobileCodeMaker";
|
|
2
|
-
export declare const createCodeMaker: (isMobile: boolean) => typeof MobileCodeMaker;
|
|
1
|
+
import MobileCodeMaker from "./mobileCodeMaker";
|
|
2
|
+
export declare const createCodeMaker: (isMobile: boolean) => typeof MobileCodeMaker;
|
package/dist/codeMaker/index.js
CHANGED
|
@@ -1,16 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
return
|
|
10
|
-
default: obj
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
const createCodeMaker = (isMobile)=>{
|
|
14
|
-
return isMobile ? _mobileCodeMaker.default : _pcCodeMaker.default;
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var mobileCodeMaker = require('./mobileCodeMaker.js');
|
|
6
|
+
var pcCodeMaker = require('./pcCodeMaker.js');
|
|
7
|
+
|
|
8
|
+
const createCodeMaker = (isMobile) => {
|
|
9
|
+
return isMobile ? mobileCodeMaker["default"] : pcCodeMaker["default"];
|
|
15
10
|
};
|
|
11
|
+
|
|
16
12
|
exports.createCodeMaker = createCodeMaker;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { Manifest } from "
|
|
2
|
-
import CodeMaker, { CodeMakerProps, ChangeCodeProps } from "./base";
|
|
3
|
-
export default class MobileCodeMaker extends CodeMaker {
|
|
4
|
-
constructor(props: CodeMakerProps);
|
|
5
|
-
changeCode(props: ChangeCodeProps): void;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import { Manifest } from "@tuya-sat/micro-utils";
|
|
2
|
+
import CodeMaker, { CodeMakerProps, ChangeCodeProps } from "./base";
|
|
3
|
+
export default class MobileCodeMaker extends CodeMaker {
|
|
4
|
+
constructor(props: CodeMakerProps);
|
|
5
|
+
changeCode(props: ChangeCodeProps): void;
|
|
6
|
+
reactReRenderTemp(): string;
|
|
7
|
+
vueReRenderTemp(): string;
|
|
8
|
+
getAuthTemp(props: {
|
|
9
|
+
privileges: Manifest["privileges"];
|
|
10
|
+
authedCode: ChangeCodeProps["authedCode"];
|
|
11
|
+
}): string;
|
|
12
|
+
}
|
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
this.resultCode = `${this.getAuthTemp({
|
|
33
|
-
privileges,
|
|
34
|
-
authedCode
|
|
35
|
-
})};${this.sourceCode};${this.permissionComponent}`;
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var base = require('./base.js');
|
|
6
|
+
|
|
7
|
+
class MobileCodeMaker extends base["default"] {
|
|
8
|
+
constructor(props) {
|
|
9
|
+
super(props);
|
|
10
|
+
}
|
|
11
|
+
changeCode(props) {
|
|
12
|
+
const { manifest, authedCode } = props;
|
|
13
|
+
const { privileges } = manifest;
|
|
14
|
+
this.resultCode = `${this.getAuthTemp({
|
|
15
|
+
privileges,
|
|
16
|
+
authedCode,
|
|
17
|
+
})};${this.sourceCode};${this.permissionComponent}`;
|
|
18
|
+
}
|
|
19
|
+
reactReRenderTemp() {
|
|
20
|
+
return `
|
|
21
|
+
const reRender = () => {
|
|
22
|
+
const ReactDom = require('react-dom');
|
|
23
|
+
const rootElement = document.getElementById('root');
|
|
24
|
+
ReactDom.unmountComponentAtNode(rootElement);
|
|
25
|
+
render(<App />, rootElement);
|
|
26
|
+
}
|
|
27
|
+
`;
|
|
28
|
+
}
|
|
29
|
+
vueReRenderTemp() {
|
|
30
|
+
return `
|
|
31
|
+
const reRender = () => {
|
|
36
32
|
}
|
|
37
|
-
|
|
38
|
-
|
|
33
|
+
`;
|
|
34
|
+
}
|
|
35
|
+
getAuthTemp(props) {
|
|
36
|
+
const { privileges = [], authedCode = [] } = props;
|
|
39
37
|
const temp = `
|
|
40
38
|
{
|
|
41
39
|
//重刷函数
|
|
42
|
-
${
|
|
40
|
+
${base.REACT_TYPES.includes(this.microFramework)
|
|
41
|
+
? this.reactReRenderTemp()
|
|
42
|
+
: this.vueReRenderTemp()}
|
|
43
43
|
//权限点
|
|
44
44
|
window._SDF = {
|
|
45
45
|
permissions:{}
|
|
@@ -83,11 +83,9 @@ class MobileCodeMaker extends _base.default {
|
|
|
83
83
|
})
|
|
84
84
|
|
|
85
85
|
}
|
|
86
|
-
`;
|
|
87
|
-
return temp;
|
|
88
|
-
}
|
|
89
|
-
constructor(props){
|
|
90
|
-
super(props);
|
|
91
|
-
}
|
|
86
|
+
`;
|
|
87
|
+
return temp;
|
|
88
|
+
}
|
|
92
89
|
}
|
|
93
|
-
|
|
90
|
+
|
|
91
|
+
exports["default"] = MobileCodeMaker;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { ParseResult } from "@babel/core";
|
|
2
|
-
import { Manifest } from "
|
|
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
|
-
}
|
|
1
|
+
import { ParseResult } from "@babel/core";
|
|
2
|
+
import { Manifest } from "@tuya-sat/micro-utils";
|
|
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
|
+
}
|
|
@@ -1,75 +1,55 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
function
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
ExportNamedDeclaration (path) {
|
|
48
|
-
let isTarget = false;
|
|
49
|
-
try {
|
|
50
|
-
isTarget = path.node.declaration.kind === "let" && path.node.declaration.declarations[0].id.name === "microProps";
|
|
51
|
-
} catch (e) {}
|
|
52
|
-
if (!isTarget) {
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
[
|
|
56
|
-
authTemp,
|
|
57
|
-
menuTemp,
|
|
58
|
-
"microProps = {}"
|
|
59
|
-
].forEach((temp)=>{
|
|
60
|
-
path.insertAfter(_template.default.ast(temp));
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
this.resultCode = (0, _generator).default(this.ast).code + ";" + this.permissionComponent;
|
|
65
|
-
}
|
|
66
|
-
getMenuCode(manifest) {
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var core = require('@babel/core');
|
|
6
|
+
var template = require('@babel/template');
|
|
7
|
+
var generate = require('@babel/generator');
|
|
8
|
+
var microUtils = require('@tuya-sat/micro-utils');
|
|
9
|
+
var base = require('./base.js');
|
|
10
|
+
|
|
11
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
12
|
+
|
|
13
|
+
var template__default = /*#__PURE__*/_interopDefaultLegacy(template);
|
|
14
|
+
var generate__default = /*#__PURE__*/_interopDefaultLegacy(generate);
|
|
15
|
+
|
|
16
|
+
class PcCodeMaker extends base["default"] {
|
|
17
|
+
constructor(props) {
|
|
18
|
+
super(props);
|
|
19
|
+
this.ast = this.parse(this.sourceCode);
|
|
20
|
+
}
|
|
21
|
+
changeCode(props) {
|
|
22
|
+
const { manifest, authedCode } = props;
|
|
23
|
+
const { privileges } = manifest;
|
|
24
|
+
const authTemp = this.getAuthTemp({ authedCode, privileges });
|
|
25
|
+
const menuTemp = this.getMenuCode(manifest);
|
|
26
|
+
core.traverse(this.ast, {
|
|
27
|
+
ExportNamedDeclaration(path) {
|
|
28
|
+
let isTarget = false;
|
|
29
|
+
try {
|
|
30
|
+
isTarget =
|
|
31
|
+
path.node.declaration.kind === "let" &&
|
|
32
|
+
path.node.declaration.declarations[0].id.name ===
|
|
33
|
+
"microProps";
|
|
34
|
+
}
|
|
35
|
+
catch (_a) { }
|
|
36
|
+
if (!isTarget) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
[authTemp, menuTemp, "microProps = {}"].forEach((temp) => {
|
|
40
|
+
path.insertAfter(template__default["default"].ast(temp));
|
|
41
|
+
});
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
this.resultCode = generate__default["default"](this.ast).code + ";" + this.permissionComponent;
|
|
45
|
+
}
|
|
46
|
+
getMenuCode(manifest) {
|
|
67
47
|
const temp = `
|
|
68
48
|
{
|
|
69
49
|
microProps.getOwnMenu = ()=> {
|
|
70
50
|
const localLng = localStorage.getItem("i18nextLng");
|
|
71
51
|
let index = localLng === "zh-CN" ? 0 : 1
|
|
72
|
-
const ownMenu = ${JSON.stringify(
|
|
52
|
+
const ownMenu = ${JSON.stringify(microUtils.getFakeMenu(manifest))}
|
|
73
53
|
ownMenu.micro_app_name = ownMenu.micro_app_name[index]
|
|
74
54
|
ownMenu.entry_name = ownMenu.entry_name[index]
|
|
75
55
|
ownMenu.sub_entry_list = ownMenu.sub_entry_list.map(item=>({
|
|
@@ -80,11 +60,11 @@ class PcCodeMaker extends _base.default {
|
|
|
80
60
|
return ownMenu
|
|
81
61
|
}
|
|
82
62
|
}
|
|
83
|
-
`;
|
|
84
|
-
return temp;
|
|
85
|
-
}
|
|
86
|
-
getAuthTemp(props) {
|
|
87
|
-
const { privileges =[]
|
|
63
|
+
`;
|
|
64
|
+
return temp;
|
|
65
|
+
}
|
|
66
|
+
getAuthTemp(props) {
|
|
67
|
+
const { privileges = [], authedCode = [] } = props;
|
|
88
68
|
const temp = `
|
|
89
69
|
{
|
|
90
70
|
window._allCodesStatusMap = new Map()
|
|
@@ -103,7 +83,9 @@ class PcCodeMaker extends _base.default {
|
|
|
103
83
|
window._allCodesStatusMap = new Map(allCodesStatus)
|
|
104
84
|
}
|
|
105
85
|
|
|
106
|
-
${
|
|
86
|
+
${base.REACT_TYPES.includes(this.microFramework)
|
|
87
|
+
? this.reactReRenderTemp()
|
|
88
|
+
: this.vueReRenderTemp()}
|
|
107
89
|
const authedCodeInfo = {
|
|
108
90
|
authedCode:${JSON.stringify(authedCode)}
|
|
109
91
|
}
|
|
@@ -124,12 +106,9 @@ class PcCodeMaker extends _base.default {
|
|
|
124
106
|
})
|
|
125
107
|
|
|
126
108
|
}
|
|
127
|
-
`;
|
|
128
|
-
return temp;
|
|
129
|
-
}
|
|
130
|
-
constructor(props){
|
|
131
|
-
super(props);
|
|
132
|
-
this.ast = this.parse(this.sourceCode);
|
|
133
|
-
}
|
|
109
|
+
`;
|
|
110
|
+
return temp;
|
|
111
|
+
}
|
|
134
112
|
}
|
|
135
|
-
|
|
113
|
+
|
|
114
|
+
exports["default"] = PcCodeMaker;
|
|
@@ -1,2 +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;
|
|
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;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
exports.default = void 0;
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
6
5
|
const permissionComponent = `
|
|
7
6
|
(function ExternalRender() {
|
|
8
7
|
const div = document.createElement('div');
|
|
@@ -11,5 +10,5 @@ const permissionComponent = `
|
|
|
11
10
|
document.body.appendChild(div);
|
|
12
11
|
})();
|
|
13
12
|
`;
|
|
14
|
-
|
|
15
|
-
exports
|
|
13
|
+
|
|
14
|
+
exports["default"] = permissionComponent;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import LayoutMockPlugin from "./plugins/layoutMock";
|
|
2
|
-
declare const addjsLoader: (sourceCode: string) => string;
|
|
3
|
-
export default addjsLoader;
|
|
4
|
-
export { LayoutMockPlugin };
|
|
1
|
+
import LayoutMockPlugin from "./plugins/layoutMock";
|
|
2
|
+
declare const addjsLoader: (sourceCode: string) => string;
|
|
3
|
+
export default addjsLoader;
|
|
4
|
+
export { LayoutMockPlugin };
|
package/dist/index.js
CHANGED
|
@@ -1,37 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const manifest = (0, _parseManifest).default();
|
|
25
|
-
const isMobile = ((ref = manifest.supportedPlatform) === null || ref === void 0 ? void 0 : ref[0]) === "MOBILE";
|
|
26
|
-
const codeMaker = new ((0, _codeMaker).createCodeMaker(isMobile))({
|
|
27
|
-
sourceCode,
|
|
28
|
-
microFramework
|
|
29
|
-
});
|
|
30
|
-
codeMaker.changeCode({
|
|
31
|
-
authedCode,
|
|
32
|
-
manifest
|
|
33
|
-
});
|
|
34
|
-
return codeMaker.getResultCode();
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var loaderUtils = require('loader-utils');
|
|
6
|
+
var index$1 = require('./codeMaker/index.js');
|
|
7
|
+
var microUtils = require('@tuya-sat/micro-utils');
|
|
8
|
+
var index = require('./plugins/layoutMock/index.js');
|
|
9
|
+
|
|
10
|
+
const addjsLoader = function (sourceCode) {
|
|
11
|
+
var _a;
|
|
12
|
+
const { authedCode = [], microFramework } = loaderUtils.getOptions(this);
|
|
13
|
+
const manifest = microUtils.parseManifest();
|
|
14
|
+
const isMobile = ((_a = manifest.supportedPlatform) === null || _a === void 0 ? void 0 : _a[0]) === "MOBILE";
|
|
15
|
+
const codeMaker = new (index$1.createCodeMaker(isMobile))({
|
|
16
|
+
sourceCode,
|
|
17
|
+
microFramework,
|
|
18
|
+
});
|
|
19
|
+
codeMaker.changeCode({
|
|
20
|
+
authedCode,
|
|
21
|
+
manifest,
|
|
22
|
+
});
|
|
23
|
+
return codeMaker.getResultCode();
|
|
35
24
|
};
|
|
36
|
-
|
|
37
|
-
exports.
|
|
25
|
+
|
|
26
|
+
exports.LayoutMockPlugin = index["default"];
|
|
27
|
+
exports["default"] = addjsLoader;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export default class LayoutMockPlugin {
|
|
2
|
-
static useLayoutStatic(app: any): void;
|
|
3
|
-
apply(compiler: any): void;
|
|
4
|
-
}
|
|
1
|
+
export default class LayoutMockPlugin {
|
|
2
|
+
static useLayoutStatic(app: any): void;
|
|
3
|
+
apply(compiler: any): void;
|
|
4
|
+
}
|
|
@@ -1,48 +1,47 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var fse = require('fs-extra');
|
|
6
|
+
var path = require('path');
|
|
7
|
+
var ejs = require('ejs');
|
|
8
|
+
var cheerio = require('cheerio');
|
|
9
|
+
var HtmlWebpackPlugin = require('html-webpack-plugin');
|
|
10
|
+
var microUtils = require('@tuya-sat/micro-utils');
|
|
11
|
+
|
|
12
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
13
|
+
|
|
14
|
+
var fse__default = /*#__PURE__*/_interopDefaultLegacy(fse);
|
|
15
|
+
var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
|
|
16
|
+
var ejs__default = /*#__PURE__*/_interopDefaultLegacy(ejs);
|
|
17
|
+
var cheerio__default = /*#__PURE__*/_interopDefaultLegacy(cheerio);
|
|
18
|
+
var HtmlWebpackPlugin__default = /*#__PURE__*/_interopDefaultLegacy(HtmlWebpackPlugin);
|
|
19
|
+
|
|
20
|
+
const manifest = microUtils.parseManifest();
|
|
21
|
+
const layoutMockTpl = fse__default["default"].readFileSync(path__default["default"].resolve(__dirname, "./layout-static/index.html"), {
|
|
22
|
+
encoding: "utf-8",
|
|
23
|
+
});
|
|
24
|
+
class LayoutMockPlugin {
|
|
25
|
+
static useLayoutStatic(app) {
|
|
26
|
+
app.get("/layout-static/*", function (req, res) {
|
|
27
|
+
res.sendFile(path__default["default"].join(__dirname, req.path));
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
apply(compiler) {
|
|
31
|
+
compiler.hooks.compilation.tap("MyPlugin", (compilation) => {
|
|
32
|
+
HtmlWebpackPlugin__default["default"].getHooks(compilation).beforeEmit.tapAsync("LayoutMockPlugin", (data, cb) => {
|
|
33
|
+
const $ = cheerio__default["default"].load(data.html);
|
|
34
|
+
const { name, defaultMenuIcon } = manifest;
|
|
35
|
+
data.html = ejs__default["default"].render(layoutMockTpl, {
|
|
36
|
+
appName: microUtils.nameProcesser2(name)[0],
|
|
37
|
+
appIcon: defaultMenuIcon.url,
|
|
38
|
+
menu: microUtils.getFakeMenu(manifest),
|
|
39
|
+
appHtml: [$("head").html(), $("body").html()].join(""),
|
|
40
|
+
});
|
|
41
|
+
cb(null, data);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
}
|
|
18
45
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
encoding: "utf-8"
|
|
22
|
-
});
|
|
23
|
-
class LayoutMockPlugin {
|
|
24
|
-
static useLayoutStatic(app) {
|
|
25
|
-
app.get("/layout-static/*", function(req, res) {
|
|
26
|
-
res.sendFile(_path.default.join(__dirname, req.path));
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
apply(compiler) {
|
|
30
|
-
compiler.hooks.compilation.tap("MyPlugin", (compilation)=>{
|
|
31
|
-
_htmlWebpackPlugin.default.getHooks(compilation).beforeEmit.tapAsync("LayoutMockPlugin", (data, cb)=>{
|
|
32
|
-
const $ = _cheerio.default.load(data.html);
|
|
33
|
-
const { name , defaultMenuIcon } = manifest;
|
|
34
|
-
data.html = _ejs.default.render(layoutMockTpl, {
|
|
35
|
-
appName: (0, _getLang).nameProcesser2(name)[0],
|
|
36
|
-
appIcon: defaultMenuIcon.url,
|
|
37
|
-
menu: (0, _getFakeMenu).getFakeMenu(manifest),
|
|
38
|
-
appHtml: [
|
|
39
|
-
$("head").html(),
|
|
40
|
-
$("body").html()
|
|
41
|
-
].join("")
|
|
42
|
-
});
|
|
43
|
-
cb(null, data);
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
exports.default = LayoutMockPlugin;
|
|
46
|
+
|
|
47
|
+
exports["default"] = LayoutMockPlugin;
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tuya-sat/micro-dev-loader",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"dev": "
|
|
8
|
-
"build": "
|
|
7
|
+
"dev": "rollup -c -w",
|
|
8
|
+
"build": "rollup -c",
|
|
9
9
|
"prepublish": "yarn build",
|
|
10
10
|
"test": "jest --verbose ./__tests__"
|
|
11
11
|
},
|
|
@@ -14,16 +14,23 @@
|
|
|
14
14
|
"@babel/generator": "^7.15.4",
|
|
15
15
|
"@babel/plugin-syntax-typescript": "^7.14.5",
|
|
16
16
|
"@babel/template": "^7.15.4",
|
|
17
|
+
"@tuya-sat/micro-utils": "1.0.7",
|
|
17
18
|
"cheerio": "^1.0.0-rc.10",
|
|
18
19
|
"ejs": "^3.1.6",
|
|
19
20
|
"fs-extra": "^10.0.0",
|
|
20
|
-
"
|
|
21
|
+
"html-webpack-plugin": "^5.5.0",
|
|
22
|
+
"loader-utils": "^2.0.0",
|
|
23
|
+
"path": "^0.12.7"
|
|
21
24
|
},
|
|
22
25
|
"devDependencies": {
|
|
23
|
-
"@
|
|
24
|
-
"@
|
|
26
|
+
"@rollup/plugin-commonjs": "^21.0.1",
|
|
27
|
+
"@rollup/plugin-node-resolve": "^13.1.3",
|
|
25
28
|
"@types/jest": "^26.0.24",
|
|
26
29
|
"jest": "^27.0.6",
|
|
30
|
+
"rollup": "^2.67.2",
|
|
31
|
+
"rollup-plugin-copy": "^3.4.0",
|
|
32
|
+
"rollup-plugin-delete": "^2.0.0",
|
|
33
|
+
"rollup-plugin-typescript2": "^0.31.2",
|
|
27
34
|
"ts-jest": "^27.0.4",
|
|
28
35
|
"typescript": "^4.4.4"
|
|
29
36
|
},
|
package/.swcrc
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { Manifest } from "./parseManifest";
|
|
2
|
-
interface FakeMenu {
|
|
3
|
-
micro_app_name: string[];
|
|
4
|
-
entry_name: string[];
|
|
5
|
-
path: string;
|
|
6
|
-
icon?: string;
|
|
7
|
-
sub_entry_list: FakeMenu[];
|
|
8
|
-
}
|
|
9
|
-
export declare function getFakeMenu(manifest: Manifest): FakeMenu;
|
|
10
|
-
export {};
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
exports.getFakeMenu = getFakeMenu;
|
|
6
|
-
var _getLang = require("./getLang");
|
|
7
|
-
function _defineProperty(obj, key, value) {
|
|
8
|
-
if (key in obj) {
|
|
9
|
-
Object.defineProperty(obj, key, {
|
|
10
|
-
value: value,
|
|
11
|
-
enumerable: true,
|
|
12
|
-
configurable: true,
|
|
13
|
-
writable: true
|
|
14
|
-
});
|
|
15
|
-
} else {
|
|
16
|
-
obj[key] = value;
|
|
17
|
-
}
|
|
18
|
-
return obj;
|
|
19
|
-
}
|
|
20
|
-
function _objectSpread(target) {
|
|
21
|
-
for(var i = 1; i < arguments.length; i++){
|
|
22
|
-
var source = arguments[i] != null ? arguments[i] : {};
|
|
23
|
-
var ownKeys = Object.keys(source);
|
|
24
|
-
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
25
|
-
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
26
|
-
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
27
|
-
}));
|
|
28
|
-
}
|
|
29
|
-
ownKeys.forEach(function(key) {
|
|
30
|
-
_defineProperty(target, key, source[key]);
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
return target;
|
|
34
|
-
}
|
|
35
|
-
function getFakeMenu(manifest) {
|
|
36
|
-
const { name: appName , entries =[] } = manifest;
|
|
37
|
-
const appNameLang = (0, _getLang).nameProcesser2(appName);
|
|
38
|
-
const fakeMenuDefault = {
|
|
39
|
-
micro_app_name: appNameLang,
|
|
40
|
-
sub_entry_list: []
|
|
41
|
-
};
|
|
42
|
-
let fakeMenu = null;
|
|
43
|
-
switch(entries.length){
|
|
44
|
-
case 0:
|
|
45
|
-
fakeMenu = _objectSpread({
|
|
46
|
-
entry_name: appNameLang,
|
|
47
|
-
path: ""
|
|
48
|
-
}, fakeMenuDefault);
|
|
49
|
-
break;
|
|
50
|
-
case 1:
|
|
51
|
-
const { name: name1 , path: path1 } = entries[0];
|
|
52
|
-
fakeMenu = _objectSpread({
|
|
53
|
-
entry_name: (0, _getLang).nameProcesser2(name1),
|
|
54
|
-
path: path1
|
|
55
|
-
}, fakeMenuDefault);
|
|
56
|
-
break;
|
|
57
|
-
default:
|
|
58
|
-
fakeMenu = _objectSpread({
|
|
59
|
-
entry_name: appNameLang,
|
|
60
|
-
path: ""
|
|
61
|
-
}, fakeMenuDefault, {
|
|
62
|
-
sub_entry_list: entries.map(({ name , path })=>_objectSpread({
|
|
63
|
-
entry_name: (0, _getLang).nameProcesser2(name),
|
|
64
|
-
path
|
|
65
|
-
}, fakeMenuDefault)
|
|
66
|
-
)
|
|
67
|
-
});
|
|
68
|
-
break;
|
|
69
|
-
}
|
|
70
|
-
return fakeMenu;
|
|
71
|
-
}
|
package/dist/utils/getLang.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const nameProcesser2: (name: any) => any[];
|
package/dist/utils/getLang.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
exports.nameProcesser2 = void 0;
|
|
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
|
-
}
|
|
13
|
-
const zhLang = _fsExtra.default.readJSONSync(_path.default.resolve(process.cwd(), "_locales/zh-CN.json"));
|
|
14
|
-
const enLang = _fsExtra.default.readJSONSync(_path.default.resolve(process.cwd(), "_locales/en.json"));
|
|
15
|
-
const nameProcesser2 = (name)=>{
|
|
16
|
-
const [_, key] = name.split(".");
|
|
17
|
-
return [
|
|
18
|
-
zhLang[key] || name,
|
|
19
|
-
enLang[key] || name
|
|
20
|
-
];
|
|
21
|
-
};
|
|
22
|
-
exports.nameProcesser2 = nameProcesser2;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
export interface Privilege {
|
|
2
|
-
name: string;
|
|
3
|
-
code: string;
|
|
4
|
-
}
|
|
5
|
-
export interface Manifest {
|
|
6
|
-
name: string;
|
|
7
|
-
defaultMenuIcon?: {
|
|
8
|
-
type: "URL";
|
|
9
|
-
url: string;
|
|
10
|
-
};
|
|
11
|
-
entries: {
|
|
12
|
-
type: string;
|
|
13
|
-
code: string;
|
|
14
|
-
appIcon?: Object;
|
|
15
|
-
name: string;
|
|
16
|
-
path: string;
|
|
17
|
-
ratio?: number;
|
|
18
|
-
}[];
|
|
19
|
-
supportedPlatform: ["MOBILE" | "DESKTOP"];
|
|
20
|
-
privileges: Privilege[];
|
|
21
|
-
}
|
|
22
|
-
export default function parseManifest(): Manifest;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
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
|
-
}
|
|
13
|
-
function parseManifest() {
|
|
14
|
-
const MANIFEST_FILE = "manifest.json";
|
|
15
|
-
const cwd = process.cwd();
|
|
16
|
-
const manifest = _fsExtra.default.readJSONSync(_path.default.resolve(cwd, MANIFEST_FILE), "utf-8");
|
|
17
|
-
return manifest;
|
|
18
|
-
}
|