@tuya-sat/micro-script 3.0.27-beta.2 → 3.0.27-beta.4
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.
- package/dist/framework/react.config.js +11 -12
- package/dist/module/main/fakeSaas.js +69 -10
- package/dist/module/main/fakeSaasInfo.js +38 -0
- package/dist/scripts/build.js +1 -2
- package/dist/scripts/start.js +35 -18
- package/dist/scripts/startInMain.js +1 -2
- package/dist/template/micro-app/index.tsx +1 -1
- package/dist/template/micro-app/interfaces.ts +3 -2
- package/package.json +4 -4
|
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.reactJsConfig = exports.reactTsConfig = void 0;
|
|
7
7
|
const react_refresh_webpack_plugin_1 = __importDefault(require("@pmmmwh/react-refresh-webpack-plugin"));
|
|
8
8
|
const tsconfig_paths_webpack_plugin_1 = __importDefault(require("tsconfig-paths-webpack-plugin"));
|
|
9
|
-
const fork_ts_checker_webpack_plugin_1 = __importDefault(require("fork-ts-checker-webpack-plugin"));
|
|
10
9
|
const paths_1 = __importDefault(require("../config/paths"));
|
|
11
10
|
const reactConfig = ({ isDev, isBuild, currentFramework, isTs, }) => {
|
|
12
11
|
return {
|
|
@@ -56,17 +55,17 @@ const reactConfig = ({ isDev, isBuild, currentFramework, isTs, }) => {
|
|
|
56
55
|
},
|
|
57
56
|
plugins: [
|
|
58
57
|
isDev && new react_refresh_webpack_plugin_1.default(),
|
|
59
|
-
isTs &&
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
58
|
+
// isTs &&
|
|
59
|
+
// new ForkTsCheckerWebpackPlugin({
|
|
60
|
+
// //https://github.com/TypeStrong/fork-ts-checker-webpack-plugin#typescript-options
|
|
61
|
+
// typescript: {
|
|
62
|
+
// diagnosticOptions: {
|
|
63
|
+
// semantic: true,
|
|
64
|
+
// syntactic: true,
|
|
65
|
+
// },
|
|
66
|
+
// mode: 'write-references',
|
|
67
|
+
// },
|
|
68
|
+
// }),
|
|
70
69
|
].filter((value) => Boolean(value)),
|
|
71
70
|
};
|
|
72
71
|
};
|
|
@@ -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) {
|
|
@@ -15,6 +38,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
38
|
exports.getFakeUser = void 0;
|
|
16
39
|
const axios_1 = __importDefault(require("axios"));
|
|
17
40
|
const chalk_1 = __importDefault(require("chalk"));
|
|
41
|
+
const fs = __importStar(require("fs"));
|
|
42
|
+
const path = __importStar(require("path"));
|
|
18
43
|
function parse_SDF_CONFIG(html) {
|
|
19
44
|
var _a;
|
|
20
45
|
const REGEX = /(?<=window._SDF_CONFIG=).*?(?=;)/;
|
|
@@ -36,16 +61,50 @@ function getFakeSaas(config) {
|
|
|
36
61
|
console.log(chalk_1.default.red('没有配置target'));
|
|
37
62
|
process.exit(1);
|
|
38
63
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
64
|
+
if (config.isMainApp && fs.existsSync(path.join(process.cwd(), 'apps'))) {
|
|
65
|
+
const saas = {
|
|
66
|
+
_SDF: {
|
|
67
|
+
base: '',
|
|
68
|
+
env: '',
|
|
69
|
+
region: '',
|
|
70
|
+
saas: {
|
|
71
|
+
background_image: 'https://images.tuyacn.com/rms-static/537a3fd0-1b5a-11ec-b7af-2d39f353debc-1632283530317.jpg?tyName=login.jpg',
|
|
72
|
+
charge_status: 'TRIAL',
|
|
73
|
+
entries: { entry_mode: 'normal' },
|
|
74
|
+
favicon: 'https://images.tuyacn.com/rms-static/ae9ba1b0-41d4-11ec-89bb-d7b7de210e4b-1636514225995.png?tyName=favicon.png',
|
|
75
|
+
host_filing: '备案:fast-cn.wgine',
|
|
76
|
+
is_custom: false,
|
|
77
|
+
is_need_jiyan: true,
|
|
78
|
+
is_support_mobile: true,
|
|
79
|
+
message_switch: true,
|
|
80
|
+
label: '',
|
|
81
|
+
legal_notice: 'https://ruomu-abc-001.fast-cn.wgine.com/policies/legal',
|
|
82
|
+
logo: 'https://images.tuyacn.com/rms-static/bc42adb0-6f86-11ec-b5fa-7deb2a111a61-1641538501643.png?tyName=%E9%BB%98%E8%AE%A4logo%2056X56%20.png',
|
|
83
|
+
privacy_policy: "https://ruomu-abc-001.fast-cn.wgine.com/policies/privacy",
|
|
84
|
+
service_terms: "https://ruomu-abc-001.fast-cn.wgine.com/policies/service",
|
|
85
|
+
supported_language: { en: 'English', zh: '简体中文' },
|
|
86
|
+
tenant_register_support: false,
|
|
87
|
+
tenant_type: "SINGLE_TENANT",
|
|
88
|
+
title: "SaaS UI"
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
_SDF_CONFIG: {},
|
|
92
|
+
__MAIN_APP_PUBLIC_PATH: 'https://static1.tuyacn.com/static/sdf-main-app/0.0.0-123/',
|
|
93
|
+
};
|
|
94
|
+
return saas;
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
const { data } = yield axios_1.default.get(new URL('/login?disable_third_login=true', config.target).href);
|
|
98
|
+
const _SDF_CONFIG = parse_SDF_CONFIG(data);
|
|
99
|
+
const _SDF = parse_SDF(data);
|
|
100
|
+
const __MAIN_APP_PUBLIC_PATH = parse__MAIN_APP_PUBLIC_PATH(data);
|
|
101
|
+
const saas = {
|
|
102
|
+
_SDF_CONFIG: JSON.parse(_SDF_CONFIG),
|
|
103
|
+
_SDF: JSON.parse(_SDF),
|
|
104
|
+
__MAIN_APP_PUBLIC_PATH: JSON.parse(__MAIN_APP_PUBLIC_PATH),
|
|
105
|
+
};
|
|
106
|
+
return saas;
|
|
107
|
+
}
|
|
49
108
|
});
|
|
50
109
|
}
|
|
51
110
|
exports.default = getFakeSaas;
|
|
@@ -40,6 +40,44 @@ function mockSaasInfo(app, microPort) {
|
|
|
40
40
|
multiApps === null || multiApps === void 0 ? void 0 : multiApps.forEach((app) => {
|
|
41
41
|
idsMap.set(app.name, { entry_id: (0, uuid_1.v4)(), oem_micro_app_id: (0, uid_1.uid)(16) });
|
|
42
42
|
});
|
|
43
|
+
if (isMainApp && fs_extra_1.default.existsSync(path.join(process.cwd(), 'apps'))) {
|
|
44
|
+
app.get('/api/saas-info', (req, res) => {
|
|
45
|
+
const lang = 'zh';
|
|
46
|
+
const result = {
|
|
47
|
+
apps: [],
|
|
48
|
+
entry_info: { entries: [], entry_mode: 'normal' },
|
|
49
|
+
permissions: {},
|
|
50
|
+
saas_id_info_list: [],
|
|
51
|
+
};
|
|
52
|
+
const dirs = fs_extra_1.default.readdirSync(path.join(process.cwd(), 'apps'));
|
|
53
|
+
dirs.forEach((dir) => {
|
|
54
|
+
const entry_id = (0, uuid_1.v4)();
|
|
55
|
+
const manifest = fs_extra_1.default.readJSONSync(path.join(process.cwd(), 'apps', dir, 'manifest.json'), 'utf-8');
|
|
56
|
+
const oem_micro_app_id = (0, uid_1.uid)(16);
|
|
57
|
+
const baseUrl = `/apps/${oem_micro_app_id}`;
|
|
58
|
+
result.saas_id_info_list.push({
|
|
59
|
+
oem_micro_app_id: oem_micro_app_id,
|
|
60
|
+
universal_id: '',
|
|
61
|
+
});
|
|
62
|
+
const appConfig = fs_extra_1.default.readJSONSync(path.join(process.cwd(), 'node_modules', '.micro', 'app.config.json'));
|
|
63
|
+
const micoApp = consturctApp(manifest, oem_micro_app_id, baseUrl, lang, appConfig[dir]);
|
|
64
|
+
const entryInfo = consturctEntry(manifest, oem_micro_app_id, entry_id, baseUrl, lang, `apps/${dir}`);
|
|
65
|
+
const permission = (manifest === null || manifest === void 0 ? void 0 : manifest.privileges.map(item => {
|
|
66
|
+
return { permission_group: item.code };
|
|
67
|
+
})) || [];
|
|
68
|
+
result.apps.push(micoApp);
|
|
69
|
+
result.entry_info.entries.push(entryInfo);
|
|
70
|
+
result.permissions[oem_micro_app_id] = permission;
|
|
71
|
+
});
|
|
72
|
+
res.send({
|
|
73
|
+
code: null,
|
|
74
|
+
errorMsg: null,
|
|
75
|
+
msg: null,
|
|
76
|
+
result,
|
|
77
|
+
success: true,
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
}
|
|
43
81
|
if (!isMainApp) {
|
|
44
82
|
app.get('/api/saas-info', (req, res) => {
|
|
45
83
|
const lang = parseCookie(req.headers['cookie'], 'main-i18next');
|
package/dist/scripts/build.js
CHANGED
|
@@ -17,12 +17,11 @@ const chalk_1 = __importDefault(require("chalk"));
|
|
|
17
17
|
const ora_1 = __importDefault(require("ora"));
|
|
18
18
|
const webpack_config_1 = __importDefault(require("../config/webpack.config"));
|
|
19
19
|
const template_1 = __importDefault(require("../template"));
|
|
20
|
-
const apis_1 = __importDefault(require("../apis"));
|
|
21
20
|
const BUILD_FAIL_TIP = '糟糕:打包失败了,下面是具体信息';
|
|
22
21
|
const spinner = (0, ora_1.default)('building').start();
|
|
23
22
|
const config = (0, webpack_config_1.default)();
|
|
24
23
|
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
25
|
-
|
|
24
|
+
// await apis();
|
|
26
25
|
yield (0, template_1.default)();
|
|
27
26
|
(0, webpack_1.default)(config).run((err, stats) => {
|
|
28
27
|
if (err) {
|
package/dist/scripts/start.js
CHANGED
|
@@ -18,30 +18,47 @@ const mock_1 = __importDefault(require("../module/mock"));
|
|
|
18
18
|
const bundleServer_1 = require("../module/bundleServer");
|
|
19
19
|
const proxy_1 = __importDefault(require("../module/proxy"));
|
|
20
20
|
const template_1 = __importDefault(require("../template"));
|
|
21
|
-
const apis_1 = __importDefault(require("../apis"));
|
|
22
21
|
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
23
|
-
|
|
22
|
+
// await apis();
|
|
24
23
|
yield (0, template_1.default)();
|
|
25
24
|
let defaultPort = 9000;
|
|
26
25
|
console.log(chalk_1.default.yellow('如果是pc端的微应用调试,请勿使用该命令,考虑使用`start --main`或`start --main --proxy`'));
|
|
27
26
|
//检测端口占用情况
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
return middleware;
|
|
27
|
+
console.log("process.env.PROD", process.env.PROD);
|
|
28
|
+
if (process.env.PROD) {
|
|
29
|
+
const compiler = (0, bundleServer_1.createServerCompiler)();
|
|
30
|
+
(0, bundleServer_1.runBundleServer)({
|
|
31
|
+
port: Number(process.env.PROD),
|
|
32
|
+
compiler,
|
|
33
|
+
internalDevConfig: {
|
|
34
|
+
open: true,
|
|
35
|
+
setupMiddlewares(middleware, { app }) {
|
|
36
|
+
(0, mock_1.default)(app);
|
|
37
|
+
(0, proxy_1.default)(app);
|
|
38
|
+
return middleware;
|
|
39
|
+
},
|
|
42
40
|
},
|
|
43
|
-
}
|
|
44
|
-
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
const port = yield portfinder_1.default.getPortPromise({
|
|
45
|
+
port: defaultPort,
|
|
46
|
+
stopPort: defaultPort + 100,
|
|
47
|
+
});
|
|
48
|
+
const compiler = (0, bundleServer_1.createServerCompiler)();
|
|
49
|
+
(0, bundleServer_1.runBundleServer)({
|
|
50
|
+
port,
|
|
51
|
+
compiler,
|
|
52
|
+
internalDevConfig: {
|
|
53
|
+
open: true,
|
|
54
|
+
setupMiddlewares(middleware, { app }) {
|
|
55
|
+
(0, mock_1.default)(app);
|
|
56
|
+
(0, proxy_1.default)(app);
|
|
57
|
+
return middleware;
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
}
|
|
45
62
|
}))().catch((err) => {
|
|
46
63
|
console.log(err);
|
|
47
64
|
});
|
|
@@ -18,9 +18,8 @@ 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
20
|
const template_1 = __importDefault(require("../template"));
|
|
21
|
-
const apis_1 = __importDefault(require("../apis"));
|
|
22
21
|
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
23
|
-
|
|
22
|
+
// await apis();
|
|
24
23
|
yield (0, template_1.default)();
|
|
25
24
|
let defaultPort = 9000;
|
|
26
25
|
//检测端口占用情况
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { CaptureContext, Event, Severity } from '@sentry/types';
|
|
2
2
|
|
|
3
|
+
type IState = { [k in string]: string | number | null };
|
|
3
4
|
interface mainHistory {
|
|
4
|
-
push: (path, state
|
|
5
|
-
replace: (path, state
|
|
5
|
+
push: (path: string, state?: IState) => void;
|
|
6
|
+
replace: (path: string, state?: IState) => void;
|
|
6
7
|
go: (n: number) => void;
|
|
7
8
|
goBack: () => void;
|
|
8
9
|
goForward: () => void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tuya-sat/micro-script",
|
|
3
|
-
"version": "3.0.27-beta.
|
|
3
|
+
"version": "3.0.27-beta.4",
|
|
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.27-beta.
|
|
27
|
-
"@tuya-sat/micro-dev-proxy": "3.0.27-beta.
|
|
28
|
-
"@tuya-sat/micro-utils": "3.0.27-beta.
|
|
26
|
+
"@tuya-sat/micro-dev-loader": "3.0.27-beta.4",
|
|
27
|
+
"@tuya-sat/micro-dev-proxy": "3.0.27-beta.4",
|
|
28
|
+
"@tuya-sat/micro-utils": "3.0.27-beta.4",
|
|
29
29
|
"@types/kill-port": "^2.0.0",
|
|
30
30
|
"babel-loader": "8.2.4",
|
|
31
31
|
"babel-plugin-import": "1.13.3",
|