Browse Source

fix indexof bug

yangkaixiang 1 year ago
parent
commit
9cf249b4bd
5 changed files with 45 additions and 4 deletions
  1. 5 0
      .husky/pre-commit
  2. 4 2
      package.json
  3. 5 1
      src/useDtTheme/index.jsx
  4. 1 1
      src/useDtTheme/utils.jsx
  5. 30 0
      updateVersion.js

+ 5 - 0
.husky/pre-commit

@@ -0,0 +1,5 @@
+#!/usr/bin/env sh
+. "$(dirname -- "$0")/_/husky.sh"
+
+npm version patch --no-git-tag-version
+node updateVersion.js

+ 4 - 2
package.json

@@ -1,6 +1,6 @@
 {
   "name": "dt-theme",
-  "version": "1.0.5",
+  "version": "1.0.8",
   "main": "lib/index.js",
   "dependencies": {
     "@testing-library/jest-dom": "^5.17.0",
@@ -15,7 +15,8 @@
     "test": "react-scripts test",
     "eject": "react-scripts eject",
     "pub1": "npx webpack --config webpack.config.js && npm publish",
-    "pub2": "npm version patch --no-git-tag-version && npx webpack --config webpack.config.js && npm publish"
+    "pub2": "npm version patch --no-git-tag-version && npx webpack --config webpack.config.js && npm publish",
+    "prepare": "husky install"
   },
   "eslintConfig": {
     "extends": [
@@ -43,6 +44,7 @@
     "react": "^18.3.1",
     "react-dom": "^18.3.1",
     "react-scripts": "5.0.1",
+    "husky": "^8.0.1",
     "less": "^4.2.0",
     "less-loader": "^11.1.3",
     "react-app-rewired": "^2.2.1",

+ 5 - 1
src/useDtTheme/index.jsx

@@ -67,7 +67,7 @@ export function changeTheme(theme) {
   });
 }
 
-const useLocalStorageThemeName = () => {
+const useLocalStorageThemeName = (presetTheme) => {
   if (!window.__MICRO_APP_ENVIRONMENT__) {
     var orignalSetItem = localStorage.setItem;
     localStorage.setItem = function (key, newValue) {
@@ -80,6 +80,10 @@ const useLocalStorageThemeName = () => {
   }
 
   const [themeName, setThemeName] = useState(() => {
+    if (presetTheme) {
+      return presetTheme
+    }
+
     if (APP_THEME_CHANGEABLE_KEY == 'false') {
       return APP_THEME_KEY
     }

+ 1 - 1
src/useDtTheme/utils.jsx

@@ -97,7 +97,7 @@ const antdTokenCorRes = {
 }
 
 const isDarkTheme = (themeKey) => {
-  if ((themeKey ?? '').indexOf('dark') !== -1) {
+  if (String(themeKey).indexOf('dark') !== -1) {
     return 1
   }
   return 0

+ 30 - 0
updateVersion.js

@@ -0,0 +1,30 @@
+// const fs = require('fs')
+
+// const packageJsonPath = './package.json'
+
+// // 读取package.json文件
+// const packageJson = JSON.parse(fs.readFileSync(packageJsonPath))
+
+// // 获取当前版本号
+// const currentVersion = packageJson.version
+
+// // 自增修订版本号
+// const versionParts = currentVersion.split('.')
+// versionParts[2] = parseInt(versionParts[2], 10) + 1
+
+// // 更新package.json文件中的版本号
+// packageJson.version = versionParts.join('.')
+
+// // 将更新后的package.json文件写入磁盘
+// fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2))
+
+// // 输出更新后的版本号
+// console.log(`版本号已更新为 ${packageJson.version}`)
+
+const { exec } = require('child_process')
+
+exec("git add ./package.json", {}, (error, stdout, stderr) => {
+  if (error) {
+      console.log(error)
+  }
+})