@tuya-sat/micro-script 3.0.17 → 3.0.18-beta.1

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.
@@ -215,7 +215,12 @@ function getCommonConfig({ isDev, isBuild, }) {
215
215
  }
216
216
  if (multiApps && multiApps.length > 0) {
217
217
  multiApps.forEach((app) => {
218
- multiAppsWebpackConfig.entry[app.name] = `${path_1.default.join(process.cwd(), app.dir)}/${(0, utils_1.isMonorepo)() ? 'src/' : ''}index.tsx`;
218
+ if ((0, utils_1.isMonorepo)()) {
219
+ multiAppsWebpackConfig.entry[app.name] = `${path_1.default.join(process.cwd(), 'node_modules/.micro')}/${app.dir}/index.tsx`;
220
+ }
221
+ else {
222
+ multiAppsWebpackConfig.entry[app.name] = `${path_1.default.join(process.cwd(), app.dir)}/index.tsx`;
223
+ }
219
224
  multiAppsWebpackConfig.plugins.push(new html_webpack_plugin_1.default({
220
225
  inject: true,
221
226
  filename: app.htmlContentHash
@@ -14,7 +14,7 @@ const reactConfig = ({ isDev, isBuild, currentFramework, isTs, }) => {
14
14
  rules: [
15
15
  {
16
16
  test: /\.(js|mjs|jsx|ts|tsx)$/,
17
- exclude: /node_modules/,
17
+ // exclude: /node_modules/,
18
18
  use: [
19
19
  {
20
20
  loader: require.resolve('babel-loader'),
@@ -17,7 +17,9 @@ const open_1 = __importDefault(require("open"));
17
17
  const mainServer_1 = __importDefault(require("../module/mainServer"));
18
18
  const bundleServer_1 = require("../module/bundleServer");
19
19
  const kill_port_1 = __importDefault(require("kill-port"));
20
+ const template_1 = __importDefault(require("../template"));
20
21
  (() => __awaiter(void 0, void 0, void 0, function* () {
22
+ yield (0, template_1.default)();
21
23
  let defaultPort = 9000;
22
24
  //检测端口占用情况
23
25
  const bundledServerPort = yield portfinder_1.default.getPortPromise({
@@ -0,0 +1,2 @@
1
+ declare const _default: () => Promise<void>;
2
+ export default _default;
@@ -0,0 +1,57 @@
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
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ Object.defineProperty(exports, "__esModule", { value: true });
35
+ const fs = __importStar(require("fs"));
36
+ const path = __importStar(require("path"));
37
+ const isMonorepo = () => {
38
+ return (fs.existsSync(path.join(process.cwd(), 'apps')) &&
39
+ fs.existsSync(path.join(process.cwd(), 'packages')));
40
+ };
41
+ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
42
+ if (isMonorepo()) {
43
+ fs.readdirSync(path.join(process.cwd(), 'apps')).forEach((dir) => {
44
+ console.log('directory ' + dir);
45
+ const microPath = path.join(process.cwd(), 'node_modules/.micro', dir);
46
+ !fs.existsSync(microPath) && fs.mkdirSync(microPath);
47
+ fs.copyFileSync(path.join(__dirname, './micro-app/index.css'), path.join(microPath, 'index.css'));
48
+ fs.copyFileSync(path.join(__dirname, './micro-app/public-path.js'), path.join(microPath, 'public-path.js'));
49
+ let content = fs.readFileSync(path.join('./micro-app/index.tsx'), {
50
+ encoding: 'utf8',
51
+ });
52
+ content = content.replace("import App from './App';", `import App from '../../../apps/${dir}/src/App'`);
53
+ content = content.replace("import './lang';", `import '../../../apps/${dir}/src/lang';`);
54
+ fs.writeFileSync(microPath + '/index.tsx', content);
55
+ });
56
+ }
57
+ });
@@ -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,88 @@
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 { CaptureContext, Event, Severity } from '@sentry/types';
7
+ import App from './App';
8
+ import './lang';
9
+ import './index.css';
10
+ import 'theme';
11
+
12
+ export interface IQiankunProps {
13
+ base: string;
14
+ container: HTMLElement; // 子应用所在容器
15
+ dynamicProps: DynamicProps; // 面包屑
16
+ getOwnMenu: () => { entry_name: string }; // 获取当前选中菜单
17
+ hasPermission: (permissionCode: string) => boolean;
18
+ isSupportMobile: boolean; // 是否支持移动端
19
+ mainHistory: mainHistory; // 用于微应用间跳转
20
+ modifySelectedMenu: () => void; //
21
+ region: 'tx' | 'us' | 'eu' | 'in' | 'ueaz' | 'we' | 'sea';
22
+ resourcePrefix: string; // 静态资源地址
23
+ sentry: {
24
+ captureEvent: (event: Event) => string;
25
+ captureMessage: (
26
+ message: string,
27
+ captureContext?: CaptureContext | Severity
28
+ ) => string;
29
+ captureException: (
30
+ exception: any,
31
+ captureContext?: CaptureContext
32
+ ) => string;
33
+ };
34
+ tyLang: 'zh' | 'en'; // 当前语言
35
+ langResource: any;
36
+ }
37
+ export let microProps: IQiankunProps;
38
+
39
+ function render(props: IQiankunProps) {
40
+ const { base, container } = props as IQiankunProps;
41
+ const root = (
42
+ container
43
+ ? container.querySelector('#root')
44
+ : document.querySelector('#root')
45
+ ) as HTMLElement;
46
+ message.config({
47
+ getContainer: () => root,
48
+ });
49
+ ReactDOM.render(
50
+ <BrowserRouter basename={window.__POWERED_BY_QIANKUN__ ? base : '/'}>
51
+ <App {...props} />
52
+ </BrowserRouter>,
53
+ root
54
+ );
55
+ }
56
+
57
+ if (!window.__POWERED_BY_QIANKUN__) {
58
+ render({} as IQiankunProps);
59
+ }
60
+
61
+ export async function bootstrap() {
62
+ console.log('子应用启动');
63
+ }
64
+
65
+ export async function mount(props: IQiankunProps) {
66
+ console.log('挂载子应用', props);
67
+ props.langResource && replaceLangResource(props.langResource);
68
+ getI18n().changeLanguage(props.tyLang);
69
+ microProps = props;
70
+ render(props);
71
+ }
72
+
73
+ export async function unmount(props: IQiankunProps) {
74
+ const { container } = props;
75
+ message.destroy();
76
+ const root = (
77
+ container
78
+ ? container.querySelector('#root')
79
+ : document.querySelector('#root')
80
+ ) as HTMLElement;
81
+ ReactDOM.unmountComponentAtNode(root);
82
+ }
83
+
84
+ function replaceLangResource(langResource: any) {
85
+ Object.keys(langResource).forEach((langkey) => {
86
+ getI18n().addResourceBundle(langkey, 'translation', langResource[langkey]);
87
+ });
88
+ }
@@ -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.17",
3
+ "version": "3.0.18-beta.1",
4
4
  "bin": "./dist/bin/cli.js",
5
5
  "type": "commonjs",
6
6
  "license": "MIT",
@@ -11,7 +11,7 @@
11
11
  },
12
12
  "scripts": {
13
13
  "dev": "rm -rf dist/ && tsc --watch",
14
- "build": "rm -rf dist/ && tsc",
14
+ "build": "rm -rf dist/ && tsc && node ./scripts/copyTemplate.js",
15
15
  "prepublish": "yarn build"
16
16
  },
17
17
  "dependencies": {
@@ -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.17",
27
- "@tuya-sat/micro-dev-proxy": "3.0.17",
28
- "@tuya-sat/micro-utils": "3.0.17",
26
+ "@tuya-sat/micro-dev-loader": "3.0.18-beta.1",
27
+ "@tuya-sat/micro-dev-proxy": "3.0.18-beta.1",
28
+ "@tuya-sat/micro-utils": "3.0.18-beta.1",
29
29
  "@types/kill-port": "^2.0.0",
30
30
  "babel-loader": "8.2.4",
31
31
  "babel-plugin-import": "1.13.3",
@@ -0,0 +1,7 @@
1
+ const fs = require('fs-extra');
2
+ const path = require('path');
3
+
4
+ fs.copySync(
5
+ path.join(process.cwd(), './src/template/micro-app'),
6
+ path.join(process.cwd(), 'dist/template/micro-app')
7
+ );