mirror of
https://github.com/ialley-workshop-open/uni-halo.git
synced 2026-07-27 04:20:43 +08:00
3945ee611d
- 删除大量废弃的旧代码、依赖和配置文件 - 新增基础项目配置、工具函数、页面模板和请求库 - 重构目录结构,统一项目规范 - 添加commitlint、husky等代码规范工具
56 lines
1.8 KiB
JavaScript
56 lines
1.8 KiB
JavaScript
// 基础配置文件生成脚本
|
||
// 此脚本用于生成 src/manifest.json 和 src/pages.json 基础文件
|
||
// 由于这两个配置文件会被添加到 .gitignore 中,因此需要通过此脚本确保项目能正常运行
|
||
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 = { }
|
||
const pages = {
|
||
pages: [
|
||
{
|
||
path: 'pages/index/index',
|
||
type: 'home',
|
||
style: {
|
||
navigationStyle: 'custom',
|
||
navigationBarTitleText: '首页',
|
||
},
|
||
},
|
||
{
|
||
path: 'pages/me/me',
|
||
type: 'page',
|
||
style: {
|
||
navigationBarTitleText: '我的',
|
||
},
|
||
},
|
||
],
|
||
subPackages: [],
|
||
}
|
||
|
||
// 使用修复后的 __dirname 来解析文件路径
|
||
const manifestPath = path.resolve(__dirname, '../src/manifest.json')
|
||
const pagesPath = path.resolve(__dirname, '../src/pages.json')
|
||
|
||
// 确保 src 目录存在
|
||
const srcDir = path.resolve(__dirname, '../src')
|
||
if (!fs.existsSync(srcDir)) {
|
||
fs.mkdirSync(srcDir, { recursive: true })
|
||
}
|
||
|
||
const MIN_SIZE = `{ }`.length // 如果只有一个空对象,必定是不对的,需要重新生成
|
||
|
||
// 如果 src/manifest.json 不存在,就创建它;或者如果文件大小小于等于 MIN_SIZE,也重新创建
|
||
if (!fs.existsSync(manifestPath) || fs.statSync(manifestPath).size <= MIN_SIZE) {
|
||
fs.writeFileSync(manifestPath, JSON.stringify(manifest, null, 2))
|
||
}
|
||
|
||
// 如果 src/pages.json 不存在,就创建它;或者如果文件大小小于等于 MIN_SIZE,也重新创建
|
||
if (!fs.existsSync(pagesPath) || fs.statSync(pagesPath).size <= MIN_SIZE) {
|
||
fs.writeFileSync(pagesPath, JSON.stringify(pages, null, 2))
|
||
}
|