Quellcode durchsuchen

chore: 添加 create-base-files.js 脚本并更新 prepare 命令

在 prepare 命令中添加 create-base-files.js 脚本执行,用于自动生成 manifest.json 和 pages.json 基础配置文件
feige996 vor 7 Monaten
Ursprung
Commit
5cb35d434e
2 geänderte Dateien mit 31 neuen und 1 gelöschten Zeilen
  1. 1 1
      package.json
  2. 30 0
      scripts/create-base-files.js

+ 1 - 1
package.json

@@ -88,7 +88,7 @@
     "build:quickapp-webview-union": "uni build -p quickapp-webview-union",
     "type-check": "vue-tsc --noEmit",
     "openapi-ts-request": "openapi-ts",
-    "prepare": "git init && husky",
+    "prepare": "git init && husky && node ./scripts/create-base-files.js",
     "lint": "eslint",
     "lint:fix": "eslint --fix"
   },

+ 30 - 0
scripts/create-base-files.js

@@ -0,0 +1,30 @@
+// 生成 src/manifest.json 和 src/pages.json
+import fs from 'node:fs'
+import path from 'node:path'
+import { fileURLToPath } from 'node:url'
+
+// 获取当前文件的目录路径(替代 CommonJS 中的 __dirname)
+const __filename = fileURLToPath(import.meta.url)
+const __dirname = path.dirname(__filename)
+
+const manifest = {
+  name: 'unibest',
+  description: 'unibest - 最好的 uniapp 开发模板',
+  versionName: '1.0.0',
+  versionCode: '100',
+}
+
+const pages = {
+  pages: [
+    {
+      path: 'pages/index/index',
+      style: {
+        navigationBarTitleText: 'uni-app',
+      },
+    },
+  ],
+}
+
+// 使用修复后的 __dirname 来解析文件路径
+fs.writeFileSync(path.resolve(__dirname, '../src/manifest.json'), JSON.stringify(manifest, null, 2))
+fs.writeFileSync(path.resolve(__dirname, '../src/pages.json'), JSON.stringify(pages, null, 2))