@tuya-sat/micro-script 3.2.9 → 3.2.10

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.
@@ -31,6 +31,7 @@ const paths_1 = __importDefault(require("../config/paths"));
31
31
  const webpack_config_1 = __importDefault(require("../config/webpack.config"));
32
32
  const options_1 = __importDefault(require("./options"));
33
33
  const onceFactory_1 = require("../utils/onceFactory");
34
+ const promiser_1 = require("../utils/promiser");
34
35
  function createServerCompiler() {
35
36
  const config = Object.assign(Object.assign({}, (0, webpack_config_1.default)()), {
36
37
  //下面所有配置都是为了精简terminal输出
@@ -43,6 +44,7 @@ exports.createServerCompiler = createServerCompiler;
43
44
  function runBundleServer({ port, compiler, internalDevConfig = {}, }) {
44
45
  return __awaiter(this, void 0, void 0, function* () {
45
46
  const spinner = (0, ora_1.default)(`starting dev server in ${port} port`).start();
47
+ const { waiting, resolve } = (0, promiser_1.promiser)();
46
48
  const { devServer = (value) => value } = require(paths_1.default.microConfig);
47
49
  const { setupMiddlewares: startDevSetupMiddlewares } = internalDevConfig, restServerConfig = __rest(internalDevConfig, ["setupMiddlewares"]);
48
50
  const server = new webpack_dev_server_1.default(devServer(Object.assign({ hot: true, liveReload: false, port, headers: {
@@ -63,11 +65,13 @@ function runBundleServer({ port, compiler, internalDevConfig = {}, }) {
63
65
  });
64
66
  compiler.hooks.done.tap('MyPlugin', ({ endTime, startTime }) => {
65
67
  spinner.isSpinning && spinner.succeed();
68
+ resolve();
66
69
  console.log(`compiled time ~${endTime - startTime}ms`);
67
70
  });
68
71
  //临时提示
69
72
  compiler.hooks.done.tap('once-tip', (0, onceFactory_1.onceFactory)(() => { }));
70
73
  yield server.start();
74
+ yield waiting;
71
75
  console.log('\n The local application server has started');
72
76
  });
73
77
  }
@@ -3,5 +3,5 @@ import { AppProxy } from '@tuya-sat/micro-dev-proxy';
3
3
  interface IApp extends Express {
4
4
  __appProxy__?: AppProxy;
5
5
  }
6
- export default function mockSaasInfo(app: IApp, microPort: number): void;
6
+ export default function mockSaasInfo(app: IApp, microPort: number): Promise<IApp>;
7
7
  export {};
@@ -44,78 +44,40 @@ const path = __importStar(require("path"));
44
44
  const fs_extra_1 = __importDefault(require("fs-extra"));
45
45
  const utils_1 = require("../../utils");
46
46
  function mockSaasInfo(app, microPort) {
47
- let { multiApps, microApps, debuggerConfig: { isMainApp, target }, } = require(paths_1.default.microConfig);
48
- const idsMap = new Map();
49
- const expressApp = app;
50
- multiApps = (0, utils_1.processMultiApps)(multiApps);
51
- if (isMainApp && fs_extra_1.default.existsSync(path.join(process.cwd(), 'apps'))) {
52
- const dirs = ((microApps === null || microApps === void 0 ? void 0 : microApps.length) > 0 && microApps) ||
53
- fs_extra_1.default.readdirSync(path.join(process.cwd(), 'apps'));
54
- dirs === null || dirs === void 0 ? void 0 : dirs.forEach((dir) => {
55
- idsMap.set(dir, { entry_id: (0, uuid_1.v4)(), oem_micro_app_id: (0, uid_1.uid)(16) });
56
- });
57
- app.get('/api/saas-info', (req, res) => {
58
- const lang = 'zh';
59
- const result = {
60
- apps: [],
61
- entry_info: { entries: [], entry_mode: 'normal' },
62
- permissions: {},
63
- saas_id_info_list: [],
64
- };
65
- dirs.forEach((dir) => {
66
- const entry_id = idsMap.get(dir).entry_id;
67
- const manifest = fs_extra_1.default.readJSONSync(path.join(process.cwd(), 'apps', dir, 'manifest.json'), 'utf-8');
68
- const oem_micro_app_id = idsMap.get(dir).oem_micro_app_id;
69
- const baseUrl = `/apps/${oem_micro_app_id}`;
70
- result.saas_id_info_list.push({
71
- oem_micro_app_id: oem_micro_app_id,
72
- universal_id: '',
73
- });
74
- const appConfig = fs_extra_1.default.readJSONSync(path.join(process.cwd(), 'node_modules', '.micro', 'app.config.json'));
75
- const micoApp = consturctApp(manifest, oem_micro_app_id, baseUrl, lang, appConfig[dir]);
76
- const entryInfo = consturctEntry(manifest, oem_micro_app_id, entry_id, baseUrl, lang, `apps/${dir}`);
77
- const permission = (manifest === null || manifest === void 0 ? void 0 : manifest.privileges.map((item) => {
78
- return { permission_group: item.code };
79
- })) || [];
80
- result.apps.push(micoApp);
81
- result.entry_info.entries.push(entryInfo);
82
- result.permissions[oem_micro_app_id] = permission;
83
- });
84
- res.send({
85
- code: null,
86
- errorMsg: null,
87
- msg: null,
88
- result,
89
- success: true,
47
+ return __awaiter(this, void 0, void 0, function* () {
48
+ let { multiApps, microApps, debuggerConfig: { isMainApp, target }, } = require(paths_1.default.microConfig);
49
+ const idsMap = new Map();
50
+ const expressApp = app;
51
+ multiApps = (0, utils_1.processMultiApps)(multiApps);
52
+ if (isMainApp && fs_extra_1.default.existsSync(path.join(process.cwd(), 'apps'))) {
53
+ const dirs = ((microApps === null || microApps === void 0 ? void 0 : microApps.length) > 0 && microApps) ||
54
+ fs_extra_1.default.readdirSync(path.join(process.cwd(), 'apps'));
55
+ dirs === null || dirs === void 0 ? void 0 : dirs.forEach((dir) => {
56
+ idsMap.set(dir, { entry_id: (0, uuid_1.v4)(), oem_micro_app_id: (0, uid_1.uid)(16) });
90
57
  });
91
- });
92
- }
93
- if (!isMainApp) {
94
- multiApps === null || multiApps === void 0 ? void 0 : multiApps.forEach((app) => {
95
- idsMap.set(app.name, { entry_id: (0, uuid_1.v4)(), oem_micro_app_id: (0, uid_1.uid)(16) });
96
- });
97
- app.get('/api/saas-info', (req, res) => __awaiter(this, void 0, void 0, function* () {
98
- const lang = parseCookie(req.headers['cookie'], 'main-i18next');
99
- if ((0, utils_1.isMonorepo)() || (multiApps && multiApps.length > 0)) {
58
+ return app.get('/api/saas-info', (req, res) => {
59
+ const lang = 'zh';
100
60
  const result = {
101
61
  apps: [],
102
62
  entry_info: { entries: [], entry_mode: 'normal' },
103
63
  permissions: {},
104
64
  saas_id_info_list: [],
105
65
  };
106
- multiApps.forEach((app) => {
107
- const entry_id = idsMap.get(app.name).entry_id;
108
- const dir = (0, utils_1.isMonorepo)() ? `apps/${app.name}` : `${app.dir}`;
109
- const manifest = fs_extra_1.default.readJSONSync(path.join(process.cwd(), dir, 'manifest.json'), 'utf-8');
110
- const oem_micro_app_id = idsMap.get(app.name).oem_micro_app_id;
66
+ dirs.forEach((dir) => {
67
+ const entry_id = idsMap.get(dir).entry_id;
68
+ const manifest = fs_extra_1.default.readJSONSync(path.join(process.cwd(), 'apps', dir, 'manifest.json'), 'utf-8');
69
+ const oem_micro_app_id = idsMap.get(dir).oem_micro_app_id;
111
70
  const baseUrl = `/apps/${oem_micro_app_id}`;
112
71
  result.saas_id_info_list.push({
113
72
  oem_micro_app_id: oem_micro_app_id,
114
73
  universal_id: '',
115
74
  });
116
- const micoApp = consturctApp(manifest, oem_micro_app_id, baseUrl, lang, microPort, app.name);
117
- const entryInfo = consturctEntry(manifest, oem_micro_app_id, entry_id, baseUrl, lang, dir);
118
- const permission = consturctPermissions();
75
+ const appConfig = fs_extra_1.default.readJSONSync(path.join(process.cwd(), 'node_modules', '.micro', 'app.config.json'));
76
+ const micoApp = consturctApp(manifest, oem_micro_app_id, baseUrl, lang, appConfig[dir]);
77
+ const entryInfo = consturctEntry(manifest, oem_micro_app_id, entry_id, baseUrl, lang, `apps/${dir}`);
78
+ const permission = (manifest === null || manifest === void 0 ? void 0 : manifest.privileges.map((item) => {
79
+ return { permission_group: item.code };
80
+ })) || [];
119
81
  result.apps.push(micoApp);
120
82
  result.entry_info.entries.push(entryInfo);
121
83
  result.permissions[oem_micro_app_id] = permission;
@@ -127,46 +89,86 @@ function mockSaasInfo(app, microPort) {
127
89
  result,
128
90
  success: true,
129
91
  });
130
- }
131
- else {
132
- const manifest = (0, micro_utils_1.parseManifest)();
133
- const entry_id = (0, uuid_1.v4)();
134
- const oem_micro_app_id = manifest.universalId;
135
- const baseUrl = `/apps/${oem_micro_app_id}`;
136
- const saasApps = yield refactorConstructApp({
137
- url: target,
138
- headers: {
139
- cookie: expressApp.__appProxy__.getCookie(''),
140
- csrf: expressApp.__appProxy__.csrfValue.value,
141
- }
142
- }, [
143
- {
144
- manifest,
145
- oem_micro_app_id,
146
- baseUrl,
147
- lang,
148
- port: microPort
149
- }
150
- ]);
151
- const entryInfo = consturctEntry(manifest, oem_micro_app_id, entry_id, baseUrl, lang, '');
152
- const permission = consturctPermissions();
153
- res.send({
154
- code: null,
155
- errorMsg: null,
156
- msg: null,
157
- result: {
158
- apps: saasApps,
159
- entry_info: { entries: [entryInfo], entry_mode: 'normal' },
160
- permissions: { [oem_micro_app_id]: permission },
161
- saas_id_info_list: [
162
- { oem_micro_app_id: oem_micro_app_id, universal_id: '' },
163
- ],
164
- },
165
- success: true,
166
- });
167
- }
168
- }));
169
- }
92
+ });
93
+ }
94
+ if (!isMainApp) {
95
+ multiApps === null || multiApps === void 0 ? void 0 : multiApps.forEach((app) => {
96
+ idsMap.set(app.name, { entry_id: (0, uuid_1.v4)(), oem_micro_app_id: (0, uid_1.uid)(16) });
97
+ });
98
+ return app.get('/api/saas-info', (req, res) => __awaiter(this, void 0, void 0, function* () {
99
+ const lang = parseCookie(req.headers['cookie'], 'main-i18next');
100
+ if ((0, utils_1.isMonorepo)() || (multiApps && multiApps.length > 0)) {
101
+ const result = {
102
+ apps: [],
103
+ entry_info: { entries: [], entry_mode: 'normal' },
104
+ permissions: {},
105
+ saas_id_info_list: [],
106
+ };
107
+ multiApps.forEach((app) => {
108
+ const entry_id = idsMap.get(app.name).entry_id;
109
+ const dir = (0, utils_1.isMonorepo)() ? `apps/${app.name}` : `${app.dir}`;
110
+ const manifest = fs_extra_1.default.readJSONSync(path.join(process.cwd(), dir, 'manifest.json'), 'utf-8');
111
+ const oem_micro_app_id = idsMap.get(app.name).oem_micro_app_id;
112
+ const baseUrl = `/apps/${oem_micro_app_id}`;
113
+ result.saas_id_info_list.push({
114
+ oem_micro_app_id: oem_micro_app_id,
115
+ universal_id: '',
116
+ });
117
+ const micoApp = consturctApp(manifest, oem_micro_app_id, baseUrl, lang, microPort, app.name);
118
+ const entryInfo = consturctEntry(manifest, oem_micro_app_id, entry_id, baseUrl, lang, dir);
119
+ const permission = consturctPermissions();
120
+ result.apps.push(micoApp);
121
+ result.entry_info.entries.push(entryInfo);
122
+ result.permissions[oem_micro_app_id] = permission;
123
+ });
124
+ res.send({
125
+ code: null,
126
+ errorMsg: null,
127
+ msg: null,
128
+ result,
129
+ success: true,
130
+ });
131
+ }
132
+ else {
133
+ const manifest = (0, micro_utils_1.parseManifest)();
134
+ const entry_id = (0, uuid_1.v4)();
135
+ const oem_micro_app_id = manifest.universalId;
136
+ const baseUrl = `/apps/${oem_micro_app_id}`;
137
+ const saasApps = yield refactorConstructApp({
138
+ url: target,
139
+ headers: {
140
+ cookie: expressApp.__appProxy__.getCookie(''),
141
+ csrf: expressApp.__appProxy__.csrfValue.value,
142
+ }
143
+ }, [
144
+ {
145
+ manifest,
146
+ oem_micro_app_id,
147
+ baseUrl,
148
+ lang,
149
+ port: microPort
150
+ }
151
+ ]);
152
+ const entryInfo = consturctEntry(manifest, oem_micro_app_id, entry_id, baseUrl, lang, '');
153
+ const permission = consturctPermissions();
154
+ res.send({
155
+ code: null,
156
+ errorMsg: null,
157
+ msg: null,
158
+ result: {
159
+ apps: saasApps,
160
+ entry_info: { entries: [entryInfo], entry_mode: 'normal' },
161
+ permissions: { [oem_micro_app_id]: permission },
162
+ saas_id_info_list: [
163
+ { oem_micro_app_id: oem_micro_app_id, universal_id: '' },
164
+ ],
165
+ },
166
+ success: true,
167
+ });
168
+ }
169
+ }));
170
+ }
171
+ });
170
172
  }
171
173
  exports.default = mockSaasInfo;
172
174
  function consturctEntry(manifest, oem_micro_app_id, entry_id, baseUrl, lang, dir) {
@@ -93,7 +93,7 @@ function runMain({ port, microPort, }) {
93
93
  (0, socket_1.bootStrap)(io);
94
94
  mainServer && mainServer.before && mainServer.before(app);
95
95
  yield (0, staticMain_1.default)(app, debuggerConfig, microPort);
96
- (0, fakeSaasInfo_1.default)(app, microPort);
96
+ yield (0, fakeSaasInfo_1.default)(app, microPort);
97
97
  (0, mock_1.default)(app);
98
98
  (0, proxy_1.default)(app);
99
99
  mainServer && mainServer.after && mainServer.after(app);
@@ -24,7 +24,7 @@ const template_1 = __importDefault(require("../template"));
24
24
  //检测端口占用情况
25
25
  if (process.env.PROT) {
26
26
  const compiler = (0, bundleServer_1.createServerCompiler)();
27
- (0, bundleServer_1.runBundleServer)({
27
+ yield (0, bundleServer_1.runBundleServer)({
28
28
  port: Number(process.env.PROT),
29
29
  compiler,
30
30
  internalDevConfig: {
@@ -43,7 +43,7 @@ const template_1 = __importDefault(require("../template"));
43
43
  stopPort: defaultPort + 100,
44
44
  });
45
45
  const compiler = (0, bundleServer_1.createServerCompiler)();
46
- (0, bundleServer_1.runBundleServer)({
46
+ yield (0, bundleServer_1.runBundleServer)({
47
47
  port,
48
48
  compiler,
49
49
  internalDevConfig: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tuya-sat/micro-script",
3
- "version": "3.2.9",
3
+ "version": "3.2.10",
4
4
  "bin": "./dist/bin/cli.js",
5
5
  "type": "commonjs",
6
6
  "license": "MIT",
@@ -23,9 +23,9 @@
23
23
  "@babel/preset-typescript": "7.16.7",
24
24
  "@babel/traverse": "^7.20.13",
25
25
  "@pmmmwh/react-refresh-webpack-plugin": "0.5.4",
26
- "@tuya-sat/micro-dev-loader": "3.2.9",
27
- "@tuya-sat/micro-dev-proxy": "3.2.9",
28
- "@tuya-sat/micro-utils": "3.2.9",
26
+ "@tuya-sat/micro-dev-loader": "3.2.10",
27
+ "@tuya-sat/micro-dev-proxy": "3.2.10",
28
+ "@tuya-sat/micro-utils": "3.2.10",
29
29
  "@types/kill-port": "^2.0.0",
30
30
  "babel-loader": "8.2.4",
31
31
  "babel-plugin-import": "1.13.3",