Explorar el Código

fix: windows下shell 无法执行,改用 nodejs 方式

Burt hace 2 años
padre
commit
f7caaa8f65
Se han modificado 3 ficheros con 25 adiciones y 5 borrados
  1. 1 1
      package.json
  2. 20 0
      shell/postinstall.js
  3. 4 4
      shell/postinstall.sh

+ 1 - 1
package.json

@@ -18,7 +18,7 @@
     "pnpm": ">=7.30"
   },
   "scripts": {
-    "postinstall": "sh ./shell/postinstall.sh",
+    "postinstall": "node ./shell/postinstall.js",
     "dev:app": "uni -p app",
     "dev:app-android": "uni -p app-android",
     "dev:app-ios": "uni -p app-ios",

+ 20 - 0
shell/postinstall.js

@@ -0,0 +1,20 @@
+/**
+ * 本文件会在依赖包安装时执行,用以生成 `src/manifest.json`
+ * 如果不存在 `src/manifest.json` 会运行报错,提示找不到 `src/manifest.json`
+ * 如果中途自己删除了 'src/manifest.json' 文件,记得手动执行本文件,可以右键 `Run Code` 快速执行
+ */
+
+// eslint-disable-next-line @typescript-eslint/no-var-requires
+const fs = require('fs')
+
+const filePath = './src/manifest.json'
+console.log(filePath)
+
+if (fs.existsSync(filePath)) {
+  console.log(`${filePath}存在`)
+} else {
+  console.log(`${filePath}不存在,需要创建`)
+  fs.writeFile(filePath, '{}\n', {}, () => {
+    console.log(`${filePath}已经成功创建,并写入{}`)
+  })
+}

+ 4 - 4
shell/postinstall.sh

@@ -1,10 +1,10 @@
+# 本文件会在依赖包安装时执行,用以生成 `src/manifest.json`
+# 如果不存在 `src/manifest.json` 会运行报错,提示找不到 `src/manifest.json`
+# 如果中途自己删除了 'src/manifest.json' 文件,记得手动执行本文件,可以右键 `Run Code` 快速执行
+
 if test -f ./src/manifest.json; then
   echo ./src/manifest.json 存在
 else
   touch ./src/manifest.json
   echo "{}" >./src/manifest.json
 fi
-
-# 本文件会在依赖包安装时执行,用以生成 `src/manifest.json`
-# 如果不存在 `src/manifest.json` 会运行报错,提示找不到 `src/manifest.json`
-# 如果中途自己删除了 'src/manifest.json' 文件,记得手动执行本文件,可以右键 `Run Code` 快速执行