@tuya-sat/micro-script 2.2.15 → 2.2.19

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.
@@ -21,6 +21,7 @@ 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
23
  const index_1 = require("@tuya-sat/micro-dev-loader/dist/less/utils/index");
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");
@@ -29,16 +30,20 @@ const toArray = (value) => {
29
30
  return Array.isArray(value) ? value : [value];
30
31
  };
31
32
  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}`);
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}`);
35
36
  return process.exit(1);
36
37
  }
37
- return MICRO_THEME;
38
+ return microTheme;
38
39
  };
39
40
  function getCommonConfig({ isDev, isBuild, }) {
40
41
  const { name: packageName } = require(paths_1.default.appPkg);
41
- const MICRO_THEME = validateMicroTheme();
42
+ const { annotations } = (0, micro_utils_1.parseManifest)();
43
+ const devMicroTheme = validateMicroTheme();
44
+ const enableThemeCompile = isDev
45
+ ? !!devMicroTheme
46
+ : annotations["sdf.feat:colorTheme"];
42
47
  //获取style处理的loader
43
48
  const getStyleLoaders = (extraLoader = []) => {
44
49
  extraLoader = toArray(extraLoader);
@@ -103,12 +108,16 @@ function getCommonConfig({ isDev, isBuild, }) {
103
108
  {
104
109
  loader: require.resolve("less-loader"),
105
110
  options: {
106
- lessOptions: Object.assign(Object.assign({}, (MICRO_THEME
107
- ? (0, index_1.getLessOptions)(isBuild ? index_1.LIGHT_THEME : MICRO_THEME)
108
- : {})), { javascriptEnabled: true }),
111
+ lessOptions: Object.assign(Object.assign({}, (isDev
112
+ ? enableThemeCompile
113
+ ? (0, index_1.getLessOptions)(devMicroTheme)
114
+ : {}
115
+ : annotations["sdf.feat:colorTheme"]
116
+ ? (0, index_1.getLessOptions)(index_1.LIGHT_THEME)
117
+ : {})), { javascriptEnabled: true }),
109
118
  },
110
119
  },
111
- MICRO_THEME &&
120
+ enableThemeCompile &&
112
121
  require("@tuya-sat/micro-dev-loader").changeAntdGlobalImport,
113
122
  ].filter(Boolean)),
114
123
  },
@@ -133,7 +142,7 @@ function getCommonConfig({ isDev, isBuild, }) {
133
142
  optimization: {
134
143
  runtimeChunk: "single",
135
144
  splitChunks: {
136
- cacheGroups: Object.assign(Object.assign({}, (MICRO_THEME
145
+ cacheGroups: Object.assign(Object.assign({}, (enableThemeCompile
137
146
  ? {
138
147
  vendorCss: {
139
148
  test: /([\\/]node_modules[\\/][\s\S]+(.less|.css)$)|([\\/]src[\\/]styles[\\/]global.less)/,
@@ -175,7 +184,7 @@ function getCommonConfig({ isDev, isBuild, }) {
175
184
  filename: "static/css/[name].[contenthash:8].css",
176
185
  chunkFilename: "static/css/[name].[contenthash:8].chunk.css",
177
186
  }),
178
- isBuild && MICRO_THEME && new micro_dev_loader_1.ThemePlugin(),
187
+ isBuild && enableThemeCompile && new micro_dev_loader_1.ThemePlugin(),
179
188
  ].filter((value) => Boolean(value)),
180
189
  };
181
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;
@@ -38,16 +38,23 @@ function getFakeSaas(config) {
38
38
  process.exit(1);
39
39
  }
40
40
  if (!fs_extra_1.default.existsSync(paths_1.default.saasCache)) {
41
- const { data } = yield axios_1.default.get(config.target);
41
+ const { data } = yield axios_1.default.get(new URL("/login", config.target).href);
42
42
  const _SDF_CONFIG = parse_SDF_CONFIG(data);
43
43
  const _SDF = parse_SDF(data);
44
44
  const __MAIN_APP_PUBLIC_PATH = parse__MAIN_APP_PUBLIC_PATH(data);
45
45
  const saas = {
46
46
  _SDF_CONFIG: JSON.parse(_SDF_CONFIG),
47
- _SDF: JSON.parse(_SDF),
47
+ _SDF: Object.assign(Object.assign({}, JSON.parse(_SDF)), { user: {
48
+ user_name: config.username || "admin@tuya.com",
49
+ roles: [
50
+ {
51
+ role_code: "FAKE_ROLE_CODE",
52
+ role_name: "FAKE_ROLE_NAME",
53
+ },
54
+ ],
55
+ } }),
48
56
  __MAIN_APP_PUBLIC_PATH: JSON.parse(__MAIN_APP_PUBLIC_PATH),
49
57
  };
50
- console.log(saas);
51
58
  fs_extra_1.default.writeJSONSync(paths_1.default.saasCache, saas);
52
59
  return saas;
53
60
  }
@@ -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.293/";
18
+ const paths_1 = __importDefault(require("../../config/paths"));
19
+ const defaultBase = "https://static1.tuyacn.com/static/sdf-gw/v1.0.1.352/";
19
20
  function staticMain(app, debuggerConfig) {
20
21
  app.get([
21
22
  "/",
@@ -29,40 +30,40 @@ function staticMain(app, debuggerConfig) {
29
30
  const { data } = yield axios_1.default.get(new URL("index.html", base).href);
30
31
  const $ = cheerio_1.default.load(data);
31
32
  modifySrcAttr($, base);
32
- insertLocalStorage($);
33
33
  yield insertScript($, debuggerConfig);
34
34
  res.send($.html());
35
35
  }));
36
36
  }
37
37
  exports.default = staticMain;
38
- function insertLocalStorage($) {
39
- //可能有坑
40
- $("head").append($("<script>").text(`
41
- window.localStorage.setItem('isLogin','Yes');
42
- window.localStorage.setItem('_USERNAME','fake_user');
43
- window.localStorage.setItem('_ROLE','普通');
44
- `));
38
+ function initalCustom_configs(saas) {
39
+ const config = {
40
+ config_group: "",
41
+ config_key: "dynamic_theme",
42
+ config_value: "",
43
+ config_label: "",
44
+ config_value_json: "",
45
+ config_name_zh: "",
46
+ config_name_en: "",
47
+ platform: "",
48
+ config_id: "",
49
+ };
50
+ saas.custom_configs.push(config);
51
+ return config;
52
+ }
53
+ function readThemeConfig() {
54
+ delete require.cache[paths_1.default.microConfig];
55
+ return require(paths_1.default.microConfig).debuggerConfig.themeConfig;
45
56
  }
46
57
  function insertScript($, debuggerConfig) {
47
58
  var _a;
48
- var _b;
49
59
  return __awaiter(this, void 0, void 0, function* () {
50
60
  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) => {
61
+ const { saas } = _SDF;
62
+ (_a = saas.custom_configs) !== null && _a !== void 0 ? _a : (saas.custom_configs = []);
63
+ let themeConfig = saas.custom_configs.find((item) => {
53
64
  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);
65
+ }) || initalCustom_configs(saas);
66
+ themeConfig.config_value_json = JSON.stringify(readThemeConfig());
66
67
  $("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
68
  localStorage.setItem('theme',${JSON.stringify(process.env.MICRO_THEME)});
68
69
  localStorage.setItem('isDebugger','true')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tuya-sat/micro-script",
3
- "version": "2.2.15",
3
+ "version": "2.2.19",
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.15",
24
- "@tuya-sat/micro-dev-proxy": "2.2.15",
25
- "@tuya-sat/micro-utils": "2.2.15",
23
+ "@tuya-sat/micro-dev-loader": "2.2.19",
24
+ "@tuya-sat/micro-dev-proxy": "2.2.19",
25
+ "@tuya-sat/micro-utils": "2.2.19",
26
26
  "babel-loader": "8.2.4",
27
27
  "babel-plugin-import": "1.13.3",
28
28
  "chalk": "4.1.2",