@tuya-sat/micro-script 3.0.0-beta.2 → 3.0.0-beta.8
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/config/webpack.common.d.ts +2 -2
- package/dist/config/webpack.common.js +135 -108
- package/dist/config/webpack.config.d.ts +2 -2
- package/dist/config/webpack.config.js +32 -5
- package/dist/module/main/fakeSaasInfo.d.ts +2 -2
- package/dist/module/main/fakeSaasInfo.js +90 -32
- package/dist/module/main/staticMain.js +7 -3
- package/dist/module/mainServer.js +3 -1
- package/dist/module/options.d.ts +4 -5
- package/dist/module/options.js +6 -5
- package/package.json +6 -4
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Configuration } from
|
|
2
|
-
import { ThemeCat } from
|
|
1
|
+
import { Configuration } from 'webpack';
|
|
2
|
+
import { ThemeCat } from '@tuya-sat/micro-dev-loader/dist/less/utils/index';
|
|
3
3
|
declare type ThemeEnv = ThemeCat | undefined;
|
|
4
4
|
export declare const validateMicroTheme: () => ThemeEnv;
|
|
5
5
|
export default function getCommonConfig({ isDev, isBuild, }: {
|
|
@@ -13,6 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.validateMicroTheme = void 0;
|
|
16
|
+
const webpack_merge_1 = require("webpack-merge");
|
|
16
17
|
//@ts-ignore
|
|
17
18
|
const copy_webpack_plugin_1 = __importDefault(require("copy-webpack-plugin"));
|
|
18
19
|
//@ts-ignore
|
|
@@ -20,6 +21,7 @@ const mini_css_extract_plugin_1 = __importDefault(require("mini-css-extract-plug
|
|
|
20
21
|
const html_webpack_plugin_1 = __importDefault(require("html-webpack-plugin"));
|
|
21
22
|
const css_minimizer_webpack_plugin_1 = __importDefault(require("css-minimizer-webpack-plugin"));
|
|
22
23
|
const micro_dev_loader_1 = require("@tuya-sat/micro-dev-loader");
|
|
24
|
+
const path_1 = __importDefault(require("path"));
|
|
23
25
|
const index_1 = require("@tuya-sat/micro-dev-loader/dist/less/utils/index");
|
|
24
26
|
const micro_utils_1 = require("@tuya-sat/micro-utils");
|
|
25
27
|
const paths_1 = __importDefault(require("./paths"));
|
|
@@ -42,23 +44,23 @@ function getCommonConfig({ isDev, isBuild, }) {
|
|
|
42
44
|
const devMicroTheme = (0, exports.validateMicroTheme)();
|
|
43
45
|
const enableThemeCompile = isDev
|
|
44
46
|
? !!devMicroTheme
|
|
45
|
-
: annotations[
|
|
47
|
+
: annotations['sdf.feat:colorTheme'];
|
|
46
48
|
//获取style处理的loader
|
|
47
49
|
const getStyleLoaders = (extraLoader = []) => {
|
|
48
50
|
extraLoader = toArray(extraLoader);
|
|
49
51
|
const loadersBeforeCssLoader = [
|
|
50
|
-
isDev && require(
|
|
51
|
-
require.resolve(
|
|
52
|
+
isDev && require('@tuya-sat/micro-dev-loader').filterCssVariableLoader,
|
|
53
|
+
require.resolve('postcss-loader'),
|
|
52
54
|
...extraLoader,
|
|
53
55
|
].filter(Boolean);
|
|
54
56
|
const loaders = [
|
|
55
|
-
isBuild ? mini_css_extract_plugin_1.default.loader : require.resolve(
|
|
57
|
+
isBuild ? mini_css_extract_plugin_1.default.loader : require.resolve('style-loader'),
|
|
56
58
|
{
|
|
57
|
-
loader: require.resolve(
|
|
59
|
+
loader: require.resolve('css-loader'),
|
|
58
60
|
options: {
|
|
59
61
|
modules: {
|
|
60
62
|
auto: true,
|
|
61
|
-
localIdentName: isDev ?
|
|
63
|
+
localIdentName: isDev ? '[path][name]__[local]' : '[hash:base64]',
|
|
62
64
|
},
|
|
63
65
|
importLoaders: loadersBeforeCssLoader.length,
|
|
64
66
|
},
|
|
@@ -67,116 +69,141 @@ function getCommonConfig({ isDev, isBuild, }) {
|
|
|
67
69
|
].filter(Boolean);
|
|
68
70
|
return loaders;
|
|
69
71
|
};
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
use: getStyleLoaders(),
|
|
72
|
+
const { multiApps } = require(paths_1.default.microConfig);
|
|
73
|
+
const multiAppsWebpackConfig = {
|
|
74
|
+
plugins: [],
|
|
75
|
+
entry: {},
|
|
76
|
+
};
|
|
77
|
+
function getWebpackConfig(htmlplugins) {
|
|
78
|
+
const baseConfig = {
|
|
79
|
+
mode: isBuild ? 'production' : 'development',
|
|
80
|
+
output: {
|
|
81
|
+
filename: isBuild
|
|
82
|
+
? 'static/js/[name].[contenthash:8].js'
|
|
83
|
+
: 'static/js/[name].bundle.js',
|
|
84
|
+
chunkFilename: isBuild
|
|
85
|
+
? 'static/js/[name].[contenthash:8].chunk.js'
|
|
86
|
+
: 'static/js/[name].chunk.js',
|
|
87
|
+
path: paths_1.default.dist,
|
|
88
|
+
clean: true,
|
|
89
|
+
library: {
|
|
90
|
+
name: packageName,
|
|
91
|
+
type: 'umd',
|
|
91
92
|
},
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
93
|
+
},
|
|
94
|
+
module: {
|
|
95
|
+
rules: [
|
|
96
|
+
{
|
|
97
|
+
test: /\.css$/,
|
|
98
|
+
use: getStyleLoaders(),
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
test: /\.less$/,
|
|
102
|
+
use: getStyleLoaders([
|
|
103
|
+
{
|
|
104
|
+
loader: require.resolve('less-loader'),
|
|
105
|
+
options: {
|
|
106
|
+
lessOptions: Object.assign(Object.assign({}, (isDev
|
|
107
|
+
? enableThemeCompile
|
|
108
|
+
? (0, index_1.getLessOptions)(devMicroTheme)
|
|
109
|
+
: {}
|
|
110
|
+
: annotations['sdf.feat:colorTheme']
|
|
111
|
+
? (0, index_1.getLessOptions)(index_1.LIGHT_THEME)
|
|
112
|
+
: {})), { javascriptEnabled: true }),
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
enableThemeCompile &&
|
|
116
|
+
require('@tuya-sat/micro-dev-loader').changeAntdGlobalImport,
|
|
117
|
+
enableThemeCompile &&
|
|
118
|
+
require('@tuya-sat/micro-dev-loader')
|
|
119
|
+
.changeTuyaSatComponentImport,
|
|
120
|
+
].filter(Boolean)),
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
test: /\.(scss|sass)$/,
|
|
124
|
+
use: getStyleLoaders(require.resolve('sass-loader')),
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
test: /\.(bmp|png|svg|jpg|jpeg|gif)$/i,
|
|
128
|
+
type: 'asset',
|
|
129
|
+
parser: {
|
|
130
|
+
dataUrlCondition: {
|
|
131
|
+
maxSize: 10 * 1024,
|
|
105
132
|
},
|
|
106
133
|
},
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
enableThemeCompile &&
|
|
110
|
-
require("@tuya-sat/micro-dev-loader")
|
|
111
|
-
.changeTuyaSatComponentImport,
|
|
112
|
-
].filter(Boolean)),
|
|
113
|
-
},
|
|
114
|
-
{
|
|
115
|
-
test: /\.(scss|sass)$/,
|
|
116
|
-
use: getStyleLoaders(require.resolve("sass-loader")),
|
|
117
|
-
},
|
|
118
|
-
{
|
|
119
|
-
test: /\.(bmp|png|svg|jpg|jpeg|gif)$/i,
|
|
120
|
-
type: "asset",
|
|
121
|
-
parser: {
|
|
122
|
-
dataUrlCondition: {
|
|
123
|
-
maxSize: 10 * 1024,
|
|
134
|
+
generator: {
|
|
135
|
+
filename: 'static/img/[hash][ext][query]',
|
|
124
136
|
},
|
|
125
137
|
},
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
138
|
+
].filter(Boolean),
|
|
139
|
+
},
|
|
140
|
+
optimization: {
|
|
141
|
+
runtimeChunk: 'single',
|
|
142
|
+
splitChunks: {
|
|
143
|
+
cacheGroups: Object.assign(Object.assign({}, (enableThemeCompile
|
|
144
|
+
? {
|
|
145
|
+
vendorCss: {
|
|
146
|
+
test: /([\\/]node_modules[\\/][\s\S]+(\.less|\.css)$)|([\\/]src[\\/]styles[\\/]global\.less)/,
|
|
147
|
+
name: 'light',
|
|
148
|
+
chunks: 'all',
|
|
149
|
+
priority: 2,
|
|
150
|
+
},
|
|
151
|
+
}
|
|
152
|
+
: {})), { vendor: {
|
|
153
|
+
test: /[\\/]node_modules[\\/]/,
|
|
154
|
+
name: 'vendors-others',
|
|
155
|
+
chunks: 'all',
|
|
156
|
+
priority: 0,
|
|
157
|
+
}, react: {
|
|
158
|
+
test: /[\\/]node_modules[\\/](react|react-dom)[\\/]/,
|
|
159
|
+
name: 'react-related',
|
|
160
|
+
chunks: 'all',
|
|
161
|
+
priority: 1,
|
|
162
|
+
} }),
|
|
129
163
|
},
|
|
130
|
-
|
|
131
|
-
},
|
|
132
|
-
optimization: {
|
|
133
|
-
runtimeChunk: "single",
|
|
134
|
-
splitChunks: {
|
|
135
|
-
cacheGroups: Object.assign(Object.assign({}, (enableThemeCompile
|
|
136
|
-
? {
|
|
137
|
-
vendorCss: {
|
|
138
|
-
test: /([\\/]node_modules[\\/][\s\S]+(\.less|\.css)$)|([\\/]src[\\/]styles[\\/]global\.less)/,
|
|
139
|
-
name: "light",
|
|
140
|
-
chunks: "all",
|
|
141
|
-
priority: 2,
|
|
142
|
-
},
|
|
143
|
-
}
|
|
144
|
-
: {})), { vendor: {
|
|
145
|
-
test: /[\\/]node_modules[\\/]/,
|
|
146
|
-
name: "vendors-others",
|
|
147
|
-
chunks: "all",
|
|
148
|
-
priority: 0,
|
|
149
|
-
}, react: {
|
|
150
|
-
test: /[\\/]node_modules[\\/](react|react-dom)[\\/]/,
|
|
151
|
-
name: "react-related",
|
|
152
|
-
chunks: "all",
|
|
153
|
-
priority: 1,
|
|
154
|
-
} }),
|
|
164
|
+
minimizer: ['...', new css_minimizer_webpack_plugin_1.default()],
|
|
155
165
|
},
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
166
|
+
plugins: [
|
|
167
|
+
new html_webpack_plugin_1.default({
|
|
168
|
+
inject: true,
|
|
169
|
+
template: paths_1.default.spaHtml,
|
|
170
|
+
}),
|
|
171
|
+
...htmlplugins,
|
|
172
|
+
new copy_webpack_plugin_1.default({
|
|
173
|
+
patterns: [
|
|
174
|
+
{
|
|
175
|
+
from: paths_1.default.publicDir,
|
|
176
|
+
filter: (resourcePath) => __awaiter(this, void 0, void 0, function* () { return resourcePath !== paths_1.default.spaHtml; }),
|
|
177
|
+
noErrorOnMissing: true,
|
|
178
|
+
},
|
|
179
|
+
],
|
|
180
|
+
}),
|
|
181
|
+
isBuild &&
|
|
182
|
+
new mini_css_extract_plugin_1.default({
|
|
183
|
+
filename: 'static/css/[name].[contenthash:8].css',
|
|
184
|
+
chunkFilename: 'static/css/[name].[contenthash:8].chunk.css',
|
|
185
|
+
}),
|
|
186
|
+
isBuild && enableThemeCompile && new micro_dev_loader_1.ThemePlugin(),
|
|
187
|
+
isBuild && new locales_1.default(),
|
|
188
|
+
].filter((value) => Boolean(value)),
|
|
189
|
+
};
|
|
190
|
+
return baseConfig;
|
|
191
|
+
}
|
|
192
|
+
if (isBuild && multiApps && multiApps.length > 0) {
|
|
193
|
+
multiApps.forEach((app) => {
|
|
194
|
+
multiAppsWebpackConfig.entry[app.name] = `${path_1.default.join(process.cwd(), app.dir)}/index.tsx`;
|
|
195
|
+
multiAppsWebpackConfig.plugins.push(new html_webpack_plugin_1.default({
|
|
160
196
|
inject: true,
|
|
197
|
+
filename: `${app.name}.html`,
|
|
161
198
|
template: paths_1.default.spaHtml,
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
}),
|
|
172
|
-
isBuild &&
|
|
173
|
-
new mini_css_extract_plugin_1.default({
|
|
174
|
-
filename: "static/css/[name].[contenthash:8].css",
|
|
175
|
-
chunkFilename: "static/css/[name].[contenthash:8].chunk.css",
|
|
176
|
-
}),
|
|
177
|
-
isBuild && enableThemeCompile && new micro_dev_loader_1.ThemePlugin(),
|
|
178
|
-
isBuild && new locales_1.default(),
|
|
179
|
-
].filter((value) => Boolean(value)),
|
|
180
|
-
};
|
|
199
|
+
chunks: [app.name],
|
|
200
|
+
}));
|
|
201
|
+
});
|
|
202
|
+
console.log('multiAppsWebpackConfig', multiAppsWebpackConfig);
|
|
203
|
+
return (0, webpack_merge_1.merge)(getWebpackConfig(multiAppsWebpackConfig.plugins), {
|
|
204
|
+
entry: multiAppsWebpackConfig.entry,
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
return getWebpackConfig([]);
|
|
181
208
|
}
|
|
182
209
|
exports.default = getCommonConfig;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Configuration } from
|
|
1
|
+
import { Configuration } from 'webpack';
|
|
2
2
|
export interface BaseParams {
|
|
3
3
|
isDev: boolean;
|
|
4
4
|
isBuild: boolean;
|
|
@@ -6,5 +6,5 @@ export interface BaseParams {
|
|
|
6
6
|
export interface WebpackCombineFunction {
|
|
7
7
|
(arg0: Configuration, arg1: BaseParams): Configuration;
|
|
8
8
|
}
|
|
9
|
-
declare const _default: () =>
|
|
9
|
+
declare const _default: () => {};
|
|
10
10
|
export default _default;
|
|
@@ -9,9 +9,9 @@ const framework_1 = __importDefault(require("../framework"));
|
|
|
9
9
|
const webpack_common_1 = __importDefault(require("./webpack.common"));
|
|
10
10
|
const micro_utils_1 = require("@tuya-sat/micro-utils");
|
|
11
11
|
exports.default = () => {
|
|
12
|
-
const isBuild = process.env.NODE_ENV ===
|
|
13
|
-
const isDev = process.env.NODE_ENV ===
|
|
14
|
-
const { annotations: { [
|
|
12
|
+
const isBuild = process.env.NODE_ENV === 'production';
|
|
13
|
+
const isDev = process.env.NODE_ENV === 'development';
|
|
14
|
+
const { annotations: { ['sdf.cli:microFramework']: currentFramework }, } = (0, micro_utils_1.parseManifest)();
|
|
15
15
|
//框架的webpack配置
|
|
16
16
|
const frameworkConfig = (0, framework_1.default)({
|
|
17
17
|
currentFramework,
|
|
@@ -20,10 +20,37 @@ exports.default = () => {
|
|
|
20
20
|
});
|
|
21
21
|
//公用的webpack配置
|
|
22
22
|
const commonConfig = (0, webpack_common_1.default)({ isDev, isBuild });
|
|
23
|
-
|
|
23
|
+
let baseConfig = {};
|
|
24
|
+
// const { multiApps } = require(paths.microConfig);
|
|
25
|
+
// console.log('multiApps', multiApps, process.cwd());
|
|
26
|
+
// if (isBuild && multiApps && multiApps.length > 0) {
|
|
27
|
+
// const multiAppsWebpackConfig: any = {
|
|
28
|
+
// plugins: [],
|
|
29
|
+
// entry: {},
|
|
30
|
+
// };
|
|
31
|
+
// multiApps.forEach((app: IMicroApp) => {
|
|
32
|
+
// multiAppsWebpackConfig.entry[app.name] = `${path.join(
|
|
33
|
+
// process.cwd(),
|
|
34
|
+
// app.dir
|
|
35
|
+
// )}/index.tsx`;
|
|
36
|
+
// multiAppsWebpackConfig.plugins.push(
|
|
37
|
+
// new HtmlWebpackPlugin({
|
|
38
|
+
// inject: true,
|
|
39
|
+
// filename: `${app.name}.html`,
|
|
40
|
+
// template: paths.spaHtml,
|
|
41
|
+
// chunks: [app.name],
|
|
42
|
+
// })
|
|
43
|
+
// );
|
|
44
|
+
// });
|
|
45
|
+
// console.log('multiAppsWebpackConfig', multiAppsWebpackConfig);
|
|
46
|
+
// baseConfig = merge(frameworkConfig, commonConfig, multiAppsWebpackConfig);
|
|
47
|
+
// } else {
|
|
48
|
+
// baseConfig = merge(frameworkConfig, commonConfig);
|
|
49
|
+
// }
|
|
50
|
+
baseConfig = (0, webpack_merge_1.merge)(frameworkConfig, commonConfig);
|
|
24
51
|
//额外的webpack结合function
|
|
25
52
|
const webpackCombineFunction = require(paths_1.default.microConfig).webpack;
|
|
26
|
-
if (webpackCombineFunction && typeof webpackCombineFunction ===
|
|
53
|
+
if (webpackCombineFunction && typeof webpackCombineFunction === 'function') {
|
|
27
54
|
return webpackCombineFunction(baseConfig, { isDev, isBuild });
|
|
28
55
|
}
|
|
29
56
|
return baseConfig;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Express } from
|
|
2
|
-
export default function mockSaasInfo(app: Express, microPort: number):
|
|
1
|
+
import { Express } from 'express';
|
|
2
|
+
export default function mockSaasInfo(app: Express, microPort: number): void;
|
|
@@ -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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
27
|
};
|
|
@@ -6,33 +29,68 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
29
|
const micro_utils_1 = require("@tuya-sat/micro-utils");
|
|
7
30
|
const uuid_1 = require("uuid");
|
|
8
31
|
const paths_1 = __importDefault(require("../../config/paths"));
|
|
32
|
+
const uid_1 = require("uid");
|
|
33
|
+
const path = __importStar(require("path"));
|
|
34
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
9
35
|
function mockSaasInfo(app, microPort) {
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
36
|
+
const { multiApps } = require(paths_1.default.microConfig);
|
|
37
|
+
const idsMap = new Map();
|
|
38
|
+
multiApps === null || multiApps === void 0 ? void 0 : multiApps.forEach((app) => {
|
|
39
|
+
idsMap.set(app.name, { entry_id: (0, uuid_1.v4)(), oem_micro_app_id: (0, uid_1.uid)(16) });
|
|
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
|
+
};
|
|
49
|
+
multiApps.forEach((app) => {
|
|
50
|
+
const entry_id = idsMap.get(app.name).entry_id;
|
|
51
|
+
const manifest = fs_extra_1.default.readJSONSync(path.join(process.cwd(), `${app.dir}/manifest.json`), 'utf-8');
|
|
52
|
+
const oem_micro_app_id = idsMap.get(app.name).oem_micro_app_id;
|
|
53
|
+
const baseUrl = `/apps/${oem_micro_app_id}`;
|
|
54
|
+
const micoApp = consturctApp(manifest, oem_micro_app_id, baseUrl, lang, microPort, app.name);
|
|
55
|
+
const entryInfo = consturctEntry(manifest, oem_micro_app_id, entry_id, baseUrl, lang, app.dir);
|
|
56
|
+
const permission = consturctPermissions();
|
|
57
|
+
result.apps.push(micoApp);
|
|
58
|
+
result.entry_info.entries.push(entryInfo);
|
|
59
|
+
result.permissions[oem_micro_app_id] = permission;
|
|
60
|
+
});
|
|
61
|
+
res.send({
|
|
62
|
+
code: null,
|
|
63
|
+
errorMsg: null,
|
|
64
|
+
msg: null,
|
|
65
|
+
result,
|
|
66
|
+
success: true,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
const manifest = (0, micro_utils_1.parseManifest)();
|
|
71
|
+
const entry_id = (0, uuid_1.v4)();
|
|
72
|
+
const oem_micro_app_id = manifest.universalId;
|
|
73
|
+
const baseUrl = `/apps/${oem_micro_app_id}`;
|
|
74
|
+
const app = consturctApp(manifest, oem_micro_app_id, baseUrl, lang, microPort);
|
|
75
|
+
const entryInfo = consturctEntry(manifest, oem_micro_app_id, entry_id, baseUrl, lang, '');
|
|
76
|
+
const permission = consturctPermissions();
|
|
77
|
+
res.send({
|
|
78
|
+
code: null,
|
|
79
|
+
errorMsg: null,
|
|
80
|
+
msg: null,
|
|
81
|
+
result: {
|
|
82
|
+
apps: [app],
|
|
83
|
+
entry_info: { entries: [entryInfo], entry_mode: 'normal' },
|
|
84
|
+
permissions: { [oem_micro_app_id]: permission },
|
|
85
|
+
},
|
|
86
|
+
success: true,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
30
89
|
});
|
|
31
|
-
return baseUrl;
|
|
32
90
|
}
|
|
33
91
|
exports.default = mockSaasInfo;
|
|
34
|
-
function consturctEntry(manifest, oem_micro_app_id, entry_id, baseUrl, lang) {
|
|
35
|
-
const fakeMenu = (0, micro_utils_1.getFakeMenu)(manifest);
|
|
92
|
+
function consturctEntry(manifest, oem_micro_app_id, entry_id, baseUrl, lang, dir) {
|
|
93
|
+
const fakeMenu = (0, micro_utils_1.getFakeMenu)(manifest, dir);
|
|
36
94
|
let stack = [fakeMenu];
|
|
37
95
|
while (stack.length) {
|
|
38
96
|
const menu = stack.shift();
|
|
@@ -49,15 +107,15 @@ function consturctEntry(manifest, oem_micro_app_id, entry_id, baseUrl, lang) {
|
|
|
49
107
|
}
|
|
50
108
|
return fakeMenu;
|
|
51
109
|
}
|
|
52
|
-
function consturctApp(manifest, oem_micro_app_id, baseUrl, lang, port) {
|
|
110
|
+
function consturctApp(manifest, oem_micro_app_id, baseUrl, lang, port, code) {
|
|
53
111
|
const packageInfo = (0, micro_utils_1.getPackage)();
|
|
54
112
|
return {
|
|
55
113
|
active_rule: baseUrl,
|
|
56
|
-
dependencies: [
|
|
114
|
+
dependencies: [''],
|
|
57
115
|
ext_info: null,
|
|
58
|
-
micro_app_code: `${packageInfo.name}`,
|
|
59
|
-
micro_app_name: `${
|
|
60
|
-
micro_app_version:
|
|
116
|
+
micro_app_code: code || `${packageInfo.name}`,
|
|
117
|
+
micro_app_name: code ? `${code}-dev` : `${packageInfo.name}-dev`,
|
|
118
|
+
micro_app_version: '0.0.0-x',
|
|
61
119
|
oem_micro_app_id,
|
|
62
120
|
resource: `http://localhost:${port}`,
|
|
63
121
|
schema: null,
|
|
@@ -71,15 +129,15 @@ function consturctPermissions() {
|
|
|
71
129
|
return mockPermissions.map((code) => ({ permission_group: code }));
|
|
72
130
|
}
|
|
73
131
|
function pickText(texts, lang) {
|
|
74
|
-
return lang ===
|
|
132
|
+
return lang === 'en' ? texts[1] : texts[0];
|
|
75
133
|
}
|
|
76
134
|
function parseCookie(cookie, key) {
|
|
77
|
-
const cookies = (cookie ||
|
|
135
|
+
const cookies = (cookie || '').split(';');
|
|
78
136
|
for (let cookieItem of cookies) {
|
|
79
|
-
const [cookieKey, value] = cookieItem.split(
|
|
137
|
+
const [cookieKey, value] = cookieItem.split('=');
|
|
80
138
|
if (cookieKey.trim() === key) {
|
|
81
139
|
return value;
|
|
82
140
|
}
|
|
83
141
|
}
|
|
84
|
-
return
|
|
142
|
+
return '';
|
|
85
143
|
}
|
|
@@ -96,10 +96,14 @@ function insertScript($, debuggerConfig) {
|
|
|
96
96
|
return item.config_key === "dynamic_theme";
|
|
97
97
|
}) || initalCustom_configs(saas);
|
|
98
98
|
const theme = (0, webpack_common_1.validateMicroTheme)();
|
|
99
|
-
themeConfig.config_value_json = JSON.stringify(Object.assign(Object.assign(Object.assign({}, JSON.parse(themeConfig.config_value_json)), (theme
|
|
100
|
-
|
|
101
|
-
|
|
99
|
+
themeConfig.config_value_json = JSON.stringify(Object.assign(Object.assign(Object.assign({}, JSON.parse(themeConfig.config_value_json)), (theme
|
|
100
|
+
? {
|
|
101
|
+
supportedTheme: theme,
|
|
102
|
+
}
|
|
103
|
+
: {})), readThemeConfig()));
|
|
102
104
|
overrideNotification(saas);
|
|
105
|
+
// 本地开发态多语言剥离多语言平台,走本地多语言兜底逻辑
|
|
106
|
+
_SDF.saas.saas_locales = {};
|
|
103
107
|
$("head").append($("<script>").text(`window._SDF_CONFIG=${JSON.stringify(_SDF_CONFIG)};window._SDF=${JSON.stringify(_SDF)};window.__MAIN_APP_PUBLIC_PATH=${JSON.stringify(__MAIN_APP_PUBLIC_PATH)};
|
|
104
108
|
localStorage.setItem('theme',${JSON.stringify(process.env.MICRO_THEME)});
|
|
105
109
|
localStorage.setItem('isDebugger','true')
|
|
@@ -23,13 +23,15 @@ const proxy_1 = __importDefault(require("../module/proxy"));
|
|
|
23
23
|
const validate_1 = require("../utils/validate");
|
|
24
24
|
function runMain({ port, microPort, }) {
|
|
25
25
|
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
-
const { debuggerConfig } = require(paths_1.default.microConfig);
|
|
26
|
+
const { debuggerConfig, mainServer } = require(paths_1.default.microConfig);
|
|
27
27
|
(0, validate_1.validateDebuggerConfig)(debuggerConfig);
|
|
28
28
|
const app = (0, express_1.default)();
|
|
29
|
+
mainServer && mainServer.before && mainServer.before(app);
|
|
29
30
|
(0, staticMain_1.default)(app, debuggerConfig);
|
|
30
31
|
(0, fakeSaasInfo_1.default)(app, microPort);
|
|
31
32
|
(0, mock_1.default)(app);
|
|
32
33
|
(0, proxy_1.default)(app);
|
|
34
|
+
mainServer && mainServer.after && mainServer.after(app);
|
|
33
35
|
const { waiting, resolve } = (0, promiser_1.promiser)();
|
|
34
36
|
app.listen(port, () => {
|
|
35
37
|
(0, ora_1.default)(`main server in ${port} port`).succeed();
|
package/dist/module/options.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
declare const _default: {
|
|
1
|
+
import { ExpressRequestHandler } from 'webpack-dev-server';
|
|
2
|
+
declare const option: {
|
|
4
3
|
name: string;
|
|
5
4
|
path: string;
|
|
6
|
-
middleware:
|
|
5
|
+
middleware: ExpressRequestHandler;
|
|
7
6
|
};
|
|
8
|
-
export default
|
|
7
|
+
export default option;
|
package/dist/module/options.js
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const middleware = (req, res, next) => {
|
|
4
|
-
if (req.method ===
|
|
4
|
+
if (req.method === 'OPTIONS') {
|
|
5
5
|
res.statusCode = 204;
|
|
6
|
-
res.send(
|
|
6
|
+
res.send('ok');
|
|
7
7
|
return;
|
|
8
8
|
}
|
|
9
9
|
next();
|
|
10
10
|
};
|
|
11
|
-
|
|
12
|
-
name:
|
|
13
|
-
path:
|
|
11
|
+
const option = {
|
|
12
|
+
name: 'options-middleware',
|
|
13
|
+
path: '*',
|
|
14
14
|
middleware,
|
|
15
15
|
};
|
|
16
|
+
exports.default = option;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tuya-sat/micro-script",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.8",
|
|
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.
|
|
24
|
-
"@tuya-sat/micro-dev-proxy": "3.0.0-beta.
|
|
25
|
-
"@tuya-sat/micro-utils": "3.0.0-beta.
|
|
23
|
+
"@tuya-sat/micro-dev-loader": "3.0.0-beta.8",
|
|
24
|
+
"@tuya-sat/micro-dev-proxy": "3.0.0-beta.8",
|
|
25
|
+
"@tuya-sat/micro-utils": "3.0.0-beta.8",
|
|
26
26
|
"babel-loader": "8.2.4",
|
|
27
27
|
"babel-plugin-import": "1.13.3",
|
|
28
28
|
"chalk": "4.1.2",
|
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
"css-minimizer-webpack-plugin": "3.4.1",
|
|
33
33
|
"express": "4.17.3",
|
|
34
34
|
"fork-ts-checker-webpack-plugin": "7.2.1",
|
|
35
|
+
"fs-extra": "^10.1.0",
|
|
35
36
|
"html-webpack-plugin": "5.5.0",
|
|
36
37
|
"http-proxy-middleware": "2.0.4",
|
|
37
38
|
"joi": "17.6.0",
|
|
@@ -52,6 +53,7 @@
|
|
|
52
53
|
"style-loader": "3.3.1",
|
|
53
54
|
"svg-url-loader": "7.1.1",
|
|
54
55
|
"tsconfig-paths-webpack-plugin": "3.5.2",
|
|
56
|
+
"uid": "^2.0.1",
|
|
55
57
|
"url-loader": "4.1.1",
|
|
56
58
|
"uuid": "8.3.2",
|
|
57
59
|
"vue-loader": "17.0.0",
|