@tuya-sat/micro-script 3.2.8 → 3.2.10
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.
|
@@ -31,6 +31,7 @@ const paths_1 = __importDefault(require("../config/paths"));
|
|
|
31
31
|
const webpack_config_1 = __importDefault(require("../config/webpack.config"));
|
|
32
32
|
const options_1 = __importDefault(require("./options"));
|
|
33
33
|
const onceFactory_1 = require("../utils/onceFactory");
|
|
34
|
+
const promiser_1 = require("../utils/promiser");
|
|
34
35
|
function createServerCompiler() {
|
|
35
36
|
const config = Object.assign(Object.assign({}, (0, webpack_config_1.default)()), {
|
|
36
37
|
//下面所有配置都是为了精简terminal输出
|
|
@@ -43,6 +44,7 @@ exports.createServerCompiler = createServerCompiler;
|
|
|
43
44
|
function runBundleServer({ port, compiler, internalDevConfig = {}, }) {
|
|
44
45
|
return __awaiter(this, void 0, void 0, function* () {
|
|
45
46
|
const spinner = (0, ora_1.default)(`starting dev server in ${port} port`).start();
|
|
47
|
+
const { waiting, resolve } = (0, promiser_1.promiser)();
|
|
46
48
|
const { devServer = (value) => value } = require(paths_1.default.microConfig);
|
|
47
49
|
const { setupMiddlewares: startDevSetupMiddlewares } = internalDevConfig, restServerConfig = __rest(internalDevConfig, ["setupMiddlewares"]);
|
|
48
50
|
const server = new webpack_dev_server_1.default(devServer(Object.assign({ hot: true, liveReload: false, port, headers: {
|
|
@@ -63,11 +65,13 @@ function runBundleServer({ port, compiler, internalDevConfig = {}, }) {
|
|
|
63
65
|
});
|
|
64
66
|
compiler.hooks.done.tap('MyPlugin', ({ endTime, startTime }) => {
|
|
65
67
|
spinner.isSpinning && spinner.succeed();
|
|
68
|
+
resolve();
|
|
66
69
|
console.log(`compiled time ~${endTime - startTime}ms`);
|
|
67
70
|
});
|
|
68
71
|
//临时提示
|
|
69
72
|
compiler.hooks.done.tap('once-tip', (0, onceFactory_1.onceFactory)(() => { }));
|
|
70
73
|
yield server.start();
|
|
74
|
+
yield waiting;
|
|
71
75
|
console.log('\n The local application server has started');
|
|
72
76
|
});
|
|
73
77
|
}
|
|
@@ -114,7 +114,7 @@ function getFakeSaas(config) {
|
|
|
114
114
|
const __MAIN_APP_PUBLIC_PATH = parse__MAIN_APP_PUBLIC_PATH(data);
|
|
115
115
|
const saas = {
|
|
116
116
|
_SDF_CONFIG: JSON.parse(_SDF_CONFIG),
|
|
117
|
-
_SDF: Object.assign(Object.assign({}, JSON.parse(_SDF)), { isOpenCode: !!((_a = process.env) === null || _a === void 0 ? void 0 : _a.IS_OPEN_CODE) }),
|
|
117
|
+
_SDF: Object.assign(Object.assign({}, JSON.parse(_SDF)), { isOpenCode: !!((_a = process.env) === null || _a === void 0 ? void 0 : _a.IS_OPEN_CODE), __THIS_IS_LOCAL_DEVELOPMENT_MODE__: true }),
|
|
118
118
|
__MAIN_APP_PUBLIC_PATH: JSON.parse(__MAIN_APP_PUBLIC_PATH),
|
|
119
119
|
};
|
|
120
120
|
return saas;
|
|
@@ -3,5 +3,5 @@ import { AppProxy } from '@tuya-sat/micro-dev-proxy';
|
|
|
3
3
|
interface IApp extends Express {
|
|
4
4
|
__appProxy__?: AppProxy;
|
|
5
5
|
}
|
|
6
|
-
export default function mockSaasInfo(app: IApp, microPort: number):
|
|
6
|
+
export default function mockSaasInfo(app: IApp, microPort: number): Promise<IApp>;
|
|
7
7
|
export {};
|
|
@@ -44,78 +44,40 @@ const path = __importStar(require("path"));
|
|
|
44
44
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
45
45
|
const utils_1 = require("../../utils");
|
|
46
46
|
function mockSaasInfo(app, microPort) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
app.get('/api/saas-info', (req, res) => {
|
|
58
|
-
const lang = 'zh';
|
|
59
|
-
const result = {
|
|
60
|
-
apps: [],
|
|
61
|
-
entry_info: { entries: [], entry_mode: 'normal' },
|
|
62
|
-
permissions: {},
|
|
63
|
-
saas_id_info_list: [],
|
|
64
|
-
};
|
|
65
|
-
dirs.forEach((dir) => {
|
|
66
|
-
const entry_id = idsMap.get(dir).entry_id;
|
|
67
|
-
const manifest = fs_extra_1.default.readJSONSync(path.join(process.cwd(), 'apps', dir, 'manifest.json'), 'utf-8');
|
|
68
|
-
const oem_micro_app_id = idsMap.get(dir).oem_micro_app_id;
|
|
69
|
-
const baseUrl = `/apps/${oem_micro_app_id}`;
|
|
70
|
-
result.saas_id_info_list.push({
|
|
71
|
-
oem_micro_app_id: oem_micro_app_id,
|
|
72
|
-
universal_id: '',
|
|
73
|
-
});
|
|
74
|
-
const appConfig = fs_extra_1.default.readJSONSync(path.join(process.cwd(), 'node_modules', '.micro', 'app.config.json'));
|
|
75
|
-
const micoApp = consturctApp(manifest, oem_micro_app_id, baseUrl, lang, appConfig[dir]);
|
|
76
|
-
const entryInfo = consturctEntry(manifest, oem_micro_app_id, entry_id, baseUrl, lang, `apps/${dir}`);
|
|
77
|
-
const permission = (manifest === null || manifest === void 0 ? void 0 : manifest.privileges.map((item) => {
|
|
78
|
-
return { permission_group: item.code };
|
|
79
|
-
})) || [];
|
|
80
|
-
result.apps.push(micoApp);
|
|
81
|
-
result.entry_info.entries.push(entryInfo);
|
|
82
|
-
result.permissions[oem_micro_app_id] = permission;
|
|
83
|
-
});
|
|
84
|
-
res.send({
|
|
85
|
-
code: null,
|
|
86
|
-
errorMsg: null,
|
|
87
|
-
msg: null,
|
|
88
|
-
result,
|
|
89
|
-
success: true,
|
|
47
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
+
let { multiApps, microApps, debuggerConfig: { isMainApp, target }, } = require(paths_1.default.microConfig);
|
|
49
|
+
const idsMap = new Map();
|
|
50
|
+
const expressApp = app;
|
|
51
|
+
multiApps = (0, utils_1.processMultiApps)(multiApps);
|
|
52
|
+
if (isMainApp && fs_extra_1.default.existsSync(path.join(process.cwd(), 'apps'))) {
|
|
53
|
+
const dirs = ((microApps === null || microApps === void 0 ? void 0 : microApps.length) > 0 && microApps) ||
|
|
54
|
+
fs_extra_1.default.readdirSync(path.join(process.cwd(), 'apps'));
|
|
55
|
+
dirs === null || dirs === void 0 ? void 0 : dirs.forEach((dir) => {
|
|
56
|
+
idsMap.set(dir, { entry_id: (0, uuid_1.v4)(), oem_micro_app_id: (0, uid_1.uid)(16) });
|
|
90
57
|
});
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
if (!isMainApp) {
|
|
94
|
-
multiApps === null || multiApps === void 0 ? void 0 : multiApps.forEach((app) => {
|
|
95
|
-
idsMap.set(app.name, { entry_id: (0, uuid_1.v4)(), oem_micro_app_id: (0, uid_1.uid)(16) });
|
|
96
|
-
});
|
|
97
|
-
app.get('/api/saas-info', (req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
98
|
-
const lang = parseCookie(req.headers['cookie'], 'main-i18next');
|
|
99
|
-
if ((0, utils_1.isMonorepo)() || (multiApps && multiApps.length > 0)) {
|
|
58
|
+
return app.get('/api/saas-info', (req, res) => {
|
|
59
|
+
const lang = 'zh';
|
|
100
60
|
const result = {
|
|
101
61
|
apps: [],
|
|
102
62
|
entry_info: { entries: [], entry_mode: 'normal' },
|
|
103
63
|
permissions: {},
|
|
104
64
|
saas_id_info_list: [],
|
|
105
65
|
};
|
|
106
|
-
|
|
107
|
-
const entry_id = idsMap.get(
|
|
108
|
-
const
|
|
109
|
-
const
|
|
110
|
-
const oem_micro_app_id = idsMap.get(app.name).oem_micro_app_id;
|
|
66
|
+
dirs.forEach((dir) => {
|
|
67
|
+
const entry_id = idsMap.get(dir).entry_id;
|
|
68
|
+
const manifest = fs_extra_1.default.readJSONSync(path.join(process.cwd(), 'apps', dir, 'manifest.json'), 'utf-8');
|
|
69
|
+
const oem_micro_app_id = idsMap.get(dir).oem_micro_app_id;
|
|
111
70
|
const baseUrl = `/apps/${oem_micro_app_id}`;
|
|
112
71
|
result.saas_id_info_list.push({
|
|
113
72
|
oem_micro_app_id: oem_micro_app_id,
|
|
114
73
|
universal_id: '',
|
|
115
74
|
});
|
|
116
|
-
const
|
|
117
|
-
const
|
|
118
|
-
const
|
|
75
|
+
const appConfig = fs_extra_1.default.readJSONSync(path.join(process.cwd(), 'node_modules', '.micro', 'app.config.json'));
|
|
76
|
+
const micoApp = consturctApp(manifest, oem_micro_app_id, baseUrl, lang, appConfig[dir]);
|
|
77
|
+
const entryInfo = consturctEntry(manifest, oem_micro_app_id, entry_id, baseUrl, lang, `apps/${dir}`);
|
|
78
|
+
const permission = (manifest === null || manifest === void 0 ? void 0 : manifest.privileges.map((item) => {
|
|
79
|
+
return { permission_group: item.code };
|
|
80
|
+
})) || [];
|
|
119
81
|
result.apps.push(micoApp);
|
|
120
82
|
result.entry_info.entries.push(entryInfo);
|
|
121
83
|
result.permissions[oem_micro_app_id] = permission;
|
|
@@ -127,46 +89,86 @@ function mockSaasInfo(app, microPort) {
|
|
|
127
89
|
result,
|
|
128
90
|
success: true,
|
|
129
91
|
});
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
apps
|
|
159
|
-
entry_info
|
|
160
|
-
permissions
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
if (!isMainApp) {
|
|
95
|
+
multiApps === null || multiApps === void 0 ? void 0 : multiApps.forEach((app) => {
|
|
96
|
+
idsMap.set(app.name, { entry_id: (0, uuid_1.v4)(), oem_micro_app_id: (0, uid_1.uid)(16) });
|
|
97
|
+
});
|
|
98
|
+
return app.get('/api/saas-info', (req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
99
|
+
const lang = parseCookie(req.headers['cookie'], 'main-i18next');
|
|
100
|
+
if ((0, utils_1.isMonorepo)() || (multiApps && multiApps.length > 0)) {
|
|
101
|
+
const result = {
|
|
102
|
+
apps: [],
|
|
103
|
+
entry_info: { entries: [], entry_mode: 'normal' },
|
|
104
|
+
permissions: {},
|
|
105
|
+
saas_id_info_list: [],
|
|
106
|
+
};
|
|
107
|
+
multiApps.forEach((app) => {
|
|
108
|
+
const entry_id = idsMap.get(app.name).entry_id;
|
|
109
|
+
const dir = (0, utils_1.isMonorepo)() ? `apps/${app.name}` : `${app.dir}`;
|
|
110
|
+
const manifest = fs_extra_1.default.readJSONSync(path.join(process.cwd(), dir, 'manifest.json'), 'utf-8');
|
|
111
|
+
const oem_micro_app_id = idsMap.get(app.name).oem_micro_app_id;
|
|
112
|
+
const baseUrl = `/apps/${oem_micro_app_id}`;
|
|
113
|
+
result.saas_id_info_list.push({
|
|
114
|
+
oem_micro_app_id: oem_micro_app_id,
|
|
115
|
+
universal_id: '',
|
|
116
|
+
});
|
|
117
|
+
const micoApp = consturctApp(manifest, oem_micro_app_id, baseUrl, lang, microPort, app.name);
|
|
118
|
+
const entryInfo = consturctEntry(manifest, oem_micro_app_id, entry_id, baseUrl, lang, dir);
|
|
119
|
+
const permission = consturctPermissions();
|
|
120
|
+
result.apps.push(micoApp);
|
|
121
|
+
result.entry_info.entries.push(entryInfo);
|
|
122
|
+
result.permissions[oem_micro_app_id] = permission;
|
|
123
|
+
});
|
|
124
|
+
res.send({
|
|
125
|
+
code: null,
|
|
126
|
+
errorMsg: null,
|
|
127
|
+
msg: null,
|
|
128
|
+
result,
|
|
129
|
+
success: true,
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
const manifest = (0, micro_utils_1.parseManifest)();
|
|
134
|
+
const entry_id = (0, uuid_1.v4)();
|
|
135
|
+
const oem_micro_app_id = manifest.universalId;
|
|
136
|
+
const baseUrl = `/apps/${oem_micro_app_id}`;
|
|
137
|
+
const saasApps = yield refactorConstructApp({
|
|
138
|
+
url: target,
|
|
139
|
+
headers: {
|
|
140
|
+
cookie: expressApp.__appProxy__.getCookie(''),
|
|
141
|
+
csrf: expressApp.__appProxy__.csrfValue.value,
|
|
142
|
+
}
|
|
143
|
+
}, [
|
|
144
|
+
{
|
|
145
|
+
manifest,
|
|
146
|
+
oem_micro_app_id,
|
|
147
|
+
baseUrl,
|
|
148
|
+
lang,
|
|
149
|
+
port: microPort
|
|
150
|
+
}
|
|
151
|
+
]);
|
|
152
|
+
const entryInfo = consturctEntry(manifest, oem_micro_app_id, entry_id, baseUrl, lang, '');
|
|
153
|
+
const permission = consturctPermissions();
|
|
154
|
+
res.send({
|
|
155
|
+
code: null,
|
|
156
|
+
errorMsg: null,
|
|
157
|
+
msg: null,
|
|
158
|
+
result: {
|
|
159
|
+
apps: saasApps,
|
|
160
|
+
entry_info: { entries: [entryInfo], entry_mode: 'normal' },
|
|
161
|
+
permissions: { [oem_micro_app_id]: permission },
|
|
162
|
+
saas_id_info_list: [
|
|
163
|
+
{ oem_micro_app_id: oem_micro_app_id, universal_id: '' },
|
|
164
|
+
],
|
|
165
|
+
},
|
|
166
|
+
success: true,
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
}));
|
|
170
|
+
}
|
|
171
|
+
});
|
|
170
172
|
}
|
|
171
173
|
exports.default = mockSaasInfo;
|
|
172
174
|
function consturctEntry(manifest, oem_micro_app_id, entry_id, baseUrl, lang, dir) {
|
|
@@ -93,7 +93,7 @@ function runMain({ port, microPort, }) {
|
|
|
93
93
|
(0, socket_1.bootStrap)(io);
|
|
94
94
|
mainServer && mainServer.before && mainServer.before(app);
|
|
95
95
|
yield (0, staticMain_1.default)(app, debuggerConfig, microPort);
|
|
96
|
-
(0, fakeSaasInfo_1.default)(app, microPort);
|
|
96
|
+
yield (0, fakeSaasInfo_1.default)(app, microPort);
|
|
97
97
|
(0, mock_1.default)(app);
|
|
98
98
|
(0, proxy_1.default)(app);
|
|
99
99
|
mainServer && mainServer.after && mainServer.after(app);
|
package/dist/scripts/start.js
CHANGED
|
@@ -24,7 +24,7 @@ const template_1 = __importDefault(require("../template"));
|
|
|
24
24
|
//检测端口占用情况
|
|
25
25
|
if (process.env.PROT) {
|
|
26
26
|
const compiler = (0, bundleServer_1.createServerCompiler)();
|
|
27
|
-
(0, bundleServer_1.runBundleServer)({
|
|
27
|
+
yield (0, bundleServer_1.runBundleServer)({
|
|
28
28
|
port: Number(process.env.PROT),
|
|
29
29
|
compiler,
|
|
30
30
|
internalDevConfig: {
|
|
@@ -43,7 +43,7 @@ const template_1 = __importDefault(require("../template"));
|
|
|
43
43
|
stopPort: defaultPort + 100,
|
|
44
44
|
});
|
|
45
45
|
const compiler = (0, bundleServer_1.createServerCompiler)();
|
|
46
|
-
(0, bundleServer_1.runBundleServer)({
|
|
46
|
+
yield (0, bundleServer_1.runBundleServer)({
|
|
47
47
|
port,
|
|
48
48
|
compiler,
|
|
49
49
|
internalDevConfig: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tuya-sat/micro-script",
|
|
3
|
-
"version": "3.2.
|
|
3
|
+
"version": "3.2.10",
|
|
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.2.
|
|
27
|
-
"@tuya-sat/micro-dev-proxy": "3.2.
|
|
28
|
-
"@tuya-sat/micro-utils": "3.2.
|
|
26
|
+
"@tuya-sat/micro-dev-loader": "3.2.10",
|
|
27
|
+
"@tuya-sat/micro-dev-proxy": "3.2.10",
|
|
28
|
+
"@tuya-sat/micro-utils": "3.2.10",
|
|
29
29
|
"@types/kill-port": "^2.0.0",
|
|
30
30
|
"babel-loader": "8.2.4",
|
|
31
31
|
"babel-plugin-import": "1.13.3",
|