@tuya-sat/micro-script 1.0.4 → 1.1.0
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/bin/cli.d.ts +1 -0
- package/dist/bin/cli.js +8 -1
- package/dist/framework/react.config.js +2 -1
- package/dist/framework/vue.config.js +2 -1
- package/dist/module/bundleServer.d.ts +8 -0
- package/dist/module/bundleServer.js +70 -0
- package/dist/module/mainServer.d.ts +4 -0
- package/dist/module/mainServer.js +138 -0
- package/dist/scripts/start.js +22 -48
- package/dist/scripts/startInMain.d.ts +1 -0
- package/dist/scripts/startInMain.js +63 -0
- package/dist/utils/filterLoaderInRule.d.ts +7 -0
- package/dist/utils/filterLoaderInRule.js +21 -0
- package/dist/utils/promiser.d.ts +5 -0
- package/dist/utils/promiser.js +17 -0
- package/package.json +10 -3
package/dist/bin/cli.d.ts
CHANGED
package/dist/bin/cli.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
3
|
const PORXY_SIGN = "--proxy";
|
|
4
|
+
const IS_MAIN = "--main";
|
|
4
5
|
const params = process.argv.slice(2);
|
|
5
6
|
const [action, ...rest] = params;
|
|
6
7
|
if (rest.includes(PORXY_SIGN)) {
|
|
@@ -8,7 +9,13 @@ if (rest.includes(PORXY_SIGN)) {
|
|
|
8
9
|
}
|
|
9
10
|
if (action === "start") {
|
|
10
11
|
process.env.NODE_ENV = "development";
|
|
11
|
-
|
|
12
|
+
if (rest.includes(IS_MAIN)) {
|
|
13
|
+
process.env.START_IN_MAIN = "true";
|
|
14
|
+
require("../scripts/startInMain");
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
require("../scripts/start");
|
|
18
|
+
}
|
|
12
19
|
}
|
|
13
20
|
else {
|
|
14
21
|
process.env.NODE_ENV = "production";
|
|
@@ -52,7 +52,8 @@ const reactConfig = ({ isDev, isBuild, currentFramework, isTs, }) => {
|
|
|
52
52
|
},
|
|
53
53
|
],
|
|
54
54
|
},
|
|
55
|
-
isDev &&
|
|
55
|
+
isDev &&
|
|
56
|
+
process.env.START_IN_MAIN !== "true" && {
|
|
56
57
|
test: isTs ? paths_1.default.ReactTsEntryFile : paths_1.default.ReactJsEntryFile,
|
|
57
58
|
include: paths_1.default.appSrc,
|
|
58
59
|
use: [
|
|
@@ -50,7 +50,8 @@ const vueConfig = ({ isDev, isBuild, currentFramework, isTs, }) => {
|
|
|
50
50
|
},
|
|
51
51
|
],
|
|
52
52
|
},
|
|
53
|
-
isDev &&
|
|
53
|
+
isDev &&
|
|
54
|
+
process.env.START_IN_MAIN !== "true" && {
|
|
54
55
|
test: isTs ? paths_js_1.default.vueTsEntryFile : paths_js_1.default.vueJsEntryFile,
|
|
55
56
|
include: paths_js_1.default.appSrc,
|
|
56
57
|
use: [
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import webpack, { Compiler } from "webpack";
|
|
2
|
+
import { Configuration } from "webpack-dev-server";
|
|
3
|
+
export declare function createServerCompiler(): webpack.Compiler;
|
|
4
|
+
export declare function runBundleServer({ port, compiler, internalDevConfig, }: {
|
|
5
|
+
port: number;
|
|
6
|
+
compiler: Compiler;
|
|
7
|
+
internalDevConfig?: Pick<Configuration, "open" | "setupMiddlewares">;
|
|
8
|
+
}): Promise<void>;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
+
var t = {};
|
|
13
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
+
t[p] = s[p];
|
|
15
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
+
t[p[i]] = s[p[i]];
|
|
19
|
+
}
|
|
20
|
+
return t;
|
|
21
|
+
};
|
|
22
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.runBundleServer = exports.createServerCompiler = void 0;
|
|
27
|
+
const webpack_1 = __importDefault(require("webpack"));
|
|
28
|
+
const webpack_dev_server_1 = __importDefault(require("webpack-dev-server"));
|
|
29
|
+
const ora_1 = __importDefault(require("ora"));
|
|
30
|
+
const paths_1 = __importDefault(require("../config/paths"));
|
|
31
|
+
const webpack_config_1 = __importDefault(require("../config/webpack.config"));
|
|
32
|
+
const options_1 = __importDefault(require("./options"));
|
|
33
|
+
function createServerCompiler() {
|
|
34
|
+
const config = Object.assign(Object.assign({}, (0, webpack_config_1.default)()), {
|
|
35
|
+
//下面所有配置都是为了精简terminal输出
|
|
36
|
+
infrastructureLogging: {
|
|
37
|
+
level: "warn",
|
|
38
|
+
}, stats: "errors-warnings" });
|
|
39
|
+
return (0, webpack_1.default)(config);
|
|
40
|
+
}
|
|
41
|
+
exports.createServerCompiler = createServerCompiler;
|
|
42
|
+
function runBundleServer({ port, compiler, internalDevConfig = {}, }) {
|
|
43
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
+
const spinner = (0, ora_1.default)(`starting dev server in ${port} port`).start();
|
|
45
|
+
const { devServer = (value) => value } = require(paths_1.default.microConfig);
|
|
46
|
+
const { setupMiddlewares: startDevSetupMiddlewares } = internalDevConfig, restServerConfig = __rest(internalDevConfig, ["setupMiddlewares"]);
|
|
47
|
+
const server = new webpack_dev_server_1.default(devServer(Object.assign({ hot: true, liveReload: false, port, headers: {
|
|
48
|
+
"Access-Control-Allow-Origin": "*",
|
|
49
|
+
"Access-Control-Allow-Headers": "*",
|
|
50
|
+
}, historyApiFallback: true, setupMiddlewares(middleware, devServer) {
|
|
51
|
+
//可能会有问题
|
|
52
|
+
middleware.push(options_1.default);
|
|
53
|
+
return startDevSetupMiddlewares
|
|
54
|
+
? startDevSetupMiddlewares(middleware, devServer)
|
|
55
|
+
: middleware;
|
|
56
|
+
} }, restServerConfig)), compiler);
|
|
57
|
+
compiler.hooks.watchRun.tap("MyPlugin", () => {
|
|
58
|
+
spinner.isSpinning && spinner.succeed();
|
|
59
|
+
spinner.color = "yellow";
|
|
60
|
+
spinner.text = "webpack compiling";
|
|
61
|
+
spinner.start();
|
|
62
|
+
});
|
|
63
|
+
compiler.hooks.done.tap("MyPlugin", ({ endTime, startTime }) => {
|
|
64
|
+
spinner.isSpinning && spinner.succeed();
|
|
65
|
+
console.log(`compiled time ~${endTime - startTime}ms`);
|
|
66
|
+
});
|
|
67
|
+
server.start();
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
exports.runBundleServer = runBundleServer;
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const express_1 = __importDefault(require("express"));
|
|
16
|
+
const ora_1 = __importDefault(require("ora"));
|
|
17
|
+
const http_proxy_middleware_1 = require("http-proxy-middleware");
|
|
18
|
+
const micro_utils_1 = require("@tuya-sat/micro-utils");
|
|
19
|
+
//@ts-ignore
|
|
20
|
+
const uuid_1 = require("uuid");
|
|
21
|
+
const promiser_1 = require("../utils/promiser");
|
|
22
|
+
const mock_1 = __importDefault(require("../module/mock"));
|
|
23
|
+
const paths_1 = __importDefault(require("../config/paths"));
|
|
24
|
+
const oem_micro_app_id = (0, uuid_1.v4)();
|
|
25
|
+
const entry_id = (0, uuid_1.v4)();
|
|
26
|
+
function runMain({ port, microPort, }) {
|
|
27
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
const { debuggerConfig: { target }, } = require(paths_1.default.microConfig);
|
|
29
|
+
const app = (0, express_1.default)();
|
|
30
|
+
//use mock
|
|
31
|
+
(0, mock_1.default)(app);
|
|
32
|
+
app.use([
|
|
33
|
+
//html
|
|
34
|
+
"/",
|
|
35
|
+
"/apps/:appId",
|
|
36
|
+
"/login",
|
|
37
|
+
"/apps/:appId/*",
|
|
38
|
+
"/application",
|
|
39
|
+
"/application/*",
|
|
40
|
+
//api
|
|
41
|
+
"/open-api/*",
|
|
42
|
+
"/custom-api/*",
|
|
43
|
+
"/api/*",
|
|
44
|
+
], (0, http_proxy_middleware_1.createProxyMiddleware)({
|
|
45
|
+
target,
|
|
46
|
+
changeOrigin: true,
|
|
47
|
+
selfHandleResponse: true,
|
|
48
|
+
onProxyReq(proxyReq, req) {
|
|
49
|
+
if (req.url === "/api/saas-info") {
|
|
50
|
+
//该死的,会有缓存
|
|
51
|
+
proxyReq.setHeader("if-none-match", "");
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
onProxyRes: (0, http_proxy_middleware_1.responseInterceptor)((responseBuffer, proxyRes, req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
55
|
+
if (req.url !== "/api/saas-info" || res.statusCode !== 200) {
|
|
56
|
+
return responseBuffer;
|
|
57
|
+
}
|
|
58
|
+
let response = responseBuffer;
|
|
59
|
+
try {
|
|
60
|
+
const lang = req.headers["accept-language"];
|
|
61
|
+
const data = JSON.parse(response.toString("utf8"));
|
|
62
|
+
response = JSON.stringify(processSaasInfo(data, lang, microPort));
|
|
63
|
+
}
|
|
64
|
+
catch (err) {
|
|
65
|
+
console.log(`----json 解析错误----`, err);
|
|
66
|
+
}
|
|
67
|
+
return response;
|
|
68
|
+
})),
|
|
69
|
+
}));
|
|
70
|
+
const { pp, resolve } = (0, promiser_1.promiser)();
|
|
71
|
+
app.listen(port, () => {
|
|
72
|
+
(0, ora_1.default)(`main server in ${port} port`).succeed();
|
|
73
|
+
resolve();
|
|
74
|
+
});
|
|
75
|
+
yield pp;
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
exports.default = runMain;
|
|
79
|
+
function processSaasInfo(data, lang, port) {
|
|
80
|
+
if (data === null || data === void 0 ? void 0 : data.success) {
|
|
81
|
+
const { result: { entry_info, apps, permissions }, } = data;
|
|
82
|
+
const baseUrl = `/apps/${oem_micro_app_id}`;
|
|
83
|
+
const manifest = (0, micro_utils_1.parseManifest)();
|
|
84
|
+
const entry = consturctEntry(manifest, oem_micro_app_id, baseUrl, lang);
|
|
85
|
+
const app = consturctApp(manifest, oem_micro_app_id, baseUrl, lang, port);
|
|
86
|
+
if (entry_info.entry_mode === "group") {
|
|
87
|
+
entry_info.entries[0].sub_entry_list.unshift(entry);
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
entry_info.entries.unshift(entry);
|
|
91
|
+
}
|
|
92
|
+
delete require.cache[paths_1.default.microConfig];
|
|
93
|
+
const { mockPermissions = [] } = require(paths_1.default.microConfig).debuggerConfig || {};
|
|
94
|
+
permissions[oem_micro_app_id] = mockPermissions;
|
|
95
|
+
apps.unshift(app);
|
|
96
|
+
}
|
|
97
|
+
return data;
|
|
98
|
+
}
|
|
99
|
+
function consturctEntry(manifest, oem_micro_app_id, baseUrl, lang) {
|
|
100
|
+
const fakeMenu = (0, micro_utils_1.getFakeMenu)(manifest);
|
|
101
|
+
let stack = [fakeMenu];
|
|
102
|
+
while (stack.length) {
|
|
103
|
+
const menu = stack.shift();
|
|
104
|
+
//@ts-ignore
|
|
105
|
+
menu.oem_micro_app_id = oem_micro_app_id;
|
|
106
|
+
//@ts-ignore
|
|
107
|
+
menu.entry_id = entry_id;
|
|
108
|
+
//@ts-ignore
|
|
109
|
+
menu.entry_name = pickText(menu.entry_name, lang);
|
|
110
|
+
//@ts-ignore
|
|
111
|
+
menu.micro_app_name = pickText(menu.micro_app_name, lang);
|
|
112
|
+
//@ts-ignore
|
|
113
|
+
menu.path = `${baseUrl}${menu.path}`;
|
|
114
|
+
if (menu.sub_entry_list.length) {
|
|
115
|
+
stack.push(...menu.sub_entry_list);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return fakeMenu;
|
|
119
|
+
}
|
|
120
|
+
function consturctApp(manifest, oem_micro_app_id, baseUrl, lang, port) {
|
|
121
|
+
const packageInfo = (0, micro_utils_1.getPackage)();
|
|
122
|
+
return {
|
|
123
|
+
active_rule: baseUrl,
|
|
124
|
+
dependencies: [""],
|
|
125
|
+
ext_info: null,
|
|
126
|
+
micro_app_code: `${packageInfo.name}`,
|
|
127
|
+
micro_app_name: `${pickText((0, micro_utils_1.nameProcesser2)("name"), lang)}-dev`,
|
|
128
|
+
micro_app_version: "0.0.0-x",
|
|
129
|
+
oem_micro_app_id,
|
|
130
|
+
resource: `http://localhost:${port}`,
|
|
131
|
+
schema: null,
|
|
132
|
+
universal_id: manifest.universalId,
|
|
133
|
+
isAuth: true,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
function pickText(texts, lang) {
|
|
137
|
+
return lang === "en-US" ? texts[1] : texts[0];
|
|
138
|
+
}
|
package/dist/scripts/start.js
CHANGED
|
@@ -11,27 +11,28 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
|
-
var _a;
|
|
15
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
const webpack_1 = __importDefault(require("webpack"));
|
|
17
|
-
const webpack_dev_server_1 = __importDefault(require("webpack-dev-server"));
|
|
18
|
-
const ora_1 = __importDefault(require("ora"));
|
|
19
|
-
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
20
15
|
const portfinder_1 = __importDefault(require("portfinder"));
|
|
21
16
|
const micro_dev_loader_1 = require("@tuya-sat/micro-dev-loader");
|
|
17
|
+
const micro_utils_1 = require("@tuya-sat/micro-utils");
|
|
22
18
|
const paths_1 = __importDefault(require("../config/paths"));
|
|
23
|
-
const webpack_config_1 = __importDefault(require("../config/webpack.config"));
|
|
24
19
|
const mock_1 = __importDefault(require("../module/mock"));
|
|
25
|
-
const
|
|
26
|
-
const
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
20
|
+
const bundleServer_1 = require("../module/bundleServer");
|
|
21
|
+
const needLayout = !(0, micro_utils_1.isMobile)();
|
|
22
|
+
const internalDevConfig = {
|
|
23
|
+
open: true,
|
|
24
|
+
setupMiddlewares(middleware, { app }) {
|
|
25
|
+
needLayout && micro_dev_loader_1.LayoutMockPlugin.useLayoutStatic(app);
|
|
26
|
+
(0, mock_1.default)(app);
|
|
27
|
+
const isProxy = process.env.MICRO_DEBUGGER === "true";
|
|
28
|
+
if (isProxy) {
|
|
29
|
+
const createProxy = require("@tuya-sat/micro-dev-proxy").default;
|
|
30
|
+
const { debuggerConfig } = require(paths_1.default.microConfig);
|
|
31
|
+
createProxy(debuggerConfig)(app);
|
|
32
|
+
}
|
|
33
|
+
return middleware;
|
|
34
|
+
},
|
|
35
|
+
};
|
|
35
36
|
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
36
37
|
let defaultPort = 9000;
|
|
37
38
|
//检测端口占用情况
|
|
@@ -39,40 +40,13 @@ needMainLayout && new micro_dev_loader_1.LayoutMockPlugin().apply(compiler);
|
|
|
39
40
|
port: defaultPort,
|
|
40
41
|
stopPort: defaultPort + 100,
|
|
41
42
|
});
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
hot: true,
|
|
46
|
-
liveReload: false,
|
|
47
|
-
open: true,
|
|
43
|
+
const compiler = (0, bundleServer_1.createServerCompiler)();
|
|
44
|
+
needLayout && new micro_dev_loader_1.LayoutMockPlugin().apply(compiler);
|
|
45
|
+
(0, bundleServer_1.runBundleServer)({
|
|
48
46
|
port,
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
"Access-Control-Allow-Headers": "*",
|
|
52
|
-
},
|
|
53
|
-
historyApiFallback: true,
|
|
54
|
-
setupMiddlewares(middlewares, { app }) {
|
|
55
|
-
needMainLayout && micro_dev_loader_1.LayoutMockPlugin.useLayoutStatic(app);
|
|
56
|
-
middlewares.push(options_1.default);
|
|
57
|
-
(0, mock_1.default)(app);
|
|
58
|
-
if (process.env.MICRO_DEBUGGER === "true") {
|
|
59
|
-
const createProxy = require("@tuya-sat/micro-dev-proxy").default;
|
|
60
|
-
createProxy(debuggerConfig)(app);
|
|
61
|
-
}
|
|
62
|
-
return middlewares;
|
|
63
|
-
},
|
|
64
|
-
}), compiler);
|
|
65
|
-
compiler.hooks.watchRun.tap("MyPlugin", () => {
|
|
66
|
-
spinner.isSpinning && spinner.succeed();
|
|
67
|
-
spinner.color = "yellow";
|
|
68
|
-
spinner.text = "webpack compiling";
|
|
69
|
-
spinner.start();
|
|
70
|
-
});
|
|
71
|
-
compiler.hooks.done.tap("MyPlugin", ({ endTime, startTime }) => {
|
|
72
|
-
spinner.isSpinning && spinner.succeed();
|
|
73
|
-
console.log(`compiled time ~${endTime - startTime}ms`);
|
|
47
|
+
compiler,
|
|
48
|
+
internalDevConfig,
|
|
74
49
|
});
|
|
75
|
-
server.start();
|
|
76
50
|
}))().catch((err) => {
|
|
77
51
|
console.log(err);
|
|
78
52
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const portfinder_1 = __importDefault(require("portfinder"));
|
|
16
|
+
const open_1 = __importDefault(require("open"));
|
|
17
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
18
|
+
const path_1 = __importDefault(require("path"));
|
|
19
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
20
|
+
const mainServer_1 = __importDefault(require("../module/mainServer"));
|
|
21
|
+
const micro_utils_1 = require("@tuya-sat/micro-utils");
|
|
22
|
+
const bundleServer_1 = require("../module/bundleServer");
|
|
23
|
+
function onceFactory(fn, count = 1) {
|
|
24
|
+
let executeCount = 0;
|
|
25
|
+
return () => {
|
|
26
|
+
if (executeCount >= count) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
executeCount++;
|
|
30
|
+
return fn();
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
34
|
+
let defaultPort = 9000;
|
|
35
|
+
//检测端口占用情况
|
|
36
|
+
const bundledServerPort = yield portfinder_1.default.getPortPromise({
|
|
37
|
+
port: defaultPort,
|
|
38
|
+
stopPort: defaultPort + 100,
|
|
39
|
+
});
|
|
40
|
+
const mainServerPort = yield portfinder_1.default.getPortPromise({
|
|
41
|
+
port: bundledServerPort + 1,
|
|
42
|
+
stopPort: bundledServerPort + 100,
|
|
43
|
+
});
|
|
44
|
+
const compiler = (0, bundleServer_1.createServerCompiler)();
|
|
45
|
+
yield (0, mainServer_1.default)({
|
|
46
|
+
port: mainServerPort,
|
|
47
|
+
microPort: bundledServerPort,
|
|
48
|
+
});
|
|
49
|
+
const packagePath = path_1.default.resolve(__dirname, "../../package.json");
|
|
50
|
+
const { name, version } = fs_extra_1.default.readJSONSync(packagePath);
|
|
51
|
+
(0, micro_utils_1.isNewVersions)(name, version);
|
|
52
|
+
(0, open_1.default)(`http://localhost:${mainServerPort}`);
|
|
53
|
+
(0, bundleServer_1.runBundleServer)({
|
|
54
|
+
port: bundledServerPort,
|
|
55
|
+
compiler,
|
|
56
|
+
});
|
|
57
|
+
//临时提示
|
|
58
|
+
compiler.hooks.done.tap("once-tip", onceFactory(() => {
|
|
59
|
+
console.log(chalk_1.default.yellow(`Tip: 如果HMR失效且保存文件时造成多次compile,请考虑调高aggregateTimeout参数(可以尝试100)`));
|
|
60
|
+
}));
|
|
61
|
+
}))().catch((err) => {
|
|
62
|
+
console.log(err);
|
|
63
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ModuleOptions } from "webpack";
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
* @param loaderName loader的名字
|
|
5
|
+
* @param ruleConfig webpack内的rule项的config
|
|
6
|
+
*/
|
|
7
|
+
export declare function filterRulesWithLoader(loaderName: string, ruleConfig: ModuleOptions["rules"]): (import("webpack").RuleSetRule | "...")[];
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.filterRulesWithLoader = void 0;
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
* @param loaderName loader的名字
|
|
7
|
+
* @param ruleConfig webpack内的rule项的config
|
|
8
|
+
*/
|
|
9
|
+
function filterRulesWithLoader(loaderName, ruleConfig) {
|
|
10
|
+
return ruleConfig.filter((rule) => {
|
|
11
|
+
if (rule !== "..." && rule.use instanceof Array) {
|
|
12
|
+
for (const useItem of rule.use) {
|
|
13
|
+
if (typeof useItem === "object" && useItem.loader === loaderName) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return true;
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
exports.filterRulesWithLoader = filterRulesWithLoader;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.promiser = void 0;
|
|
4
|
+
const promiser = () => {
|
|
5
|
+
let resolve;
|
|
6
|
+
let reject;
|
|
7
|
+
let pp = new Promise((resolve$, reject$) => {
|
|
8
|
+
resolve = resolve$;
|
|
9
|
+
reject = reject$;
|
|
10
|
+
});
|
|
11
|
+
return {
|
|
12
|
+
pp,
|
|
13
|
+
resolve,
|
|
14
|
+
reject,
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
exports.promiser = promiser;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tuya-sat/micro-script",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"bin": "./dist/bin/cli.js",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"license": "MIT",
|
|
@@ -15,19 +15,23 @@
|
|
|
15
15
|
"@babel/preset-react": "^7.14.5",
|
|
16
16
|
"@babel/preset-typescript": "^7.15.0",
|
|
17
17
|
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.1",
|
|
18
|
-
"@tuya-sat/micro-dev-loader": "1.0
|
|
19
|
-
"@tuya-sat/micro-dev-proxy": "1.0
|
|
18
|
+
"@tuya-sat/micro-dev-loader": "1.1.0",
|
|
19
|
+
"@tuya-sat/micro-dev-proxy": "1.1.0",
|
|
20
|
+
"@tuya-sat/micro-utils": "1.1.0",
|
|
20
21
|
"babel-loader": "^8.2.2",
|
|
21
22
|
"babel-plugin-import": "^1.13.3",
|
|
22
23
|
"chalk": "4.1.2",
|
|
23
24
|
"copy-webpack-plugin": "^9.0.1",
|
|
24
25
|
"css-loader": "^6.4.0",
|
|
25
26
|
"css-minimizer-webpack-plugin": "^3.2.0",
|
|
27
|
+
"express": "^4.17.2",
|
|
26
28
|
"fork-ts-checker-webpack-plugin": "^6.4.0",
|
|
27
29
|
"html-webpack-plugin": "^5.3.2",
|
|
30
|
+
"http-proxy-middleware": "^2.0.1",
|
|
28
31
|
"less": "^4.1.2",
|
|
29
32
|
"less-loader": "^10.1.0",
|
|
30
33
|
"mini-css-extract-plugin": "^2.4.2",
|
|
34
|
+
"open": "^8.4.0",
|
|
31
35
|
"ora": "5.4.1",
|
|
32
36
|
"path-to-regexp": "^6.2.0",
|
|
33
37
|
"portfinder": "^1.0.28",
|
|
@@ -42,12 +46,15 @@
|
|
|
42
46
|
"svg-url-loader": "^7.1.1",
|
|
43
47
|
"tsconfig-paths-webpack-plugin": "^3.5.1",
|
|
44
48
|
"url-loader": "^4.1.1",
|
|
49
|
+
"uuid": "^8.3.2",
|
|
45
50
|
"vue-loader": "16.8.2",
|
|
46
51
|
"webpack": "^5.58.1",
|
|
47
52
|
"webpack-dev-server": "^4.3.1",
|
|
48
53
|
"webpack-merge": "^5.8.0"
|
|
49
54
|
},
|
|
50
55
|
"devDependencies": {
|
|
56
|
+
"@types/express": "^4.17.13",
|
|
57
|
+
"@types/webpack-dev-server": "^4.5.0",
|
|
51
58
|
"typescript": "^4.4.4"
|
|
52
59
|
},
|
|
53
60
|
"keywords": [
|