@tuya-sat/micro-script 2.2.14 → 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.
|
@@ -20,25 +20,41 @@ 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
|
|
23
|
+
const index_1 = require("@tuya-sat/micro-dev-loader/dist/less/utils/index");
|
|
24
24
|
const paths_1 = __importDefault(require("./paths"));
|
|
25
25
|
const isExistPostcssFile = () => {
|
|
26
26
|
return fs_extra_1.default.existsSync("postcss.config.js");
|
|
27
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
|
+
};
|
|
28
39
|
function getCommonConfig({ isDev, isBuild, }) {
|
|
29
40
|
const { name: packageName } = require(paths_1.default.appPkg);
|
|
41
|
+
const MICRO_THEME = validateMicroTheme();
|
|
30
42
|
//获取style处理的loader
|
|
31
|
-
const getStyleLoaders = (
|
|
32
|
-
|
|
43
|
+
const getStyleLoaders = (extraLoader = []) => {
|
|
44
|
+
extraLoader = toArray(extraLoader);
|
|
33
45
|
const loaders = [
|
|
34
46
|
isBuild ? mini_css_extract_plugin_1.default.loader : require.resolve("style-loader"),
|
|
35
47
|
{
|
|
36
48
|
loader: require.resolve("css-loader"),
|
|
37
|
-
options:
|
|
49
|
+
options: {
|
|
50
|
+
modules: {
|
|
38
51
|
auto: true,
|
|
39
52
|
localIdentName: isDev ? "[path][name]__[local]" : "[hash:base64]",
|
|
40
|
-
}
|
|
53
|
+
},
|
|
54
|
+
importLoaders: extraLoader.length + 1,
|
|
55
|
+
},
|
|
41
56
|
},
|
|
57
|
+
isDev && require("@tuya-sat/micro-dev-loader").filterCssVariableLoader,
|
|
42
58
|
/**
|
|
43
59
|
* 优化运行时速度
|
|
44
60
|
* dev环境就不需要postcss-loader了
|
|
@@ -55,7 +71,7 @@ function getCommonConfig({ isDev, isBuild, }) {
|
|
|
55
71
|
},
|
|
56
72
|
};
|
|
57
73
|
})()),
|
|
58
|
-
extraLoader,
|
|
74
|
+
...extraLoader,
|
|
59
75
|
].filter(Boolean);
|
|
60
76
|
return loaders;
|
|
61
77
|
};
|
|
@@ -79,30 +95,26 @@ function getCommonConfig({ isDev, isBuild, }) {
|
|
|
79
95
|
rules: [
|
|
80
96
|
{
|
|
81
97
|
test: /\.css$/,
|
|
82
|
-
use: getStyleLoaders(
|
|
83
|
-
importLoaders: 0,
|
|
84
|
-
}),
|
|
98
|
+
use: getStyleLoaders(),
|
|
85
99
|
},
|
|
86
100
|
{
|
|
87
101
|
test: /\.less$/,
|
|
88
|
-
use: getStyleLoaders(
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
}
|
|
97
|
-
: {})), { 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
|
+
},
|
|
98
110
|
},
|
|
99
|
-
|
|
111
|
+
MICRO_THEME &&
|
|
112
|
+
require("@tuya-sat/micro-dev-loader").changeAntdGlobalImport,
|
|
113
|
+
].filter(Boolean)),
|
|
100
114
|
},
|
|
101
115
|
{
|
|
102
116
|
test: /\.(scss|sass)$/,
|
|
103
|
-
use: getStyleLoaders(
|
|
104
|
-
importLoaders: 1,
|
|
105
|
-
}, require.resolve("sass-loader")),
|
|
117
|
+
use: getStyleLoaders(require.resolve("sass-loader")),
|
|
106
118
|
},
|
|
107
119
|
{
|
|
108
120
|
test: /\.(bmp|png|svg|jpg|jpeg|gif)$/i,
|
|
@@ -121,7 +133,7 @@ function getCommonConfig({ isDev, isBuild, }) {
|
|
|
121
133
|
optimization: {
|
|
122
134
|
runtimeChunk: "single",
|
|
123
135
|
splitChunks: {
|
|
124
|
-
cacheGroups: Object.assign(Object.assign({}, (
|
|
136
|
+
cacheGroups: Object.assign(Object.assign({}, (MICRO_THEME
|
|
125
137
|
? {
|
|
126
138
|
vendorCss: {
|
|
127
139
|
test: /([\\/]node_modules[\\/][\s\S]+(.less|.css)$)|([\\/]src[\\/]styles[\\/]global.less)/,
|
|
@@ -163,7 +175,7 @@ function getCommonConfig({ isDev, isBuild, }) {
|
|
|
163
175
|
filename: "static/css/[name].[contenthash:8].css",
|
|
164
176
|
chunkFilename: "static/css/[name].[contenthash:8].chunk.css",
|
|
165
177
|
}),
|
|
166
|
-
isBuild &&
|
|
178
|
+
isBuild && MICRO_THEME && new micro_dev_loader_1.ThemePlugin(),
|
|
167
179
|
].filter((value) => Boolean(value)),
|
|
168
180
|
};
|
|
169
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.
|
|
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.
|
|
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.
|
|
24
|
-
"@tuya-sat/micro-dev-proxy": "2.2.
|
|
25
|
-
"@tuya-sat/micro-utils": "2.2.
|
|
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",
|