@tuya-sat/micro-dev-loader 3.0.0-beta.3 → 3.0.0

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.
package/dist/index.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import ThemePlugin from "./plugins/theme";
2
- import LocalesPlugin from "./plugins/locales";
3
2
  declare const filterCssVariableLoader: string;
4
3
  declare const changeAntdGlobalImport: string;
5
4
  declare const changeTuyaSatComponentImport: string;
6
- export { ThemePlugin, LocalesPlugin, filterCssVariableLoader, changeAntdGlobalImport, changeTuyaSatComponentImport, };
5
+ export { ThemePlugin, filterCssVariableLoader, changeAntdGlobalImport, changeTuyaSatComponentImport, };
package/dist/index.js CHANGED
@@ -3,14 +3,12 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var index = require('./plugins/theme/index.js');
6
- var index$1 = require('./plugins/locales/index.js');
7
6
 
8
7
  const filterCssVariableLoader = require.resolve("./loader/filterCssVariableLoader");
9
8
  const changeAntdGlobalImport = require.resolve("./loader/changeAntdGlobalImport");
10
9
  const changeTuyaSatComponentImport = require.resolve("./loader/changeTuyaSatComponentImport");
11
10
 
12
11
  exports.ThemePlugin = index["default"];
13
- exports.LocalesPlugin = index$1["default"];
14
12
  exports.changeAntdGlobalImport = changeAntdGlobalImport;
15
13
  exports.changeTuyaSatComponentImport = changeTuyaSatComponentImport;
16
14
  exports.filterCssVariableLoader = filterCssVariableLoader;
@@ -564,7 +564,7 @@ html {
564
564
  // ---
565
565
  @anchor-bg: transparent;
566
566
  @anchor-border-color: @border-color-split;
567
- @anchor-link-top: 7px;
567
+ @anchor-link-top: 7px; // 注意,一些版本可能会有样式问题
568
568
  @anchor-link-left: 16px;
569
569
  @anchor-link-padding: @anchor-link-top 0 @anchor-link-top @anchor-link-left;
570
570
 
@@ -616,7 +616,7 @@ html {
616
616
  @modal-header-title-line-height: 22px;
617
617
  @modal-header-title-font-size: @font-size-lg;
618
618
  @modal-header-border-color-split: @border-color-split;
619
- @modal-header-close-size: 56px;
619
+ @modal-header-close-size: @modal-header-title-line-height + 2 * @modal-header-padding-vertical;
620
620
  @modal-content-bg: @component-background;
621
621
  @modal-heading-color: @heading-color;
622
622
  @modal-close-color: @text-color-secondary;
@@ -629,6 +629,7 @@ html {
629
629
  @modal-mask-bg: fade(@black, 45%);
630
630
  @modal-confirm-body-padding: 32px 32px 24px;
631
631
  @modal-confirm-title-font-size: @font-size-lg;
632
+ @modal-border-radius: @border-radius-base;
632
633
 
633
634
  // Progress
634
635
  // --
@@ -927,7 +928,7 @@ html {
927
928
  @breadcrumb-font-size: @font-size-base;
928
929
  @breadcrumb-icon-font-size: @font-size-base;
929
930
  @breadcrumb-link-color: @text-color-secondary;
930
- @breadcrumb-link-color-hover: @primary-5;
931
+ @breadcrumb-link-color-hover: @text-color;
931
932
  @breadcrumb-separator-color: @text-color-secondary;
932
933
  @breadcrumb-separator-margin: 0 @padding-xs;
933
934
 
@@ -1418,3 +1419,11 @@ html {
1418
1419
  // Mentions
1419
1420
  // ---
1420
1421
  @mentions-dropdown-bg: @popover-background;
1422
+
1423
+ // Segmented
1424
+ // ---
1425
+ @segmented-bg: fade(@black, 25%);
1426
+ @segmented-hover-bg: fade(@black, 45%);
1427
+ @segmented-selected-bg: #333333;
1428
+ @segmented-label-color: fade(@white, 65%);
1429
+ @segmented-label-hover-color: fade(@white, 85%);
@@ -4,19 +4,18 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var tslib = require('tslib');
6
6
  var path = require('path');
7
- var fse = require('fs-extra');
8
7
  var less = require('less');
8
+ var patch = require('../utils/patch.js');
9
9
 
10
10
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
11
11
 
12
12
  var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
13
- var fse__default = /*#__PURE__*/_interopDefaultLegacy(fse);
14
13
 
15
14
  class HandleImport extends less.FileManager {
16
15
  constructor() {
17
16
  super(...arguments);
18
17
  this.interceptReg = /antd\/(es|lib)\/style\/themes\/variable\.less$/;
19
- this.darkVariableContent = fse__default["default"].readFileSync(require.resolve("./dark.variable.less"), "utf-8");
18
+ this.darkVariableContent = patch.getDarkLessContent();
20
19
  }
21
20
  loadFile(filename, currentDirectory, options, environment) {
22
21
  const _super = Object.create(null, {
@@ -25,7 +24,7 @@ class HandleImport extends less.FileManager {
25
24
  return tslib.__awaiter(this, void 0, void 0, function* () {
26
25
  if (filename.startsWith("~")) {
27
26
  let filenamed = filename.replace("~", "");
28
- const fullPath = require.resolve(filenamed);
27
+ const fullPath = require.resolve(filenamed, { paths: [currentDirectory] });
29
28
  if (this.interceptReg.test(fullPath)) {
30
29
  return {
31
30
  filename: fullPath,
@@ -0,0 +1,2 @@
1
+ export declare function patchLessForAntd(version: string, content: string): string;
2
+ export declare function getDarkLessContent(): string;
@@ -0,0 +1,28 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var path = require('path');
6
+ var semver = require('semver');
7
+ var fse = require('fs-extra');
8
+
9
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
10
+
11
+ var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
12
+ var fse__default = /*#__PURE__*/_interopDefaultLegacy(fse);
13
+
14
+ function patchLessForAntd(version, content) {
15
+ if (semver.gte(version, "4.20.6")) {
16
+ return `${content}@anchor-link-top: 4px;\n`;
17
+ }
18
+ return content;
19
+ }
20
+ function getDarkLessContent() {
21
+ const antdPkgPath = require.resolve('antd/package.json', { paths: [process.cwd()] });
22
+ const { version } = fse__default["default"].readJSONSync(antdPkgPath);
23
+ const originDarkVariableContent = fse__default["default"].readFileSync(path__default["default"].join(__dirname, '../plugin/dark.variable.less'), "utf-8");
24
+ return patchLessForAntd(version, originDarkVariableContent);
25
+ }
26
+
27
+ exports.getDarkLessContent = getDarkLessContent;
28
+ exports.patchLessForAntd = patchLessForAntd;
@@ -3,6 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var tslib = require('tslib');
6
+ var crypto = require('crypto');
6
7
  var HtmlWebpackPlugin = require('html-webpack-plugin');
7
8
  var cheerio = require('cheerio');
8
9
  var less = require('less');
@@ -34,9 +35,13 @@ class ThemePlugin {
34
35
  name: this.pluginName,
35
36
  stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL,
36
37
  }, (assets, callback) => tslib.__awaiter(this, void 0, void 0, function* () {
37
- const [pathname] = Object.entries(assets).find(([pathname]) => {
38
+ const lightAsset = Object.entries(assets).find(([pathname]) => {
38
39
  return /\/light\.[\s\S]+?\.css$/.test(pathname);
39
40
  });
41
+ if (!lightAsset) {
42
+ return callback();
43
+ }
44
+ const [pathname] = lightAsset;
40
45
  const chunk = compilation.namedChunks.get("light");
41
46
  compilation.chunkGraph.getChunkModules(chunk).forEach((item) => {
42
47
  this.lessFiles.push(item.nameForCondition());
@@ -45,8 +50,8 @@ class ThemePlugin {
45
50
  return new RawSource(this.filterCssVarible(source.source().toString())[0]);
46
51
  });
47
52
  const [content, storeHtmlVariable] = yield this.runCssbundle();
48
- const { contenthash } = compilation.assetsInfo.get(pathname);
49
- const darkCssFileName = `dark.${contenthash}.css`;
53
+ const darkHash = crypto.createHash("sha256").update(content).digest("hex").substring(0, 8);
54
+ const darkCssFileName = `dark.${darkHash}.css`;
50
55
  compilation.emitAsset(`${this.stylePath}/${darkCssFileName}`, new RawSource(content));
51
56
  HtmlWebpackPlugin__default["default"].getHooks(compilation).beforeAssetTagGeneration.tapAsync(this.pluginName, (data, cb) => {
52
57
  HtmlWebpackPlugin__default["default"].getHooks(compilation).beforeEmit.tapAsync(this.pluginName, (data, cb) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tuya-sat/micro-dev-loader",
3
- "version": "3.0.0-beta.3",
3
+ "version": "3.0.0",
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": "3.0.0-beta.3",
17
+ "@tuya-sat/micro-utils": "3.0.0",
18
18
  "cheerio": "1.0.0-rc.10",
19
19
  "ejs": "3.1.6",
20
20
  "fs-extra": "10.0.1",
@@ -25,6 +25,7 @@
25
25
  "loader-utils": "3.2.0",
26
26
  "path": "0.12.7",
27
27
  "postcss": "8.4.12",
28
+ "semver": "7.3.5",
28
29
  "tslib": "2.3.1"
29
30
  },
30
31
  "devDependencies": {
@@ -1,9 +0,0 @@
1
- import { Compiler } from "webpack";
2
- export default class LocalsPlugin {
3
- private localesOriginPath;
4
- private localesTargetPath;
5
- private pluginName;
6
- private localesFiles;
7
- constructor(localesOriginPath?: string, localesTargetPath?: string);
8
- apply(compiler: Compiler): void;
9
- }
@@ -1,66 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var tslib = require('tslib');
6
- var fs = require('fs');
7
- var path = require('path');
8
-
9
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
10
-
11
- var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
12
-
13
- class LocalsPlugin {
14
- constructor(localesOriginPath = "./src/lang", localesTargetPath = "./_locales/ui") {
15
- this.localesOriginPath = localesOriginPath;
16
- this.localesTargetPath = localesTargetPath;
17
- this.pluginName = "LocalsPlugin";
18
- this.localesFiles = [];
19
- }
20
- apply(compiler) {
21
- const isProduction = process.env.NODE_ENV === "production";
22
- if (isProduction) {
23
- compiler.hooks.thisCompilation.tap(this.pluginName, (compilation) => {
24
- compilation.hooks.processAssets.tapAsync({
25
- name: this.pluginName,
26
- stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL,
27
- }, (assets, callback) => tslib.__awaiter(this, void 0, void 0, function* () {
28
- const filenames = yield fs__default["default"].readdirSync(this.localesOriginPath);
29
- fs__default["default"].existsSync(this.localesTargetPath) &&
30
- fs__default["default"].rmdirSync(path.resolve(this.localesTargetPath), {
31
- recursive: true,
32
- });
33
- fs__default["default"].mkdirSync(path.resolve(this.localesTargetPath));
34
- const jiti = require("jiti")(path.resolve(this.localesOriginPath));
35
- filenames.forEach((v) => tslib.__awaiter(this, void 0, void 0, function* () {
36
- var _a;
37
- if (v.substring(0, 5) === "index")
38
- return;
39
- const lang = v.split(".")[0];
40
- const content = jiti(`./${v}`);
41
- const resObj = {};
42
- const recursive = (value, prefix, key) => {
43
- if (typeof value === "object") {
44
- prefix += `.${key}`;
45
- Object.keys(value).forEach((k) => {
46
- recursive(value[k], prefix, k);
47
- });
48
- }
49
- else {
50
- key = `${prefix}.${key}`.substring(2);
51
- resObj[key] = value;
52
- return;
53
- }
54
- };
55
- recursive((_a = content.default) === null || _a === void 0 ? void 0 : _a.translation, "", "");
56
- const resJson = JSON.stringify(resObj);
57
- fs__default["default"].appendFileSync(path.resolve(`${this.localesTargetPath}/${lang}.json`), resJson);
58
- }));
59
- callback();
60
- }));
61
- });
62
- }
63
- }
64
- }
65
-
66
- exports["default"] = LocalsPlugin;