@tuya-sat/micro-script 3.0.27-beta.7 → 3.0.27-beta.8
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.
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Express } from
|
|
1
|
+
import { Express } from "express";
|
|
2
2
|
export default function mockSaasInfo(app: Express, microPort: number): void;
|
|
@@ -34,35 +34,36 @@ const path = __importStar(require("path"));
|
|
|
34
34
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
35
35
|
const utils_1 = require("../../utils");
|
|
36
36
|
function mockSaasInfo(app, microPort) {
|
|
37
|
-
let { multiApps, debuggerConfig: { isMainApp }, } = require(paths_1.default.microConfig);
|
|
37
|
+
let { multiApps, microApps, debuggerConfig: { isMainApp }, } = require(paths_1.default.microConfig);
|
|
38
38
|
const idsMap = new Map();
|
|
39
39
|
multiApps = (0, utils_1.processMultiApps)(multiApps);
|
|
40
|
-
if (isMainApp && fs_extra_1.default.existsSync(path.join(process.cwd(),
|
|
41
|
-
const dirs =
|
|
42
|
-
|
|
40
|
+
if (isMainApp && fs_extra_1.default.existsSync(path.join(process.cwd(), "apps"))) {
|
|
41
|
+
const dirs = ((microApps === null || microApps === void 0 ? void 0 : microApps.length) > 0 && microApps) ||
|
|
42
|
+
fs_extra_1.default.readdirSync(path.join(process.cwd(), "apps"));
|
|
43
|
+
dirs === null || dirs === void 0 ? void 0 : dirs.forEach((dir) => {
|
|
43
44
|
idsMap.set(dir, { entry_id: (0, uuid_1.v4)(), oem_micro_app_id: (0, uid_1.uid)(16) });
|
|
44
45
|
});
|
|
45
|
-
app.get(
|
|
46
|
-
const lang =
|
|
46
|
+
app.get("/api/saas-info", (req, res) => {
|
|
47
|
+
const lang = "zh";
|
|
47
48
|
const result = {
|
|
48
49
|
apps: [],
|
|
49
|
-
entry_info: { entries: [], entry_mode:
|
|
50
|
+
entry_info: { entries: [], entry_mode: "normal" },
|
|
50
51
|
permissions: {},
|
|
51
52
|
saas_id_info_list: [],
|
|
52
53
|
};
|
|
53
54
|
dirs.forEach((dir) => {
|
|
54
55
|
const entry_id = idsMap.get(dir).entry_id;
|
|
55
|
-
const manifest = fs_extra_1.default.readJSONSync(path.join(process.cwd(),
|
|
56
|
+
const manifest = fs_extra_1.default.readJSONSync(path.join(process.cwd(), "apps", dir, "manifest.json"), "utf-8");
|
|
56
57
|
const oem_micro_app_id = idsMap.get(dir).oem_micro_app_id;
|
|
57
58
|
const baseUrl = `/apps/${oem_micro_app_id}`;
|
|
58
59
|
result.saas_id_info_list.push({
|
|
59
60
|
oem_micro_app_id: oem_micro_app_id,
|
|
60
|
-
universal_id:
|
|
61
|
+
universal_id: "",
|
|
61
62
|
});
|
|
62
|
-
const appConfig = fs_extra_1.default.readJSONSync(path.join(process.cwd(),
|
|
63
|
+
const appConfig = fs_extra_1.default.readJSONSync(path.join(process.cwd(), "node_modules", ".micro", "app.config.json"));
|
|
63
64
|
const micoApp = consturctApp(manifest, oem_micro_app_id, baseUrl, lang, appConfig[dir]);
|
|
64
65
|
const entryInfo = consturctEntry(manifest, oem_micro_app_id, entry_id, baseUrl, lang, `apps/${dir}`);
|
|
65
|
-
const permission = (manifest === null || manifest === void 0 ? void 0 : manifest.privileges.map(item => {
|
|
66
|
+
const permission = (manifest === null || manifest === void 0 ? void 0 : manifest.privileges.map((item) => {
|
|
66
67
|
return { permission_group: item.code };
|
|
67
68
|
})) || [];
|
|
68
69
|
result.apps.push(micoApp);
|
|
@@ -82,24 +83,24 @@ function mockSaasInfo(app, microPort) {
|
|
|
82
83
|
multiApps === null || multiApps === void 0 ? void 0 : multiApps.forEach((app) => {
|
|
83
84
|
idsMap.set(app.name, { entry_id: (0, uuid_1.v4)(), oem_micro_app_id: (0, uid_1.uid)(16) });
|
|
84
85
|
});
|
|
85
|
-
app.get(
|
|
86
|
-
const lang = parseCookie(req.headers[
|
|
86
|
+
app.get("/api/saas-info", (req, res) => {
|
|
87
|
+
const lang = parseCookie(req.headers["cookie"], "main-i18next");
|
|
87
88
|
if ((0, utils_1.isMonorepo)() || (multiApps && multiApps.length > 0)) {
|
|
88
89
|
const result = {
|
|
89
90
|
apps: [],
|
|
90
|
-
entry_info: { entries: [], entry_mode:
|
|
91
|
+
entry_info: { entries: [], entry_mode: "normal" },
|
|
91
92
|
permissions: {},
|
|
92
93
|
saas_id_info_list: [],
|
|
93
94
|
};
|
|
94
95
|
multiApps.forEach((app) => {
|
|
95
96
|
const entry_id = idsMap.get(app.name).entry_id;
|
|
96
97
|
const dir = (0, utils_1.isMonorepo)() ? `apps/${app.name}` : `${app.dir}`;
|
|
97
|
-
const manifest = fs_extra_1.default.readJSONSync(path.join(process.cwd(), dir,
|
|
98
|
+
const manifest = fs_extra_1.default.readJSONSync(path.join(process.cwd(), dir, "manifest.json"), "utf-8");
|
|
98
99
|
const oem_micro_app_id = idsMap.get(app.name).oem_micro_app_id;
|
|
99
100
|
const baseUrl = `/apps/${oem_micro_app_id}`;
|
|
100
101
|
result.saas_id_info_list.push({
|
|
101
102
|
oem_micro_app_id: oem_micro_app_id,
|
|
102
|
-
universal_id:
|
|
103
|
+
universal_id: "",
|
|
103
104
|
});
|
|
104
105
|
const micoApp = consturctApp(manifest, oem_micro_app_id, baseUrl, lang, microPort, app.name);
|
|
105
106
|
const entryInfo = consturctEntry(manifest, oem_micro_app_id, entry_id, baseUrl, lang, dir);
|
|
@@ -122,7 +123,7 @@ function mockSaasInfo(app, microPort) {
|
|
|
122
123
|
const oem_micro_app_id = manifest.universalId;
|
|
123
124
|
const baseUrl = `/apps/${oem_micro_app_id}`;
|
|
124
125
|
const app = consturctApp(manifest, oem_micro_app_id, baseUrl, lang, microPort);
|
|
125
|
-
const entryInfo = consturctEntry(manifest, oem_micro_app_id, entry_id, baseUrl, lang,
|
|
126
|
+
const entryInfo = consturctEntry(manifest, oem_micro_app_id, entry_id, baseUrl, lang, "");
|
|
126
127
|
const permission = consturctPermissions();
|
|
127
128
|
res.send({
|
|
128
129
|
code: null,
|
|
@@ -130,10 +131,10 @@ function mockSaasInfo(app, microPort) {
|
|
|
130
131
|
msg: null,
|
|
131
132
|
result: {
|
|
132
133
|
apps: [app],
|
|
133
|
-
entry_info: { entries: [entryInfo], entry_mode:
|
|
134
|
+
entry_info: { entries: [entryInfo], entry_mode: "normal" },
|
|
134
135
|
permissions: { [oem_micro_app_id]: permission },
|
|
135
136
|
saas_id_info_list: [
|
|
136
|
-
{ oem_micro_app_id: oem_micro_app_id, universal_id:
|
|
137
|
+
{ oem_micro_app_id: oem_micro_app_id, universal_id: "" },
|
|
137
138
|
],
|
|
138
139
|
},
|
|
139
140
|
success: true,
|
|
@@ -151,9 +152,9 @@ function consturctEntry(manifest, oem_micro_app_id, entry_id, baseUrl, lang, dir
|
|
|
151
152
|
menu.oem_micro_app_id = oem_micro_app_id;
|
|
152
153
|
menu.entry_id = entry_id;
|
|
153
154
|
//@ts-ignore
|
|
154
|
-
menu.entry_name_zh = pickText(menu.entry_name,
|
|
155
|
+
menu.entry_name_zh = pickText(menu.entry_name, "zh");
|
|
155
156
|
//@ts-ignore
|
|
156
|
-
menu.entry_name_en = pickText(menu.entry_name,
|
|
157
|
+
menu.entry_name_en = pickText(menu.entry_name, "en");
|
|
157
158
|
//@ts-ignore
|
|
158
159
|
menu.entry_name = pickText(menu.entry_name, lang);
|
|
159
160
|
//@ts-ignore
|
|
@@ -162,7 +163,8 @@ function consturctEntry(manifest, oem_micro_app_id, entry_id, baseUrl, lang, dir
|
|
|
162
163
|
if (menu.sub_entry_list.length) {
|
|
163
164
|
stack.push(...menu.sub_entry_list);
|
|
164
165
|
}
|
|
165
|
-
menu.icon =
|
|
166
|
+
menu.icon =
|
|
167
|
+
"https://images.tuyacn.com/rms-static/5d202fa0-e909-11eb-815d-e39234ce96ff-1626751199130.png?tyName=space-manage.png";
|
|
166
168
|
}
|
|
167
169
|
return fakeMenu;
|
|
168
170
|
}
|
|
@@ -170,13 +172,13 @@ function consturctApp(manifest, oem_micro_app_id, baseUrl, lang, port, code) {
|
|
|
170
172
|
const packageInfo = (0, micro_utils_1.getPackage)();
|
|
171
173
|
return {
|
|
172
174
|
active_rule: baseUrl,
|
|
173
|
-
dependencies: [
|
|
175
|
+
dependencies: [""],
|
|
174
176
|
ext_info: null,
|
|
175
177
|
micro_app_code: code || `${packageInfo.name}`,
|
|
176
178
|
micro_app_name: code ? `${code}-dev` : `${packageInfo.name}-dev`,
|
|
177
|
-
micro_app_version:
|
|
179
|
+
micro_app_version: "0.0.0-x",
|
|
178
180
|
oem_micro_app_id,
|
|
179
|
-
resource: `http://localhost:${port}/${code ||
|
|
181
|
+
resource: `http://localhost:${port}/${code || "index"}.html`,
|
|
180
182
|
schema: null,
|
|
181
183
|
universal_id: manifest.universalId,
|
|
182
184
|
isAuth: true,
|
|
@@ -188,15 +190,15 @@ function consturctPermissions() {
|
|
|
188
190
|
return mockPermissions.map((code) => ({ permission_group: code }));
|
|
189
191
|
}
|
|
190
192
|
function pickText(texts, lang) {
|
|
191
|
-
return lang ===
|
|
193
|
+
return lang === "en" ? texts[1] : texts[0];
|
|
192
194
|
}
|
|
193
195
|
function parseCookie(cookie, key) {
|
|
194
|
-
const cookies = (cookie ||
|
|
196
|
+
const cookies = (cookie || "").split(";");
|
|
195
197
|
for (let cookieItem of cookies) {
|
|
196
|
-
const [cookieKey, value] = cookieItem.split(
|
|
198
|
+
const [cookieKey, value] = cookieItem.split("=");
|
|
197
199
|
if (cookieKey.trim() === key) {
|
|
198
200
|
return value;
|
|
199
201
|
}
|
|
200
202
|
}
|
|
201
|
-
return
|
|
203
|
+
return "";
|
|
202
204
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tuya-sat/micro-script",
|
|
3
|
-
"version": "3.0.27-beta.
|
|
3
|
+
"version": "3.0.27-beta.8",
|
|
4
4
|
"bin": "./dist/bin/cli.js",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"license": "MIT",
|
|
@@ -23,9 +23,9 @@
|
|
|
23
23
|
"@babel/preset-typescript": "7.16.7",
|
|
24
24
|
"@babel/traverse": "^7.20.13",
|
|
25
25
|
"@pmmmwh/react-refresh-webpack-plugin": "0.5.4",
|
|
26
|
-
"@tuya-sat/micro-dev-loader": "3.0.27-beta.
|
|
27
|
-
"@tuya-sat/micro-dev-proxy": "3.0.27-beta.
|
|
28
|
-
"@tuya-sat/micro-utils": "3.0.27-beta.
|
|
26
|
+
"@tuya-sat/micro-dev-loader": "3.0.27-beta.8",
|
|
27
|
+
"@tuya-sat/micro-dev-proxy": "3.0.27-beta.8",
|
|
28
|
+
"@tuya-sat/micro-utils": "3.0.27-beta.8",
|
|
29
29
|
"@types/kill-port": "^2.0.0",
|
|
30
30
|
"babel-loader": "8.2.4",
|
|
31
31
|
"babel-plugin-import": "1.13.3",
|