@tuya-sat/micro-script 2.2.16 → 2.2.20

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;
@@ -7,4 +7,11 @@ export default function getFakeSaas(config: DebuggerConfig): Promise<{
7
7
  _SDF_CONFIG: anyObject;
8
8
  __MAIN_APP_PUBLIC_PATH: string;
9
9
  }>;
10
+ export declare function getFakeUser(config: DebuggerConfig): {
11
+ user_name: string;
12
+ roles: {
13
+ role_code: string;
14
+ role_name: string;
15
+ }[];
16
+ };
10
17
  export {};
@@ -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
+ exports.getFakeUser = void 0;
15
16
  const fs_extra_1 = __importDefault(require("fs-extra"));
16
17
  const axios_1 = __importDefault(require("axios"));
17
18
  const chalk_1 = __importDefault(require("chalk"));
@@ -38,7 +39,7 @@ function getFakeSaas(config) {
38
39
  process.exit(1);
39
40
  }
40
41
  if (!fs_extra_1.default.existsSync(paths_1.default.saasCache)) {
41
- const { data } = yield axios_1.default.get(config.target);
42
+ const { data } = yield axios_1.default.get(new URL("/login", config.target).href);
42
43
  const _SDF_CONFIG = parse_SDF_CONFIG(data);
43
44
  const _SDF = parse_SDF(data);
44
45
  const __MAIN_APP_PUBLIC_PATH = parse__MAIN_APP_PUBLIC_PATH(data);
@@ -47,7 +48,6 @@ function getFakeSaas(config) {
47
48
  _SDF: JSON.parse(_SDF),
48
49
  __MAIN_APP_PUBLIC_PATH: JSON.parse(__MAIN_APP_PUBLIC_PATH),
49
50
  };
50
- console.log(saas);
51
51
  fs_extra_1.default.writeJSONSync(paths_1.default.saasCache, saas);
52
52
  return saas;
53
53
  }
@@ -55,3 +55,15 @@ function getFakeSaas(config) {
55
55
  });
56
56
  }
57
57
  exports.default = getFakeSaas;
58
+ function getFakeUser(config) {
59
+ return {
60
+ user_name: config.username || "admin@tuya.com",
61
+ roles: [
62
+ {
63
+ role_code: "FAKE_ROLE_CODE",
64
+ role_name: "FAKE_ROLE_NAME",
65
+ },
66
+ ],
67
+ };
68
+ }
69
+ exports.getFakeUser = getFakeUser;
@@ -18,4 +18,6 @@ export declare type CustomConfig = {
18
18
  platform: string;
19
19
  config_id: string;
20
20
  };
21
- export default function staticMain(app: Express, debuggerConfig: DebuggerConfig): void;
21
+ export default function staticMain(app: Express & {
22
+ _isLogin?: Promise<void>;
23
+ }, debuggerConfig: DebuggerConfig): 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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
26
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
27
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -14,9 +37,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
37
  Object.defineProperty(exports, "__esModule", { value: true });
15
38
  const cheerio_1 = __importDefault(require("cheerio"));
16
39
  const axios_1 = __importDefault(require("axios"));
17
- const fakeSaas_1 = __importDefault(require("./fakeSaas"));
40
+ const fakeSaas_1 = __importStar(require("./fakeSaas"));
18
41
  const paths_1 = __importDefault(require("../../config/paths"));
19
- const defaultBase = "https://static1.tuyacn.com/static/sdf-gw/v1.0.1.293/";
42
+ const defaultBase = "https://static1.tuyacn.com/static/sdf-gw/v1.0.1.352/";
20
43
  function staticMain(app, debuggerConfig) {
21
44
  app.get([
22
45
  "/",
@@ -26,24 +49,18 @@ function staticMain(app, debuggerConfig) {
26
49
  "/application",
27
50
  "/application/*",
28
51
  ], (req, res) => __awaiter(this, void 0, void 0, function* () {
52
+ if (app._isLogin) {
53
+ yield app._isLogin;
54
+ }
29
55
  const base = debuggerConfig.base || defaultBase;
30
56
  const { data } = yield axios_1.default.get(new URL("index.html", base).href);
31
57
  const $ = cheerio_1.default.load(data);
32
58
  modifySrcAttr($, base);
33
- insertLocalStorage($);
34
59
  yield insertScript($, debuggerConfig);
35
60
  res.send($.html());
36
61
  }));
37
62
  }
38
63
  exports.default = staticMain;
39
- function insertLocalStorage($) {
40
- //可能有坑
41
- $("head").append($("<script>").text(`
42
- window.localStorage.setItem('isLogin','Yes');
43
- window.localStorage.setItem('_USERNAME','fake_user');
44
- window.localStorage.setItem('_ROLE','普通');
45
- `));
46
- }
47
64
  function initalCustom_configs(saas) {
48
65
  const config = {
49
66
  config_group: "",
@@ -67,6 +84,7 @@ function insertScript($, debuggerConfig) {
67
84
  var _a;
68
85
  return __awaiter(this, void 0, void 0, function* () {
69
86
  const { _SDF_CONFIG, _SDF, __MAIN_APP_PUBLIC_PATH } = yield (0, fakeSaas_1.default)(debuggerConfig);
87
+ _SDF.user = (0, fakeSaas_1.getFakeUser)(debuggerConfig);
70
88
  const { saas } = _SDF;
71
89
  (_a = saas.custom_configs) !== null && _a !== void 0 ? _a : (saas.custom_configs = []);
72
90
  let themeConfig = saas.custom_configs.find((item) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tuya-sat/micro-script",
3
- "version": "2.2.16",
3
+ "version": "2.2.20",
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.16",
24
- "@tuya-sat/micro-dev-proxy": "2.2.16",
25
- "@tuya-sat/micro-utils": "2.2.16",
23
+ "@tuya-sat/micro-dev-loader": "2.2.20",
24
+ "@tuya-sat/micro-dev-proxy": "2.2.20",
25
+ "@tuya-sat/micro-utils": "2.2.20",
26
26
  "babel-loader": "8.2.4",
27
27
  "babel-plugin-import": "1.13.3",
28
28
  "chalk": "4.1.2",