@tuya-sat/micro-script 2.2.12 → 2.2.15

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.
@@ -12,6 +12,7 @@ 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 fs_extra_1 = __importDefault(require("fs-extra"));
15
16
  //@ts-ignore
16
17
  const copy_webpack_plugin_1 = __importDefault(require("copy-webpack-plugin"));
17
18
  //@ts-ignore
@@ -19,36 +20,58 @@ const mini_css_extract_plugin_1 = __importDefault(require("mini-css-extract-plug
19
20
  const html_webpack_plugin_1 = __importDefault(require("html-webpack-plugin"));
20
21
  const css_minimizer_webpack_plugin_1 = __importDefault(require("css-minimizer-webpack-plugin"));
21
22
  const micro_dev_loader_1 = require("@tuya-sat/micro-dev-loader");
22
- const micro_utils_1 = require("@tuya-sat/micro-utils");
23
+ const index_1 = require("@tuya-sat/micro-dev-loader/dist/less/utils/index");
23
24
  const paths_1 = __importDefault(require("./paths"));
25
+ const isExistPostcssFile = () => {
26
+ return fs_extra_1.default.existsSync("postcss.config.js");
27
+ };
28
+ const toArray = (value) => {
29
+ return Array.isArray(value) ? value : [value];
30
+ };
31
+ const validateMicroTheme = () => {
32
+ const MICRO_THEME = process.env.MICRO_THEME;
33
+ if (MICRO_THEME && ![index_1.DARK_THEME, index_1.LIGHT_THEME].includes(MICRO_THEME)) {
34
+ console.error(`请设置正确的MICRO_THEME,当前值为${MICRO_THEME},请修改为${index_1.LIGHT_THEME}或${index_1.DARK_THEME}`);
35
+ return process.exit(1);
36
+ }
37
+ return MICRO_THEME;
38
+ };
24
39
  function getCommonConfig({ isDev, isBuild, }) {
25
40
  const { name: packageName } = require(paths_1.default.appPkg);
41
+ const MICRO_THEME = validateMicroTheme();
26
42
  //获取style处理的loader
27
- const getStyleLoaders = (cssOptions, extraLoader) => {
28
- isBuild && cssOptions.importLoaders++;
43
+ const getStyleLoaders = (extraLoader = []) => {
44
+ extraLoader = toArray(extraLoader);
29
45
  const loaders = [
30
46
  isBuild ? mini_css_extract_plugin_1.default.loader : require.resolve("style-loader"),
31
47
  {
32
48
  loader: require.resolve("css-loader"),
33
- options: Object.assign({ modules: {
49
+ options: {
50
+ modules: {
34
51
  auto: true,
35
52
  localIdentName: isDev ? "[path][name]__[local]" : "[hash:base64]",
36
- } }, cssOptions),
53
+ },
54
+ importLoaders: extraLoader.length + 1,
55
+ },
37
56
  },
57
+ isDev && require("@tuya-sat/micro-dev-loader").filterCssVariableLoader,
38
58
  /**
39
59
  * 优化运行时速度
40
60
  * dev环境就不需要postcss-loader了
41
61
  * 默认应该比较新的浏览器了
42
62
  */
43
- isBuild && {
44
- loader: require.resolve("postcss-loader"),
45
- options: {
46
- postcssOptions: {
47
- plugins: ["postcss-preset-env"],
48
- },
49
- },
50
- },
51
- extraLoader,
63
+ isBuild && Object.assign({ loader: require.resolve("postcss-loader") }, (() => {
64
+ return isExistPostcssFile()
65
+ ? {}
66
+ : {
67
+ options: {
68
+ postcssOptions: {
69
+ plugins: ["postcss-preset-env"],
70
+ },
71
+ },
72
+ };
73
+ })()),
74
+ ...extraLoader,
52
75
  ].filter(Boolean);
53
76
  return loaders;
54
77
  };
@@ -72,30 +95,26 @@ function getCommonConfig({ isDev, isBuild, }) {
72
95
  rules: [
73
96
  {
74
97
  test: /\.css$/,
75
- use: getStyleLoaders({
76
- importLoaders: 0,
77
- }),
98
+ use: getStyleLoaders(),
78
99
  },
79
100
  {
80
101
  test: /\.less$/,
81
- use: getStyleLoaders({
82
- importLoaders: 1,
83
- }, {
84
- loader: require.resolve("less-loader"),
85
- options: {
86
- lessOptions: Object.assign(Object.assign({}, (process.env.MICRO_THEME
87
- ? {
88
- modifyVars: Object.assign(Object.assign({}, micro_utils_1.theme.getAntdOverWriteFile().light), { "root-entry-name": "variable" }),
89
- }
90
- : {})), { javascriptEnabled: true }),
102
+ use: getStyleLoaders([
103
+ {
104
+ loader: require.resolve("less-loader"),
105
+ options: {
106
+ lessOptions: Object.assign(Object.assign({}, (MICRO_THEME
107
+ ? (0, index_1.getLessOptions)(isBuild ? index_1.LIGHT_THEME : MICRO_THEME)
108
+ : {})), { javascriptEnabled: true }),
109
+ },
91
110
  },
92
- }),
111
+ MICRO_THEME &&
112
+ require("@tuya-sat/micro-dev-loader").changeAntdGlobalImport,
113
+ ].filter(Boolean)),
93
114
  },
94
115
  {
95
116
  test: /\.(scss|sass)$/,
96
- use: getStyleLoaders({
97
- importLoaders: 1,
98
- }, require.resolve("sass-loader")),
117
+ use: getStyleLoaders(require.resolve("sass-loader")),
99
118
  },
100
119
  {
101
120
  test: /\.(bmp|png|svg|jpg|jpeg|gif)$/i,
@@ -114,7 +133,7 @@ function getCommonConfig({ isDev, isBuild, }) {
114
133
  optimization: {
115
134
  runtimeChunk: "single",
116
135
  splitChunks: {
117
- cacheGroups: Object.assign(Object.assign({}, (process.env.MICRO_THEME
136
+ cacheGroups: Object.assign(Object.assign({}, (MICRO_THEME
118
137
  ? {
119
138
  vendorCss: {
120
139
  test: /([\\/]node_modules[\\/][\s\S]+(.less|.css)$)|([\\/]src[\\/]styles[\\/]global.less)/,
@@ -156,7 +175,7 @@ function getCommonConfig({ isDev, isBuild, }) {
156
175
  filename: "static/css/[name].[contenthash:8].css",
157
176
  chunkFilename: "static/css/[name].[contenthash:8].chunk.css",
158
177
  }),
159
- isBuild && process.env.MICRO_THEME && new micro_dev_loader_1.ThemePlugin(),
178
+ isBuild && MICRO_THEME && new micro_dev_loader_1.ThemePlugin(),
160
179
  ].filter((value) => Boolean(value)),
161
180
  };
162
181
  }
@@ -1,7 +1,21 @@
1
1
  import { Express } from "express";
2
2
  import type { Config } from "@tuya-sat/micro-dev-proxy";
3
3
  export interface DebuggerConfig extends Config {
4
+ themeConfig?: {
5
+ primaryColor: string;
6
+ };
4
7
  mockPermissions?: string[];
5
8
  base?: string;
6
9
  }
10
+ export declare type CustomConfig = {
11
+ config_group: string;
12
+ config_key: string;
13
+ config_value: string;
14
+ config_label: string;
15
+ config_value_json: string;
16
+ config_name_zh: string;
17
+ config_name_en: string;
18
+ platform: string;
19
+ config_id: string;
20
+ };
7
21
  export default function staticMain(app: Express, debuggerConfig: DebuggerConfig): void;
@@ -15,7 +15,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
15
  const cheerio_1 = __importDefault(require("cheerio"));
16
16
  const axios_1 = __importDefault(require("axios"));
17
17
  const fakeSaas_1 = __importDefault(require("./fakeSaas"));
18
- const defaultBase = "https://static1.tuyacn.com/static/sdf-gw/v1.0.1.22/";
18
+ const defaultBase = "https://static1.tuyacn.com/static/sdf-gw/v1.0.1.293/";
19
19
  function staticMain(app, debuggerConfig) {
20
20
  app.get([
21
21
  "/",
@@ -44,9 +44,28 @@ function insertLocalStorage($) {
44
44
  `));
45
45
  }
46
46
  function insertScript($, debuggerConfig) {
47
+ var _a;
48
+ var _b;
47
49
  return __awaiter(this, void 0, void 0, function* () {
48
50
  const { _SDF_CONFIG, _SDF, __MAIN_APP_PUBLIC_PATH } = yield (0, fakeSaas_1.default)(debuggerConfig);
51
+ (_a = (_b = _SDF.saas).custom_configs) !== null && _a !== void 0 ? _a : (_b.custom_configs = []);
52
+ let themeConfig = _SDF.saas.custom_configs.find((item) => {
53
+ return item.config_key === "dynamic_theme";
54
+ }) || {
55
+ config_group: "",
56
+ config_key: "",
57
+ config_value: "",
58
+ config_label: "",
59
+ config_value_json: "",
60
+ config_name_zh: "",
61
+ config_name_en: "",
62
+ platform: "",
63
+ config_id: "",
64
+ };
65
+ themeConfig.config_value_json = JSON.stringify(debuggerConfig.themeConfig);
49
66
  $("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)};
67
+ localStorage.setItem('theme',${JSON.stringify(process.env.MICRO_THEME)});
68
+ localStorage.setItem('isDebugger','true')
50
69
  `));
51
70
  });
52
71
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tuya-sat/micro-script",
3
- "version": "2.2.12",
3
+ "version": "2.2.15",
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": "2.2.12",
24
- "@tuya-sat/micro-dev-proxy": "2.2.12",
25
- "@tuya-sat/micro-utils": "2.2.12",
23
+ "@tuya-sat/micro-dev-loader": "2.2.15",
24
+ "@tuya-sat/micro-dev-proxy": "2.2.15",
25
+ "@tuya-sat/micro-utils": "2.2.15",
26
26
  "babel-loader": "8.2.4",
27
27
  "babel-plugin-import": "1.13.3",
28
28
  "chalk": "4.1.2",