@tuya-sat/micro-dev-loader 2.2.4 → 2.2.5

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.
@@ -8,9 +8,9 @@ export default class ThemePlugin {
8
8
  apply(compiler: Compiler): void;
9
9
  getBundledLessFile(): Promise<string>;
10
10
  runCssbundle(): Promise<string>;
11
- getCustomeVarible(): {}[];
12
- getLessVarible(contentHash: any): {
11
+ private getCustomeVarible;
12
+ getLessVarible(contentHash: any): Promise<{
13
13
  fileName: string;
14
14
  content: string;
15
- }[];
15
+ }[]>;
16
16
  }
@@ -10,6 +10,7 @@ var less = require('less');
10
10
  var path = require('path');
11
11
  var fse = require('fs-extra');
12
12
  var bundle = require('./bundle.js');
13
+ var microUtils = require('@tuya-sat/micro-utils');
13
14
 
14
15
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
15
16
 
@@ -47,7 +48,7 @@ class ThemePlugin {
47
48
  const { contenthash } = compilation.assetsInfo.get(pathname);
48
49
  const darkCssFileName = `dark.${contenthash}.css`;
49
50
  const lessFileName = `theme.${contenthash}.less`;
50
- const lessVarible = this.getLessVarible(contenthash);
51
+ const lessVarible = yield this.getLessVarible(contenthash);
51
52
  compilation.emitAsset(`${this.stylePath}/${darkCssFileName}`, new RawSource(content));
52
53
  compilation.emitAsset(`${this.stylePath}/${lessFileName}`, new RawSource(lessContent));
53
54
  lessVarible.forEach(({ fileName, content }) => {
@@ -90,7 +91,7 @@ class ThemePlugin {
90
91
  const relativePath = path__default["default"].relative(cwd, file);
91
92
  fakefile += `@import "${relativePath}";\n`;
92
93
  });
93
- const file = yield bundle["default"](fakefile, path__default["default"].resolve(cwd, "fake.less"), Object.assign(Object.assign({}, theme.getThemeVariables({ dark: true })), { "entry-name": "dark" }));
94
+ const file = yield bundle["default"](fakefile, path__default["default"].resolve(cwd, "fake.less"), Object.assign(Object.assign({}, theme.getThemeVariables({ dark: true })), { "entry-name": "light" }));
94
95
  return file;
95
96
  });
96
97
  }
@@ -101,9 +102,9 @@ class ThemePlugin {
101
102
  return less__default["default"].render(bufferString, {
102
103
  filename: file,
103
104
  javascriptEnabled: true,
104
- modifyVars: Object.assign(Object.assign({}, theme.getThemeVariables({
105
+ modifyVars: Object.assign(Object.assign(Object.assign({}, theme.getThemeVariables({
105
106
  dark: true,
106
- })), { "entry-name": "dark" }),
107
+ })), microUtils.theme.getAntdOverWriteFile().dark), { "entry-name": "dark" }),
107
108
  plugins: [createHandleImportPlugin()],
108
109
  });
109
110
  });
@@ -116,44 +117,34 @@ class ThemePlugin {
116
117
  });
117
118
  }
118
119
  getCustomeVarible() {
119
- const lightFile = this.lessFiles.find((filePath) => /\/src\/styles\/light.less/.test(filePath));
120
- const darkFile = this.lessFiles.find((filePath) => /\/src\/styles\/dark.less/.test(filePath));
121
- return [
122
- convertLessFileToVarible(lightFile),
123
- convertLessFileToVarible(darkFile),
124
- ];
125
- function convertLessFileToVarible(filePath) {
126
- if (!filePath) {
127
- return {};
128
- }
129
- let content = fse__default["default"].readFileSync(filePath, "utf-8");
130
- return content
131
- .split(";")
132
- .map((item) => item.split(":"))
133
- .reduce((prev, [key, value]) => {
134
- prev[key] = value;
135
- return prev;
136
- }, {});
137
- }
120
+ return tslib.__awaiter(this, void 0, void 0, function* () {
121
+ return [
122
+ yield microUtils.theme.getCustomLightVaribleFile(),
123
+ yield microUtils.theme.getCustomDarkVaribleFile(),
124
+ ];
125
+ });
138
126
  }
139
127
  getLessVarible(contentHash) {
140
- let antdLightVarible = theme.getThemeVariables();
141
- let antdDarkVarible = theme.getThemeVariables({ dark: true });
142
- delete antdDarkVarible.hack;
143
- delete antdLightVarible.hack;
144
- const [customLightVarible, customDarkVarible] = this.getCustomeVarible();
145
- let lightLessVarible = Object.assign(Object.assign({}, antdLightVarible), customLightVarible);
146
- let darkLessVarible = Object.assign(Object.assign({}, antdDarkVarible), customDarkVarible);
147
- return [
148
- {
149
- fileName: `${this.jsFilePrefix}/dark.${contentHash}.less.js`,
150
- content: `window.darkLessVarible = ${JSON.stringify(darkLessVarible)}`,
151
- },
152
- {
153
- fileName: `${this.jsFilePrefix}/light.${contentHash}.less.js`,
154
- content: `window.lightLessVarible = ${JSON.stringify(lightLessVarible)}`,
155
- },
156
- ];
128
+ return tslib.__awaiter(this, void 0, void 0, function* () {
129
+ let antdLightVarible = theme.getThemeVariables();
130
+ let antdDarkVarible = theme.getThemeVariables({ dark: true });
131
+ const antdOverWriteVarible = microUtils.theme.getAntdOverWriteFile();
132
+ delete antdDarkVarible.hack;
133
+ delete antdLightVarible.hack;
134
+ const [customLightVarible, customDarkVarible] = yield this.getCustomeVarible();
135
+ let lightLessVarible = Object.assign(Object.assign(Object.assign({}, antdLightVarible), antdOverWriteVarible.light), customLightVarible);
136
+ let darkLessVarible = Object.assign(Object.assign(Object.assign({}, antdDarkVarible), antdOverWriteVarible.dark), customDarkVarible);
137
+ return [
138
+ {
139
+ fileName: `${this.jsFilePrefix}/dark.${contentHash}.less.js`,
140
+ content: `window.darkLessVarible = ${JSON.stringify(darkLessVarible)}`,
141
+ },
142
+ {
143
+ fileName: `${this.jsFilePrefix}/light.${contentHash}.less.js`,
144
+ content: `window.lightLessVarible = ${JSON.stringify(lightLessVarible)}`,
145
+ },
146
+ ];
147
+ });
157
148
  }
158
149
  }
159
150
  function createHandleImportPlugin() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tuya-sat/micro-dev-loader",
3
- "version": "2.2.4",
3
+ "version": "2.2.5",
4
4
  "main": "dist/index.js",
5
5
  "license": "MIT",
6
6
  "scripts": {
@@ -14,7 +14,7 @@
14
14
  "@babel/generator": "7.17.7",
15
15
  "@babel/plugin-syntax-typescript": "7.16.7",
16
16
  "@babel/template": "7.16.7",
17
- "@tuya-sat/micro-utils": "2.0.0",
17
+ "@tuya-sat/micro-utils": "2.2.5",
18
18
  "cheerio": "1.0.0-rc.10",
19
19
  "ejs": "3.1.6",
20
20
  "fs-extra": "10.0.1",