@tuya-sat/micro-script 3.0.10 → 3.0.12
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/config/webpack.common.js +13 -8
- package/dist/module/mainServer.js +66 -1
- package/dist/socket/_locales/index.d.ts +18 -0
- package/dist/socket/_locales/index.js +57 -0
- package/dist/socket/index.d.ts +2 -0
- package/dist/socket/index.js +58 -0
- package/dist/socket/lang/index.d.ts +13 -0
- package/dist/socket/lang/index.js +88 -0
- package/dist/socket/mc/index.d.ts +13 -0
- package/dist/socket/mc/index.js +90 -0
- package/dist/socket/mf/index.d.ts +15 -0
- package/dist/socket/mf/index.js +52 -0
- package/dist/socket/mock/index.d.ts +15 -0
- package/dist/socket/mock/index.js +52 -0
- package/dist/socket/pkg/index.d.ts +15 -0
- package/dist/socket/pkg/index.js +52 -0
- package/dist/socket/sdf/index.d.ts +11 -0
- package/dist/socket/sdf/index.js +15 -0
- package/package.json +9 -4
|
@@ -145,7 +145,7 @@ function getCommonConfig({ isDev, isBuild, }) {
|
|
|
145
145
|
test: /([\\/]node_modules[\\/][\s\S]+(\.less|\.css)$)|([\\/]src[\\/]styles[\\/]global\.less)/,
|
|
146
146
|
name: 'light',
|
|
147
147
|
chunks: 'all',
|
|
148
|
-
priority:
|
|
148
|
+
priority: 4,
|
|
149
149
|
},
|
|
150
150
|
}
|
|
151
151
|
: {})), { vendor: {
|
|
@@ -174,11 +174,14 @@ function getCommonConfig({ isDev, isBuild, }) {
|
|
|
174
174
|
minimizer: ['...', new css_minimizer_webpack_plugin_1.default()],
|
|
175
175
|
},
|
|
176
176
|
plugins: [
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
177
|
+
...[
|
|
178
|
+
(htmlplugins === null || htmlplugins === void 0 ? void 0 : htmlplugins.length) > 0
|
|
179
|
+
? htmlplugins
|
|
180
|
+
: new html_webpack_plugin_1.default({
|
|
181
|
+
inject: true,
|
|
182
|
+
template: paths_1.default.spaHtml,
|
|
183
|
+
}),
|
|
184
|
+
],
|
|
182
185
|
new copy_webpack_plugin_1.default({
|
|
183
186
|
patterns: [
|
|
184
187
|
{
|
|
@@ -218,10 +221,12 @@ function getCommonConfig({ isDev, isBuild, }) {
|
|
|
218
221
|
}));
|
|
219
222
|
});
|
|
220
223
|
console.log('multiAppsWebpackConfig', multiAppsWebpackConfig);
|
|
221
|
-
|
|
224
|
+
const appsResult = (0, webpack_merge_1.merge)(getWebpackConfig(multiAppsWebpackConfig.plugins), {
|
|
222
225
|
entry: multiAppsWebpackConfig.entry,
|
|
223
226
|
});
|
|
227
|
+
return appsResult;
|
|
224
228
|
}
|
|
225
|
-
|
|
229
|
+
const result = getWebpackConfig([]);
|
|
230
|
+
return result;
|
|
226
231
|
}
|
|
227
232
|
exports.default = getCommonConfig;
|
|
@@ -13,7 +13,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
const express_1 = __importDefault(require("express"));
|
|
16
|
+
const http = require('http');
|
|
16
17
|
const ora_1 = __importDefault(require("ora"));
|
|
18
|
+
const cors_1 = __importDefault(require("cors"));
|
|
17
19
|
const promiser_1 = require("../utils/promiser");
|
|
18
20
|
const mock_1 = __importDefault(require("../module/mock"));
|
|
19
21
|
const paths_1 = __importDefault(require("../config/paths"));
|
|
@@ -21,11 +23,74 @@ const fakeSaasInfo_1 = __importDefault(require("./main/fakeSaasInfo"));
|
|
|
21
23
|
const staticMain_1 = __importDefault(require("./main/staticMain"));
|
|
22
24
|
const proxy_1 = __importDefault(require("../module/proxy"));
|
|
23
25
|
const validate_1 = require("../utils/validate");
|
|
26
|
+
const socket_io_1 = require("socket.io");
|
|
27
|
+
const socket_1 = require("../socket");
|
|
24
28
|
function runMain({ port, microPort, }) {
|
|
25
29
|
return __awaiter(this, void 0, void 0, function* () {
|
|
26
30
|
const { debuggerConfig, mainServer } = require(paths_1.default.microConfig);
|
|
27
31
|
(0, validate_1.validateDebuggerConfig)(debuggerConfig);
|
|
28
32
|
const app = (0, express_1.default)();
|
|
33
|
+
app.use((0, cors_1.default)());
|
|
34
|
+
const server = http.createServer(app);
|
|
35
|
+
app.use('/ui', (req, res) => {
|
|
36
|
+
res.type('.html');
|
|
37
|
+
res.send(`<!DOCTYPE html>
|
|
38
|
+
<html lang="en">
|
|
39
|
+
|
|
40
|
+
<head>
|
|
41
|
+
<meta charset="utf-8" />
|
|
42
|
+
<link rel="icon" href="<%= webpackConfig.output.publicPath %>favicon.ico" />
|
|
43
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
44
|
+
<script src="https://cdn.socket.io/4.5.4/socket.io.min.js"></script>
|
|
45
|
+
<script>
|
|
46
|
+
var socket = io('http://localhost:9001');
|
|
47
|
+
socket.emit('R_LOCALES', "微应用");
|
|
48
|
+
socket.on('R_LOCALES', (data) => {
|
|
49
|
+
console.log("Lang: " + data);
|
|
50
|
+
})
|
|
51
|
+
socket.emit('R_LANG', "微应用");
|
|
52
|
+
socket.on('R_LANG', (data) => {
|
|
53
|
+
console.log("Lang: " + data);
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
socket.emit('R_MICRO_CONFIG', "微应用");
|
|
57
|
+
socket.on('R_MICRO_CONFIG', (data) => {
|
|
58
|
+
console.log("Lang: " + data);
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
socket.emit('R_MANIFEST', "微应用");
|
|
62
|
+
socket.on('R_MANIFEST', (data) => {
|
|
63
|
+
console.log("Lang: " + data);
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
socket.emit('R_MOCK', "微应用");
|
|
68
|
+
socket.on('R_MOCK', (data) => {
|
|
69
|
+
console.log("Lang: " + data);
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
socket.emit('R_PKG', "微应用");
|
|
73
|
+
socket.on('R_PKG', (data) => {
|
|
74
|
+
console.log("Lang: " + data);
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
</script>
|
|
78
|
+
<title></title>
|
|
79
|
+
</head>
|
|
80
|
+
|
|
81
|
+
<body>
|
|
82
|
+
<noscript>You need to enable JavaScript to run this app.</noscript>
|
|
83
|
+
<div id="root"></div>
|
|
84
|
+
</body>
|
|
85
|
+
|
|
86
|
+
</html>`);
|
|
87
|
+
});
|
|
88
|
+
const io = new socket_io_1.Server(server, {
|
|
89
|
+
cors: {
|
|
90
|
+
origin: 'http://localhost:4000',
|
|
91
|
+
},
|
|
92
|
+
});
|
|
93
|
+
(0, socket_1.bootStrap)(io);
|
|
29
94
|
mainServer && mainServer.before && mainServer.before(app);
|
|
30
95
|
(0, staticMain_1.default)(app, debuggerConfig, microPort);
|
|
31
96
|
(0, fakeSaasInfo_1.default)(app, microPort);
|
|
@@ -33,7 +98,7 @@ function runMain({ port, microPort, }) {
|
|
|
33
98
|
(0, proxy_1.default)(app);
|
|
34
99
|
mainServer && mainServer.after && mainServer.after(app);
|
|
35
100
|
const { waiting, resolve } = (0, promiser_1.promiser)();
|
|
36
|
-
|
|
101
|
+
server.listen(port, () => {
|
|
37
102
|
(0, ora_1.default)(`main server in ${port} port`).succeed();
|
|
38
103
|
resolve();
|
|
39
104
|
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare const readMF: () => {
|
|
2
|
+
zh: any;
|
|
3
|
+
en: any;
|
|
4
|
+
};
|
|
5
|
+
export declare const writeMF: (pkg: Record<string, any>) => void;
|
|
6
|
+
export declare enum Locales {
|
|
7
|
+
Read = "R_LOCALES",
|
|
8
|
+
Write = "W_LOCALES"
|
|
9
|
+
}
|
|
10
|
+
export declare const handler: (io: any, eventName: any, data: any) => void;
|
|
11
|
+
declare const _default: {
|
|
12
|
+
eventNames: {
|
|
13
|
+
Read: Locales.Read;
|
|
14
|
+
Write: Locales.Write;
|
|
15
|
+
};
|
|
16
|
+
handler: (io: any, eventName: any, data: any) => void;
|
|
17
|
+
};
|
|
18
|
+
export default _default;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.handler = exports.Locales = exports.writeMF = exports.readMF = void 0;
|
|
27
|
+
const fs = __importStar(require("fs"));
|
|
28
|
+
const path = __importStar(require("path"));
|
|
29
|
+
const zhPath = path.join(process.cwd(), './_locales/zh-CN.json');
|
|
30
|
+
const enPath = path.join(process.cwd(), './_locales/en.json');
|
|
31
|
+
const readMF = () => {
|
|
32
|
+
return {
|
|
33
|
+
zh: JSON.parse(fs.readFileSync(zhPath, { encoding: 'utf8' })),
|
|
34
|
+
en: JSON.parse(fs.readFileSync(enPath, { encoding: 'utf8' })),
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
exports.readMF = readMF;
|
|
38
|
+
const writeMF = (pkg) => {
|
|
39
|
+
fs.writeFileSync(zhPath, JSON.stringify(pkg.zh, null, 2));
|
|
40
|
+
fs.writeFileSync(enPath, JSON.stringify(pkg.en, null, 2));
|
|
41
|
+
};
|
|
42
|
+
exports.writeMF = writeMF;
|
|
43
|
+
var Locales;
|
|
44
|
+
(function (Locales) {
|
|
45
|
+
Locales["Read"] = "R_LOCALES";
|
|
46
|
+
Locales["Write"] = "W_LOCALES";
|
|
47
|
+
})(Locales = exports.Locales || (exports.Locales = {}));
|
|
48
|
+
const handler = (io, eventName, data) => {
|
|
49
|
+
if (eventName === Locales.Read) {
|
|
50
|
+
io.emit(eventName, (0, exports.readMF)());
|
|
51
|
+
}
|
|
52
|
+
if (eventName === Locales.Write) {
|
|
53
|
+
(0, exports.writeMF)(data);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
exports.handler = handler;
|
|
57
|
+
exports.default = { eventNames: Object.assign({}, Locales), handler: exports.handler };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.bootStrap = void 0;
|
|
7
|
+
const _locales_1 = __importDefault(require("./_locales"));
|
|
8
|
+
const lang_1 = __importDefault(require("./lang"));
|
|
9
|
+
const mf_1 = __importDefault(require("./mf"));
|
|
10
|
+
const mc_1 = __importDefault(require("./mc"));
|
|
11
|
+
const mock_1 = __importDefault(require("./mock"));
|
|
12
|
+
const pkg_1 = __importDefault(require("./pkg"));
|
|
13
|
+
const sdf_1 = __importDefault(require("./sdf"));
|
|
14
|
+
const bootStrap = (io) => {
|
|
15
|
+
io.on('connection', (socket) => {
|
|
16
|
+
console.log('connection');
|
|
17
|
+
socket.on(_locales_1.default.eventNames.Read, (msg) => {
|
|
18
|
+
_locales_1.default.handler(io, _locales_1.default.eventNames.Read, msg);
|
|
19
|
+
});
|
|
20
|
+
socket.on(_locales_1.default.eventNames.Write, (msg) => {
|
|
21
|
+
_locales_1.default.handler(io, _locales_1.default.eventNames.Read, msg);
|
|
22
|
+
});
|
|
23
|
+
socket.on(lang_1.default.eventNames.Read, (msg) => {
|
|
24
|
+
lang_1.default.handler(io, lang_1.default.eventNames.Read, msg);
|
|
25
|
+
});
|
|
26
|
+
socket.on(lang_1.default.eventNames.Write, (msg) => {
|
|
27
|
+
lang_1.default.handler(io, lang_1.default.eventNames.Read, msg);
|
|
28
|
+
});
|
|
29
|
+
socket.on(mc_1.default.eventNames.Read, (msg) => {
|
|
30
|
+
mc_1.default.handler(io, mc_1.default.eventNames.Read, msg);
|
|
31
|
+
});
|
|
32
|
+
socket.on(mc_1.default.eventNames.Write, (msg) => {
|
|
33
|
+
mc_1.default.handler(io, mc_1.default.eventNames.Read, msg);
|
|
34
|
+
});
|
|
35
|
+
socket.on(mf_1.default.eventNames.Read, (msg) => {
|
|
36
|
+
mf_1.default.handler(io, mf_1.default.eventNames.Read, msg);
|
|
37
|
+
});
|
|
38
|
+
socket.on(mf_1.default.eventNames.Write, (msg) => {
|
|
39
|
+
mf_1.default.handler(io, mf_1.default.eventNames.Read, msg);
|
|
40
|
+
});
|
|
41
|
+
socket.on(mock_1.default.eventNames.Read, (msg) => {
|
|
42
|
+
mock_1.default.handler(io, mock_1.default.eventNames.Read, msg);
|
|
43
|
+
});
|
|
44
|
+
socket.on(mock_1.default.eventNames.Write, (msg) => {
|
|
45
|
+
mock_1.default.handler(io, mock_1.default.eventNames.Read, msg);
|
|
46
|
+
});
|
|
47
|
+
socket.on(pkg_1.default.eventNames.Read, (msg) => {
|
|
48
|
+
pkg_1.default.handler(io, pkg_1.default.eventNames.Read, msg);
|
|
49
|
+
});
|
|
50
|
+
socket.on(pkg_1.default.eventNames.Write, (msg) => {
|
|
51
|
+
pkg_1.default.handler(io, pkg_1.default.eventNames.Read, msg);
|
|
52
|
+
});
|
|
53
|
+
socket.on(sdf_1.default.eventNames.Read, (msg) => {
|
|
54
|
+
sdf_1.default.handler(io, sdf_1.default.eventNames.Read, msg);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
exports.bootStrap = bootStrap;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare enum Lang {
|
|
2
|
+
Read = "R_LANG",
|
|
3
|
+
Write = "W_LANG"
|
|
4
|
+
}
|
|
5
|
+
export declare const handler: (io: any, eventName: any, data: any) => void;
|
|
6
|
+
declare const _default: {
|
|
7
|
+
eventNames: {
|
|
8
|
+
Read: Lang.Read;
|
|
9
|
+
Write: Lang.Write;
|
|
10
|
+
};
|
|
11
|
+
handler: (io: any, eventName: any, data: any) => void;
|
|
12
|
+
};
|
|
13
|
+
export default _default;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.handler = exports.Lang = void 0;
|
|
30
|
+
const traverse_1 = __importDefault(require("@babel/traverse"));
|
|
31
|
+
const parser_1 = require("@babel/parser");
|
|
32
|
+
const generator_1 = __importDefault(require("@babel/generator"));
|
|
33
|
+
const fs = __importStar(require("fs"));
|
|
34
|
+
const path = __importStar(require("path"));
|
|
35
|
+
const enPath = path.join(process.cwd(), './src/lang/en.ts');
|
|
36
|
+
const zhPath = path.join(process.cwd(), './src/lang/zh.ts');
|
|
37
|
+
const readLang = () => {
|
|
38
|
+
const lang = { zh: {}, en: {} };
|
|
39
|
+
['zh', 'en'].forEach((key) => {
|
|
40
|
+
const ast = (0, parser_1.parse)(fs.readFileSync(key === 'zh' ? zhPath : enPath, {
|
|
41
|
+
encoding: 'utf-8',
|
|
42
|
+
}), { sourceType: 'module' });
|
|
43
|
+
(0, traverse_1.default)(ast, {
|
|
44
|
+
ObjectExpression(path) {
|
|
45
|
+
var _a, _b, _c, _d;
|
|
46
|
+
if (((_b = (_a = path === null || path === void 0 ? void 0 : path.container) === null || _a === void 0 ? void 0 : _a.key) === null || _b === void 0 ? void 0 : _b.name) === 'translation') {
|
|
47
|
+
(_d = (_c = path === null || path === void 0 ? void 0 : path.node) === null || _c === void 0 ? void 0 : _c.properties) === null || _d === void 0 ? void 0 : _d.forEach((entry) => {
|
|
48
|
+
lang[key][entry.key.value] = entry.value.value;
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
return lang;
|
|
55
|
+
};
|
|
56
|
+
const writeLang = (lang) => {
|
|
57
|
+
['zh', 'en'].forEach((key) => {
|
|
58
|
+
const langPath = key === 'zh' ? zhPath : enPath;
|
|
59
|
+
const ast = (0, parser_1.parse)(fs.readFileSync(langPath, {
|
|
60
|
+
encoding: 'utf-8',
|
|
61
|
+
}), { sourceType: 'module' });
|
|
62
|
+
(0, traverse_1.default)(ast, {
|
|
63
|
+
ObjectExpression(path) {
|
|
64
|
+
var _a, _b, _c, _d;
|
|
65
|
+
if (((_b = (_a = path === null || path === void 0 ? void 0 : path.container) === null || _a === void 0 ? void 0 : _a.key) === null || _b === void 0 ? void 0 : _b.name) === 'translation') {
|
|
66
|
+
(_d = (_c = path === null || path === void 0 ? void 0 : path.node) === null || _c === void 0 ? void 0 : _c.properties) === null || _d === void 0 ? void 0 : _d.forEach((entry) => { });
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
const code = (0, generator_1.default)(ast).code;
|
|
71
|
+
fs.writeFileSync(langPath, code, { encoding: 'utf8' });
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
var Lang;
|
|
75
|
+
(function (Lang) {
|
|
76
|
+
Lang["Read"] = "R_LANG";
|
|
77
|
+
Lang["Write"] = "W_LANG";
|
|
78
|
+
})(Lang = exports.Lang || (exports.Lang = {}));
|
|
79
|
+
const handler = (io, eventName, data) => {
|
|
80
|
+
if (eventName === Lang.Read) {
|
|
81
|
+
io.emit(eventName, readLang());
|
|
82
|
+
}
|
|
83
|
+
if (eventName === Lang.Write) {
|
|
84
|
+
writeLang(data);
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
exports.handler = handler;
|
|
88
|
+
exports.default = { eventNames: Object.assign({}, Lang), handler: exports.handler };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare enum MicroConfig {
|
|
2
|
+
Read = "R_MICRO_CONFIG",
|
|
3
|
+
Write = "W_MICRO_CONFIG"
|
|
4
|
+
}
|
|
5
|
+
export declare const handler: (io: any, eventName: any, data: any) => void;
|
|
6
|
+
declare const _default: {
|
|
7
|
+
eventNames: {
|
|
8
|
+
Read: MicroConfig.Read;
|
|
9
|
+
Write: MicroConfig.Write;
|
|
10
|
+
};
|
|
11
|
+
handler: (io: any, eventName: any, data: any) => void;
|
|
12
|
+
};
|
|
13
|
+
export default _default;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.handler = exports.MicroConfig = void 0;
|
|
30
|
+
const traverse_1 = __importDefault(require("@babel/traverse"));
|
|
31
|
+
const parser_1 = require("@babel/parser");
|
|
32
|
+
const generator_1 = __importDefault(require("@babel/generator"));
|
|
33
|
+
const t = __importStar(require("@babel/types"));
|
|
34
|
+
const fs = __importStar(require("fs"));
|
|
35
|
+
const path = __importStar(require("path"));
|
|
36
|
+
const readMC = () => {
|
|
37
|
+
const mc = {};
|
|
38
|
+
const ast = (0, parser_1.parse)(fs.readFileSync(path.join(process.cwd(), './micro.config.js'), {
|
|
39
|
+
encoding: 'utf-8',
|
|
40
|
+
}), { sourceType: 'module' });
|
|
41
|
+
(0, traverse_1.default)(ast, {
|
|
42
|
+
ObjectExpression(path) {
|
|
43
|
+
var _a, _b, _c, _d;
|
|
44
|
+
if (((_b = (_a = path === null || path === void 0 ? void 0 : path.container) === null || _a === void 0 ? void 0 : _a.key) === null || _b === void 0 ? void 0 : _b.name) === 'debuggerConfig') {
|
|
45
|
+
const debuggerConfig = {};
|
|
46
|
+
(_d = (_c = path === null || path === void 0 ? void 0 : path.node) === null || _c === void 0 ? void 0 : _c.properties) === null || _d === void 0 ? void 0 : _d.forEach((entry) => {
|
|
47
|
+
if (entry.key.name === 'mockPermissions') {
|
|
48
|
+
debuggerConfig[entry.key.name] = entry.value.elements.map((item) => item.value);
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
debuggerConfig[entry.key.name] = entry.value.value;
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
mc.debuggerConfig = debuggerConfig;
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
return mc;
|
|
59
|
+
};
|
|
60
|
+
const writeMC = (data) => {
|
|
61
|
+
const mcPath = path.join(process.cwd(), './micro.config.js');
|
|
62
|
+
const ast = (0, parser_1.parse)(fs.readFileSync(mcPath, {
|
|
63
|
+
encoding: 'utf-8',
|
|
64
|
+
}), { sourceType: 'module' });
|
|
65
|
+
(0, traverse_1.default)(ast, {
|
|
66
|
+
ObjectExpression(path) {
|
|
67
|
+
var _a, _b;
|
|
68
|
+
if (((_b = (_a = path === null || path === void 0 ? void 0 : path.container) === null || _a === void 0 ? void 0 : _a.key) === null || _b === void 0 ? void 0 : _b.name) === 'debuggerConfig') {
|
|
69
|
+
path.node.properties.push(t.objectProperty(t.identifier('age'), t.numericLiteral(18)));
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
const code = (0, generator_1.default)(ast).code;
|
|
74
|
+
fs.writeFileSync(mcPath, code, { encoding: 'utf8' });
|
|
75
|
+
};
|
|
76
|
+
var MicroConfig;
|
|
77
|
+
(function (MicroConfig) {
|
|
78
|
+
MicroConfig["Read"] = "R_MICRO_CONFIG";
|
|
79
|
+
MicroConfig["Write"] = "W_MICRO_CONFIG";
|
|
80
|
+
})(MicroConfig = exports.MicroConfig || (exports.MicroConfig = {}));
|
|
81
|
+
const handler = (io, eventName, data) => {
|
|
82
|
+
if (eventName === MicroConfig.Read) {
|
|
83
|
+
io.emit(eventName, readMC());
|
|
84
|
+
}
|
|
85
|
+
if (eventName === MicroConfig.Write) {
|
|
86
|
+
writeMC(data);
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
exports.handler = handler;
|
|
90
|
+
exports.default = { eventNames: Object.assign({}, MicroConfig), handler: exports.handler };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare const readMF: () => any;
|
|
2
|
+
export declare const writeMF: (pkg: Record<string, any>) => void;
|
|
3
|
+
export declare enum Manifest {
|
|
4
|
+
Read = "R_MANIFEST",
|
|
5
|
+
Write = "W_MANIFEST"
|
|
6
|
+
}
|
|
7
|
+
export declare const handler: (io: any, eventName: any, data: any) => void;
|
|
8
|
+
declare const _default: {
|
|
9
|
+
eventNames: {
|
|
10
|
+
Read: Manifest.Read;
|
|
11
|
+
Write: Manifest.Write;
|
|
12
|
+
};
|
|
13
|
+
handler: (io: any, eventName: any, data: any) => void;
|
|
14
|
+
};
|
|
15
|
+
export default _default;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.handler = exports.Manifest = exports.writeMF = exports.readMF = void 0;
|
|
27
|
+
const fs = __importStar(require("fs"));
|
|
28
|
+
const path = __importStar(require("path"));
|
|
29
|
+
const mfPath = path.join(process.cwd(), 'manifest.json');
|
|
30
|
+
const readMF = () => {
|
|
31
|
+
return JSON.parse(fs.readFileSync(mfPath, { encoding: 'utf8' }));
|
|
32
|
+
};
|
|
33
|
+
exports.readMF = readMF;
|
|
34
|
+
const writeMF = (pkg) => {
|
|
35
|
+
fs.writeFileSync(mfPath, JSON.stringify(pkg, null, 2));
|
|
36
|
+
};
|
|
37
|
+
exports.writeMF = writeMF;
|
|
38
|
+
var Manifest;
|
|
39
|
+
(function (Manifest) {
|
|
40
|
+
Manifest["Read"] = "R_MANIFEST";
|
|
41
|
+
Manifest["Write"] = "W_MANIFEST";
|
|
42
|
+
})(Manifest = exports.Manifest || (exports.Manifest = {}));
|
|
43
|
+
const handler = (io, eventName, data) => {
|
|
44
|
+
if (eventName === Manifest.Read) {
|
|
45
|
+
io.emit(eventName, (0, exports.readMF)());
|
|
46
|
+
}
|
|
47
|
+
if (eventName === Manifest.Write) {
|
|
48
|
+
(0, exports.writeMF)(data);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
exports.handler = handler;
|
|
52
|
+
exports.default = { eventNames: Object.assign({}, Manifest), handler: exports.handler };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare const readMock: () => any;
|
|
2
|
+
export declare const writeMock: (pkg: Record<string, any>) => void;
|
|
3
|
+
export declare enum Mock {
|
|
4
|
+
Read = "R_MOCK",
|
|
5
|
+
Write = "W_MOCK"
|
|
6
|
+
}
|
|
7
|
+
export declare const handler: (io: any, eventName: any, data: any) => void;
|
|
8
|
+
declare const _default: {
|
|
9
|
+
eventNames: {
|
|
10
|
+
Read: Mock.Read;
|
|
11
|
+
Write: Mock.Write;
|
|
12
|
+
};
|
|
13
|
+
handler: (io: any, eventName: any, data: any) => void;
|
|
14
|
+
};
|
|
15
|
+
export default _default;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.handler = exports.Mock = exports.writeMock = exports.readMock = void 0;
|
|
27
|
+
const fs = __importStar(require("fs"));
|
|
28
|
+
const path = __importStar(require("path"));
|
|
29
|
+
const mockPath = path.join(process.cwd(), 'mock/index.json');
|
|
30
|
+
const readMock = () => {
|
|
31
|
+
return JSON.parse(fs.readFileSync(mockPath, { encoding: 'utf8' }));
|
|
32
|
+
};
|
|
33
|
+
exports.readMock = readMock;
|
|
34
|
+
const writeMock = (pkg) => {
|
|
35
|
+
fs.writeFileSync(mockPath, JSON.stringify(pkg, null, 2));
|
|
36
|
+
};
|
|
37
|
+
exports.writeMock = writeMock;
|
|
38
|
+
var Mock;
|
|
39
|
+
(function (Mock) {
|
|
40
|
+
Mock["Read"] = "R_MOCK";
|
|
41
|
+
Mock["Write"] = "W_MOCK";
|
|
42
|
+
})(Mock = exports.Mock || (exports.Mock = {}));
|
|
43
|
+
const handler = (io, eventName, data) => {
|
|
44
|
+
if (eventName === Mock.Read) {
|
|
45
|
+
io.emit(eventName, (0, exports.readMock)());
|
|
46
|
+
}
|
|
47
|
+
if (eventName === Mock.Write) {
|
|
48
|
+
(0, exports.writeMock)(data);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
exports.handler = handler;
|
|
52
|
+
exports.default = { eventNames: Object.assign({}, Mock), handler: exports.handler };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare const readPkg: () => any;
|
|
2
|
+
export declare const writePkg: (pkg: Record<string, any>) => void;
|
|
3
|
+
export declare enum PKG {
|
|
4
|
+
Read = "R_PKG",
|
|
5
|
+
Write = "W_PKG"
|
|
6
|
+
}
|
|
7
|
+
export declare const handler: (io: any, eventName: any, data: any) => void;
|
|
8
|
+
declare const _default: {
|
|
9
|
+
eventNames: {
|
|
10
|
+
Read: PKG.Read;
|
|
11
|
+
Write: PKG.Write;
|
|
12
|
+
};
|
|
13
|
+
handler: (io: any, eventName: any, data: any) => void;
|
|
14
|
+
};
|
|
15
|
+
export default _default;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.handler = exports.PKG = exports.writePkg = exports.readPkg = void 0;
|
|
27
|
+
const fs = __importStar(require("fs"));
|
|
28
|
+
const path = __importStar(require("path"));
|
|
29
|
+
const pkgPath = path.join(process.cwd(), 'package.json');
|
|
30
|
+
const readPkg = () => {
|
|
31
|
+
return JSON.parse(fs.readFileSync(pkgPath, { encoding: 'utf8' }));
|
|
32
|
+
};
|
|
33
|
+
exports.readPkg = readPkg;
|
|
34
|
+
const writePkg = (pkg) => {
|
|
35
|
+
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2));
|
|
36
|
+
};
|
|
37
|
+
exports.writePkg = writePkg;
|
|
38
|
+
var PKG;
|
|
39
|
+
(function (PKG) {
|
|
40
|
+
PKG["Read"] = "R_PKG";
|
|
41
|
+
PKG["Write"] = "W_PKG";
|
|
42
|
+
})(PKG = exports.PKG || (exports.PKG = {}));
|
|
43
|
+
const handler = (io, eventName, data) => {
|
|
44
|
+
if (eventName === PKG.Read) {
|
|
45
|
+
io.emit(eventName, (0, exports.readPkg)());
|
|
46
|
+
}
|
|
47
|
+
if (eventName === PKG.Write) {
|
|
48
|
+
(0, exports.writePkg)(data);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
exports.handler = handler;
|
|
52
|
+
exports.default = { eventNames: Object.assign({}, PKG), handler: exports.handler };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare enum SAAS_INFO {
|
|
2
|
+
Read = "R_SDF"
|
|
3
|
+
}
|
|
4
|
+
export declare const handler: (io: any, eventName: any, data: any) => void;
|
|
5
|
+
declare const _default: {
|
|
6
|
+
eventNames: {
|
|
7
|
+
Read: SAAS_INFO.Read;
|
|
8
|
+
};
|
|
9
|
+
handler: (io: any, eventName: any, data: any) => void;
|
|
10
|
+
};
|
|
11
|
+
export default _default;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.handler = exports.SAAS_INFO = void 0;
|
|
4
|
+
const { GSdf } = require('@tuya-sat/micro-dev-proxy');
|
|
5
|
+
var SAAS_INFO;
|
|
6
|
+
(function (SAAS_INFO) {
|
|
7
|
+
SAAS_INFO["Read"] = "R_SDF";
|
|
8
|
+
})(SAAS_INFO = exports.SAAS_INFO || (exports.SAAS_INFO = {}));
|
|
9
|
+
const handler = (io, eventName, data) => {
|
|
10
|
+
if (eventName === SAAS_INFO.Read) {
|
|
11
|
+
io.emit(eventName, GSdf());
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
exports.handler = handler;
|
|
15
|
+
exports.default = { eventNames: Object.assign({}, SAAS_INFO), handler: exports.handler };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tuya-sat/micro-script",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.12",
|
|
4
4
|
"bin": "./dist/bin/cli.js",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"license": "MIT",
|
|
@@ -16,19 +16,23 @@
|
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"@babel/core": "7.17.8",
|
|
19
|
+
"@babel/generator": "^7.20.14",
|
|
20
|
+
"@babel/parser": "^7.20.15",
|
|
19
21
|
"@babel/preset-env": "7.16.11",
|
|
20
22
|
"@babel/preset-react": "7.16.7",
|
|
21
23
|
"@babel/preset-typescript": "7.16.7",
|
|
24
|
+
"@babel/traverse": "^7.20.13",
|
|
22
25
|
"@pmmmwh/react-refresh-webpack-plugin": "0.5.4",
|
|
23
|
-
"@tuya-sat/micro-dev-loader": "3.0.
|
|
24
|
-
"@tuya-sat/micro-dev-proxy": "3.0.
|
|
25
|
-
"@tuya-sat/micro-utils": "3.0.
|
|
26
|
+
"@tuya-sat/micro-dev-loader": "3.0.12",
|
|
27
|
+
"@tuya-sat/micro-dev-proxy": "3.0.12",
|
|
28
|
+
"@tuya-sat/micro-utils": "3.0.12",
|
|
26
29
|
"@types/kill-port": "^2.0.0",
|
|
27
30
|
"babel-loader": "8.2.4",
|
|
28
31
|
"babel-plugin-import": "1.13.3",
|
|
29
32
|
"chalk": "4.1.2",
|
|
30
33
|
"cheerio": "1.0.0-rc.10",
|
|
31
34
|
"copy-webpack-plugin": "10.2.4",
|
|
35
|
+
"cors": "^2.8.5",
|
|
32
36
|
"css-loader": "6.7.1",
|
|
33
37
|
"css-minimizer-webpack-plugin": "3.4.1",
|
|
34
38
|
"express": "4.17.3",
|
|
@@ -52,6 +56,7 @@
|
|
|
52
56
|
"resolve-url-loader": "5.0.0",
|
|
53
57
|
"sass": "1.49.9",
|
|
54
58
|
"sass-loader": "12.6.0",
|
|
59
|
+
"socket.io": "^4.6.0",
|
|
55
60
|
"style-loader": "3.3.1",
|
|
56
61
|
"svg-url-loader": "7.1.1",
|
|
57
62
|
"tsconfig-paths-webpack-plugin": "^4.0.0",
|