@tuya-sat/micro-script 2.2.14 → 2.2.18

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.
@@ -20,25 +20,46 @@ const mini_css_extract_plugin_1 = __importDefault(require("mini-css-extract-plug
20
20
  const html_webpack_plugin_1 = __importDefault(require("html-webpack-plugin"));
21
21
  const css_minimizer_webpack_plugin_1 = __importDefault(require("css-minimizer-webpack-plugin"));
22
22
  const micro_dev_loader_1 = require("@tuya-sat/micro-dev-loader");
23
+ const index_1 = require("@tuya-sat/micro-dev-loader/dist/less/utils/index");
23
24
  const micro_utils_1 = require("@tuya-sat/micro-utils");
24
25
  const paths_1 = __importDefault(require("./paths"));
25
26
  const isExistPostcssFile = () => {
26
27
  return fs_extra_1.default.existsSync("postcss.config.js");
27
28
  };
29
+ const toArray = (value) => {
30
+ return Array.isArray(value) ? value : [value];
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
+ };
28
40
  function getCommonConfig({ isDev, isBuild, }) {
29
41
  const { name: packageName } = require(paths_1.default.appPkg);
42
+ const { annotations } = (0, micro_utils_1.parseManifest)();
43
+ const devMicroTheme = validateMicroTheme();
44
+ const enableThemeCompile = isDev
45
+ ? !!devMicroTheme
46
+ : annotations["sdf.feat:theme"];
30
47
  //获取style处理的loader
31
- const getStyleLoaders = (cssOptions, extraLoader) => {
32
- isBuild && cssOptions.importLoaders++;
48
+ const getStyleLoaders = (extraLoader = []) => {
49
+ extraLoader = toArray(extraLoader);
33
50
  const loaders = [
34
51
  isBuild ? mini_css_extract_plugin_1.default.loader : require.resolve("style-loader"),
35
52
  {
36
53
  loader: require.resolve("css-loader"),
37
- options: Object.assign({ modules: {
54
+ options: {
55
+ modules: {
38
56
  auto: true,
39
57
  localIdentName: isDev ? "[path][name]__[local]" : "[hash:base64]",
40
- } }, cssOptions),
58
+ },
59
+ importLoaders: extraLoader.length + 1,
60
+ },
41
61
  },
62
+ isDev && require("@tuya-sat/micro-dev-loader").filterCssVariableLoader,
42
63
  /**
43
64
  * 优化运行时速度
44
65
  * dev环境就不需要postcss-loader了
@@ -55,7 +76,7 @@ function getCommonConfig({ isDev, isBuild, }) {
55
76
  },
56
77
  };
57
78
  })()),
58
- extraLoader,
79
+ ...extraLoader,
59
80
  ].filter(Boolean);
60
81
  return loaders;
61
82
  };
@@ -79,30 +100,30 @@ function getCommonConfig({ isDev, isBuild, }) {
79
100
  rules: [
80
101
  {
81
102
  test: /\.css$/,
82
- use: getStyleLoaders({
83
- importLoaders: 0,
84
- }),
103
+ use: getStyleLoaders(),
85
104
  },
86
105
  {
87
106
  test: /\.less$/,
88
- use: getStyleLoaders({
89
- importLoaders: 1,
90
- }, {
91
- loader: require.resolve("less-loader"),
92
- options: {
93
- lessOptions: Object.assign(Object.assign({}, (process.env.MICRO_THEME
94
- ? {
95
- modifyVars: Object.assign(Object.assign({}, micro_utils_1.theme.getAntdOverWriteFile().light), { "root-entry-name": "variable" }),
96
- }
97
- : {})), { javascriptEnabled: true }),
107
+ use: getStyleLoaders([
108
+ {
109
+ loader: require.resolve("less-loader"),
110
+ options: {
111
+ lessOptions: Object.assign(Object.assign({}, (isDev
112
+ ? enableThemeCompile
113
+ ? (0, index_1.getLessOptions)(devMicroTheme)
114
+ : {}
115
+ : annotations["sdf.feat:theme"]
116
+ ? (0, index_1.getLessOptions)(index_1.LIGHT_THEME)
117
+ : {})), { javascriptEnabled: true }),
118
+ },
98
119
  },
99
- }),
120
+ enableThemeCompile &&
121
+ require("@tuya-sat/micro-dev-loader").changeAntdGlobalImport,
122
+ ].filter(Boolean)),
100
123
  },
101
124
  {
102
125
  test: /\.(scss|sass)$/,
103
- use: getStyleLoaders({
104
- importLoaders: 1,
105
- }, require.resolve("sass-loader")),
126
+ use: getStyleLoaders(require.resolve("sass-loader")),
106
127
  },
107
128
  {
108
129
  test: /\.(bmp|png|svg|jpg|jpeg|gif)$/i,
@@ -121,7 +142,7 @@ function getCommonConfig({ isDev, isBuild, }) {
121
142
  optimization: {
122
143
  runtimeChunk: "single",
123
144
  splitChunks: {
124
- cacheGroups: Object.assign(Object.assign({}, (process.env.MICRO_THEME
145
+ cacheGroups: Object.assign(Object.assign({}, (enableThemeCompile
125
146
  ? {
126
147
  vendorCss: {
127
148
  test: /([\\/]node_modules[\\/][\s\S]+(.less|.css)$)|([\\/]src[\\/]styles[\\/]global.less)/,
@@ -163,7 +184,7 @@ function getCommonConfig({ isDev, isBuild, }) {
163
184
  filename: "static/css/[name].[contenthash:8].css",
164
185
  chunkFilename: "static/css/[name].[contenthash:8].chunk.css",
165
186
  }),
166
- isBuild && process.env.MICRO_THEME && new micro_dev_loader_1.ThemePlugin(),
187
+ isBuild && enableThemeCompile && new micro_dev_loader_1.ThemePlugin(),
167
188
  ].filter((value) => Boolean(value)),
168
189
  };
169
190
  }
@@ -3,15 +3,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const fs_extra_1 = __importDefault(require("fs-extra"));
7
6
  const webpack_merge_1 = require("webpack-merge");
8
7
  const paths_1 = __importDefault(require("./paths"));
9
8
  const framework_1 = __importDefault(require("../framework"));
10
9
  const webpack_common_1 = __importDefault(require("./webpack.common"));
10
+ const micro_utils_1 = require("@tuya-sat/micro-utils");
11
11
  exports.default = () => {
12
12
  const isBuild = process.env.NODE_ENV === "production";
13
13
  const isDev = process.env.NODE_ENV === "development";
14
- const { annotations: { ["sdf.cli:microFramework"]: currentFramework }, } = fs_extra_1.default.readJSONSync(paths_1.default.manifest);
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,
@@ -1,12 +1,12 @@
1
1
  import { Configuration } from "webpack";
2
2
  import { BaseParams } from "../config/webpack.config";
3
+ import { MICRO_FRAMEWORKS_TYPE } from "@tuya-sat/micro-utils";
3
4
  export interface Params extends BaseParams {
4
5
  currentFramework: MICRO_FRAMEWORKS_TYPE;
5
6
  }
6
7
  export interface ParamsWithTs extends Params {
7
8
  isTs: boolean;
8
9
  }
9
- export declare type MICRO_FRAMEWORKS_TYPE = "REACT_TS" | "REACT_JS" | "VUE_TS" | "VUE_JS";
10
10
  export declare type FrameworkFunction = (arg0: Params) => Configuration;
11
11
  declare const _default: ({ currentFramework, isDev, isBuild }: Params) => Configuration;
12
12
  export default _default;
@@ -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,8 @@ 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 paths_1 = __importDefault(require("../../config/paths"));
19
+ const defaultBase = "https://static1.tuyacn.com/static/sdf-gw/v1.0.1.293/";
19
20
  function staticMain(app, debuggerConfig) {
20
21
  app.get([
21
22
  "/",
@@ -43,10 +44,38 @@ function insertLocalStorage($) {
43
44
  window.localStorage.setItem('_ROLE','普通');
44
45
  `));
45
46
  }
47
+ function initalCustom_configs(saas) {
48
+ const config = {
49
+ config_group: "",
50
+ config_key: "dynamic_theme",
51
+ config_value: "",
52
+ config_label: "",
53
+ config_value_json: "",
54
+ config_name_zh: "",
55
+ config_name_en: "",
56
+ platform: "",
57
+ config_id: "",
58
+ };
59
+ saas.custom_configs.push(config);
60
+ return config;
61
+ }
62
+ function readThemeConfig() {
63
+ delete require.cache[paths_1.default.microConfig];
64
+ return require(paths_1.default.microConfig).debuggerConfig.themeConfig;
65
+ }
46
66
  function insertScript($, debuggerConfig) {
67
+ var _a;
47
68
  return __awaiter(this, void 0, void 0, function* () {
48
69
  const { _SDF_CONFIG, _SDF, __MAIN_APP_PUBLIC_PATH } = yield (0, fakeSaas_1.default)(debuggerConfig);
70
+ const { saas } = _SDF;
71
+ (_a = saas.custom_configs) !== null && _a !== void 0 ? _a : (saas.custom_configs = []);
72
+ let themeConfig = saas.custom_configs.find((item) => {
73
+ return item.config_key === "dynamic_theme";
74
+ }) || initalCustom_configs(saas);
75
+ themeConfig.config_value_json = JSON.stringify(readThemeConfig());
49
76
  $("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)};
77
+ localStorage.setItem('theme',${JSON.stringify(process.env.MICRO_THEME)});
78
+ localStorage.setItem('isDebugger','true')
50
79
  `));
51
80
  });
52
81
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tuya-sat/micro-script",
3
- "version": "2.2.14",
3
+ "version": "2.2.18",
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.14",
24
- "@tuya-sat/micro-dev-proxy": "2.2.14",
25
- "@tuya-sat/micro-utils": "2.2.14",
23
+ "@tuya-sat/micro-dev-loader": "2.2.18",
24
+ "@tuya-sat/micro-dev-proxy": "2.2.18",
25
+ "@tuya-sat/micro-utils": "2.2.18",
26
26
  "babel-loader": "8.2.4",
27
27
  "babel-plugin-import": "1.13.3",
28
28
  "chalk": "4.1.2",