@tuya-sat/micro-script 3.0.27-beta.9 → 3.0.28
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/paths.js +4 -1
- package/dist/config/webpack.common.js +2 -1
- package/dist/module/bundleServer.js +2 -5
- package/dist/module/main/fakeSaas.js +11 -9
- package/dist/module/main/fakeSaasInfo.d.ts +1 -1
- package/dist/module/main/fakeSaasInfo.js +37 -27
- package/dist/module/main/staticMain.js +5 -4
- package/dist/module/mainServer.js +1 -1
- package/dist/module/proxy.d.ts +1 -1
- package/dist/module/proxy.js +12 -3
- package/dist/scripts/build.js +6 -3
- package/dist/scripts/start.js +1 -5
- package/dist/scripts/startInMain.js +1 -2
- package/package.json +4 -4
package/dist/config/paths.js
CHANGED
|
@@ -4,7 +4,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const path_1 = __importDefault(require("path"));
|
|
7
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
7
8
|
const cwd = process.cwd();
|
|
9
|
+
const spaHtmlPath = path_1.default.resolve(cwd, "public/index.html");
|
|
10
|
+
const spaEjsPath = path_1.default.resolve(cwd, "public/index.ejs");
|
|
8
11
|
exports.default = {
|
|
9
12
|
microConfig: path_1.default.resolve(cwd, "micro.config.js"),
|
|
10
13
|
dist: path_1.default.resolve(cwd, "dist/"),
|
|
@@ -12,7 +15,7 @@ exports.default = {
|
|
|
12
15
|
appSrc: path_1.default.resolve(cwd, "src/"),
|
|
13
16
|
mockDir: path_1.default.resolve(cwd, "mock/index.json"),
|
|
14
17
|
publicDir: path_1.default.resolve(cwd, "public/"),
|
|
15
|
-
spaHtml:
|
|
18
|
+
spaHtml: fs_extra_1.default.existsSync(spaEjsPath) ? spaEjsPath : spaHtmlPath,
|
|
16
19
|
manifest: path_1.default.resolve(cwd, "manifest.json"),
|
|
17
20
|
vueTsEntryFile: path_1.default.resolve(cwd, "src/index.ts"),
|
|
18
21
|
vueJsEntryFile: path_1.default.resolve(cwd, "src/index.js"),
|
|
@@ -174,10 +174,11 @@ function getCommonConfig({ isDev, isBuild, }) {
|
|
|
174
174
|
cacheGroups: Object.assign(Object.assign({}, (enableThemeCompile
|
|
175
175
|
? {
|
|
176
176
|
vendorCss: {
|
|
177
|
-
test: /([\\/]node_modules[\\/][\s\S]+(\.less|\.css)$)|([\\/]src[\\/]styles[\\/]global\.less)/,
|
|
177
|
+
test: /([\\/]node_modules[\\/][\s\S]+(\.less|\.css)$)|(([\\/]src)?[\\/]styles[\\/]global\.less)/,
|
|
178
178
|
name: 'light',
|
|
179
179
|
chunks: 'all',
|
|
180
180
|
priority: 4,
|
|
181
|
+
minSize: 0,
|
|
181
182
|
},
|
|
182
183
|
}
|
|
183
184
|
: {})), { vendor: {
|
|
@@ -27,7 +27,6 @@ exports.runBundleServer = exports.createServerCompiler = void 0;
|
|
|
27
27
|
const webpack_1 = __importDefault(require("webpack"));
|
|
28
28
|
const webpack_dev_server_1 = __importDefault(require("webpack-dev-server"));
|
|
29
29
|
const ora_1 = __importDefault(require("ora"));
|
|
30
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
31
30
|
const paths_1 = __importDefault(require("../config/paths"));
|
|
32
31
|
const webpack_config_1 = __importDefault(require("../config/webpack.config"));
|
|
33
32
|
const options_1 = __importDefault(require("./options"));
|
|
@@ -67,11 +66,9 @@ function runBundleServer({ port, compiler, internalDevConfig = {}, }) {
|
|
|
67
66
|
console.log(`compiled time ~${endTime - startTime}ms`);
|
|
68
67
|
});
|
|
69
68
|
//临时提示
|
|
70
|
-
compiler.hooks.done.tap('once-tip', (0, onceFactory_1.onceFactory)(() => {
|
|
71
|
-
console.log(chalk_1.default.yellow(`Tip: 如果HMR失效且保存文件时造成多次compile,请考虑调高aggregateTimeout参数(可以尝试100)`));
|
|
72
|
-
}));
|
|
69
|
+
compiler.hooks.done.tap('once-tip', (0, onceFactory_1.onceFactory)(() => { }));
|
|
73
70
|
yield server.start();
|
|
74
|
-
console.log('
|
|
71
|
+
console.log('\n The local application server has started');
|
|
75
72
|
});
|
|
76
73
|
}
|
|
77
74
|
exports.runBundleServer = runBundleServer;
|
|
@@ -42,20 +42,21 @@ const fs = __importStar(require("fs-extra"));
|
|
|
42
42
|
const path = __importStar(require("path"));
|
|
43
43
|
function parse_SDF_CONFIG(html) {
|
|
44
44
|
var _a;
|
|
45
|
-
const REGEX = /(?<=window._SDF_CONFIG=).*?(
|
|
45
|
+
const REGEX = /(?<=window._SDF_CONFIG=).*?(?=(;|<\/script>))/;
|
|
46
46
|
return ((_a = REGEX.exec(html)) === null || _a === void 0 ? void 0 : _a[0]) || '';
|
|
47
47
|
}
|
|
48
48
|
function parse_SDF(html) {
|
|
49
49
|
var _a;
|
|
50
|
-
const REGEX = /(?<=window._SDF=).*?}(
|
|
50
|
+
const REGEX = /(?<=window._SDF=).*?}(?=(;|<\/script>))/;
|
|
51
51
|
return ((_a = REGEX.exec(html)) === null || _a === void 0 ? void 0 : _a[0]) || '';
|
|
52
52
|
}
|
|
53
53
|
function parse__MAIN_APP_PUBLIC_PATH(html) {
|
|
54
54
|
var _a;
|
|
55
|
-
const REGEX = /(?<=window.__MAIN_APP_PUBLIC_PATH=).*?(
|
|
55
|
+
const REGEX = /(?<=window.__MAIN_APP_PUBLIC_PATH=).*?(?=(;|<\/script>))/;
|
|
56
56
|
return ((_a = REGEX.exec(html)) === null || _a === void 0 ? void 0 : _a[0]) || '';
|
|
57
57
|
}
|
|
58
58
|
function getFakeSaas(config) {
|
|
59
|
+
var _a;
|
|
59
60
|
return __awaiter(this, void 0, void 0, function* () {
|
|
60
61
|
if (!config.target) {
|
|
61
62
|
console.log(chalk_1.default.red('没有配置target'));
|
|
@@ -68,6 +69,7 @@ function getFakeSaas(config) {
|
|
|
68
69
|
base: '',
|
|
69
70
|
env: '',
|
|
70
71
|
region: '',
|
|
72
|
+
isOpenCode: true,
|
|
71
73
|
saas: {
|
|
72
74
|
background_image: 'https://images.tuyacn.com/rms-static/537a3fd0-1b5a-11ec-b7af-2d39f353debc-1632283530317.jpg?tyName=login.jpg',
|
|
73
75
|
charge_status: 'TRIAL',
|
|
@@ -81,18 +83,18 @@ function getFakeSaas(config) {
|
|
|
81
83
|
label: '',
|
|
82
84
|
legal_notice: 'https://ruomu-abc-001.fast-cn.wgine.com/policies/legal',
|
|
83
85
|
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:
|
|
86
|
+
privacy_policy: 'https://ruomu-abc-001.fast-cn.wgine.com/policies/privacy',
|
|
87
|
+
service_terms: 'https://ruomu-abc-001.fast-cn.wgine.com/policies/service',
|
|
86
88
|
supported_language: { en: 'English', zh: '简体中文' },
|
|
87
89
|
tenant_register_support: false,
|
|
88
|
-
tenant_type:
|
|
89
|
-
title:
|
|
90
|
+
tenant_type: 'SINGLE_TENANT',
|
|
91
|
+
title: '物联网开放平台',
|
|
90
92
|
},
|
|
91
93
|
},
|
|
92
94
|
_SDF_CONFIG: {},
|
|
93
95
|
__MAIN_APP_PUBLIC_PATH: 'https://static1.tuyacn.com/static/sdf-main-app/0.0.0-123/',
|
|
94
96
|
};
|
|
95
|
-
Object.keys(saasInfo).forEach(key => {
|
|
97
|
+
Object.keys(saasInfo).forEach((key) => {
|
|
96
98
|
saas._SDF.saas[key] = saasInfo[key] ? saasInfo[key] : saas._SDF.saas[key];
|
|
97
99
|
});
|
|
98
100
|
return saas;
|
|
@@ -104,7 +106,7 @@ function getFakeSaas(config) {
|
|
|
104
106
|
const __MAIN_APP_PUBLIC_PATH = parse__MAIN_APP_PUBLIC_PATH(data);
|
|
105
107
|
const saas = {
|
|
106
108
|
_SDF_CONFIG: JSON.parse(_SDF_CONFIG),
|
|
107
|
-
_SDF: JSON.parse(_SDF),
|
|
109
|
+
_SDF: Object.assign(Object.assign({}, JSON.parse(_SDF)), { isOpenCode: !!((_a = process.env) === null || _a === void 0 ? void 0 : _a.IS_OPEN_CODE) }),
|
|
108
110
|
__MAIN_APP_PUBLIC_PATH: JSON.parse(__MAIN_APP_PUBLIC_PATH),
|
|
109
111
|
};
|
|
110
112
|
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,26 @@ 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
|
+
var _a;
|
|
149
|
+
let fakeMenu;
|
|
150
|
+
if (dir === 'apps/iot-suite-device') {
|
|
151
|
+
fakeMenu = (0, micro_utils_1.getFakeMenu)(Object.assign(Object.assign({}, manifest), { entries: [] }), dir);
|
|
152
|
+
}
|
|
153
|
+
else if ((_a = process.env) === null || _a === void 0 ? void 0 : _a.IS_OPEN_CODE) {
|
|
154
|
+
fakeMenu = (0, micro_utils_1.getFakeMenu)(Object.assign(Object.assign({}, manifest), { entries: manifest === null || manifest === void 0 ? void 0 : manifest.entries.filter((item) => item.type !== 'DynamicMenu') }), dir);
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
fakeMenu = (0, micro_utils_1.getFakeMenu)(manifest, dir);
|
|
158
|
+
}
|
|
149
159
|
let stack = [fakeMenu];
|
|
150
160
|
while (stack.length) {
|
|
151
161
|
const menu = stack.shift();
|
|
152
162
|
menu.oem_micro_app_id = oem_micro_app_id;
|
|
153
163
|
menu.entry_id = entry_id;
|
|
154
164
|
//@ts-ignore
|
|
155
|
-
menu.entry_name_zh = pickText(menu.entry_name,
|
|
165
|
+
menu.entry_name_zh = pickText(menu.entry_name, 'zh');
|
|
156
166
|
//@ts-ignore
|
|
157
|
-
menu.entry_name_en = pickText(menu.entry_name,
|
|
167
|
+
menu.entry_name_en = pickText(menu.entry_name, 'en');
|
|
158
168
|
//@ts-ignore
|
|
159
169
|
menu.entry_name = pickText(menu.entry_name, lang);
|
|
160
170
|
//@ts-ignore
|
|
@@ -164,7 +174,7 @@ function consturctEntry(manifest, oem_micro_app_id, entry_id, baseUrl, lang, dir
|
|
|
164
174
|
stack.push(...menu.sub_entry_list);
|
|
165
175
|
}
|
|
166
176
|
menu.icon =
|
|
167
|
-
|
|
177
|
+
'https://images.tuyacn.com/rms-static/5d202fa0-e909-11eb-815d-e39234ce96ff-1626751199130.png?tyName=space-manage.png';
|
|
168
178
|
}
|
|
169
179
|
return fakeMenu;
|
|
170
180
|
}
|
|
@@ -172,13 +182,13 @@ function consturctApp(manifest, oem_micro_app_id, baseUrl, lang, port, code) {
|
|
|
172
182
|
const packageInfo = (0, micro_utils_1.getPackage)();
|
|
173
183
|
return {
|
|
174
184
|
active_rule: baseUrl,
|
|
175
|
-
dependencies: [
|
|
185
|
+
dependencies: [''],
|
|
176
186
|
ext_info: null,
|
|
177
187
|
micro_app_code: code || `${packageInfo.name}`,
|
|
178
188
|
micro_app_name: code ? `${code}-dev` : `${packageInfo.name}-dev`,
|
|
179
|
-
micro_app_version:
|
|
189
|
+
micro_app_version: '0.0.0-x',
|
|
180
190
|
oem_micro_app_id,
|
|
181
|
-
resource: `http://localhost:${port}/${code ||
|
|
191
|
+
resource: `http://localhost:${port}/${code || 'index'}.html`,
|
|
182
192
|
schema: null,
|
|
183
193
|
universal_id: manifest.universalId,
|
|
184
194
|
isAuth: true,
|
|
@@ -190,15 +200,15 @@ function consturctPermissions() {
|
|
|
190
200
|
return mockPermissions.map((code) => ({ permission_group: code }));
|
|
191
201
|
}
|
|
192
202
|
function pickText(texts, lang) {
|
|
193
|
-
return lang ===
|
|
203
|
+
return lang === 'en' ? texts[1] : texts[0];
|
|
194
204
|
}
|
|
195
205
|
function parseCookie(cookie, key) {
|
|
196
|
-
const cookies = (cookie ||
|
|
206
|
+
const cookies = (cookie || '').split(';');
|
|
197
207
|
for (let cookieItem of cookies) {
|
|
198
|
-
const [cookieKey, value] = cookieItem.split(
|
|
208
|
+
const [cookieKey, value] = cookieItem.split('=');
|
|
199
209
|
if (cookieKey.trim() === key) {
|
|
200
210
|
return value;
|
|
201
211
|
}
|
|
202
212
|
}
|
|
203
|
-
return
|
|
213
|
+
return '';
|
|
204
214
|
}
|
|
@@ -45,7 +45,7 @@ const fs = __importStar(require("fs-extra"));
|
|
|
45
45
|
const path = __importStar(require("path"));
|
|
46
46
|
function parse_SDF(html) {
|
|
47
47
|
var _a;
|
|
48
|
-
const REGEX = /(?<=window._SDF=).*?}(
|
|
48
|
+
const REGEX = /(?<=window._SDF=).*?}(?=(;|<\/script>))/;
|
|
49
49
|
return ((_a = REGEX.exec(html)) === null || _a === void 0 ? void 0 : _a[0]) || '';
|
|
50
50
|
}
|
|
51
51
|
function staticMain(app, debuggerConfig, microPort) {
|
|
@@ -126,9 +126,10 @@ function insertScript($, debuggerConfig) {
|
|
|
126
126
|
$('head').prepend('<link rel="icon" />');
|
|
127
127
|
$favicon = $('link[rel="icon"]');
|
|
128
128
|
}
|
|
129
|
-
const favicon = (saasInfo === null || saasInfo === void 0 ? void 0 : saasInfo.favicon)
|
|
130
|
-
|
|
131
|
-
.
|
|
129
|
+
const favicon = (saasInfo === null || saasInfo === void 0 ? void 0 : saasInfo.favicon)
|
|
130
|
+
? saasInfo.favicon
|
|
131
|
+
: 'https://images.tuyacn.com/rms-static/ae9ba1b0-41d4-11ec-89bb-d7b7de210e4b-1636514225995.png?tyName=favicon.png';
|
|
132
|
+
$favicon.attr('href', favicon);
|
|
132
133
|
}
|
|
133
134
|
// 本地开发态多语言剥离多语言平台,走本地多语言兜底逻辑
|
|
134
135
|
delete _SDF.saas.saas_locales;
|
package/dist/module/proxy.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Application } from
|
|
1
|
+
import { Application } from 'express';
|
|
2
2
|
export default function useProxy(app: Application): void;
|
package/dist/module/proxy.js
CHANGED
|
@@ -4,11 +4,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const paths_1 = __importDefault(require("../config/paths"));
|
|
7
|
+
const http_proxy_middleware_1 = require("http-proxy-middleware");
|
|
7
8
|
function useProxy(app) {
|
|
8
|
-
const isProxy = process.env.MICRO_PROXY ===
|
|
9
|
+
const isProxy = process.env.MICRO_PROXY === 'true';
|
|
10
|
+
const { debuggerConfig } = require(paths_1.default.microConfig);
|
|
11
|
+
const customApiUrl = debuggerConfig === null || debuggerConfig === void 0 ? void 0 : debuggerConfig.customApiUrl;
|
|
12
|
+
if (customApiUrl) {
|
|
13
|
+
app.use('/custom-api', (0, http_proxy_middleware_1.createProxyMiddleware)({
|
|
14
|
+
target: customApiUrl,
|
|
15
|
+
pathRewrite: { '^/custom-api': '' },
|
|
16
|
+
changeOrigin: true,
|
|
17
|
+
}));
|
|
18
|
+
}
|
|
9
19
|
if (isProxy) {
|
|
10
|
-
const createProxy = require(
|
|
11
|
-
const { debuggerConfig } = require(paths_1.default.microConfig);
|
|
20
|
+
const createProxy = require('@tuya-sat/micro-dev-proxy').default;
|
|
12
21
|
createProxy(debuggerConfig)(app);
|
|
13
22
|
}
|
|
14
23
|
}
|
package/dist/scripts/build.js
CHANGED
|
@@ -17,7 +17,6 @@ const chalk_1 = __importDefault(require("chalk"));
|
|
|
17
17
|
const ora_1 = __importDefault(require("ora"));
|
|
18
18
|
const webpack_config_1 = __importDefault(require("../config/webpack.config"));
|
|
19
19
|
const template_1 = __importDefault(require("../template"));
|
|
20
|
-
const apis_1 = __importDefault(require("../apis"));
|
|
21
20
|
const paths_1 = __importDefault(require("../config/paths"));
|
|
22
21
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
23
22
|
const path_1 = __importDefault(require("path"));
|
|
@@ -27,7 +26,7 @@ let { debuggerConfig: { isMainApp }, } = require(paths_1.default.microConfig);
|
|
|
27
26
|
const config = (0, webpack_config_1.default)();
|
|
28
27
|
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
29
28
|
yield (0, template_1.default)();
|
|
30
|
-
|
|
29
|
+
// await apis();
|
|
31
30
|
(0, webpack_1.default)(config).run((err, stats) => {
|
|
32
31
|
if (err) {
|
|
33
32
|
spinner.fail();
|
|
@@ -48,7 +47,11 @@ const config = (0, webpack_config_1.default)();
|
|
|
48
47
|
const files = fs_extra_1.default.readdirSync(path_1.default.join(process.cwd(), 'dist/static/img')) || [];
|
|
49
48
|
const manifest = fs_extra_1.default.readJSONSync(path_1.default.join(process.cwd(), 'dist/manifest.json'));
|
|
50
49
|
const result = files.reduce((acc, file) => {
|
|
51
|
-
|
|
50
|
+
if (file) {
|
|
51
|
+
const key = file.split('.')[0];
|
|
52
|
+
acc[key] = `static/img/${file}`;
|
|
53
|
+
}
|
|
54
|
+
return acc;
|
|
52
55
|
}, {});
|
|
53
56
|
fs_extra_1.default.writeJSONSync(path_1.default.join(process.cwd(), 'dist/manifest.json'), Object.assign(Object.assign({}, manifest), result));
|
|
54
57
|
}
|
package/dist/scripts/start.js
CHANGED
|
@@ -12,20 +12,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
16
15
|
const portfinder_1 = __importDefault(require("portfinder"));
|
|
17
16
|
const mock_1 = __importDefault(require("../module/mock"));
|
|
18
17
|
const bundleServer_1 = require("../module/bundleServer");
|
|
19
18
|
const proxy_1 = __importDefault(require("../module/proxy"));
|
|
20
19
|
const template_1 = __importDefault(require("../template"));
|
|
21
|
-
const apis_1 = __importDefault(require("../apis"));
|
|
22
20
|
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
23
21
|
yield (0, template_1.default)();
|
|
24
|
-
|
|
22
|
+
// await apis();
|
|
25
23
|
let defaultPort = 9000;
|
|
26
|
-
console.log(chalk_1.default.yellow('如果是pc端的微应用调试,请勿使用该命令,考虑使用`start --main`或`start --main --proxy`'));
|
|
27
24
|
//检测端口占用情况
|
|
28
|
-
console.log('process.env.PROT', process.env.PROT);
|
|
29
25
|
if (process.env.PROT) {
|
|
30
26
|
const compiler = (0, bundleServer_1.createServerCompiler)();
|
|
31
27
|
(0, bundleServer_1.runBundleServer)({
|
|
@@ -18,10 +18,9 @@ const mainServer_1 = __importDefault(require("../module/mainServer"));
|
|
|
18
18
|
const bundleServer_1 = require("../module/bundleServer");
|
|
19
19
|
const kill_port_1 = __importDefault(require("kill-port"));
|
|
20
20
|
const template_1 = __importDefault(require("../template"));
|
|
21
|
-
const apis_1 = __importDefault(require("../apis"));
|
|
22
21
|
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
23
22
|
yield (0, template_1.default)();
|
|
24
|
-
|
|
23
|
+
// await apis();
|
|
25
24
|
let defaultPort = 9000;
|
|
26
25
|
//检测端口占用情况
|
|
27
26
|
const bundledServerPort = yield portfinder_1.default.getPortPromise({
|
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.28",
|
|
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
|
-
"@tuya-sat/micro-dev-proxy": "3.0.
|
|
28
|
-
"@tuya-sat/micro-utils": "3.0.
|
|
26
|
+
"@tuya-sat/micro-dev-loader": "3.0.28",
|
|
27
|
+
"@tuya-sat/micro-dev-proxy": "3.0.28",
|
|
28
|
+
"@tuya-sat/micro-utils": "3.0.28",
|
|
29
29
|
"@types/kill-port": "^2.0.0",
|
|
30
30
|
"babel-loader": "8.2.4",
|
|
31
31
|
"babel-plugin-import": "1.13.3",
|