@tuya-sat/micro-script 3.0.22 → 3.0.23

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.
@@ -1,4 +1,27 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
26
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
27
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -25,6 +48,7 @@ const webpack_stats_plugin_1 = require("webpack-stats-plugin");
25
48
  const micro_dev_loader_1 = require("@tuya-sat/micro-dev-loader");
26
49
  const path_1 = __importDefault(require("path"));
27
50
  const utils_1 = require("../utils");
51
+ const fs = __importStar(require("fs"));
28
52
  const index_1 = require("@tuya-sat/micro-dev-loader/dist/less/utils/index");
29
53
  const paths_1 = __importDefault(require("./paths"));
30
54
  const utils_2 = require("../utils");
@@ -242,7 +266,7 @@ function getCommonConfig({ isDev, isBuild, }) {
242
266
  entry: multiAppsWebpackConfig.entry,
243
267
  });
244
268
  }
245
- if (isMainApp) {
269
+ if (isMainApp || !fs.existsSync(path_1.default.join(process.cwd(), 'src/index.tsx'))) {
246
270
  return (0, webpack_merge_1.merge)(getWebpackConfig([]), {
247
271
  entry: `${path_1.default.join(process.cwd(), 'node_modules/.micro')}/index.tsx`,
248
272
  });
@@ -54,16 +54,15 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
54
54
  fs.copyFileSync(path.join(__dirname, './main-app/index.tsx'), path.join(microPath, 'index.tsx'));
55
55
  fs.copyFileSync(path.join(__dirname, './main-app/utils.ts'), path.join(microPath, 'utils.ts'));
56
56
  }
57
- if (isMonorepo()) {
57
+ else if (isMonorepo()) {
58
58
  fs.readdirSync(path.join(process.cwd(), 'apps')).forEach((dir) => {
59
59
  console.log('directory ' + dir);
60
60
  const microPath = path.join(process.cwd(), 'node_modules/.micro', dir);
61
61
  !fs.existsSync(microPath) && fs.mkdirSync(microPath, { recursive: true });
62
- fs.copyFileSync(path.join(__dirname, './micro-app/index.css'), path.join(microPath, 'index.css'));
63
- fs.copyFileSync(path.join(__dirname, './micro-app/public-path.js'), path.join(microPath, 'public-path.js'));
64
- fs.copyFileSync(path.join(__dirname, './micro-app/interfaces.ts'), path.join(microPath, 'interfaces.ts'));
65
- fs.copyFileSync(path.join(__dirname, './micro-app/interfaces.ts'), path.join(path.join(process.cwd(), 'node_modules/.micro'), 'interfaces.ts'));
66
- let content = fs.readFileSync(path.join(__dirname, './micro-app/index.tsx'), {
62
+ fs.copyFileSync(path.join(__dirname, './multi-micro-app/index.css'), path.join(microPath, 'index.css'));
63
+ fs.copyFileSync(path.join(__dirname, './multi-micro-app/public-path.js'), path.join(microPath, 'public-path.js'));
64
+ fs.copyFileSync(path.join(__dirname, './multi-micro-app/interfaces.ts'), path.join(microPath, 'interfaces.ts'));
65
+ let content = fs.readFileSync(path.join(__dirname, './multi-micro-app/index.tsx'), {
67
66
  encoding: 'utf8',
68
67
  });
69
68
  content = content.replace("import App from './App';", `import App from '../../../apps/${dir}/src/App'`);
@@ -71,4 +70,18 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
71
70
  fs.writeFileSync(microPath + '/index.tsx', content);
72
71
  });
73
72
  }
73
+ else {
74
+ const microPath = path.join(process.cwd(), 'node_modules/.micro');
75
+ !fs.existsSync(microPath) && fs.mkdirSync(microPath, { recursive: true });
76
+ fs.copyFileSync(path.join(__dirname, './micro-app/index.css'), path.join(microPath, 'index.css'));
77
+ fs.copyFileSync(path.join(__dirname, './micro-app/public-path.js'), path.join(microPath, 'public-path.js'));
78
+ fs.copyFileSync(path.join(__dirname, './micro-app/interfaces.ts'), path.join(microPath, 'interfaces.ts'));
79
+ let content = fs.readFileSync(path.join(__dirname, './micro-app/index.tsx'), {
80
+ encoding: 'utf8',
81
+ });
82
+ content = content.replace("import App from './App';", `import App from '../../src/App'`);
83
+ content = content.replace("import './lang';", `import '../../src/lang';`);
84
+ content = content.replace("import './styles/global.less';", `import '../../src/styles/global.less';`);
85
+ fs.writeFileSync(microPath + '/index.tsx', content);
86
+ }
74
87
  });
@@ -1,25 +1,26 @@
1
1
  body {
2
- margin: 0;
3
- font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu',
4
- 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
5
- -webkit-font-smoothing: antialiased;
6
- -moz-osx-font-smoothing: grayscale;
7
- background-color: transparent !important;
8
- }
9
-
10
- code {
11
- font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', monospace;
12
- }
13
-
14
- #root {
15
- height: 100%;
16
- }
17
-
18
- .layout {
19
- margin-bottom: 20px;
20
- }
21
-
22
- .square {
23
- width: 20px;
24
- height: 20px;
25
- }
2
+ margin: 0;
3
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu',
4
+ 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
5
+ -webkit-font-smoothing: antialiased;
6
+ -moz-osx-font-smoothing: grayscale;
7
+ background-color: transparent !important;
8
+ }
9
+
10
+ code {
11
+ font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', monospace;
12
+ }
13
+
14
+ #root {
15
+ height: 100%;
16
+ }
17
+
18
+ .layout {
19
+ margin-bottom: 20px;
20
+ }
21
+
22
+ .square {
23
+ width: 20px;
24
+ height: 20px;
25
+ }
26
+
@@ -3,11 +3,12 @@ import ReactDOM from 'react-dom';
3
3
  import { BrowserRouter } from 'react-router-dom';
4
4
  import { getI18n } from 'react-i18next';
5
5
  import { message } from 'antd';
6
+ import { CaptureContext, Event, Severity } from '@sentry/types';
6
7
  import { IQiankunProps } from './interfaces';
7
8
  import App from './App';
8
9
  import './lang';
9
10
  import './index.css';
10
- import 'theme';
11
+ import './styles/global.less';
11
12
 
12
13
  export let microProps: IQiankunProps;
13
14
 
@@ -0,0 +1,25 @@
1
+ body {
2
+ margin: 0;
3
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu',
4
+ 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
5
+ -webkit-font-smoothing: antialiased;
6
+ -moz-osx-font-smoothing: grayscale;
7
+ background-color: transparent !important;
8
+ }
9
+
10
+ code {
11
+ font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', monospace;
12
+ }
13
+
14
+ #root {
15
+ height: 100%;
16
+ }
17
+
18
+ .layout {
19
+ margin-bottom: 20px;
20
+ }
21
+
22
+ .square {
23
+ width: 20px;
24
+ height: 20px;
25
+ }
@@ -0,0 +1,63 @@
1
+ import './public-path';
2
+ import ReactDOM from 'react-dom';
3
+ import { BrowserRouter } from 'react-router-dom';
4
+ import { getI18n } from 'react-i18next';
5
+ import { message } from 'antd';
6
+ import { IQiankunProps } from './interfaces';
7
+ import App from './App';
8
+ import './lang';
9
+ import './index.css';
10
+ import 'theme';
11
+
12
+ export let microProps: IQiankunProps;
13
+
14
+ function render(props: IQiankunProps) {
15
+ const { base, container } = props as IQiankunProps;
16
+ const root = (
17
+ container
18
+ ? container.querySelector('#root')
19
+ : document.querySelector('#root')
20
+ ) as HTMLElement;
21
+ message.config({
22
+ getContainer: () => root,
23
+ });
24
+ ReactDOM.render(
25
+ <BrowserRouter basename={window.__POWERED_BY_QIANKUN__ ? base : '/'}>
26
+ <App {...props} />
27
+ </BrowserRouter>,
28
+ root
29
+ );
30
+ }
31
+
32
+ if (!window.__POWERED_BY_QIANKUN__) {
33
+ render({} as IQiankunProps);
34
+ }
35
+
36
+ export async function bootstrap() {
37
+ console.log('子应用启动');
38
+ }
39
+
40
+ export async function mount(props: IQiankunProps) {
41
+ console.log('挂载子应用', props);
42
+ props.langResource && replaceLangResource(props.langResource);
43
+ getI18n().changeLanguage(props.tyLang);
44
+ microProps = props;
45
+ render(props);
46
+ }
47
+
48
+ export async function unmount(props: IQiankunProps) {
49
+ const { container } = props;
50
+ message.destroy();
51
+ const root = (
52
+ container
53
+ ? container.querySelector('#root')
54
+ : document.querySelector('#root')
55
+ ) as HTMLElement;
56
+ ReactDOM.unmountComponentAtNode(root);
57
+ }
58
+
59
+ function replaceLangResource(langResource: any) {
60
+ Object.keys(langResource).forEach((langkey) => {
61
+ getI18n().addResourceBundle(langkey, 'translation', langResource[langkey]);
62
+ });
63
+ }
@@ -0,0 +1,61 @@
1
+ import { CaptureContext, Event, Severity } from '@sentry/types';
2
+
3
+ interface mainHistory {
4
+ push: (path, state?) => void;
5
+ replace: (path, state?) => void;
6
+ go: (n: number) => void;
7
+ goBack: () => void;
8
+ goForward: () => void;
9
+ }
10
+
11
+ interface DynamicProps {
12
+ setBreadcrumb: SetBreadcrumb;
13
+ [key: string]: any;
14
+ }
15
+
16
+ interface SetBreadcrumb {
17
+ (breadcrumbInfos?: BreadcrumbInfoInput[]): void;
18
+ }
19
+
20
+ type BreadcrumbInfoInput =
21
+ | {
22
+ type: 'auto' | 'root';
23
+ name?: never;
24
+ path?: never;
25
+ }
26
+ | {
27
+ type: 'menu';
28
+ name?: never;
29
+ path: string;
30
+ }
31
+ | {
32
+ type: 'c';
33
+ name: string;
34
+ path: string;
35
+ };
36
+
37
+ export interface IQiankunProps {
38
+ base: string;
39
+ container: HTMLElement; // 子应用所在容器
40
+ dynamicProps: DynamicProps; // 面包屑
41
+ getOwnMenu: () => { entry_name: string }; // 获取当前选中菜单
42
+ hasPermission: (permissionCode: string) => boolean;
43
+ isSupportMobile: boolean; // 是否支持移动端
44
+ mainHistory: mainHistory; // 用于微应用间跳转
45
+ modifySelectedMenu: () => void; //
46
+ region: 'tx' | 'us' | 'eu' | 'in' | 'ueaz' | 'we' | 'sea';
47
+ resourcePrefix: string; // 静态资源地址
48
+ sentry: {
49
+ captureEvent: (event: Event) => string;
50
+ captureMessage: (
51
+ message: string,
52
+ captureContext?: CaptureContext | Severity
53
+ ) => string;
54
+ captureException: (
55
+ exception: any,
56
+ captureContext?: CaptureContext
57
+ ) => string;
58
+ };
59
+ tyLang: 'zh' | 'en'; // 当前语言
60
+ langResource: any;
61
+ }
@@ -0,0 +1,4 @@
1
+ /* eslint-disable no-undef */
2
+ if (window.__POWERED_BY_QIANKUN__) {
3
+ __webpack_public_path__ = window.__INJECTED_PUBLIC_PATH_BY_QIANKUN__;
4
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tuya-sat/micro-script",
3
- "version": "3.0.22",
3
+ "version": "3.0.23",
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.0.22",
27
- "@tuya-sat/micro-dev-proxy": "3.0.22",
28
- "@tuya-sat/micro-utils": "3.0.22",
26
+ "@tuya-sat/micro-dev-loader": "3.0.23",
27
+ "@tuya-sat/micro-dev-proxy": "3.0.23",
28
+ "@tuya-sat/micro-utils": "3.0.23",
29
29
  "@types/kill-port": "^2.0.0",
30
30
  "babel-loader": "8.2.4",
31
31
  "babel-plugin-import": "1.13.3",
@@ -65,7 +65,7 @@
65
65
  "url-loader": "4.1.1",
66
66
  "uuid": "8.3.2",
67
67
  "vue-loader": "17.0.0",
68
- "webpack": "5.76.0",
68
+ "webpack": "5.75.0",
69
69
  "webpack-cli": "5.0.1",
70
70
  "webpack-dev-server": "4.11.1",
71
71
  "webpack-manifest-plugin": "^5.0.0",
@@ -1,11 +1,17 @@
1
1
  const fs = require('fs-extra');
2
2
  const path = require('path');
3
3
 
4
+
4
5
  fs.copySync(
5
6
  path.join(process.cwd(), './src/template/micro-app'),
6
7
  path.join(process.cwd(), 'dist/template/micro-app')
7
8
  );
8
9
 
10
+ fs.copySync(
11
+ path.join(process.cwd(), './src/template/multi-micro-app'),
12
+ path.join(process.cwd(), 'dist/template/multi-micro-app')
13
+ );
14
+
9
15
  fs.copySync(
10
16
  path.join(process.cwd(), './src/template/main-app'),
11
17
  path.join(process.cwd(), 'dist/template/main-app')