@tuya-sat/micro-script 3.0.0-beta.14 → 3.0.0-beta.16
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/module/bundleServer.d.ts +3 -3
- package/dist/module/bundleServer.js +11 -10
- package/dist/module/main/fakeSaasInfo.js +58 -56
- package/dist/module/main/staticMain.d.ts +1 -1
- package/dist/module/main/staticMain.js +6 -3
- package/dist/module/mainServer.js +2 -1
- package/dist/scripts/startInMain.js +6 -6
- package/package.json +4 -4
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import webpack, { Compiler } from
|
|
2
|
-
import { Configuration } from
|
|
1
|
+
import webpack, { Compiler } from 'webpack';
|
|
2
|
+
import { Configuration } from 'webpack-dev-server';
|
|
3
3
|
export declare type CustomDevServer = (value: Configuration) => typeof value;
|
|
4
4
|
export declare function createServerCompiler(): webpack.Compiler;
|
|
5
5
|
export declare function runBundleServer({ port, compiler, internalDevConfig, }: {
|
|
6
6
|
port: number;
|
|
7
7
|
compiler: Compiler;
|
|
8
|
-
internalDevConfig?: Pick<Configuration,
|
|
8
|
+
internalDevConfig?: Pick<Configuration, 'open' | 'setupMiddlewares' | 'allowedHosts'>;
|
|
9
9
|
}): Promise<void>;
|
|
@@ -36,8 +36,8 @@ function createServerCompiler() {
|
|
|
36
36
|
const config = Object.assign(Object.assign({}, (0, webpack_config_1.default)()), {
|
|
37
37
|
//下面所有配置都是为了精简terminal输出
|
|
38
38
|
infrastructureLogging: {
|
|
39
|
-
level:
|
|
40
|
-
}, stats:
|
|
39
|
+
level: 'warn',
|
|
40
|
+
}, stats: 'errors-warnings' });
|
|
41
41
|
return (0, webpack_1.default)(config);
|
|
42
42
|
}
|
|
43
43
|
exports.createServerCompiler = createServerCompiler;
|
|
@@ -47,8 +47,8 @@ function runBundleServer({ port, compiler, internalDevConfig = {}, }) {
|
|
|
47
47
|
const { devServer = (value) => value } = require(paths_1.default.microConfig);
|
|
48
48
|
const { setupMiddlewares: startDevSetupMiddlewares } = internalDevConfig, restServerConfig = __rest(internalDevConfig, ["setupMiddlewares"]);
|
|
49
49
|
const server = new webpack_dev_server_1.default(devServer(Object.assign({ hot: true, liveReload: false, port, headers: {
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
'Access-Control-Allow-Origin': '*',
|
|
51
|
+
'Access-Control-Allow-Headers': '*',
|
|
52
52
|
}, historyApiFallback: true, setupMiddlewares(middleware, devServer) {
|
|
53
53
|
//可能会有问题
|
|
54
54
|
middleware.push(options_1.default);
|
|
@@ -56,21 +56,22 @@ function runBundleServer({ port, compiler, internalDevConfig = {}, }) {
|
|
|
56
56
|
? startDevSetupMiddlewares(middleware, devServer)
|
|
57
57
|
: middleware;
|
|
58
58
|
} }, restServerConfig)), compiler);
|
|
59
|
-
compiler.hooks.watchRun.tap(
|
|
59
|
+
compiler.hooks.watchRun.tap('MyPlugin', () => {
|
|
60
60
|
spinner.isSpinning && spinner.succeed();
|
|
61
|
-
spinner.color =
|
|
62
|
-
spinner.text =
|
|
61
|
+
spinner.color = 'yellow';
|
|
62
|
+
spinner.text = 'webpack compiling';
|
|
63
63
|
spinner.start();
|
|
64
64
|
});
|
|
65
|
-
compiler.hooks.done.tap(
|
|
65
|
+
compiler.hooks.done.tap('MyPlugin', ({ endTime, startTime }) => {
|
|
66
66
|
spinner.isSpinning && spinner.succeed();
|
|
67
67
|
console.log(`compiled time ~${endTime - startTime}ms`);
|
|
68
68
|
});
|
|
69
69
|
//临时提示
|
|
70
|
-
compiler.hooks.done.tap(
|
|
70
|
+
compiler.hooks.done.tap('once-tip', (0, onceFactory_1.onceFactory)(() => {
|
|
71
71
|
console.log(chalk_1.default.yellow(`Tip: 如果HMR失效且保存文件时造成多次compile,请考虑调高aggregateTimeout参数(可以尝试100)`));
|
|
72
72
|
}));
|
|
73
|
-
server.start();
|
|
73
|
+
yield server.start();
|
|
74
|
+
console.log('本地应用服务已启动');
|
|
74
75
|
});
|
|
75
76
|
}
|
|
76
77
|
exports.runBundleServer = runBundleServer;
|
|
@@ -33,68 +33,70 @@ const uid_1 = require("uid");
|
|
|
33
33
|
const path = __importStar(require("path"));
|
|
34
34
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
35
35
|
function mockSaasInfo(app, microPort) {
|
|
36
|
-
const { multiApps } = require(paths_1.default.microConfig);
|
|
36
|
+
const { multiApps, isMainApp } = require(paths_1.default.microConfig);
|
|
37
37
|
const idsMap = new Map();
|
|
38
38
|
multiApps === null || multiApps === void 0 ? void 0 : multiApps.forEach((app) => {
|
|
39
39
|
idsMap.set(app.name, { entry_id: (0, uuid_1.v4)(), oem_micro_app_id: (0, uid_1.uid)(16) });
|
|
40
40
|
});
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
41
|
+
if (!isMainApp) {
|
|
42
|
+
app.get('/api/saas-info', (req, res) => {
|
|
43
|
+
const lang = parseCookie(req.headers['cookie'], 'main-i18next');
|
|
44
|
+
if (multiApps && multiApps.length > 0) {
|
|
45
|
+
const result = {
|
|
46
|
+
apps: [],
|
|
47
|
+
entry_info: { entries: [], entry_mode: 'normal' },
|
|
48
|
+
permissions: {},
|
|
49
|
+
saas_id_info_list: [],
|
|
50
|
+
};
|
|
51
|
+
multiApps.forEach((app) => {
|
|
52
|
+
const entry_id = idsMap.get(app.name).entry_id;
|
|
53
|
+
const manifest = fs_extra_1.default.readJSONSync(path.join(process.cwd(), `${app.dir}/manifest.json`), 'utf-8');
|
|
54
|
+
const oem_micro_app_id = idsMap.get(app.name).oem_micro_app_id;
|
|
55
|
+
const baseUrl = `/apps/${oem_micro_app_id}`;
|
|
56
|
+
result.saas_id_info_list.push({
|
|
57
|
+
oem_micro_app_id: oem_micro_app_id,
|
|
58
|
+
universal_id: '',
|
|
59
|
+
});
|
|
60
|
+
const micoApp = consturctApp(manifest, oem_micro_app_id, baseUrl, lang, microPort, app.name);
|
|
61
|
+
const entryInfo = consturctEntry(manifest, oem_micro_app_id, entry_id, baseUrl, lang, app.dir);
|
|
62
|
+
const permission = consturctPermissions();
|
|
63
|
+
result.apps.push(micoApp);
|
|
64
|
+
result.entry_info.entries.push(entryInfo);
|
|
65
|
+
result.permissions[oem_micro_app_id] = permission;
|
|
66
|
+
});
|
|
67
|
+
res.send({
|
|
68
|
+
code: null,
|
|
69
|
+
errorMsg: null,
|
|
70
|
+
msg: null,
|
|
71
|
+
result,
|
|
72
|
+
success: true,
|
|
58
73
|
});
|
|
59
|
-
|
|
60
|
-
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
const manifest = (0, micro_utils_1.parseManifest)();
|
|
77
|
+
const entry_id = (0, uuid_1.v4)();
|
|
78
|
+
const oem_micro_app_id = manifest.universalId;
|
|
79
|
+
const baseUrl = `/apps/${oem_micro_app_id}`;
|
|
80
|
+
const app = consturctApp(manifest, oem_micro_app_id, baseUrl, lang, microPort);
|
|
81
|
+
const entryInfo = consturctEntry(manifest, oem_micro_app_id, entry_id, baseUrl, lang, '');
|
|
61
82
|
const permission = consturctPermissions();
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
const app = consturctApp(manifest, oem_micro_app_id, baseUrl, lang, microPort);
|
|
80
|
-
const entryInfo = consturctEntry(manifest, oem_micro_app_id, entry_id, baseUrl, lang, '');
|
|
81
|
-
const permission = consturctPermissions();
|
|
82
|
-
res.send({
|
|
83
|
-
code: null,
|
|
84
|
-
errorMsg: null,
|
|
85
|
-
msg: null,
|
|
86
|
-
result: {
|
|
87
|
-
apps: [app],
|
|
88
|
-
entry_info: { entries: [entryInfo], entry_mode: 'normal' },
|
|
89
|
-
permissions: { [oem_micro_app_id]: permission },
|
|
90
|
-
saas_id_info_list: [
|
|
91
|
-
{ oem_micro_app_id: oem_micro_app_id, universal_id: '' },
|
|
92
|
-
],
|
|
93
|
-
},
|
|
94
|
-
success: true,
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
});
|
|
83
|
+
res.send({
|
|
84
|
+
code: null,
|
|
85
|
+
errorMsg: null,
|
|
86
|
+
msg: null,
|
|
87
|
+
result: {
|
|
88
|
+
apps: [app],
|
|
89
|
+
entry_info: { entries: [entryInfo], entry_mode: 'normal' },
|
|
90
|
+
permissions: { [oem_micro_app_id]: permission },
|
|
91
|
+
saas_id_info_list: [
|
|
92
|
+
{ oem_micro_app_id: oem_micro_app_id, universal_id: '' },
|
|
93
|
+
],
|
|
94
|
+
},
|
|
95
|
+
success: true,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}
|
|
98
100
|
}
|
|
99
101
|
exports.default = mockSaasInfo;
|
|
100
102
|
function consturctEntry(manifest, oem_micro_app_id, entry_id, baseUrl, lang, dir) {
|
|
@@ -41,7 +41,7 @@ const fakeSaas_1 = __importStar(require("./fakeSaas"));
|
|
|
41
41
|
const paths_1 = __importDefault(require("../../config/paths"));
|
|
42
42
|
const webpack_common_1 = require("../../config/webpack.common");
|
|
43
43
|
const defaultBase = 'https://static1.tuyacn.com/static/sdf-gw/v1.0.1.516/';
|
|
44
|
-
function staticMain(app, debuggerConfig) {
|
|
44
|
+
function staticMain(app, debuggerConfig, microPort) {
|
|
45
45
|
app.get([
|
|
46
46
|
'/',
|
|
47
47
|
'/apps/:appId',
|
|
@@ -50,10 +50,13 @@ function staticMain(app, debuggerConfig) {
|
|
|
50
50
|
'/application',
|
|
51
51
|
'/application/*',
|
|
52
52
|
], (req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
53
|
-
if (app._isLogin) {
|
|
53
|
+
if (!debuggerConfig.isMainApp && app._isLogin) {
|
|
54
54
|
yield app._isLogin;
|
|
55
55
|
}
|
|
56
|
-
|
|
56
|
+
let base = debuggerConfig.base || defaultBase;
|
|
57
|
+
if (debuggerConfig.isMainApp) {
|
|
58
|
+
base = `http://localhost:${microPort}`;
|
|
59
|
+
}
|
|
57
60
|
const { data } = yield axios_1.default.get(new URL('index.html', base).href);
|
|
58
61
|
const $ = cheerio_1.default.load(data);
|
|
59
62
|
modifySrcAttr($, base);
|
|
@@ -27,7 +27,7 @@ function runMain({ port, microPort, }) {
|
|
|
27
27
|
(0, validate_1.validateDebuggerConfig)(debuggerConfig);
|
|
28
28
|
const app = (0, express_1.default)();
|
|
29
29
|
mainServer && mainServer.before && mainServer.before(app);
|
|
30
|
-
(0, staticMain_1.default)(app, debuggerConfig);
|
|
30
|
+
(0, staticMain_1.default)(app, debuggerConfig, microPort);
|
|
31
31
|
(0, fakeSaasInfo_1.default)(app, microPort);
|
|
32
32
|
(0, mock_1.default)(app);
|
|
33
33
|
(0, proxy_1.default)(app);
|
|
@@ -38,6 +38,7 @@ function runMain({ port, microPort, }) {
|
|
|
38
38
|
resolve();
|
|
39
39
|
});
|
|
40
40
|
yield waiting;
|
|
41
|
+
console.log('代理服务已启动');
|
|
41
42
|
});
|
|
42
43
|
}
|
|
43
44
|
exports.default = runMain;
|
|
@@ -29,18 +29,18 @@ const kill_port_1 = __importDefault(require("kill-port"));
|
|
|
29
29
|
stopPort: bundledServerPort + 100,
|
|
30
30
|
});
|
|
31
31
|
const compiler = (0, bundleServer_1.createServerCompiler)();
|
|
32
|
-
yield (0,
|
|
33
|
-
port: mainServerPort,
|
|
34
|
-
microPort: bundledServerPort,
|
|
35
|
-
});
|
|
36
|
-
(0, open_1.default)(`http://localhost:${mainServerPort}`);
|
|
37
|
-
(0, bundleServer_1.runBundleServer)({
|
|
32
|
+
yield (0, bundleServer_1.runBundleServer)({
|
|
38
33
|
port: bundledServerPort,
|
|
39
34
|
compiler,
|
|
40
35
|
internalDevConfig: {
|
|
41
36
|
allowedHosts: 'all',
|
|
42
37
|
},
|
|
43
38
|
});
|
|
39
|
+
yield (0, mainServer_1.default)({
|
|
40
|
+
port: mainServerPort,
|
|
41
|
+
microPort: bundledServerPort,
|
|
42
|
+
});
|
|
43
|
+
(0, open_1.default)(`http://localhost:${mainServerPort}`);
|
|
44
44
|
process.on('exit', () => {
|
|
45
45
|
(0, kill_port_1.default)(bundledServerPort, 'tcp').then(console.log).catch(console.log);
|
|
46
46
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tuya-sat/micro-script",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.16",
|
|
4
4
|
"bin": "./dist/bin/cli.js",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"license": "MIT",
|
|
@@ -20,9 +20,9 @@
|
|
|
20
20
|
"@babel/preset-react": "7.16.7",
|
|
21
21
|
"@babel/preset-typescript": "7.16.7",
|
|
22
22
|
"@pmmmwh/react-refresh-webpack-plugin": "0.5.4",
|
|
23
|
-
"@tuya-sat/micro-dev-loader": "3.0.0-beta.
|
|
24
|
-
"@tuya-sat/micro-dev-proxy": "3.0.0-beta.
|
|
25
|
-
"@tuya-sat/micro-utils": "3.0.0-beta.
|
|
23
|
+
"@tuya-sat/micro-dev-loader": "3.0.0-beta.16",
|
|
24
|
+
"@tuya-sat/micro-dev-proxy": "3.0.0-beta.16",
|
|
25
|
+
"@tuya-sat/micro-utils": "3.0.0-beta.16",
|
|
26
26
|
"@types/kill-port": "^2.0.0",
|
|
27
27
|
"babel-loader": "8.2.4",
|
|
28
28
|
"babel-plugin-import": "1.13.3",
|