@tuya-sat/micro-script 1.0.7 → 1.1.2

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.
@@ -27,9 +27,11 @@ 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"));
30
31
  const paths_1 = __importDefault(require("../config/paths"));
31
32
  const webpack_config_1 = __importDefault(require("../config/webpack.config"));
32
33
  const options_1 = __importDefault(require("./options"));
34
+ const onceFactory_1 = require("../utils/onceFactory");
33
35
  function createServerCompiler() {
34
36
  const config = Object.assign(Object.assign({}, (0, webpack_config_1.default)()), {
35
37
  //下面所有配置都是为了精简terminal输出
@@ -64,6 +66,10 @@ function runBundleServer({ port, compiler, internalDevConfig = {}, }) {
64
66
  spinner.isSpinning && spinner.succeed();
65
67
  console.log(`compiled time ~${endTime - startTime}ms`);
66
68
  });
69
+ //临时提示
70
+ compiler.hooks.done.tap("once-tip", (0, onceFactory_1.onceFactory)(() => {
71
+ console.log(chalk_1.default.yellow(`Tip: 如果HMR失效且保存文件时造成多次compile,请考虑调高aggregateTimeout参数(可以尝试100)`));
72
+ }));
67
73
  server.start();
68
74
  });
69
75
  }
@@ -23,9 +23,19 @@ const mock_1 = __importDefault(require("../module/mock"));
23
23
  const paths_1 = __importDefault(require("../config/paths"));
24
24
  const oem_micro_app_id = (0, uuid_1.v4)();
25
25
  const entry_id = (0, uuid_1.v4)();
26
+ function parseCookie(cookie, key) {
27
+ const cookies = (cookie || "").split(";");
28
+ for (let cookieItem of cookies) {
29
+ const [cookieKey, value] = cookieItem.split("=");
30
+ if (cookieKey.trim() === key) {
31
+ return value;
32
+ }
33
+ }
34
+ return "";
35
+ }
26
36
  function runMain({ port, microPort, }) {
27
37
  return __awaiter(this, void 0, void 0, function* () {
28
- const { debuggerConfig: { target }, } = require(paths_1.default.microConfig);
38
+ const { debuggerConfig: { target, additionHeaders = {} }, } = require(paths_1.default.microConfig);
29
39
  const app = (0, express_1.default)();
30
40
  //use mock
31
41
  (0, mock_1.default)(app);
@@ -46,6 +56,9 @@ function runMain({ port, microPort, }) {
46
56
  changeOrigin: true,
47
57
  selfHandleResponse: true,
48
58
  onProxyReq(proxyReq, req) {
59
+ //强制覆盖host字段,优先级高于changeOrigin
60
+ const { host } = additionHeaders;
61
+ host && proxyReq.setHeader("host", host);
49
62
  if (req.url === "/api/saas-info") {
50
63
  //该死的,会有缓存
51
64
  proxyReq.setHeader("if-none-match", "");
@@ -57,7 +70,7 @@ function runMain({ port, microPort, }) {
57
70
  }
58
71
  let response = responseBuffer;
59
72
  try {
60
- const lang = req.headers["accept-language"];
73
+ const lang = parseCookie(req.headers["cookie"], "main-i18next");
61
74
  const data = JSON.parse(response.toString("utf8"));
62
75
  response = JSON.stringify(processSaasInfo(data, lang, microPort));
63
76
  }
@@ -66,6 +79,7 @@ function runMain({ port, microPort, }) {
66
79
  }
67
80
  return response;
68
81
  })),
82
+ headers: additionHeaders,
69
83
  }));
70
84
  const { pp, resolve } = (0, promiser_1.promiser)();
71
85
  app.listen(port, () => {
@@ -134,5 +148,5 @@ function consturctApp(manifest, oem_micro_app_id, baseUrl, lang, port) {
134
148
  };
135
149
  }
136
150
  function pickText(texts, lang) {
137
- return lang === "en-US" ? texts[1] : texts[0];
151
+ return lang === "en" ? texts[1] : texts[0];
138
152
  }
@@ -20,17 +20,8 @@ const chalk_1 = __importDefault(require("chalk"));
20
20
  const mainServer_1 = __importDefault(require("../module/mainServer"));
21
21
  const micro_utils_1 = require("@tuya-sat/micro-utils");
22
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
23
  (() => __awaiter(void 0, void 0, void 0, function* () {
24
+ console.log(chalk_1.default.yellow(`Tip: 目前--main命令是个体验命令,请知悉`));
34
25
  let defaultPort = 9000;
35
26
  //检测端口占用情况
36
27
  const bundledServerPort = yield portfinder_1.default.getPortPromise({
@@ -54,10 +45,6 @@ function onceFactory(fn, count = 1) {
54
45
  port: bundledServerPort,
55
46
  compiler,
56
47
  });
57
- //临时提示
58
- compiler.hooks.done.tap("once-tip", onceFactory(() => {
59
- console.log(chalk_1.default.yellow(`Tip: 如果HMR失效且保存文件时造成多次compile,请考虑调高aggregateTimeout参数(可以尝试100)`));
60
- }));
61
48
  }))().catch((err) => {
62
49
  console.log(err);
63
50
  });
@@ -0,0 +1 @@
1
+ export declare function onceFactory(fn: Function, count?: number): () => any;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.onceFactory = void 0;
4
+ function onceFactory(fn, count = 1) {
5
+ let executeCount = 0;
6
+ return () => {
7
+ if (executeCount >= count) {
8
+ return;
9
+ }
10
+ executeCount++;
11
+ return fn();
12
+ };
13
+ }
14
+ exports.onceFactory = onceFactory;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tuya-sat/micro-script",
3
- "version": "1.0.7",
3
+ "version": "1.1.2",
4
4
  "bin": "./dist/bin/cli.js",
5
5
  "type": "commonjs",
6
6
  "license": "MIT",
@@ -15,9 +15,9 @@
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.7",
19
- "@tuya-sat/micro-dev-proxy": "1.0.7",
20
- "@tuya-sat/micro-utils": "1.0.7",
18
+ "@tuya-sat/micro-dev-loader": "1.1.2",
19
+ "@tuya-sat/micro-dev-proxy": "1.1.2",
20
+ "@tuya-sat/micro-utils": "1.1.2",
21
21
  "babel-loader": "^8.2.2",
22
22
  "babel-plugin-import": "^1.13.3",
23
23
  "chalk": "4.1.2",