@tuya-sat/micro-script 3.0.0-beta.2 → 3.0.0-beta.22
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 +150 -111
- package/dist/config/webpack.config.d.ts +1 -1
- package/dist/config/webpack.config.js +5 -6
- package/dist/framework/react.config.d.ts +1 -1
- package/dist/framework/react.config.js +11 -11
- package/dist/module/bundleServer.d.ts +3 -3
- package/dist/module/bundleServer.js +11 -10
- package/dist/module/main/fakeSaasInfo.d.ts +2 -2
- package/dist/module/main/fakeSaasInfo.js +101 -33
- package/dist/module/main/staticMain.d.ts +3 -3
- package/dist/module/main/staticMain.js +35 -28
- package/dist/module/mainServer.js +5 -2
- package/dist/module/options.d.ts +4 -5
- package/dist/module/options.js +6 -5
- package/dist/scripts/startInMain.js +10 -6
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +43 -0
- package/package.json +13 -7
|
@@ -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,17 +13,19 @@ 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
|
|
19
20
|
const mini_css_extract_plugin_1 = __importDefault(require("mini-css-extract-plugin"));
|
|
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"));
|
|
23
|
+
const terser_webpack_plugin_1 = __importDefault(require("terser-webpack-plugin"));
|
|
22
24
|
const micro_dev_loader_1 = require("@tuya-sat/micro-dev-loader");
|
|
25
|
+
const path_1 = __importDefault(require("path"));
|
|
23
26
|
const index_1 = require("@tuya-sat/micro-dev-loader/dist/less/utils/index");
|
|
24
|
-
const micro_utils_1 = require("@tuya-sat/micro-utils");
|
|
25
27
|
const paths_1 = __importDefault(require("./paths"));
|
|
26
|
-
const
|
|
28
|
+
const utils_1 = require("../utils");
|
|
27
29
|
const toArray = (value) => {
|
|
28
30
|
return Array.isArray(value) ? value : [value];
|
|
29
31
|
};
|
|
@@ -38,27 +40,27 @@ const validateMicroTheme = () => {
|
|
|
38
40
|
exports.validateMicroTheme = validateMicroTheme;
|
|
39
41
|
function getCommonConfig({ isDev, isBuild, }) {
|
|
40
42
|
const { name: packageName } = require(paths_1.default.appPkg);
|
|
41
|
-
const {
|
|
43
|
+
const { debuggerConfig: { isMainApp }, } = require(paths_1.default.microConfig);
|
|
42
44
|
const devMicroTheme = (0, exports.validateMicroTheme)();
|
|
43
45
|
const enableThemeCompile = isDev
|
|
44
46
|
? !!devMicroTheme
|
|
45
|
-
:
|
|
47
|
+
: (0, utils_1.getAnnotations)()['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,153 @@ 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: isMainApp ? 'development' : 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
|
+
: (0, utils_1.getAnnotations)()['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
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
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
|
+
}, main: {
|
|
158
|
+
test: /[\\/]node_modules[\\/](@tuya-sat\/sdf-main-sdk)[\\/]/,
|
|
159
|
+
name: 'main-related',
|
|
160
|
+
chunks: 'all',
|
|
161
|
+
priority: 1,
|
|
162
|
+
}, antd: {
|
|
163
|
+
test: /[\\/]node_modules[\\/](antd|@tuya-sat\/galaxy)[\\/]/,
|
|
164
|
+
name: 'antd-related',
|
|
165
|
+
chunks: 'all',
|
|
141
166
|
priority: 2,
|
|
142
|
-
},
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
name: "react-related",
|
|
152
|
-
chunks: "all",
|
|
153
|
-
priority: 1,
|
|
154
|
-
} }),
|
|
167
|
+
}, react: {
|
|
168
|
+
test: /[\\/]node_modules[\\/](react|react-dom|react-router-dom)[\\/]/,
|
|
169
|
+
name: 'react-related',
|
|
170
|
+
chunks: 'all',
|
|
171
|
+
priority: 3,
|
|
172
|
+
} }),
|
|
173
|
+
},
|
|
174
|
+
minimize: isBuild,
|
|
175
|
+
minimizer: ['...', new terser_webpack_plugin_1.default(), new css_minimizer_webpack_plugin_1.default()],
|
|
155
176
|
},
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
177
|
+
plugins: [
|
|
178
|
+
new html_webpack_plugin_1.default({
|
|
179
|
+
inject: true,
|
|
180
|
+
template: paths_1.default.spaHtml,
|
|
181
|
+
}),
|
|
182
|
+
...htmlplugins,
|
|
183
|
+
new copy_webpack_plugin_1.default({
|
|
184
|
+
patterns: [
|
|
185
|
+
{
|
|
186
|
+
from: paths_1.default.publicDir,
|
|
187
|
+
filter: (resourcePath) => __awaiter(this, void 0, void 0, function* () { return resourcePath !== paths_1.default.spaHtml; }),
|
|
188
|
+
noErrorOnMissing: true,
|
|
189
|
+
},
|
|
190
|
+
],
|
|
191
|
+
}),
|
|
192
|
+
isBuild &&
|
|
193
|
+
new mini_css_extract_plugin_1.default({
|
|
194
|
+
filename: 'static/css/[name].[contenthash:8].css',
|
|
195
|
+
chunkFilename: 'static/css/[name].[contenthash:8].chunk.css',
|
|
196
|
+
}),
|
|
197
|
+
isBuild && enableThemeCompile && new micro_dev_loader_1.ThemePlugin(),
|
|
198
|
+
].filter((value) => Boolean(value)),
|
|
199
|
+
};
|
|
200
|
+
return baseConfig;
|
|
201
|
+
}
|
|
202
|
+
if (multiApps && multiApps.length > 0) {
|
|
203
|
+
multiApps.forEach((app) => {
|
|
204
|
+
multiAppsWebpackConfig.entry[app.name] = `${path_1.default.join(process.cwd(), app.dir)}/index.tsx`;
|
|
205
|
+
multiAppsWebpackConfig.plugins.push(new html_webpack_plugin_1.default({
|
|
160
206
|
inject: true,
|
|
207
|
+
filename: app.htmlContentHash
|
|
208
|
+
? `${app.name}-[contenthash].html`
|
|
209
|
+
: `${app.name}.html`,
|
|
161
210
|
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
|
-
};
|
|
211
|
+
chunks: [app.name],
|
|
212
|
+
}));
|
|
213
|
+
});
|
|
214
|
+
console.log('multiAppsWebpackConfig', multiAppsWebpackConfig);
|
|
215
|
+
return (0, webpack_merge_1.merge)(getWebpackConfig(multiAppsWebpackConfig.plugins), {
|
|
216
|
+
entry: multiAppsWebpackConfig.entry,
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
return getWebpackConfig([]);
|
|
181
220
|
}
|
|
182
221
|
exports.default = getCommonConfig;
|
|
@@ -7,14 +7,13 @@ const webpack_merge_1 = require("webpack-merge");
|
|
|
7
7
|
const paths_1 = __importDefault(require("./paths"));
|
|
8
8
|
const framework_1 = __importDefault(require("../framework"));
|
|
9
9
|
const webpack_common_1 = __importDefault(require("./webpack.common"));
|
|
10
|
-
const
|
|
10
|
+
const utils_1 = require("../utils");
|
|
11
11
|
exports.default = () => {
|
|
12
|
-
const isBuild = process.env.NODE_ENV ===
|
|
13
|
-
const isDev = process.env.NODE_ENV ===
|
|
14
|
-
const { annotations: { ["sdf.cli:microFramework"]: currentFramework }, } = (0, micro_utils_1.parseManifest)();
|
|
12
|
+
const isBuild = process.env.NODE_ENV === 'production';
|
|
13
|
+
const isDev = process.env.NODE_ENV === 'development';
|
|
15
14
|
//框架的webpack配置
|
|
16
15
|
const frameworkConfig = (0, framework_1.default)({
|
|
17
|
-
currentFramework,
|
|
16
|
+
currentFramework: (0, utils_1.getAnnotations)()['sdf.cli:microFramework'],
|
|
18
17
|
isDev,
|
|
19
18
|
isBuild,
|
|
20
19
|
});
|
|
@@ -23,7 +22,7 @@ exports.default = () => {
|
|
|
23
22
|
const baseConfig = (0, webpack_merge_1.merge)(frameworkConfig, commonConfig);
|
|
24
23
|
//额外的webpack结合function
|
|
25
24
|
const webpackCombineFunction = require(paths_1.default.microConfig).webpack;
|
|
26
|
-
if (webpackCombineFunction && typeof webpackCombineFunction ===
|
|
25
|
+
if (webpackCombineFunction && typeof webpackCombineFunction === 'function') {
|
|
27
26
|
return webpackCombineFunction(baseConfig, { isDev, isBuild });
|
|
28
27
|
}
|
|
29
28
|
return baseConfig;
|
|
@@ -17,26 +17,26 @@ const reactConfig = ({ isDev, isBuild, currentFramework, isTs, }) => {
|
|
|
17
17
|
include: paths_1.default.appSrc,
|
|
18
18
|
use: [
|
|
19
19
|
{
|
|
20
|
-
loader: require.resolve(
|
|
20
|
+
loader: require.resolve('babel-loader'),
|
|
21
21
|
options: {
|
|
22
22
|
presets: [
|
|
23
23
|
[
|
|
24
|
-
require.resolve(
|
|
24
|
+
require.resolve('@babel/preset-env'),
|
|
25
25
|
{
|
|
26
|
-
useBuiltIns:
|
|
26
|
+
useBuiltIns: 'entry',
|
|
27
27
|
corejs: 3,
|
|
28
28
|
},
|
|
29
29
|
],
|
|
30
30
|
[
|
|
31
|
-
require.resolve(
|
|
31
|
+
require.resolve('@babel/preset-react'),
|
|
32
32
|
{
|
|
33
|
-
runtime:
|
|
33
|
+
runtime: 'automatic',
|
|
34
34
|
},
|
|
35
35
|
],
|
|
36
|
-
isTs && require.resolve(
|
|
36
|
+
isTs && require.resolve('@babel/preset-typescript'),
|
|
37
37
|
].filter(Boolean),
|
|
38
38
|
plugins: [
|
|
39
|
-
isDev && require.resolve(
|
|
39
|
+
isDev && require.resolve('react-refresh/babel'),
|
|
40
40
|
].filter(Boolean),
|
|
41
41
|
},
|
|
42
42
|
},
|
|
@@ -48,7 +48,7 @@ const reactConfig = ({ isDev, isBuild, currentFramework, isTs, }) => {
|
|
|
48
48
|
exclude: paths_1.default.appSrc,
|
|
49
49
|
use: [
|
|
50
50
|
{
|
|
51
|
-
loader: require.resolve(
|
|
51
|
+
loader: require.resolve('babel-loader'),
|
|
52
52
|
},
|
|
53
53
|
],
|
|
54
54
|
},
|
|
@@ -64,18 +64,18 @@ const reactConfig = ({ isDev, isBuild, currentFramework, isTs, }) => {
|
|
|
64
64
|
semantic: true,
|
|
65
65
|
syntactic: true,
|
|
66
66
|
},
|
|
67
|
-
mode:
|
|
67
|
+
mode: 'write-references',
|
|
68
68
|
},
|
|
69
69
|
}),
|
|
70
70
|
].filter((value) => Boolean(value)),
|
|
71
71
|
};
|
|
72
72
|
};
|
|
73
73
|
const reactTsConfig = ({ isDev, isBuild, currentFramework, }) => (Object.assign({ entry: paths_1.default.ReactTsEntryFile, resolve: {
|
|
74
|
-
extensions: [
|
|
74
|
+
extensions: ['.tsx', '.ts', '.js'],
|
|
75
75
|
plugins: [new tsconfig_paths_webpack_plugin_1.default()],
|
|
76
76
|
} }, reactConfig({ isDev, isBuild, currentFramework, isTs: true })));
|
|
77
77
|
exports.reactTsConfig = reactTsConfig;
|
|
78
78
|
const reactJsConfig = ({ isDev, isBuild, currentFramework, }) => (Object.assign({ entry: paths_1.default.ReactJsEntryFile, resolve: {
|
|
79
|
-
extensions: [
|
|
79
|
+
extensions: ['.jsx', '.js'],
|
|
80
80
|
} }, reactConfig({ isDev, isBuild, currentFramework, isTs: false })));
|
|
81
81
|
exports.reactJsConfig = reactJsConfig;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import webpack, { Compiler } from
|
|
2
|
-
import { Configuration } from
|
|
1
|
+
import webpack, { Compiler } from 'webpack';
|
|
2
|
+
import { Configuration } from 'webpack-dev-server';
|
|
3
3
|
export declare type CustomDevServer = (value: Configuration) => typeof value;
|
|
4
4
|
export declare function createServerCompiler(): webpack.Compiler;
|
|
5
5
|
export declare function runBundleServer({ port, compiler, internalDevConfig, }: {
|
|
6
6
|
port: number;
|
|
7
7
|
compiler: Compiler;
|
|
8
|
-
internalDevConfig?: Pick<Configuration,
|
|
8
|
+
internalDevConfig?: Pick<Configuration, 'open' | 'setupMiddlewares' | 'allowedHosts'>;
|
|
9
9
|
}): Promise<void>;
|
|
@@ -36,8 +36,8 @@ function createServerCompiler() {
|
|
|
36
36
|
const config = Object.assign(Object.assign({}, (0, webpack_config_1.default)()), {
|
|
37
37
|
//下面所有配置都是为了精简terminal输出
|
|
38
38
|
infrastructureLogging: {
|
|
39
|
-
level:
|
|
40
|
-
}, stats:
|
|
39
|
+
level: 'warn',
|
|
40
|
+
}, stats: 'errors-warnings' });
|
|
41
41
|
return (0, webpack_1.default)(config);
|
|
42
42
|
}
|
|
43
43
|
exports.createServerCompiler = createServerCompiler;
|
|
@@ -47,8 +47,8 @@ function runBundleServer({ port, compiler, internalDevConfig = {}, }) {
|
|
|
47
47
|
const { devServer = (value) => value } = require(paths_1.default.microConfig);
|
|
48
48
|
const { setupMiddlewares: startDevSetupMiddlewares } = internalDevConfig, restServerConfig = __rest(internalDevConfig, ["setupMiddlewares"]);
|
|
49
49
|
const server = new webpack_dev_server_1.default(devServer(Object.assign({ hot: true, liveReload: false, port, headers: {
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
'Access-Control-Allow-Origin': '*',
|
|
51
|
+
'Access-Control-Allow-Headers': '*',
|
|
52
52
|
}, historyApiFallback: true, setupMiddlewares(middleware, devServer) {
|
|
53
53
|
//可能会有问题
|
|
54
54
|
middleware.push(options_1.default);
|
|
@@ -56,21 +56,22 @@ function runBundleServer({ port, compiler, internalDevConfig = {}, }) {
|
|
|
56
56
|
? startDevSetupMiddlewares(middleware, devServer)
|
|
57
57
|
: middleware;
|
|
58
58
|
} }, restServerConfig)), compiler);
|
|
59
|
-
compiler.hooks.watchRun.tap(
|
|
59
|
+
compiler.hooks.watchRun.tap('MyPlugin', () => {
|
|
60
60
|
spinner.isSpinning && spinner.succeed();
|
|
61
|
-
spinner.color =
|
|
62
|
-
spinner.text =
|
|
61
|
+
spinner.color = 'yellow';
|
|
62
|
+
spinner.text = 'webpack compiling';
|
|
63
63
|
spinner.start();
|
|
64
64
|
});
|
|
65
|
-
compiler.hooks.done.tap(
|
|
65
|
+
compiler.hooks.done.tap('MyPlugin', ({ endTime, startTime }) => {
|
|
66
66
|
spinner.isSpinning && spinner.succeed();
|
|
67
67
|
console.log(`compiled time ~${endTime - startTime}ms`);
|
|
68
68
|
});
|
|
69
69
|
//临时提示
|
|
70
|
-
compiler.hooks.done.tap(
|
|
70
|
+
compiler.hooks.done.tap('once-tip', (0, onceFactory_1.onceFactory)(() => {
|
|
71
71
|
console.log(chalk_1.default.yellow(`Tip: 如果HMR失效且保存文件时造成多次compile,请考虑调高aggregateTimeout参数(可以尝试100)`));
|
|
72
72
|
}));
|
|
73
|
-
server.start();
|
|
73
|
+
yield server.start();
|
|
74
|
+
console.log('本地应用服务已启动');
|
|
74
75
|
});
|
|
75
76
|
}
|
|
76
77
|
exports.runBundleServer = runBundleServer;
|
|
@@ -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,78 @@ 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
|
-
app.get("/api/saas-info", (req, res) => {
|
|
15
|
-
const lang = parseCookie(req.headers["cookie"], "main-i18next");
|
|
16
|
-
const app = consturctApp(manifest, oem_micro_app_id, baseUrl, lang, microPort);
|
|
17
|
-
const entryInfo = consturctEntry(manifest, oem_micro_app_id, entry_id, baseUrl, lang);
|
|
18
|
-
const permission = consturctPermissions();
|
|
19
|
-
res.send({
|
|
20
|
-
code: null,
|
|
21
|
-
errorMsg: null,
|
|
22
|
-
msg: null,
|
|
23
|
-
result: {
|
|
24
|
-
apps: [app],
|
|
25
|
-
entry_info: { entries: [entryInfo], entry_mode: "normal" },
|
|
26
|
-
permissions: { [oem_micro_app_id]: permission },
|
|
27
|
-
},
|
|
28
|
-
success: true,
|
|
29
|
-
});
|
|
36
|
+
const { multiApps, debuggerConfig: { isMainApp }, } = 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) });
|
|
30
40
|
});
|
|
31
|
-
|
|
41
|
+
if (!isMainApp) {
|
|
42
|
+
app.get('/api/saas-info', (req, res) => {
|
|
43
|
+
const lang = parseCookie(req.headers['cookie'], 'main-i18next');
|
|
44
|
+
if (multiApps && multiApps.length > 0) {
|
|
45
|
+
const result = {
|
|
46
|
+
apps: [],
|
|
47
|
+
entry_info: { entries: [], entry_mode: 'normal' },
|
|
48
|
+
permissions: {},
|
|
49
|
+
saas_id_info_list: [],
|
|
50
|
+
};
|
|
51
|
+
multiApps.forEach((app) => {
|
|
52
|
+
const entry_id = idsMap.get(app.name).entry_id;
|
|
53
|
+
const manifest = fs_extra_1.default.readJSONSync(path.join(process.cwd(), `${app.dir}/manifest.json`), 'utf-8');
|
|
54
|
+
const oem_micro_app_id = idsMap.get(app.name).oem_micro_app_id;
|
|
55
|
+
const baseUrl = `/apps/${oem_micro_app_id}`;
|
|
56
|
+
result.saas_id_info_list.push({
|
|
57
|
+
oem_micro_app_id: oem_micro_app_id,
|
|
58
|
+
universal_id: '',
|
|
59
|
+
});
|
|
60
|
+
const micoApp = consturctApp(manifest, oem_micro_app_id, baseUrl, lang, microPort, app.name);
|
|
61
|
+
const entryInfo = consturctEntry(manifest, oem_micro_app_id, entry_id, baseUrl, lang, app.dir);
|
|
62
|
+
const permission = consturctPermissions();
|
|
63
|
+
result.apps.push(micoApp);
|
|
64
|
+
result.entry_info.entries.push(entryInfo);
|
|
65
|
+
result.permissions[oem_micro_app_id] = permission;
|
|
66
|
+
});
|
|
67
|
+
res.send({
|
|
68
|
+
code: null,
|
|
69
|
+
errorMsg: null,
|
|
70
|
+
msg: null,
|
|
71
|
+
result,
|
|
72
|
+
success: true,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
const manifest = (0, micro_utils_1.parseManifest)();
|
|
77
|
+
const entry_id = (0, uuid_1.v4)();
|
|
78
|
+
const oem_micro_app_id = manifest.universalId;
|
|
79
|
+
const baseUrl = `/apps/${oem_micro_app_id}`;
|
|
80
|
+
const app = consturctApp(manifest, oem_micro_app_id, baseUrl, lang, microPort);
|
|
81
|
+
const entryInfo = consturctEntry(manifest, oem_micro_app_id, entry_id, baseUrl, lang, '');
|
|
82
|
+
const permission = consturctPermissions();
|
|
83
|
+
res.send({
|
|
84
|
+
code: null,
|
|
85
|
+
errorMsg: null,
|
|
86
|
+
msg: null,
|
|
87
|
+
result: {
|
|
88
|
+
apps: [app],
|
|
89
|
+
entry_info: { entries: [entryInfo], entry_mode: 'normal' },
|
|
90
|
+
permissions: { [oem_micro_app_id]: permission },
|
|
91
|
+
saas_id_info_list: [
|
|
92
|
+
{ oem_micro_app_id: oem_micro_app_id, universal_id: '' },
|
|
93
|
+
],
|
|
94
|
+
},
|
|
95
|
+
success: true,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}
|
|
32
100
|
}
|
|
33
101
|
exports.default = mockSaasInfo;
|
|
34
|
-
function consturctEntry(manifest, oem_micro_app_id, entry_id, baseUrl, lang) {
|
|
35
|
-
const fakeMenu = (0, micro_utils_1.getFakeMenu)(manifest);
|
|
102
|
+
function consturctEntry(manifest, oem_micro_app_id, entry_id, baseUrl, lang, dir) {
|
|
103
|
+
const fakeMenu = (0, micro_utils_1.getFakeMenu)(manifest, dir);
|
|
36
104
|
let stack = [fakeMenu];
|
|
37
105
|
while (stack.length) {
|
|
38
106
|
const menu = stack.shift();
|
|
@@ -49,17 +117,17 @@ function consturctEntry(manifest, oem_micro_app_id, entry_id, baseUrl, lang) {
|
|
|
49
117
|
}
|
|
50
118
|
return fakeMenu;
|
|
51
119
|
}
|
|
52
|
-
function consturctApp(manifest, oem_micro_app_id, baseUrl, lang, port) {
|
|
120
|
+
function consturctApp(manifest, oem_micro_app_id, baseUrl, lang, port, code) {
|
|
53
121
|
const packageInfo = (0, micro_utils_1.getPackage)();
|
|
54
122
|
return {
|
|
55
123
|
active_rule: baseUrl,
|
|
56
|
-
dependencies: [
|
|
124
|
+
dependencies: [''],
|
|
57
125
|
ext_info: null,
|
|
58
|
-
micro_app_code: `${packageInfo.name}`,
|
|
59
|
-
micro_app_name: `${
|
|
60
|
-
micro_app_version:
|
|
126
|
+
micro_app_code: code || `${packageInfo.name}`,
|
|
127
|
+
micro_app_name: code ? `${code}-dev` : `${packageInfo.name}-dev`,
|
|
128
|
+
micro_app_version: '0.0.0-x',
|
|
61
129
|
oem_micro_app_id,
|
|
62
|
-
resource: `http://localhost:${port}`,
|
|
130
|
+
resource: `http://localhost:${port}/${code || 'index'}.html`,
|
|
63
131
|
schema: null,
|
|
64
132
|
universal_id: manifest.universalId,
|
|
65
133
|
isAuth: true,
|
|
@@ -71,15 +139,15 @@ function consturctPermissions() {
|
|
|
71
139
|
return mockPermissions.map((code) => ({ permission_group: code }));
|
|
72
140
|
}
|
|
73
141
|
function pickText(texts, lang) {
|
|
74
|
-
return lang ===
|
|
142
|
+
return lang === 'en' ? texts[1] : texts[0];
|
|
75
143
|
}
|
|
76
144
|
function parseCookie(cookie, key) {
|
|
77
|
-
const cookies = (cookie ||
|
|
145
|
+
const cookies = (cookie || '').split(';');
|
|
78
146
|
for (let cookieItem of cookies) {
|
|
79
|
-
const [cookieKey, value] = cookieItem.split(
|
|
147
|
+
const [cookieKey, value] = cookieItem.split('=');
|
|
80
148
|
if (cookieKey.trim() === key) {
|
|
81
149
|
return value;
|
|
82
150
|
}
|
|
83
151
|
}
|
|
84
|
-
return
|
|
152
|
+
return '';
|
|
85
153
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Express } from
|
|
2
|
-
import type { Config } from
|
|
1
|
+
import { Express } from 'express';
|
|
2
|
+
import type { Config } from '@tuya-sat/micro-dev-proxy';
|
|
3
3
|
export interface DebuggerConfig extends Config {
|
|
4
4
|
themeConfig?: {
|
|
5
5
|
primaryColor: string;
|
|
@@ -20,4 +20,4 @@ export declare type CustomConfig = {
|
|
|
20
20
|
};
|
|
21
21
|
export default function staticMain(app: Express & {
|
|
22
22
|
_isLogin?: Promise<void>;
|
|
23
|
-
}, debuggerConfig: DebuggerConfig): void;
|
|
23
|
+
}, debuggerConfig: DebuggerConfig, microPort: number): void;
|
|
@@ -40,21 +40,24 @@ const axios_1 = __importDefault(require("axios"));
|
|
|
40
40
|
const fakeSaas_1 = __importStar(require("./fakeSaas"));
|
|
41
41
|
const paths_1 = __importDefault(require("../../config/paths"));
|
|
42
42
|
const webpack_common_1 = require("../../config/webpack.common");
|
|
43
|
-
const defaultBase =
|
|
44
|
-
function staticMain(app, debuggerConfig) {
|
|
43
|
+
const defaultBase = 'https://static1.tuyacn.com/static/sdf-gw/v1.0.1.516/';
|
|
44
|
+
function staticMain(app, debuggerConfig, microPort) {
|
|
45
45
|
app.get([
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
46
|
+
'/',
|
|
47
|
+
'/apps/:appId',
|
|
48
|
+
'/login',
|
|
49
|
+
'/apps/:appId/*',
|
|
50
|
+
'/application',
|
|
51
|
+
'/application/*',
|
|
52
52
|
], (req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
53
|
-
if (app._isLogin) {
|
|
53
|
+
if (!debuggerConfig.isMainApp && app._isLogin) {
|
|
54
54
|
yield app._isLogin;
|
|
55
55
|
}
|
|
56
|
-
|
|
57
|
-
|
|
56
|
+
let base = debuggerConfig.base || defaultBase;
|
|
57
|
+
if (debuggerConfig.isMainApp) {
|
|
58
|
+
base = `http://localhost:${microPort}`;
|
|
59
|
+
}
|
|
60
|
+
const { data } = yield axios_1.default.get(new URL('index.html', base).href);
|
|
58
61
|
const $ = cheerio_1.default.load(data);
|
|
59
62
|
modifySrcAttr($, base);
|
|
60
63
|
yield insertScript($, debuggerConfig);
|
|
@@ -64,15 +67,15 @@ function staticMain(app, debuggerConfig) {
|
|
|
64
67
|
exports.default = staticMain;
|
|
65
68
|
function initalCustom_configs(saas) {
|
|
66
69
|
const config = {
|
|
67
|
-
config_group:
|
|
68
|
-
config_key:
|
|
69
|
-
config_value:
|
|
70
|
-
config_label:
|
|
71
|
-
config_value_json:
|
|
72
|
-
config_name_zh:
|
|
73
|
-
config_name_en:
|
|
74
|
-
platform:
|
|
75
|
-
config_id:
|
|
70
|
+
config_group: '',
|
|
71
|
+
config_key: 'dynamic_theme',
|
|
72
|
+
config_value: '',
|
|
73
|
+
config_label: '',
|
|
74
|
+
config_value_json: '{}',
|
|
75
|
+
config_name_zh: '',
|
|
76
|
+
config_name_en: '',
|
|
77
|
+
platform: '',
|
|
78
|
+
config_id: '',
|
|
76
79
|
};
|
|
77
80
|
saas.custom_configs.push(config);
|
|
78
81
|
return config;
|
|
@@ -82,7 +85,7 @@ function readThemeConfig() {
|
|
|
82
85
|
return require(paths_1.default.microConfig).debuggerConfig.themeConfig;
|
|
83
86
|
}
|
|
84
87
|
function overrideNotification(value) {
|
|
85
|
-
const isProxy = process.env.MICRO_PROXY ===
|
|
88
|
+
const isProxy = process.env.MICRO_PROXY === 'true';
|
|
86
89
|
!isProxy && (value.message_switch = false);
|
|
87
90
|
}
|
|
88
91
|
function insertScript($, debuggerConfig) {
|
|
@@ -93,23 +96,27 @@ function insertScript($, debuggerConfig) {
|
|
|
93
96
|
const { saas } = _SDF;
|
|
94
97
|
(_a = saas.custom_configs) !== null && _a !== void 0 ? _a : (saas.custom_configs = []);
|
|
95
98
|
let themeConfig = saas.custom_configs.find((item) => {
|
|
96
|
-
return item.config_key ===
|
|
99
|
+
return item.config_key === 'dynamic_theme';
|
|
97
100
|
}) || initalCustom_configs(saas);
|
|
98
101
|
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
|
-
|
|
102
|
+
themeConfig.config_value_json = JSON.stringify(Object.assign(Object.assign(Object.assign({}, JSON.parse(themeConfig.config_value_json)), (theme
|
|
103
|
+
? {
|
|
104
|
+
supportedTheme: theme,
|
|
105
|
+
}
|
|
106
|
+
: {})), readThemeConfig()));
|
|
102
107
|
overrideNotification(saas);
|
|
103
|
-
|
|
108
|
+
// 本地开发态多语言剥离多语言平台,走本地多语言兜底逻辑
|
|
109
|
+
delete _SDF.saas.saas_locales;
|
|
110
|
+
$('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
111
|
localStorage.setItem('theme',${JSON.stringify(process.env.MICRO_THEME)});
|
|
105
112
|
localStorage.setItem('isDebugger','true')
|
|
106
113
|
`));
|
|
107
114
|
});
|
|
108
115
|
}
|
|
109
116
|
function modifySrcAttr($, base) {
|
|
110
|
-
const tags = [
|
|
117
|
+
const tags = ['img src', 'link href', 'script src'];
|
|
111
118
|
tags.forEach((p) => {
|
|
112
|
-
const [tagName, attr] = p.split(
|
|
119
|
+
const [tagName, attr] = p.split(' ');
|
|
113
120
|
$(tagName).map(function () {
|
|
114
121
|
const origin = $(this).attr(attr);
|
|
115
122
|
if (/^(\/|http:|https:)/.test(origin))
|
|
@@ -23,19 +23,22 @@ 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
|
-
|
|
29
|
+
mainServer && mainServer.before && mainServer.before(app);
|
|
30
|
+
(0, staticMain_1.default)(app, debuggerConfig, microPort);
|
|
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();
|
|
36
38
|
resolve();
|
|
37
39
|
});
|
|
38
40
|
yield waiting;
|
|
41
|
+
console.log('代理服务已启动');
|
|
39
42
|
});
|
|
40
43
|
}
|
|
41
44
|
exports.default = runMain;
|
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;
|
|
@@ -16,6 +16,7 @@ const portfinder_1 = __importDefault(require("portfinder"));
|
|
|
16
16
|
const open_1 = __importDefault(require("open"));
|
|
17
17
|
const mainServer_1 = __importDefault(require("../module/mainServer"));
|
|
18
18
|
const bundleServer_1 = require("../module/bundleServer");
|
|
19
|
+
const kill_port_1 = __importDefault(require("kill-port"));
|
|
19
20
|
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
20
21
|
let defaultPort = 9000;
|
|
21
22
|
//检测端口占用情况
|
|
@@ -28,17 +29,20 @@ const bundleServer_1 = require("../module/bundleServer");
|
|
|
28
29
|
stopPort: bundledServerPort + 100,
|
|
29
30
|
});
|
|
30
31
|
const compiler = (0, bundleServer_1.createServerCompiler)();
|
|
32
|
+
yield (0, bundleServer_1.runBundleServer)({
|
|
33
|
+
port: bundledServerPort,
|
|
34
|
+
compiler,
|
|
35
|
+
internalDevConfig: {
|
|
36
|
+
allowedHosts: 'all',
|
|
37
|
+
},
|
|
38
|
+
});
|
|
31
39
|
yield (0, mainServer_1.default)({
|
|
32
40
|
port: mainServerPort,
|
|
33
41
|
microPort: bundledServerPort,
|
|
34
42
|
});
|
|
35
43
|
(0, open_1.default)(`http://localhost:${mainServerPort}`);
|
|
36
|
-
(
|
|
37
|
-
|
|
38
|
-
compiler,
|
|
39
|
-
internalDevConfig: {
|
|
40
|
-
allowedHosts: "all",
|
|
41
|
-
},
|
|
44
|
+
process.on('exit', () => {
|
|
45
|
+
(0, kill_port_1.default)(bundledServerPort, 'tcp').then(console.log).catch(console.log);
|
|
42
46
|
});
|
|
43
47
|
}))().catch((err) => {
|
|
44
48
|
console.log(err);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getAnnotations: () => any;
|
|
@@ -0,0 +1,43 @@
|
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.getAnnotations = void 0;
|
|
30
|
+
const micro_utils_1 = require("@tuya-sat/micro-utils");
|
|
31
|
+
const path = __importStar(require("path"));
|
|
32
|
+
const paths_1 = __importDefault(require("../config/paths"));
|
|
33
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
34
|
+
const getAnnotations = () => {
|
|
35
|
+
const { multiApps } = require(paths_1.default.microConfig);
|
|
36
|
+
if (multiApps && multiApps.length > 0) {
|
|
37
|
+
return fs_extra_1.default.readJSONSync(path.join(process.cwd(), multiApps[0].dir, 'manifest.json')).annotations;
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
return (0, micro_utils_1.parseManifest)().annotations;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
exports.getAnnotations = getAnnotations;
|
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.22",
|
|
4
4
|
"bin": "./dist/bin/cli.js",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"license": "MIT",
|
|
@@ -20,9 +20,10 @@
|
|
|
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.22",
|
|
24
|
+
"@tuya-sat/micro-dev-proxy": "3.0.0-beta.22",
|
|
25
|
+
"@tuya-sat/micro-utils": "3.0.0-beta.22",
|
|
26
|
+
"@types/kill-port": "^2.0.0",
|
|
26
27
|
"babel-loader": "8.2.4",
|
|
27
28
|
"babel-plugin-import": "1.13.3",
|
|
28
29
|
"chalk": "4.1.2",
|
|
@@ -32,9 +33,11 @@
|
|
|
32
33
|
"css-minimizer-webpack-plugin": "3.4.1",
|
|
33
34
|
"express": "4.17.3",
|
|
34
35
|
"fork-ts-checker-webpack-plugin": "7.2.1",
|
|
36
|
+
"fs-extra": "^10.1.0",
|
|
35
37
|
"html-webpack-plugin": "5.5.0",
|
|
36
38
|
"http-proxy-middleware": "2.0.4",
|
|
37
39
|
"joi": "17.6.0",
|
|
40
|
+
"kill-port": "^2.0.1",
|
|
38
41
|
"less": "4.1.2",
|
|
39
42
|
"less-loader": "10.2.0",
|
|
40
43
|
"mini-css-extract-plugin": "2.6.0",
|
|
@@ -51,12 +54,14 @@
|
|
|
51
54
|
"sass-loader": "12.6.0",
|
|
52
55
|
"style-loader": "3.3.1",
|
|
53
56
|
"svg-url-loader": "7.1.1",
|
|
54
|
-
"tsconfig-paths-webpack-plugin": "
|
|
57
|
+
"tsconfig-paths-webpack-plugin": "^4.0.0",
|
|
58
|
+
"uid": "^2.0.1",
|
|
55
59
|
"url-loader": "4.1.1",
|
|
56
60
|
"uuid": "8.3.2",
|
|
57
61
|
"vue-loader": "17.0.0",
|
|
58
|
-
"webpack": "5.
|
|
59
|
-
"webpack-
|
|
62
|
+
"webpack": "5.75.0",
|
|
63
|
+
"webpack-cli": "5.0.1",
|
|
64
|
+
"webpack-dev-server": "4.11.1",
|
|
60
65
|
"webpack-merge": "5.8.0"
|
|
61
66
|
},
|
|
62
67
|
"devDependencies": {
|
|
@@ -64,6 +69,7 @@
|
|
|
64
69
|
"@types/jest": "27.4.1",
|
|
65
70
|
"@types/uuid": "8.3.4",
|
|
66
71
|
"jest": "27.5.1",
|
|
72
|
+
"terser-webpack-plugin": "^5.3.6",
|
|
67
73
|
"ts-jest": "27.1.3",
|
|
68
74
|
"typescript": "4.6.2"
|
|
69
75
|
},
|