@tuya-sat/micro-script 3.0.0-beta.13 → 3.0.0-beta.15

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.
@@ -191,7 +191,9 @@ function getCommonConfig({ isDev, isBuild, }) {
191
191
  multiAppsWebpackConfig.entry[app.name] = `${path_1.default.join(process.cwd(), app.dir)}/index.tsx`;
192
192
  multiAppsWebpackConfig.plugins.push(new html_webpack_plugin_1.default({
193
193
  inject: true,
194
- filename: `${app.name}.html`,
194
+ filename: app.htmlContentHash
195
+ ? `${app.name}-[contenthash].html`
196
+ : `${app.name}.html`,
195
197
  template: paths_1.default.spaHtml,
196
198
  chunks: [app.name],
197
199
  }));
@@ -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
- 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
- saas_id_info_list: [],
49
- };
50
- multiApps.forEach((app) => {
51
- const entry_id = idsMap.get(app.name).entry_id;
52
- const manifest = fs_extra_1.default.readJSONSync(path.join(process.cwd(), `${app.dir}/manifest.json`), 'utf-8');
53
- const oem_micro_app_id = idsMap.get(app.name).oem_micro_app_id;
54
- const baseUrl = `/apps/${oem_micro_app_id}`;
55
- result.saas_id_info_list.push({
56
- oem_micro_app_id: oem_micro_app_id,
57
- universal_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,
58
73
  });
59
- const micoApp = consturctApp(manifest, oem_micro_app_id, baseUrl, lang, microPort, app.name);
60
- const entryInfo = consturctEntry(manifest, oem_micro_app_id, entry_id, baseUrl, lang, app.dir);
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
- result.apps.push(micoApp);
63
- result.entry_info.entries.push(entryInfo);
64
- result.permissions[oem_micro_app_id] = permission;
65
- });
66
- res.send({
67
- code: null,
68
- errorMsg: null,
69
- msg: null,
70
- result,
71
- success: true,
72
- });
73
- }
74
- else {
75
- const manifest = (0, micro_utils_1.parseManifest)();
76
- const entry_id = (0, uuid_1.v4)();
77
- const oem_micro_app_id = manifest.universalId;
78
- const baseUrl = `/apps/${oem_micro_app_id}`;
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) {
@@ -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;
@@ -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
- const base = debuggerConfig.base || defaultBase;
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);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tuya-sat/micro-script",
3
- "version": "3.0.0-beta.13",
3
+ "version": "3.0.0-beta.15",
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.13",
24
- "@tuya-sat/micro-dev-proxy": "3.0.0-beta.13",
25
- "@tuya-sat/micro-utils": "3.0.0-beta.13",
23
+ "@tuya-sat/micro-dev-loader": "3.0.0-beta.15",
24
+ "@tuya-sat/micro-dev-proxy": "3.0.0-beta.15",
25
+ "@tuya-sat/micro-utils": "3.0.0-beta.15",
26
26
  "@types/kill-port": "^2.0.0",
27
27
  "babel-loader": "8.2.4",
28
28
  "babel-plugin-import": "1.13.3",