@tuya-sat/micro-script 3.0.27-beta.10 → 3.0.27-beta.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.
|
@@ -68,6 +68,7 @@ function getFakeSaas(config) {
|
|
|
68
68
|
base: '',
|
|
69
69
|
env: '',
|
|
70
70
|
region: '',
|
|
71
|
+
isOpenCode: true,
|
|
71
72
|
saas: {
|
|
72
73
|
background_image: 'https://images.tuyacn.com/rms-static/537a3fd0-1b5a-11ec-b7af-2d39f353debc-1632283530317.jpg?tyName=login.jpg',
|
|
73
74
|
charge_status: 'TRIAL',
|
|
@@ -81,18 +82,18 @@ function getFakeSaas(config) {
|
|
|
81
82
|
label: '',
|
|
82
83
|
legal_notice: 'https://ruomu-abc-001.fast-cn.wgine.com/policies/legal',
|
|
83
84
|
logo: 'https://images.tuyacn.com/rms-static/bc42adb0-6f86-11ec-b5fa-7deb2a111a61-1641538501643.png?tyName=%E9%BB%98%E8%AE%A4logo%2056X56%20.png',
|
|
84
|
-
privacy_policy:
|
|
85
|
-
service_terms:
|
|
85
|
+
privacy_policy: 'https://ruomu-abc-001.fast-cn.wgine.com/policies/privacy',
|
|
86
|
+
service_terms: 'https://ruomu-abc-001.fast-cn.wgine.com/policies/service',
|
|
86
87
|
supported_language: { en: 'English', zh: '简体中文' },
|
|
87
88
|
tenant_register_support: false,
|
|
88
|
-
tenant_type:
|
|
89
|
-
title:
|
|
89
|
+
tenant_type: 'SINGLE_TENANT',
|
|
90
|
+
title: '物联网开放平台',
|
|
90
91
|
},
|
|
91
92
|
},
|
|
92
93
|
_SDF_CONFIG: {},
|
|
93
94
|
__MAIN_APP_PUBLIC_PATH: 'https://static1.tuyacn.com/static/sdf-main-app/0.0.0-123/',
|
|
94
95
|
};
|
|
95
|
-
Object.keys(saasInfo).forEach(key => {
|
|
96
|
+
Object.keys(saasInfo).forEach((key) => {
|
|
96
97
|
saas._SDF.saas[key] = saasInfo[key] ? saasInfo[key] : saas._SDF.saas[key];
|
|
97
98
|
});
|
|
98
99
|
return saas;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Express } from
|
|
1
|
+
import { Express } from 'express';
|
|
2
2
|
export default function mockSaasInfo(app: Express, microPort: number): void;
|
|
@@ -37,30 +37,30 @@ function mockSaasInfo(app, microPort) {
|
|
|
37
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(),
|
|
40
|
+
if (isMainApp && fs_extra_1.default.existsSync(path.join(process.cwd(), 'apps'))) {
|
|
41
41
|
const dirs = ((microApps === null || microApps === void 0 ? void 0 : microApps.length) > 0 && microApps) ||
|
|
42
|
-
fs_extra_1.default.readdirSync(path.join(process.cwd(),
|
|
42
|
+
fs_extra_1.default.readdirSync(path.join(process.cwd(), 'apps'));
|
|
43
43
|
dirs === null || dirs === void 0 ? void 0 : dirs.forEach((dir) => {
|
|
44
44
|
idsMap.set(dir, { entry_id: (0, uuid_1.v4)(), oem_micro_app_id: (0, uid_1.uid)(16) });
|
|
45
45
|
});
|
|
46
|
-
app.get(
|
|
47
|
-
const lang =
|
|
46
|
+
app.get('/api/saas-info', (req, res) => {
|
|
47
|
+
const lang = 'zh';
|
|
48
48
|
const result = {
|
|
49
49
|
apps: [],
|
|
50
|
-
entry_info: { entries: [], entry_mode:
|
|
50
|
+
entry_info: { entries: [], entry_mode: 'normal' },
|
|
51
51
|
permissions: {},
|
|
52
52
|
saas_id_info_list: [],
|
|
53
53
|
};
|
|
54
54
|
dirs.forEach((dir) => {
|
|
55
55
|
const entry_id = idsMap.get(dir).entry_id;
|
|
56
|
-
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');
|
|
57
57
|
const oem_micro_app_id = idsMap.get(dir).oem_micro_app_id;
|
|
58
58
|
const baseUrl = `/apps/${oem_micro_app_id}`;
|
|
59
59
|
result.saas_id_info_list.push({
|
|
60
60
|
oem_micro_app_id: oem_micro_app_id,
|
|
61
|
-
universal_id:
|
|
61
|
+
universal_id: '',
|
|
62
62
|
});
|
|
63
|
-
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'));
|
|
64
64
|
const micoApp = consturctApp(manifest, oem_micro_app_id, baseUrl, lang, appConfig[dir]);
|
|
65
65
|
const entryInfo = consturctEntry(manifest, oem_micro_app_id, entry_id, baseUrl, lang, `apps/${dir}`);
|
|
66
66
|
const permission = (manifest === null || manifest === void 0 ? void 0 : manifest.privileges.map((item) => {
|
|
@@ -83,24 +83,24 @@ function mockSaasInfo(app, microPort) {
|
|
|
83
83
|
multiApps === null || multiApps === void 0 ? void 0 : multiApps.forEach((app) => {
|
|
84
84
|
idsMap.set(app.name, { entry_id: (0, uuid_1.v4)(), oem_micro_app_id: (0, uid_1.uid)(16) });
|
|
85
85
|
});
|
|
86
|
-
app.get(
|
|
87
|
-
const lang = parseCookie(req.headers[
|
|
86
|
+
app.get('/api/saas-info', (req, res) => {
|
|
87
|
+
const lang = parseCookie(req.headers['cookie'], 'main-i18next');
|
|
88
88
|
if ((0, utils_1.isMonorepo)() || (multiApps && multiApps.length > 0)) {
|
|
89
89
|
const result = {
|
|
90
90
|
apps: [],
|
|
91
|
-
entry_info: { entries: [], entry_mode:
|
|
91
|
+
entry_info: { entries: [], entry_mode: 'normal' },
|
|
92
92
|
permissions: {},
|
|
93
93
|
saas_id_info_list: [],
|
|
94
94
|
};
|
|
95
95
|
multiApps.forEach((app) => {
|
|
96
96
|
const entry_id = idsMap.get(app.name).entry_id;
|
|
97
97
|
const dir = (0, utils_1.isMonorepo)() ? `apps/${app.name}` : `${app.dir}`;
|
|
98
|
-
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');
|
|
99
99
|
const oem_micro_app_id = idsMap.get(app.name).oem_micro_app_id;
|
|
100
100
|
const baseUrl = `/apps/${oem_micro_app_id}`;
|
|
101
101
|
result.saas_id_info_list.push({
|
|
102
102
|
oem_micro_app_id: oem_micro_app_id,
|
|
103
|
-
universal_id:
|
|
103
|
+
universal_id: '',
|
|
104
104
|
});
|
|
105
105
|
const micoApp = consturctApp(manifest, oem_micro_app_id, baseUrl, lang, microPort, app.name);
|
|
106
106
|
const entryInfo = consturctEntry(manifest, oem_micro_app_id, entry_id, baseUrl, lang, dir);
|
|
@@ -123,7 +123,7 @@ function mockSaasInfo(app, microPort) {
|
|
|
123
123
|
const oem_micro_app_id = manifest.universalId;
|
|
124
124
|
const baseUrl = `/apps/${oem_micro_app_id}`;
|
|
125
125
|
const app = consturctApp(manifest, oem_micro_app_id, baseUrl, lang, microPort);
|
|
126
|
-
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, '');
|
|
127
127
|
const permission = consturctPermissions();
|
|
128
128
|
res.send({
|
|
129
129
|
code: null,
|
|
@@ -131,10 +131,10 @@ function mockSaasInfo(app, microPort) {
|
|
|
131
131
|
msg: null,
|
|
132
132
|
result: {
|
|
133
133
|
apps: [app],
|
|
134
|
-
entry_info: { entries: [entryInfo], entry_mode:
|
|
134
|
+
entry_info: { entries: [entryInfo], entry_mode: 'normal' },
|
|
135
135
|
permissions: { [oem_micro_app_id]: permission },
|
|
136
136
|
saas_id_info_list: [
|
|
137
|
-
{ oem_micro_app_id: oem_micro_app_id, universal_id:
|
|
137
|
+
{ oem_micro_app_id: oem_micro_app_id, universal_id: '' },
|
|
138
138
|
],
|
|
139
139
|
},
|
|
140
140
|
success: true,
|
|
@@ -145,16 +145,22 @@ function mockSaasInfo(app, microPort) {
|
|
|
145
145
|
}
|
|
146
146
|
exports.default = mockSaasInfo;
|
|
147
147
|
function consturctEntry(manifest, oem_micro_app_id, entry_id, baseUrl, lang, dir) {
|
|
148
|
-
|
|
148
|
+
let fakeMenu;
|
|
149
|
+
if (dir === 'iot-suite-device') {
|
|
150
|
+
fakeMenu = (0, micro_utils_1.getFakeMenu)(Object.assign(Object.assign({}, manifest), { entries: [] }), dir);
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
fakeMenu = (0, micro_utils_1.getFakeMenu)(manifest, dir);
|
|
154
|
+
}
|
|
149
155
|
let stack = [fakeMenu];
|
|
150
156
|
while (stack.length) {
|
|
151
157
|
const menu = stack.shift();
|
|
152
158
|
menu.oem_micro_app_id = oem_micro_app_id;
|
|
153
159
|
menu.entry_id = entry_id;
|
|
154
160
|
//@ts-ignore
|
|
155
|
-
menu.entry_name_zh = pickText(menu.entry_name,
|
|
161
|
+
menu.entry_name_zh = pickText(menu.entry_name, 'zh');
|
|
156
162
|
//@ts-ignore
|
|
157
|
-
menu.entry_name_en = pickText(menu.entry_name,
|
|
163
|
+
menu.entry_name_en = pickText(menu.entry_name, 'en');
|
|
158
164
|
//@ts-ignore
|
|
159
165
|
menu.entry_name = pickText(menu.entry_name, lang);
|
|
160
166
|
//@ts-ignore
|
|
@@ -164,7 +170,7 @@ function consturctEntry(manifest, oem_micro_app_id, entry_id, baseUrl, lang, dir
|
|
|
164
170
|
stack.push(...menu.sub_entry_list);
|
|
165
171
|
}
|
|
166
172
|
menu.icon =
|
|
167
|
-
|
|
173
|
+
'https://images.tuyacn.com/rms-static/5d202fa0-e909-11eb-815d-e39234ce96ff-1626751199130.png?tyName=space-manage.png';
|
|
168
174
|
}
|
|
169
175
|
return fakeMenu;
|
|
170
176
|
}
|
|
@@ -172,13 +178,13 @@ function consturctApp(manifest, oem_micro_app_id, baseUrl, lang, port, code) {
|
|
|
172
178
|
const packageInfo = (0, micro_utils_1.getPackage)();
|
|
173
179
|
return {
|
|
174
180
|
active_rule: baseUrl,
|
|
175
|
-
dependencies: [
|
|
181
|
+
dependencies: [''],
|
|
176
182
|
ext_info: null,
|
|
177
183
|
micro_app_code: code || `${packageInfo.name}`,
|
|
178
184
|
micro_app_name: code ? `${code}-dev` : `${packageInfo.name}-dev`,
|
|
179
|
-
micro_app_version:
|
|
185
|
+
micro_app_version: '0.0.0-x',
|
|
180
186
|
oem_micro_app_id,
|
|
181
|
-
resource: `http://localhost:${port}/${code ||
|
|
187
|
+
resource: `http://localhost:${port}/${code || 'index'}.html`,
|
|
182
188
|
schema: null,
|
|
183
189
|
universal_id: manifest.universalId,
|
|
184
190
|
isAuth: true,
|
|
@@ -190,15 +196,15 @@ function consturctPermissions() {
|
|
|
190
196
|
return mockPermissions.map((code) => ({ permission_group: code }));
|
|
191
197
|
}
|
|
192
198
|
function pickText(texts, lang) {
|
|
193
|
-
return lang ===
|
|
199
|
+
return lang === 'en' ? texts[1] : texts[0];
|
|
194
200
|
}
|
|
195
201
|
function parseCookie(cookie, key) {
|
|
196
|
-
const cookies = (cookie ||
|
|
202
|
+
const cookies = (cookie || '').split(';');
|
|
197
203
|
for (let cookieItem of cookies) {
|
|
198
|
-
const [cookieKey, value] = cookieItem.split(
|
|
204
|
+
const [cookieKey, value] = cookieItem.split('=');
|
|
199
205
|
if (cookieKey.trim() === key) {
|
|
200
206
|
return value;
|
|
201
207
|
}
|
|
202
208
|
}
|
|
203
|
-
return
|
|
209
|
+
return '';
|
|
204
210
|
}
|
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.12",
|
|
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.12",
|
|
27
|
+
"@tuya-sat/micro-dev-proxy": "3.0.27-beta.12",
|
|
28
|
+
"@tuya-sat/micro-utils": "3.0.27-beta.12",
|
|
29
29
|
"@types/kill-port": "^2.0.0",
|
|
30
30
|
"babel-loader": "8.2.4",
|
|
31
31
|
"babel-plugin-import": "1.13.3",
|