@tuya-sat/micro-script 2.3.5 → 3.0.0-beta.10

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,5 +1,9 @@
1
- import { Configuration } from "webpack";
1
+ import { Configuration } from 'webpack';
2
+ import { ThemeCat } from '@tuya-sat/micro-dev-loader/dist/less/utils/index';
3
+ declare type ThemeEnv = ThemeCat | undefined;
4
+ export declare const validateMicroTheme: () => ThemeEnv;
2
5
  export default function getCommonConfig({ isDev, isBuild, }: {
3
6
  isDev: boolean;
4
7
  isBuild: boolean;
5
8
  }): Configuration;
9
+ export {};
@@ -12,7 +12,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- const path_1 = __importDefault(require("path"));
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,140 +21,188 @@ 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
- const micro_utils_1 = require("@tuya-sat/micro-utils");
25
26
  const paths_1 = __importDefault(require("./paths"));
26
- const theme_1 = require("../utils/theme");
27
- const DYNAMIC_CHUNK_PREFIX = "micro_app_lazy";
27
+ const locales_1 = __importDefault(require("@tuya-sat/micro-dev-loader/dist/plugins/locales"));
28
+ const utils_1 = require("../utils");
28
29
  const toArray = (value) => {
29
30
  return Array.isArray(value) ? value : [value];
30
31
  };
32
+ const validateMicroTheme = () => {
33
+ const microTheme = process.env.MICRO_THEME;
34
+ if (microTheme && ![index_1.DARK_THEME, index_1.LIGHT_THEME].includes(microTheme)) {
35
+ console.error(`请设置正确的MICRO_THEME环境变量,当前值为${microTheme},请修改为${index_1.LIGHT_THEME}或${index_1.DARK_THEME}`);
36
+ return process.exit(1);
37
+ }
38
+ return microTheme;
39
+ };
40
+ exports.validateMicroTheme = validateMicroTheme;
31
41
  function getCommonConfig({ isDev, isBuild, }) {
32
42
  const { name: packageName } = require(paths_1.default.appPkg);
33
- const { annotations } = (0, micro_utils_1.parseManifest)();
34
- const enableThemeCompile = annotations["sdf.feat:colorTheme"];
43
+ const devMicroTheme = (0, exports.validateMicroTheme)();
44
+ const enableThemeCompile = isDev
45
+ ? !!devMicroTheme
46
+ : (0, utils_1.getAnnotations)()['sdf.feat:colorTheme'];
35
47
  //获取style处理的loader
36
48
  const getStyleLoaders = (extraLoader = []) => {
37
49
  extraLoader = toArray(extraLoader);
38
50
  const loadersBeforeCssLoader = [
39
- isDev && require("@tuya-sat/micro-dev-loader").filterCssVariableLoader,
40
- require.resolve("postcss-loader"),
51
+ isDev && require('@tuya-sat/micro-dev-loader').filterCssVariableLoader,
52
+ require.resolve('postcss-loader'),
41
53
  ...extraLoader,
42
54
  ].filter(Boolean);
43
55
  const loaders = [
44
- isBuild ? mini_css_extract_plugin_1.default.loader : require.resolve("style-loader"),
56
+ isBuild ? mini_css_extract_plugin_1.default.loader : require.resolve('style-loader'),
45
57
  {
46
- loader: require.resolve("css-loader"),
58
+ loader: require.resolve('css-loader'),
47
59
  options: {
48
60
  modules: {
49
61
  auto: true,
50
- localIdentName: isDev ? "[path][name]__[local]" : "[hash:base64]",
62
+ localIdentName: isDev ? '[path][name]__[local]' : '[hash:base64]',
51
63
  },
52
64
  importLoaders: loadersBeforeCssLoader.length,
53
65
  },
54
66
  },
55
- ...loadersBeforeCssLoader
67
+ ...loadersBeforeCssLoader,
56
68
  ].filter(Boolean);
57
69
  return loaders;
58
70
  };
59
- return {
60
- mode: isBuild ? "production" : "development",
61
- output: {
62
- filename: isBuild
63
- ? "static/js/[name].[contenthash:8].js"
64
- : "static/js/[name].bundle.js",
65
- chunkFilename: isBuild
66
- ? `static/js/${DYNAMIC_CHUNK_PREFIX}-[name].[contenthash:8].chunk.js`
67
- : "static/js/[name].chunk.js",
68
- path: paths_1.default.dist,
69
- clean: true,
70
- library: {
71
- name: packageName,
72
- type: "umd",
73
- },
74
- },
75
- module: {
76
- rules: [
77
- {
78
- test: /\.css$/,
79
- use: getStyleLoaders(),
71
+ const { multiApps } = require(paths_1.default.microConfig);
72
+ const multiAppsWebpackConfig = {
73
+ plugins: [],
74
+ entry: {},
75
+ };
76
+ function getWebpackConfig(htmlplugins) {
77
+ const baseConfig = {
78
+ mode: isBuild ? 'production' : 'development',
79
+ output: {
80
+ filename: isBuild
81
+ ? 'static/js/[name].[contenthash:8].js'
82
+ : 'static/js/[name].bundle.js',
83
+ chunkFilename: isBuild
84
+ ? 'static/js/[name].[contenthash:8].chunk.js'
85
+ : 'static/js/[name].chunk.js',
86
+ path: paths_1.default.dist,
87
+ clean: true,
88
+ library: {
89
+ name: packageName,
90
+ type: 'umd',
80
91
  },
81
- {
82
- test: /\.less$/,
83
- use: getStyleLoaders([
84
- {
85
- loader: require.resolve("less-loader"),
86
- options: {
87
- lessOptions: Object.assign(Object.assign({}, (enableThemeCompile
88
- ? isDev
89
- ? (0, index_1.getLessOptions)((0, theme_1.getBaseTheme)())
90
- : (0, index_1.getLessOptions)(index_1.LIGHT_THEME)
91
- : {})), { javascriptEnabled: true }),
92
+ },
93
+ module: {
94
+ rules: [
95
+ {
96
+ test: /\.css$/,
97
+ use: getStyleLoaders(),
98
+ },
99
+ {
100
+ test: /\.less$/,
101
+ use: getStyleLoaders([
102
+ {
103
+ loader: require.resolve('less-loader'),
104
+ options: {
105
+ lessOptions: Object.assign(Object.assign({}, (isDev
106
+ ? enableThemeCompile
107
+ ? (0, index_1.getLessOptions)(devMicroTheme)
108
+ : {}
109
+ : (0, utils_1.getAnnotations)()['sdf.feat:colorTheme']
110
+ ? (0, index_1.getLessOptions)(index_1.LIGHT_THEME)
111
+ : {})), { javascriptEnabled: true }),
112
+ },
113
+ },
114
+ enableThemeCompile &&
115
+ require('@tuya-sat/micro-dev-loader').changeAntdGlobalImport,
116
+ enableThemeCompile &&
117
+ require('@tuya-sat/micro-dev-loader')
118
+ .changeTuyaSatComponentImport,
119
+ ].filter(Boolean)),
120
+ },
121
+ {
122
+ test: /\.(scss|sass)$/,
123
+ use: getStyleLoaders(require.resolve('sass-loader')),
124
+ },
125
+ {
126
+ test: /\.(bmp|png|svg|jpg|jpeg|gif)$/i,
127
+ type: 'asset',
128
+ parser: {
129
+ dataUrlCondition: {
130
+ maxSize: 10 * 1024,
92
131
  },
93
132
  },
94
- enableThemeCompile &&
95
- require("@tuya-sat/micro-dev-loader").changeAntdGlobalImport,
96
- enableThemeCompile &&
97
- require("@tuya-sat/micro-dev-loader")
98
- .changeTuyaSatComponentImport,
99
- ].filter(Boolean)),
100
- },
101
- {
102
- test: /\.(scss|sass)$/,
103
- use: getStyleLoaders(require.resolve("sass-loader")),
104
- },
105
- {
106
- test: /\.(bmp|png|svg|jpg|jpeg|gif)$/i,
107
- type: "asset",
108
- parser: {
109
- dataUrlCondition: {
110
- maxSize: 10 * 1024,
133
+ generator: {
134
+ filename: 'static/img/[hash][ext][query]',
111
135
  },
112
136
  },
113
- generator: {
114
- filename: "static/img/[hash][ext][query]",
115
- },
137
+ ].filter(Boolean),
138
+ },
139
+ optimization: {
140
+ runtimeChunk: 'single',
141
+ splitChunks: {
142
+ cacheGroups: Object.assign(Object.assign({}, (enableThemeCompile
143
+ ? {
144
+ vendorCss: {
145
+ test: /([\\/]node_modules[\\/][\s\S]+(\.less|\.css)$)|([\\/]src[\\/]styles[\\/]global\.less)/,
146
+ name: 'light',
147
+ chunks: 'all',
148
+ priority: 2,
149
+ },
150
+ }
151
+ : {})), { vendor: {
152
+ test: /[\\/]node_modules[\\/]/,
153
+ name: 'vendors-others',
154
+ chunks: 'all',
155
+ priority: 0,
156
+ }, react: {
157
+ test: /[\\/]node_modules[\\/](react|react-dom)[\\/]/,
158
+ name: 'react-related',
159
+ chunks: 'all',
160
+ priority: 1,
161
+ } }),
116
162
  },
117
- ].filter(Boolean),
118
- },
119
- optimization: {
120
- splitChunks: {
121
- cacheGroups: Object.assign({}, (enableThemeCompile
122
- ? {
123
- vendorCss: {
124
- test: /([\\/]node_modules[\\/][\s\S]+(\.less|\.css)$)|([\\/]src[\\/]styles[\\/]global\.less)/,
125
- name: "light",
126
- chunks: "all",
127
- minSize: 0,
128
- priority: 2,
129
- },
130
- }
131
- : {})),
163
+ minimizer: ['...', new css_minimizer_webpack_plugin_1.default()],
132
164
  },
133
- minimizer: ["...", new css_minimizer_webpack_plugin_1.default()],
134
- },
135
- plugins: [
136
- new html_webpack_plugin_1.default({
165
+ plugins: [
166
+ new html_webpack_plugin_1.default({
167
+ inject: true,
168
+ template: paths_1.default.spaHtml,
169
+ }),
170
+ ...htmlplugins,
171
+ new copy_webpack_plugin_1.default({
172
+ patterns: [
173
+ {
174
+ from: paths_1.default.publicDir,
175
+ filter: (resourcePath) => __awaiter(this, void 0, void 0, function* () { return resourcePath !== paths_1.default.spaHtml; }),
176
+ noErrorOnMissing: true,
177
+ },
178
+ ],
179
+ }),
180
+ isBuild &&
181
+ new mini_css_extract_plugin_1.default({
182
+ filename: 'static/css/[name].[contenthash:8].css',
183
+ chunkFilename: 'static/css/[name].[contenthash:8].chunk.css',
184
+ }),
185
+ isBuild && enableThemeCompile && new micro_dev_loader_1.ThemePlugin(),
186
+ isBuild && new locales_1.default(),
187
+ ].filter((value) => Boolean(value)),
188
+ };
189
+ return baseConfig;
190
+ }
191
+ if (multiApps && multiApps.length > 0) {
192
+ multiApps.forEach((app) => {
193
+ multiAppsWebpackConfig.entry[app.name] = `${path_1.default.join(process.cwd(), app.dir)}/index.tsx`;
194
+ multiAppsWebpackConfig.plugins.push(new html_webpack_plugin_1.default({
137
195
  inject: true,
196
+ filename: `${app.name}.html`,
138
197
  template: paths_1.default.spaHtml,
139
- }),
140
- new copy_webpack_plugin_1.default({
141
- patterns: [
142
- {
143
- from: paths_1.default.publicDir,
144
- // 使用path.resolve纠正resourcePath,因为这个resourcePath值在windows平台显示的是POSIX值;
145
- filter: (resourcePath) => __awaiter(this, void 0, void 0, function* () { return path_1.default.resolve(resourcePath) !== paths_1.default.spaHtml; }),
146
- noErrorOnMissing: true,
147
- },
148
- ],
149
- }),
150
- isBuild &&
151
- new mini_css_extract_plugin_1.default({
152
- filename: "static/css/[name].[contenthash:8].css",
153
- chunkFilename: `static/css/${DYNAMIC_CHUNK_PREFIX}-[name].[contenthash:8].chunk.css`,
154
- }),
155
- isBuild && enableThemeCompile && new micro_dev_loader_1.ThemePlugin(),
156
- ].filter((value) => Boolean(value)),
157
- };
198
+ chunks: [app.name],
199
+ }));
200
+ });
201
+ console.log('multiAppsWebpackConfig', multiAppsWebpackConfig);
202
+ return (0, webpack_merge_1.merge)(getWebpackConfig(multiAppsWebpackConfig.plugins), {
203
+ entry: multiAppsWebpackConfig.entry,
204
+ });
205
+ }
206
+ return getWebpackConfig([]);
158
207
  }
159
208
  exports.default = getCommonConfig;
@@ -1,4 +1,4 @@
1
- import { Configuration } from "webpack";
1
+ import { Configuration } from 'webpack';
2
2
  export interface BaseParams {
3
3
  isDev: boolean;
4
4
  isBuild: boolean;
@@ -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 micro_utils_1 = require("@tuya-sat/micro-utils");
10
+ const utils_1 = require("../utils");
11
11
  exports.default = () => {
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)();
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 === "function") {
25
+ if (webpackCombineFunction && typeof webpackCombineFunction === 'function') {
27
26
  return webpackCombineFunction(baseConfig, { isDev, isBuild });
28
27
  }
29
28
  return baseConfig;
@@ -1,2 +1,2 @@
1
- import { Express } from "express";
2
- export default function mockSaasInfo(app: Express, microPort: number): string;
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 manifest = (0, micro_utils_1.parseManifest)();
11
- const entry_id = (0, uuid_1.v4)();
12
- const oem_micro_app_id = manifest.universalId;
13
- const baseUrl = `/apps/${oem_micro_app_id}`;
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 } = 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,17 +107,17 @@ 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: `${pickText((0, micro_utils_1.nameProcesser2)("name"), lang)}-dev`,
60
- micro_app_version: "0.0.0-x",
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
- resource: `http://localhost:${port}`,
120
+ resource: `http://localhost:${port}/${code || 'index'}.html`,
63
121
  schema: null,
64
122
  universal_id: manifest.universalId,
65
123
  isAuth: true,
@@ -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 === "en" ? texts[1] : texts[0];
132
+ return lang === 'en' ? texts[1] : texts[0];
75
133
  }
76
134
  function parseCookie(cookie, key) {
77
- const cookies = (cookie || "").split(";");
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
  }
@@ -39,7 +39,7 @@ const cheerio_1 = __importDefault(require("cheerio"));
39
39
  const axios_1 = __importDefault(require("axios"));
40
40
  const fakeSaas_1 = __importStar(require("./fakeSaas"));
41
41
  const paths_1 = __importDefault(require("../../config/paths"));
42
- const theme_1 = require("../../utils/theme");
42
+ const webpack_common_1 = require("../../config/webpack.common");
43
43
  const defaultBase = "https://static1.tuyacn.com/static/sdf-gw/v1.0.1.516/";
44
44
  function staticMain(app, debuggerConfig) {
45
45
  app.get([
@@ -95,11 +95,15 @@ function insertScript($, debuggerConfig) {
95
95
  let themeConfig = saas.custom_configs.find((item) => {
96
96
  return item.config_key === "dynamic_theme";
97
97
  }) || initalCustom_configs(saas);
98
- const theme = (0, theme_1.getBaseTheme)();
99
- themeConfig.config_value_json = JSON.stringify(Object.assign(Object.assign(Object.assign({}, JSON.parse(themeConfig.config_value_json)), (theme ? {
100
- supportedTheme: theme,
101
- } : {})), readThemeConfig()));
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
+ 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();
@@ -1,8 +1,7 @@
1
- /// <reference types="qs" />
2
- /// <reference types="express" />
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: import("express").RequestHandler<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>;
5
+ middleware: ExpressRequestHandler;
7
6
  };
8
- export default _default;
7
+ export default option;
@@ -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 === "OPTIONS") {
4
+ if (req.method === 'OPTIONS') {
5
5
  res.statusCode = 204;
6
- res.send("ok");
6
+ res.send('ok');
7
7
  return;
8
8
  }
9
9
  next();
10
10
  };
11
- exports.default = {
12
- name: "options-middleware",
13
- path: "*",
11
+ const option = {
12
+ name: 'options-middleware',
13
+ path: '*',
14
14
  middleware,
15
15
  };
16
+ exports.default = option;
@@ -30,16 +30,11 @@ const config = (0, webpack_config_1.default)();
30
30
  console.log(warnings.map((item) => item.message).join("\n"));
31
31
  }
32
32
  console.log(chalk_1.default.yellow(`当前打包工具:webpack@${version}`));
33
- if (assets) {
34
- console.log(chalk_1.default.blue("资源清单:"));
35
- const assetsInfo = assets.map(({ size, name }) => {
36
- return ` ${name} ${chalk_1.default.white(size > 1024 ? `~${Math.floor(size / 1024)}KB` : `${size}B`)}`;
37
- });
38
- assetsInfo.map((item) => {
39
- console.log(chalk_1.default.blue(item));
40
- });
41
- }
42
- else {
43
- console.log(chalk_1.default.blue("无资源清单"));
44
- }
33
+ console.log(chalk_1.default.blue("资源清单:"));
34
+ const assetsInfo = assets.map(({ size, name }) => {
35
+ return ` ${name} ${chalk_1.default.white(size > 1024 ? `~${Math.floor(size / 1024)}KB` : `${size}B`)}`;
36
+ });
37
+ assetsInfo.map((item) => {
38
+ console.log(chalk_1.default.blue(item));
39
+ });
45
40
  });
@@ -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
  //检测端口占用情况
@@ -37,9 +38,12 @@ const bundleServer_1 = require("../module/bundleServer");
37
38
  port: bundledServerPort,
38
39
  compiler,
39
40
  internalDevConfig: {
40
- allowedHosts: "all",
41
+ allowedHosts: 'all',
41
42
  },
42
43
  });
44
+ process.on('exit', () => {
45
+ (0, kill_port_1.default)(bundledServerPort, 'tcp').then(console.log).catch(console.log);
46
+ });
43
47
  }))().catch((err) => {
44
48
  console.log(err);
45
49
  });
@@ -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": "2.3.5",
3
+ "version": "3.0.0-beta.10",
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": "2.3.5",
24
- "@tuya-sat/micro-dev-proxy": "2.3.5",
25
- "@tuya-sat/micro-utils": "2.3.5",
23
+ "@tuya-sat/micro-dev-loader": "3.0.0-beta.10",
24
+ "@tuya-sat/micro-dev-proxy": "3.0.0-beta.10",
25
+ "@tuya-sat/micro-utils": "3.0.0-beta.10",
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",
@@ -52,6 +55,7 @@
52
55
  "style-loader": "3.3.1",
53
56
  "svg-url-loader": "7.1.1",
54
57
  "tsconfig-paths-webpack-plugin": "3.5.2",
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",
@@ -1,2 +0,0 @@
1
- import { ThemeCat } from "@tuya-sat/micro-dev-loader/dist/less/utils/index";
2
- export declare const getBaseTheme: () => ThemeCat;
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getBaseTheme = void 0;
4
- const index_1 = require("@tuya-sat/micro-dev-loader/dist/less/utils/index");
5
- const getBaseTheme = () => {
6
- const microTheme = process.env.MICRO_THEME;
7
- if (!microTheme || ![index_1.DARK_THEME, index_1.LIGHT_THEME].includes(microTheme))
8
- return index_1.LIGHT_THEME;
9
- return microTheme;
10
- };
11
- exports.getBaseTheme = getBaseTheme;