From 5cb35d434e4ee867c11f5b407fc96c666249d489 Mon Sep 17 00:00:00 2001 From: feige996 <1020102647@qq.com> Date: Thu, 11 Sep 2025 09:55:38 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E6=B7=BB=E5=8A=A0=20create-base-files?= =?UTF-8?q?.js=20=E8=84=9A=E6=9C=AC=E5=B9=B6=E6=9B=B4=E6=96=B0=20prepare?= =?UTF-8?q?=20=E5=91=BD=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在 prepare 命令中添加 create-base-files.js 脚本执行,用于自动生成 manifest.json 和 pages.json 基础配置文件 --- package.json | 2 +- scripts/create-base-files.js | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 scripts/create-base-files.js diff --git a/package.json b/package.json index ce48561..9461c7f 100644 --- a/package.json +++ b/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" }, diff --git a/scripts/create-base-files.js b/scripts/create-base-files.js new file mode 100644 index 0000000..f6cb3dc --- /dev/null +++ b/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))