@tuya-sat/micro-script 3.0.0-beta.9 → 3.0.3

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.
@@ -7,10 +7,10 @@ declare const _default: {
7
7
  publicDir: string;
8
8
  spaHtml: string;
9
9
  manifest: string;
10
- saasCache: string;
11
10
  vueTsEntryFile: string;
12
11
  vueJsEntryFile: string;
13
12
  ReactTsEntryFile: string;
14
13
  ReactJsEntryFile: string;
14
+ node_modules: string;
15
15
  };
16
16
  export default _default;
@@ -14,9 +14,9 @@ exports.default = {
14
14
  publicDir: path_1.default.resolve(cwd, "public/"),
15
15
  spaHtml: path_1.default.resolve(cwd, "public/index.html"),
16
16
  manifest: path_1.default.resolve(cwd, "manifest.json"),
17
- saasCache: path_1.default.resolve(cwd, ".saas-cache.json"),
18
17
  vueTsEntryFile: path_1.default.resolve(cwd, "src/index.ts"),
19
18
  vueJsEntryFile: path_1.default.resolve(cwd, "src/index.js"),
20
19
  ReactTsEntryFile: path_1.default.resolve(cwd, "src/index.tsx"),
21
20
  ReactJsEntryFile: path_1.default.resolve(cwd, "src/index.jsx"),
21
+ node_modules: path_1.default.resolve(cwd, "node_modules")
22
22
  };
@@ -24,7 +24,6 @@ const micro_dev_loader_1 = require("@tuya-sat/micro-dev-loader");
24
24
  const path_1 = __importDefault(require("path"));
25
25
  const index_1 = require("@tuya-sat/micro-dev-loader/dist/less/utils/index");
26
26
  const paths_1 = __importDefault(require("./paths"));
27
- const locales_1 = __importDefault(require("@tuya-sat/micro-dev-loader/dist/plugins/locales"));
28
27
  const utils_1 = require("../utils");
29
28
  const toArray = (value) => {
30
29
  return Array.isArray(value) ? value : [value];
@@ -68,7 +67,7 @@ function getCommonConfig({ isDev, isBuild, }) {
68
67
  ].filter(Boolean);
69
68
  return loaders;
70
69
  };
71
- const { multiApps } = require(paths_1.default.microConfig);
70
+ const { multiApps, debuggerConfig: { isMainApp } } = require(paths_1.default.microConfig);
72
71
  const multiAppsWebpackConfig = {
73
72
  plugins: [],
74
73
  entry: {},
@@ -153,13 +152,24 @@ function getCommonConfig({ isDev, isBuild, }) {
153
152
  name: 'vendors-others',
154
153
  chunks: 'all',
155
154
  priority: 0,
155
+ }, main: {
156
+ test: /[\\/]node_modules[\\/](@tuya-sat\/sdf-main-sdk)[\\/]/,
157
+ name: 'main-related',
158
+ chunks: 'all',
159
+ priority: 1,
160
+ }, antd: {
161
+ test: /[\\/]node_modules[\\/](antd|@tuya-sat\/galaxy)[\\/]/,
162
+ name: 'antd-related',
163
+ chunks: 'all',
164
+ priority: 2,
156
165
  }, react: {
157
- test: /[\\/]node_modules[\\/](react|react-dom)[\\/]/,
166
+ test: /[\\/]node_modules[\\/](react|react-dom|react-router-dom)[\\/]/,
158
167
  name: 'react-related',
159
168
  chunks: 'all',
160
- priority: 1,
169
+ priority: 3,
161
170
  } }),
162
171
  },
172
+ minimize: isBuild,
163
173
  minimizer: ['...', new css_minimizer_webpack_plugin_1.default()],
164
174
  },
165
175
  plugins: [
@@ -175,7 +185,13 @@ function getCommonConfig({ isDev, isBuild, }) {
175
185
  filter: (resourcePath) => __awaiter(this, void 0, void 0, function* () { return resourcePath !== paths_1.default.spaHtml; }),
176
186
  noErrorOnMissing: true,
177
187
  },
178
- ],
188
+ isMainApp && {
189
+ from: `${paths_1.default.node_modules}/@tuya-sat/sdf-main-sdk/dist/**/*.png`,
190
+ to() {
191
+ return "static/img/[name][ext]";
192
+ },
193
+ },
194
+ ].filter((value) => Boolean(value)),
179
195
  }),
180
196
  isBuild &&
181
197
  new mini_css_extract_plugin_1.default({
@@ -183,7 +199,6 @@ function getCommonConfig({ isDev, isBuild, }) {
183
199
  chunkFilename: 'static/css/[name].[contenthash:8].chunk.css',
184
200
  }),
185
201
  isBuild && enableThemeCompile && new micro_dev_loader_1.ThemePlugin(),
186
- isBuild && new locales_1.default(),
187
202
  ].filter((value) => Boolean(value)),
188
203
  };
189
204
  return baseConfig;
@@ -193,7 +208,9 @@ function getCommonConfig({ isDev, isBuild, }) {
193
208
  multiAppsWebpackConfig.entry[app.name] = `${path_1.default.join(process.cwd(), app.dir)}/index.tsx`;
194
209
  multiAppsWebpackConfig.plugins.push(new html_webpack_plugin_1.default({
195
210
  inject: true,
196
- filename: `${app.name}.html`,
211
+ filename: app.htmlContentHash
212
+ ? `${app.name}-[contenthash].html`
213
+ : `${app.name}.html`,
197
214
  template: paths_1.default.spaHtml,
198
215
  chunks: [app.name],
199
216
  }));
@@ -1,4 +1,4 @@
1
- import { FrameworkFunction } from "./index";
1
+ import { FrameworkFunction } from './index';
2
2
  declare const reactTsConfig: FrameworkFunction;
3
3
  declare const reactJsConfig: FrameworkFunction;
4
4
  export { reactTsConfig, reactJsConfig };
@@ -17,26 +17,26 @@ const reactConfig = ({ isDev, isBuild, currentFramework, isTs, }) => {
17
17
  include: paths_1.default.appSrc,
18
18
  use: [
19
19
  {
20
- loader: require.resolve("babel-loader"),
20
+ loader: require.resolve('babel-loader'),
21
21
  options: {
22
22
  presets: [
23
23
  [
24
- require.resolve("@babel/preset-env"),
24
+ require.resolve('@babel/preset-env'),
25
25
  {
26
- useBuiltIns: "entry",
26
+ useBuiltIns: 'entry',
27
27
  corejs: 3,
28
28
  },
29
29
  ],
30
30
  [
31
- require.resolve("@babel/preset-react"),
31
+ require.resolve('@babel/preset-react'),
32
32
  {
33
- runtime: "automatic",
33
+ runtime: 'automatic',
34
34
  },
35
35
  ],
36
- isTs && require.resolve("@babel/preset-typescript"),
36
+ isTs && require.resolve('@babel/preset-typescript'),
37
37
  ].filter(Boolean),
38
38
  plugins: [
39
- isDev && require.resolve("react-refresh/babel"),
39
+ isDev && require.resolve('react-refresh/babel'),
40
40
  ].filter(Boolean),
41
41
  },
42
42
  },
@@ -48,7 +48,7 @@ const reactConfig = ({ isDev, isBuild, currentFramework, isTs, }) => {
48
48
  exclude: paths_1.default.appSrc,
49
49
  use: [
50
50
  {
51
- loader: require.resolve("babel-loader"),
51
+ loader: require.resolve('babel-loader'),
52
52
  },
53
53
  ],
54
54
  },
@@ -64,18 +64,18 @@ const reactConfig = ({ isDev, isBuild, currentFramework, isTs, }) => {
64
64
  semantic: true,
65
65
  syntactic: true,
66
66
  },
67
- mode: "write-references",
67
+ mode: 'write-references',
68
68
  },
69
69
  }),
70
70
  ].filter((value) => Boolean(value)),
71
71
  };
72
72
  };
73
73
  const reactTsConfig = ({ isDev, isBuild, currentFramework, }) => (Object.assign({ entry: paths_1.default.ReactTsEntryFile, resolve: {
74
- extensions: [".tsx", ".ts", ".js"],
74
+ extensions: ['.tsx', '.ts', '.js'],
75
75
  plugins: [new tsconfig_paths_webpack_plugin_1.default()],
76
76
  } }, reactConfig({ isDev, isBuild, currentFramework, isTs: true })));
77
77
  exports.reactTsConfig = reactTsConfig;
78
78
  const reactJsConfig = ({ isDev, isBuild, currentFramework, }) => (Object.assign({ entry: paths_1.default.ReactJsEntryFile, resolve: {
79
- extensions: [".jsx", ".js"],
79
+ extensions: ['.jsx', '.js'],
80
80
  } }, reactConfig({ isDev, isBuild, currentFramework, isTs: false })));
81
81
  exports.reactJsConfig = reactJsConfig;
@@ -1,9 +1,9 @@
1
- import webpack, { Compiler } from "webpack";
2
- import { Configuration } from "webpack-dev-server";
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, "open" | "setupMiddlewares" | "allowedHosts">;
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: "warn",
40
- }, stats: "errors-warnings" });
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
- "Access-Control-Allow-Origin": "*",
51
- "Access-Control-Allow-Headers": "*",
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("MyPlugin", () => {
59
+ compiler.hooks.watchRun.tap('MyPlugin', () => {
60
60
  spinner.isSpinning && spinner.succeed();
61
- spinner.color = "yellow";
62
- spinner.text = "webpack compiling";
61
+ spinner.color = 'yellow';
62
+ spinner.text = 'webpack compiling';
63
63
  spinner.start();
64
64
  });
65
- compiler.hooks.done.tap("MyPlugin", ({ endTime, startTime }) => {
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("once-tip", (0, onceFactory_1.onceFactory)(() => {
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;
@@ -1,4 +1,4 @@
1
- import { DebuggerConfig } from "./staticMain";
1
+ import { DebuggerConfig } from './staticMain';
2
2
  interface anyObject {
3
3
  [key: string]: any;
4
4
  }
@@ -13,55 +13,49 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.getFakeUser = void 0;
16
- const fs_extra_1 = __importDefault(require("fs-extra"));
17
16
  const axios_1 = __importDefault(require("axios"));
18
17
  const chalk_1 = __importDefault(require("chalk"));
19
- const paths_1 = __importDefault(require("../../config/paths"));
20
18
  function parse_SDF_CONFIG(html) {
21
19
  var _a;
22
20
  const REGEX = /(?<=window._SDF_CONFIG=).*?(?=;)/;
23
- return ((_a = REGEX.exec(html)) === null || _a === void 0 ? void 0 : _a[0]) || "";
21
+ return ((_a = REGEX.exec(html)) === null || _a === void 0 ? void 0 : _a[0]) || '';
24
22
  }
25
23
  function parse_SDF(html) {
26
24
  var _a;
27
25
  const REGEX = /(?<=window._SDF=).*?(?=;)/;
28
- return ((_a = REGEX.exec(html)) === null || _a === void 0 ? void 0 : _a[0]) || "";
26
+ return ((_a = REGEX.exec(html)) === null || _a === void 0 ? void 0 : _a[0]) || '';
29
27
  }
30
28
  function parse__MAIN_APP_PUBLIC_PATH(html) {
31
29
  var _a;
32
30
  const REGEX = /(?<=window.__MAIN_APP_PUBLIC_PATH=).*?(?=;)/;
33
- return ((_a = REGEX.exec(html)) === null || _a === void 0 ? void 0 : _a[0]) || "";
31
+ return ((_a = REGEX.exec(html)) === null || _a === void 0 ? void 0 : _a[0]) || '';
34
32
  }
35
33
  function getFakeSaas(config) {
36
34
  return __awaiter(this, void 0, void 0, function* () {
37
- if (!fs_extra_1.default.existsSync(paths_1.default.saasCache) && !config.target) {
38
- console.log(chalk_1.default.red("不存在缓存文件,且没有配置target"));
35
+ if (!config.target) {
36
+ console.log(chalk_1.default.red('没有配置target'));
39
37
  process.exit(1);
40
38
  }
41
- if (!fs_extra_1.default.existsSync(paths_1.default.saasCache)) {
42
- const { data } = yield axios_1.default.get(new URL("/login", config.target).href);
43
- const _SDF_CONFIG = parse_SDF_CONFIG(data);
44
- const _SDF = parse_SDF(data);
45
- const __MAIN_APP_PUBLIC_PATH = parse__MAIN_APP_PUBLIC_PATH(data);
46
- const saas = {
47
- _SDF_CONFIG: JSON.parse(_SDF_CONFIG),
48
- _SDF: JSON.parse(_SDF),
49
- __MAIN_APP_PUBLIC_PATH: JSON.parse(__MAIN_APP_PUBLIC_PATH),
50
- };
51
- fs_extra_1.default.writeJSONSync(paths_1.default.saasCache, saas);
52
- return saas;
53
- }
54
- return fs_extra_1.default.readJSONSync(paths_1.default.saasCache);
39
+ const { data } = yield axios_1.default.get(new URL('/login', config.target).href);
40
+ const _SDF_CONFIG = parse_SDF_CONFIG(data);
41
+ const _SDF = parse_SDF(data);
42
+ const __MAIN_APP_PUBLIC_PATH = parse__MAIN_APP_PUBLIC_PATH(data);
43
+ const saas = {
44
+ _SDF_CONFIG: JSON.parse(_SDF_CONFIG),
45
+ _SDF: JSON.parse(_SDF),
46
+ __MAIN_APP_PUBLIC_PATH: JSON.parse(__MAIN_APP_PUBLIC_PATH),
47
+ };
48
+ return saas;
55
49
  });
56
50
  }
57
51
  exports.default = getFakeSaas;
58
52
  function getFakeUser(config) {
59
53
  return {
60
- user_name: config.username || "admin@tuya.com",
54
+ user_name: config.username || 'admin@tuya.com',
61
55
  roles: [
62
56
  {
63
- role_code: "FAKE_ROLE_CODE",
64
- role_name: "FAKE_ROLE_NAME",
57
+ role_code: 'FAKE_ROLE_CODE',
58
+ role_name: 'FAKE_ROLE_NAME',
65
59
  },
66
60
  ],
67
61
  };
@@ -33,60 +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, debuggerConfig: { 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
- app.get('/api/saas-info', (req, res) => {
42
- const lang = parseCookie(req.headers['cookie'], 'main-i18next');
43
- if (multiApps && multiApps.length > 0) {
44
- const result = {
45
- apps: [],
46
- entry_info: { entries: [], entry_mode: 'normal' },
47
- permissions: {},
48
- };
49
- multiApps.forEach((app) => {
50
- const entry_id = idsMap.get(app.name).entry_id;
51
- const manifest = fs_extra_1.default.readJSONSync(path.join(process.cwd(), `${app.dir}/manifest.json`), 'utf-8');
52
- const oem_micro_app_id = idsMap.get(app.name).oem_micro_app_id;
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,
73
+ });
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;
53
79
  const baseUrl = `/apps/${oem_micro_app_id}`;
54
- const micoApp = consturctApp(manifest, oem_micro_app_id, baseUrl, lang, microPort, app.name);
55
- const entryInfo = consturctEntry(manifest, oem_micro_app_id, entry_id, baseUrl, lang, app.dir);
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, '');
56
82
  const permission = consturctPermissions();
57
- result.apps.push(micoApp);
58
- result.entry_info.entries.push(entryInfo);
59
- result.permissions[oem_micro_app_id] = permission;
60
- });
61
- res.send({
62
- code: null,
63
- errorMsg: null,
64
- msg: null,
65
- result,
66
- success: true,
67
- });
68
- }
69
- else {
70
- const manifest = (0, micro_utils_1.parseManifest)();
71
- const entry_id = (0, uuid_1.v4)();
72
- const oem_micro_app_id = manifest.universalId;
73
- const baseUrl = `/apps/${oem_micro_app_id}`;
74
- const app = consturctApp(manifest, oem_micro_app_id, baseUrl, lang, microPort);
75
- const entryInfo = consturctEntry(manifest, oem_micro_app_id, entry_id, baseUrl, lang, '');
76
- const permission = consturctPermissions();
77
- res.send({
78
- code: null,
79
- errorMsg: null,
80
- msg: null,
81
- result: {
82
- apps: [app],
83
- entry_info: { entries: [entryInfo], entry_mode: 'normal' },
84
- permissions: { [oem_micro_app_id]: permission },
85
- },
86
- success: true,
87
- });
88
- }
89
- });
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
+ }
90
100
  }
91
101
  exports.default = mockSaasInfo;
92
102
  function consturctEntry(manifest, oem_micro_app_id, entry_id, baseUrl, lang, dir) {
@@ -1,5 +1,5 @@
1
- import { Express } from "express";
2
- import type { Config } from "@tuya-sat/micro-dev-proxy";
1
+ import { Express } from 'express';
2
+ import type { Config } from '@tuya-sat/micro-dev-proxy';
3
3
  export interface DebuggerConfig extends Config {
4
4
  themeConfig?: {
5
5
  primaryColor: string;
@@ -20,4 +20,4 @@ export declare type CustomConfig = {
20
20
  };
21
21
  export default function staticMain(app: Express & {
22
22
  _isLogin?: Promise<void>;
23
- }, debuggerConfig: DebuggerConfig): void;
23
+ }, debuggerConfig: DebuggerConfig, microPort: number): void;
@@ -40,21 +40,24 @@ const axios_1 = __importDefault(require("axios"));
40
40
  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
- const defaultBase = "https://static1.tuyacn.com/static/sdf-gw/v1.0.1.516/";
44
- function staticMain(app, debuggerConfig) {
43
+ const defaultBase = 'https://static1.tuyacn.com/static/sdf-gw/v1.0.1.516/';
44
+ function staticMain(app, debuggerConfig, microPort) {
45
45
  app.get([
46
- "/",
47
- "/apps/:appId",
48
- "/login",
49
- "/apps/:appId/*",
50
- "/application",
51
- "/application/*",
46
+ '/',
47
+ '/apps/:appId',
48
+ '/login',
49
+ '/apps/:appId/*',
50
+ '/application',
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
- const base = debuggerConfig.base || defaultBase;
57
- const { data } = yield axios_1.default.get(new URL("index.html", base).href);
56
+ let base = debuggerConfig.base || defaultBase;
57
+ if (debuggerConfig.isMainApp) {
58
+ base = `http://localhost:${microPort}`;
59
+ }
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);
60
63
  yield insertScript($, debuggerConfig);
@@ -64,15 +67,15 @@ function staticMain(app, debuggerConfig) {
64
67
  exports.default = staticMain;
65
68
  function initalCustom_configs(saas) {
66
69
  const config = {
67
- config_group: "",
68
- config_key: "dynamic_theme",
69
- config_value: "",
70
- config_label: "",
71
- config_value_json: "{}",
72
- config_name_zh: "",
73
- config_name_en: "",
74
- platform: "",
75
- config_id: "",
70
+ config_group: '',
71
+ config_key: 'dynamic_theme',
72
+ config_value: '',
73
+ config_label: '',
74
+ config_value_json: '{}',
75
+ config_name_zh: '',
76
+ config_name_en: '',
77
+ platform: '',
78
+ config_id: '',
76
79
  };
77
80
  saas.custom_configs.push(config);
78
81
  return config;
@@ -82,7 +85,7 @@ function readThemeConfig() {
82
85
  return require(paths_1.default.microConfig).debuggerConfig.themeConfig;
83
86
  }
84
87
  function overrideNotification(value) {
85
- const isProxy = process.env.MICRO_PROXY === "true";
88
+ const isProxy = process.env.MICRO_PROXY === 'true';
86
89
  !isProxy && (value.message_switch = false);
87
90
  }
88
91
  function insertScript($, debuggerConfig) {
@@ -93,7 +96,7 @@ function insertScript($, debuggerConfig) {
93
96
  const { saas } = _SDF;
94
97
  (_a = saas.custom_configs) !== null && _a !== void 0 ? _a : (saas.custom_configs = []);
95
98
  let themeConfig = saas.custom_configs.find((item) => {
96
- return item.config_key === "dynamic_theme";
99
+ return item.config_key === 'dynamic_theme';
97
100
  }) || initalCustom_configs(saas);
98
101
  const theme = (0, webpack_common_1.validateMicroTheme)();
99
102
  themeConfig.config_value_json = JSON.stringify(Object.assign(Object.assign(Object.assign({}, JSON.parse(themeConfig.config_value_json)), (theme
@@ -103,17 +106,17 @@ function insertScript($, debuggerConfig) {
103
106
  : {})), readThemeConfig()));
104
107
  overrideNotification(saas);
105
108
  // 本地开发态多语言剥离多语言平台,走本地多语言兜底逻辑
106
- _SDF.saas.saas_locales = {};
107
- $("head").append($("<script>").text(`window._SDF_CONFIG=${JSON.stringify(_SDF_CONFIG)};window._SDF=${JSON.stringify(_SDF)};window.__MAIN_APP_PUBLIC_PATH=${JSON.stringify(__MAIN_APP_PUBLIC_PATH)};
109
+ delete _SDF.saas.saas_locales;
110
+ $('head').append($('<script>').text(`window._SDF_CONFIG=${JSON.stringify(_SDF_CONFIG)};window._SDF=${JSON.stringify(_SDF)};window.__MAIN_APP_PUBLIC_PATH=${JSON.stringify(__MAIN_APP_PUBLIC_PATH)};
108
111
  localStorage.setItem('theme',${JSON.stringify(process.env.MICRO_THEME)});
109
112
  localStorage.setItem('isDebugger','true')
110
113
  `));
111
114
  });
112
115
  }
113
116
  function modifySrcAttr($, base) {
114
- const tags = ["img src", "link href", "script src"];
117
+ const tags = ['img src', 'link href', 'script src'];
115
118
  tags.forEach((p) => {
116
- const [tagName, attr] = p.split(" ");
119
+ const [tagName, attr] = p.split(' ');
117
120
  $(tagName).map(function () {
118
121
  const origin = $(this).attr(attr);
119
122
  if (/^(\/|http:|https:)/.test(origin))
@@ -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;
@@ -16,6 +16,7 @@ const portfinder_1 = __importDefault(require("portfinder"));
16
16
  const open_1 = __importDefault(require("open"));
17
17
  const mainServer_1 = __importDefault(require("../module/mainServer"));
18
18
  const bundleServer_1 = require("../module/bundleServer");
19
+ const kill_port_1 = __importDefault(require("kill-port"));
19
20
  (() => __awaiter(void 0, void 0, void 0, function* () {
20
21
  let defaultPort = 9000;
21
22
  //检测端口占用情况
@@ -28,17 +29,20 @@ const bundleServer_1 = require("../module/bundleServer");
28
29
  stopPort: bundledServerPort + 100,
29
30
  });
30
31
  const compiler = (0, bundleServer_1.createServerCompiler)();
32
+ yield (0, bundleServer_1.runBundleServer)({
33
+ port: bundledServerPort,
34
+ compiler,
35
+ internalDevConfig: {
36
+ allowedHosts: 'all',
37
+ },
38
+ });
31
39
  yield (0, mainServer_1.default)({
32
40
  port: mainServerPort,
33
41
  microPort: bundledServerPort,
34
42
  });
35
43
  (0, open_1.default)(`http://localhost:${mainServerPort}`);
36
- (0, bundleServer_1.runBundleServer)({
37
- port: bundledServerPort,
38
- compiler,
39
- internalDevConfig: {
40
- allowedHosts: "all",
41
- },
44
+ process.on('exit', () => {
45
+ (0, kill_port_1.default)(bundledServerPort, 'tcp').then(console.log).catch(console.log);
42
46
  });
43
47
  }))().catch((err) => {
44
48
  console.log(err);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tuya-sat/micro-script",
3
- "version": "3.0.0-beta.9",
3
+ "version": "3.0.3",
4
4
  "bin": "./dist/bin/cli.js",
5
5
  "type": "commonjs",
6
6
  "license": "MIT",
@@ -20,9 +20,10 @@
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.9",
24
- "@tuya-sat/micro-dev-proxy": "3.0.0-beta.9",
25
- "@tuya-sat/micro-utils": "3.0.0-beta.9",
23
+ "@tuya-sat/micro-dev-loader": "3.0.3",
24
+ "@tuya-sat/micro-dev-proxy": "3.0.3",
25
+ "@tuya-sat/micro-utils": "3.0.3",
26
+ "@types/kill-port": "^2.0.0",
26
27
  "babel-loader": "8.2.4",
27
28
  "babel-plugin-import": "1.13.3",
28
29
  "chalk": "4.1.2",
@@ -36,6 +37,7 @@
36
37
  "html-webpack-plugin": "5.5.0",
37
38
  "http-proxy-middleware": "2.0.4",
38
39
  "joi": "17.6.0",
40
+ "kill-port": "^2.0.1",
39
41
  "less": "4.1.2",
40
42
  "less-loader": "10.2.0",
41
43
  "mini-css-extract-plugin": "2.6.0",
@@ -52,13 +54,14 @@
52
54
  "sass-loader": "12.6.0",
53
55
  "style-loader": "3.3.1",
54
56
  "svg-url-loader": "7.1.1",
55
- "tsconfig-paths-webpack-plugin": "3.5.2",
57
+ "tsconfig-paths-webpack-plugin": "^4.0.0",
56
58
  "uid": "^2.0.1",
57
59
  "url-loader": "4.1.1",
58
60
  "uuid": "8.3.2",
59
61
  "vue-loader": "17.0.0",
60
- "webpack": "5.70.0",
61
- "webpack-dev-server": "4.7.4",
62
+ "webpack": "5.75.0",
63
+ "webpack-cli": "5.0.1",
64
+ "webpack-dev-server": "4.11.1",
62
65
  "webpack-merge": "5.8.0"
63
66
  },
64
67
  "devDependencies": {
@@ -66,6 +69,7 @@
66
69
  "@types/jest": "27.4.1",
67
70
  "@types/uuid": "8.3.4",
68
71
  "jest": "27.5.1",
72
+ "terser-webpack-plugin": "^5.3.6",
69
73
  "ts-jest": "27.1.3",
70
74
  "typescript": "4.6.2"
71
75
  },