@tuya-sat/micro-dev-loader 0.0.1 → 0.0.5
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.js
CHANGED
|
@@ -19,16 +19,16 @@ function _interopRequireDefault(obj) {
|
|
|
19
19
|
default: obj
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
sourceCode
|
|
27
|
-
microFramework
|
|
22
|
+
const addjsLoader = function(sourceCode) {
|
|
23
|
+
const { authedCode =[] , microFramework } = (0, _loaderUtils).getOptions(this);
|
|
24
|
+
const { privileges } = (0, _parseManifest).default();
|
|
25
|
+
const codeMaker = new _transform.default({
|
|
26
|
+
sourceCode,
|
|
27
|
+
microFramework
|
|
28
28
|
});
|
|
29
29
|
codeMaker.changeAst({
|
|
30
|
-
privileges
|
|
31
|
-
authedCode
|
|
30
|
+
privileges,
|
|
31
|
+
authedCode
|
|
32
32
|
});
|
|
33
33
|
return codeMaker.gtAst() + _manifestDom.default;
|
|
34
34
|
};
|
package/dist/manifestDom.js
CHANGED
|
@@ -3,6 +3,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
5
|
exports.default = void 0;
|
|
6
|
-
|
|
6
|
+
const manifestDom = `
|
|
7
|
+
(function ExternalRender() {
|
|
8
|
+
const div = document.createElement('div');
|
|
9
|
+
const { insertDom } = require("@tuya-sat/micro-dev-component");
|
|
10
|
+
insertDom(div)
|
|
11
|
+
document.body.appendChild(div);
|
|
12
|
+
})();
|
|
13
|
+
`;
|
|
7
14
|
var _default = manifestDom;
|
|
8
15
|
exports.default = _default;
|
|
@@ -9,28 +9,6 @@ var _ejs = _interopRequireDefault(require("ejs"));
|
|
|
9
9
|
var _cheerio = _interopRequireDefault(require("cheerio"));
|
|
10
10
|
var _htmlWebpackPlugin = _interopRequireDefault(require("html-webpack-plugin"));
|
|
11
11
|
var _parseManifest = _interopRequireDefault(require("../../utils/parseManifest"));
|
|
12
|
-
function _arrayWithHoles(arr) {
|
|
13
|
-
if (Array.isArray(arr)) return arr;
|
|
14
|
-
}
|
|
15
|
-
function _classCallCheck(instance, Constructor) {
|
|
16
|
-
if (!(instance instanceof Constructor)) {
|
|
17
|
-
throw new TypeError("Cannot call a class as a function");
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
function _defineProperties(target, props) {
|
|
21
|
-
for(var i = 0; i < props.length; i++){
|
|
22
|
-
var descriptor = props[i];
|
|
23
|
-
descriptor.enumerable = descriptor.enumerable || false;
|
|
24
|
-
descriptor.configurable = true;
|
|
25
|
-
if ("value" in descriptor) descriptor.writable = true;
|
|
26
|
-
Object.defineProperty(target, descriptor.key, descriptor);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
function _createClass(Constructor, protoProps, staticProps) {
|
|
30
|
-
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
31
|
-
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
32
|
-
return Constructor;
|
|
33
|
-
}
|
|
34
12
|
function _defineProperty(obj, key, value) {
|
|
35
13
|
if (key in obj) {
|
|
36
14
|
Object.defineProperty(obj, key, {
|
|
@@ -49,35 +27,9 @@ function _interopRequireDefault(obj) {
|
|
|
49
27
|
default: obj
|
|
50
28
|
};
|
|
51
29
|
}
|
|
52
|
-
function _iterableToArrayLimit(arr, i) {
|
|
53
|
-
var _arr = [];
|
|
54
|
-
var _n = true;
|
|
55
|
-
var _d = false;
|
|
56
|
-
var _e = undefined;
|
|
57
|
-
try {
|
|
58
|
-
for(var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true){
|
|
59
|
-
_arr.push(_s.value);
|
|
60
|
-
if (i && _arr.length === i) break;
|
|
61
|
-
}
|
|
62
|
-
} catch (err) {
|
|
63
|
-
_d = true;
|
|
64
|
-
_e = err;
|
|
65
|
-
} finally{
|
|
66
|
-
try {
|
|
67
|
-
if (!_n && _i["return"] != null) _i["return"]();
|
|
68
|
-
} finally{
|
|
69
|
-
if (_d) throw _e;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
return _arr;
|
|
73
|
-
}
|
|
74
|
-
function _nonIterableRest() {
|
|
75
|
-
throw new TypeError("Invalid attempt to destructure non-iterable instance");
|
|
76
|
-
}
|
|
77
30
|
function _objectSpread(target) {
|
|
78
31
|
for(var i = 1; i < arguments.length; i++){
|
|
79
|
-
var source = arguments[i] != null ? arguments[i] : {
|
|
80
|
-
};
|
|
32
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
81
33
|
var ownKeys = Object.keys(source);
|
|
82
34
|
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
83
35
|
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
@@ -90,61 +42,51 @@ function _objectSpread(target) {
|
|
|
90
42
|
}
|
|
91
43
|
return target;
|
|
92
44
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
var manifest = (0, _parseManifest).default();
|
|
97
|
-
var lang = _fsExtra.default.readJSONSync(_path.default.resolve(process.cwd(), "_locales/zh-CN.json"));
|
|
98
|
-
var layoutMockTpl = _fsExtra.default.readFileSync(_path.default.resolve(__dirname, "./layout-static/index.html"), {
|
|
45
|
+
const manifest = (0, _parseManifest).default();
|
|
46
|
+
const lang = _fsExtra.default.readJSONSync(_path.default.resolve(process.cwd(), "_locales/zh-CN.json"));
|
|
47
|
+
const layoutMockTpl = _fsExtra.default.readFileSync(_path.default.resolve(__dirname, "./layout-static/index.html"), {
|
|
99
48
|
encoding: "utf-8"
|
|
100
49
|
});
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
50
|
+
class LayoutMockPlugin {
|
|
51
|
+
static useLayoutStatic(app) {
|
|
52
|
+
app.get("/layout-static/*", function(req, res) {
|
|
53
|
+
res.sendFile(_path.default.join(__dirname, req.path));
|
|
54
|
+
});
|
|
105
55
|
}
|
|
106
|
-
|
|
107
|
-
{
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
], [
|
|
139
|
-
{
|
|
140
|
-
key: "useLayoutStatic",
|
|
141
|
-
value: function useLayoutStatic(app) {
|
|
142
|
-
app.get("/layout-static/*", function(req, res) {
|
|
143
|
-
res.sendFile(_path.default.join(__dirname, req.path));
|
|
56
|
+
apply(compiler) {
|
|
57
|
+
compiler.hooks.compilation.tap("MyPlugin", (compilation)=>{
|
|
58
|
+
_htmlWebpackPlugin.default.getHooks(compilation).beforeEmit.tapAsync("LayoutMockPlugin", (data, cb)=>{
|
|
59
|
+
const $ = _cheerio.default.load(data.html);
|
|
60
|
+
const { name: name1 , defaultMenuIcon , entries } = manifest;
|
|
61
|
+
const nameProcesser = (name)=>{
|
|
62
|
+
const [_, key] = name.split(".");
|
|
63
|
+
return lang[key] || name;
|
|
64
|
+
};
|
|
65
|
+
data.html = _ejs.default.render(layoutMockTpl, {
|
|
66
|
+
appName: nameProcesser(name1),
|
|
67
|
+
appIcon: defaultMenuIcon.url,
|
|
68
|
+
menus: (()=>{
|
|
69
|
+
const processer = (item)=>{
|
|
70
|
+
return _objectSpread({}, item, {
|
|
71
|
+
langName: nameProcesser(item.name)
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
const entries$ = entries.length ? entries : [
|
|
75
|
+
{
|
|
76
|
+
name: name1,
|
|
77
|
+
path: "/"
|
|
78
|
+
},
|
|
79
|
+
];
|
|
80
|
+
return entries$.map(processer);
|
|
81
|
+
})(),
|
|
82
|
+
appHtml: [
|
|
83
|
+
$("head").html(),
|
|
84
|
+
$("body").html()
|
|
85
|
+
].join("")
|
|
144
86
|
});
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
}
|
|
87
|
+
cb(null, data);
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
150
92
|
exports.default = LayoutMockPlugin;
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en" style="margin: 0; padding: 0">
|
|
3
|
+
<head>
|
|
4
|
+
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
|
|
5
|
+
<meta charset="utf-8" />
|
|
6
|
+
<link rel="icon" href="favicon.ico" />
|
|
7
|
+
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
|
8
|
+
<meta name="theme-color" content="#000000" />
|
|
9
|
+
<meta name="description" content="Tuya General Management Portal" />
|
|
10
|
+
<title><%= appName %></title>
|
|
11
|
+
<style>
|
|
12
|
+
.c-debugger-container {
|
|
13
|
+
width: 100vw;
|
|
14
|
+
height: 100vh;
|
|
15
|
+
display: flex;
|
|
16
|
+
flex-direction: column;
|
|
17
|
+
}
|
|
18
|
+
.c-debugger-header {
|
|
19
|
+
flex: 0 0 auto;
|
|
20
|
+
display: flex;
|
|
21
|
+
align-items: center;
|
|
22
|
+
justify-content: space-between;
|
|
23
|
+
height: 55px;
|
|
24
|
+
padding: 0 16px;
|
|
25
|
+
border-bottom: 1px solid #eee;
|
|
26
|
+
color: rgba(0, 0, 0, 0.85);
|
|
27
|
+
}
|
|
28
|
+
.c-debugger-logo {
|
|
29
|
+
position: relative;
|
|
30
|
+
overflow: hidden;
|
|
31
|
+
display: flex;
|
|
32
|
+
align-items: center;
|
|
33
|
+
}
|
|
34
|
+
.c-debugger-title {
|
|
35
|
+
color: #000;
|
|
36
|
+
font-size: 14px;
|
|
37
|
+
font-weight: 700;
|
|
38
|
+
height: 32px;
|
|
39
|
+
line-height: 32px;
|
|
40
|
+
margin: 0 0 0 12px;
|
|
41
|
+
}
|
|
42
|
+
.c-debugger-main {
|
|
43
|
+
display: flex;
|
|
44
|
+
flex: 1 1 auto;
|
|
45
|
+
}
|
|
46
|
+
.c-debugger-side {
|
|
47
|
+
flex: 0 0 auto;
|
|
48
|
+
width: 208px;
|
|
49
|
+
height: 100%;
|
|
50
|
+
border-right: 1px solid #f0f2f5;
|
|
51
|
+
}
|
|
52
|
+
.c-debugger-content {
|
|
53
|
+
flex: 1 1 auto;
|
|
54
|
+
height: 100%;
|
|
55
|
+
background-color: #f0f2f5;
|
|
56
|
+
}
|
|
57
|
+
#root {
|
|
58
|
+
width: 100%;
|
|
59
|
+
height: 100%;
|
|
60
|
+
}
|
|
61
|
+
.c-debugger-lang-trigger {
|
|
62
|
+
position: relative;
|
|
63
|
+
display: flex;
|
|
64
|
+
align-items: center;
|
|
65
|
+
white-space: nowrap;
|
|
66
|
+
cursor: pointer;
|
|
67
|
+
font-size: 14px;
|
|
68
|
+
font-weight: normal;
|
|
69
|
+
height: 100%;
|
|
70
|
+
}
|
|
71
|
+
.c-debugger-lang-trigger:hover .c-debugger-lang-list {
|
|
72
|
+
display: block;
|
|
73
|
+
line-height: 1.5;
|
|
74
|
+
}
|
|
75
|
+
.c-debugger-lang-trigger .c-debugger-lang-list {
|
|
76
|
+
position: absolute;
|
|
77
|
+
top: 42px;
|
|
78
|
+
right: -5px;
|
|
79
|
+
display: none;
|
|
80
|
+
background: #ffffff;
|
|
81
|
+
border-radius: 2px;
|
|
82
|
+
outline: none;
|
|
83
|
+
box-shadow: 0 3px 6px -4px rgb(0 0 0 / 12%),
|
|
84
|
+
0 6px 16px 0 rgb(0 0 0 / 8%), 0 9px 28px 8px rgb(0 0 0 / 5%);
|
|
85
|
+
z-index: 100;
|
|
86
|
+
}
|
|
87
|
+
.c-debugger-lang-trigger .c-debugger-lang-list span {
|
|
88
|
+
display: block;
|
|
89
|
+
padding: 5px 12px;
|
|
90
|
+
}
|
|
91
|
+
.c-debugger-lang-trigger .c-debugger-lang-list span:hover {
|
|
92
|
+
background-color: #f5f5f5;
|
|
93
|
+
}
|
|
94
|
+
.c-debugger-menu {
|
|
95
|
+
display: flex;
|
|
96
|
+
justify-content: flex-start;
|
|
97
|
+
align-items: center;
|
|
98
|
+
height: 40px;
|
|
99
|
+
padding: 0 0 0 17px;
|
|
100
|
+
margin: 4px 0 8px;
|
|
101
|
+
cursor: pointer;
|
|
102
|
+
font-size: 14px;
|
|
103
|
+
color: rgba(0, 0, 0, 0.85);
|
|
104
|
+
}
|
|
105
|
+
.c-debugger-menu-name {
|
|
106
|
+
margin-left: 10px;
|
|
107
|
+
}
|
|
108
|
+
.c-debugger-menu:hover {
|
|
109
|
+
color: #1890ff;
|
|
110
|
+
}
|
|
111
|
+
</style>
|
|
112
|
+
</head>
|
|
113
|
+
<body style="margin: 0; padding: 0">
|
|
114
|
+
<div class="c-debugger-container">
|
|
115
|
+
<div class="c-debugger-header">
|
|
116
|
+
<div class="c-debugger-logo">
|
|
117
|
+
<img
|
|
118
|
+
src="https://promotion-static.tuyacn.com/static/242969466160533504.png"
|
|
119
|
+
alt=""
|
|
120
|
+
style="height: 28px"
|
|
121
|
+
/>
|
|
122
|
+
<div class="c-debugger-title"><%= appName %></div>
|
|
123
|
+
</div>
|
|
124
|
+
|
|
125
|
+
<div class="c-debugger-lang-trigger">
|
|
126
|
+
<span id="c-debugger-lang-name"></span>
|
|
127
|
+
<div class="c-debugger-lang-list">
|
|
128
|
+
<span onclick="changeLng('en-US')">English</span>
|
|
129
|
+
<span onclick="changeLng('zh-CN')">简体中文</span>
|
|
130
|
+
</div>
|
|
131
|
+
</div>
|
|
132
|
+
</div>
|
|
133
|
+
<div class="c-debugger-main">
|
|
134
|
+
<div class="c-debugger-side">
|
|
135
|
+
<% menus.forEach(function(menu){ %>
|
|
136
|
+
<div class="c-debugger-menu" onclick="toPage('<%= menu.path %>')">
|
|
137
|
+
<svg
|
|
138
|
+
viewBox="0 0 1024 1024"
|
|
139
|
+
version="1.1"
|
|
140
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
141
|
+
p-id="2323"
|
|
142
|
+
width="14"
|
|
143
|
+
height="14"
|
|
144
|
+
>
|
|
145
|
+
<path
|
|
146
|
+
d="M192.037 287.953h640.124c17.673 0 32-14.327 32-32s-14.327-32-32-32H192.037c-17.673 0-32 14.327-32 32s14.327 32 32 32zM192.028 543.17h638.608c17.673 0 32-14.327 32-32s-14.327-32-32-32H192.028c-17.673 0-32 14.327-32 32s14.327 32 32 32zM832.161 735.802H192.037c-17.673 0-32 14.327-32 32s14.327 32 32 32h640.124c17.673 0 32-14.327 32-32s-14.327-32-32-32z"
|
|
147
|
+
fill=""
|
|
148
|
+
p-id="2324"
|
|
149
|
+
></path>
|
|
150
|
+
</svg>
|
|
151
|
+
<div class="c-debugger-menu-name"><%= menu.langName %></div>
|
|
152
|
+
</div>
|
|
153
|
+
<% }); %>
|
|
154
|
+
</div>
|
|
155
|
+
<div class="c-debugger-content"><%- appHtml %></div>
|
|
156
|
+
</div>
|
|
157
|
+
</div>
|
|
158
|
+
<script>
|
|
159
|
+
(() => {
|
|
160
|
+
const lngMap = {
|
|
161
|
+
"en-US": "English",
|
|
162
|
+
"zh-CN": "简体中文",
|
|
163
|
+
};
|
|
164
|
+
const localLng = localStorage.getItem("i18nextLng");
|
|
165
|
+
const lng = lngMap[localLng] ? localLng : "zh-CN";
|
|
166
|
+
console.log(lng);
|
|
167
|
+
document.querySelector("#c-debugger-lang-name").textContent =
|
|
168
|
+
lngMap[lng];
|
|
169
|
+
})();
|
|
170
|
+
|
|
171
|
+
function toPage(path) {
|
|
172
|
+
window.location.href = new URL(path, window.location.origin);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function changeLng(lng, name) {
|
|
176
|
+
localStorage.setItem("i18nextLng", lng);
|
|
177
|
+
location.reload();
|
|
178
|
+
}
|
|
179
|
+
</script>
|
|
180
|
+
</body>
|
|
181
|
+
</html>
|
package/dist/transform.js
CHANGED
|
@@ -7,111 +7,116 @@ var _core = require("@babel/core");
|
|
|
7
7
|
var _template = _interopRequireDefault(require("@babel/template"));
|
|
8
8
|
var _generator = _interopRequireDefault(require("@babel/generator"));
|
|
9
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");
|
|
13
|
-
}
|
|
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);
|
|
22
|
-
}
|
|
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
10
|
function _interopRequireDefault(obj) {
|
|
30
11
|
return obj && obj.__esModule ? obj : {
|
|
31
12
|
default: obj
|
|
32
13
|
};
|
|
33
14
|
}
|
|
34
|
-
|
|
15
|
+
const VUE_TYPES = [
|
|
35
16
|
"VUE_TS",
|
|
36
17
|
"VUE_JS"
|
|
37
18
|
];
|
|
38
|
-
|
|
19
|
+
const REACT_TYPES = [
|
|
39
20
|
"REACT_TS",
|
|
40
21
|
"REACT_JS"
|
|
41
22
|
];
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
+
});
|
|
49
36
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
]
|
|
64
|
-
});
|
|
65
|
-
}
|
|
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;
|
|
37
|
+
changeAst(props) {
|
|
38
|
+
const temp = this.getTemp(props);
|
|
39
|
+
(0, _core).traverse(this.ast, {
|
|
40
|
+
ExportNamedDeclaration (path) {
|
|
41
|
+
let isTarget = false;
|
|
42
|
+
try {
|
|
43
|
+
isTarget = path.node.declaration.kind === "let" && path.node.declaration.declarations[0].id.name === "hasPermission";
|
|
44
|
+
} catch (e) {}
|
|
45
|
+
if (!isTarget) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
let tempNode = _template.default.ast(temp);
|
|
49
|
+
path.insertAfter(tempNode);
|
|
112
50
|
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
gtAst() {
|
|
54
|
+
const { code } = (0, _generator).default(this.ast);
|
|
55
|
+
return code;
|
|
56
|
+
}
|
|
57
|
+
vueReRenderTemp() {
|
|
58
|
+
return `
|
|
59
|
+
const reRender = () => {
|
|
60
|
+
app.unmount()
|
|
61
|
+
render({})
|
|
62
|
+
}
|
|
63
|
+
`;
|
|
64
|
+
}
|
|
65
|
+
reactReRenderTemp() {
|
|
66
|
+
return `
|
|
67
|
+
const reRender = () => {
|
|
68
|
+
ReactDOM.unmountComponentAtNode(document.querySelector('#root'))
|
|
69
|
+
render({})
|
|
70
|
+
}
|
|
71
|
+
`;
|
|
72
|
+
}
|
|
73
|
+
getTemp(props) {
|
|
74
|
+
const { privileges , authedCode } = props;
|
|
75
|
+
const temp = `
|
|
76
|
+
{
|
|
77
|
+
window._allCodesStatusMap = new Map()
|
|
78
|
+
window._authedCodeInfoProxy = {}
|
|
79
|
+
hasPermission = (code) => {
|
|
80
|
+
return window._allCodesStatusMap.get(code)
|
|
81
|
+
};
|
|
82
|
+
const changeAuthedMap = (authedCode) => {
|
|
83
|
+
const privileges = ${JSON.stringify(privileges)}
|
|
84
|
+
const allCodesStatus = privileges?.map(
|
|
85
|
+
({ name, code }) => [
|
|
86
|
+
code,
|
|
87
|
+
authedCode.includes(code),
|
|
88
|
+
]
|
|
89
|
+
);
|
|
90
|
+
window._allCodesStatusMap = new Map(allCodesStatus)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
${REACT_TYPES.includes(this.microFramework) ? this.reactReRenderTemp() : this.vueReRenderTemp()}
|
|
94
|
+
const authedCodeInfo = {
|
|
95
|
+
authedCode:${JSON.stringify(authedCode)}
|
|
113
96
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
97
|
+
|
|
98
|
+
changeAuthedMap(authedCodeInfo.authedCode)
|
|
99
|
+
window._authedCodeInfoProxy = new Proxy(authedCodeInfo,{
|
|
100
|
+
get(target,prop){
|
|
101
|
+
return target[prop]
|
|
102
|
+
},
|
|
103
|
+
set(target,prop,value){
|
|
104
|
+
if(prop === 'authedCode') {
|
|
105
|
+
changeAuthedMap(value)
|
|
106
|
+
reRender()
|
|
107
|
+
}
|
|
108
|
+
target[prop] = value
|
|
109
|
+
return true
|
|
110
|
+
}
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
}
|
|
114
|
+
`;
|
|
115
|
+
return temp;
|
|
116
|
+
}
|
|
117
|
+
constructor({ sourceCode , microFramework }){
|
|
118
|
+
this.ast = this.parse(sourceCode);
|
|
119
|
+
this.microFramework = microFramework;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
117
122
|
exports.default = CodeMaker;
|
|
@@ -11,8 +11,8 @@ function _interopRequireDefault(obj) {
|
|
|
11
11
|
};
|
|
12
12
|
}
|
|
13
13
|
function parseManifest() {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
17
|
return manifest;
|
|
18
18
|
}
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tuya-sat/micro-dev-loader",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"dev": "swc src -D -w -d dist",
|
|
8
|
-
"build": "swc src -d dist",
|
|
8
|
+
"build": "swc src -D -d dist",
|
|
9
9
|
"prepublish": "yarn build",
|
|
10
10
|
"test": "jest --verbose ./__tests__"
|
|
11
11
|
},
|