create-base-files.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // 生成 src/manifest.json 和 src/pages.json
  2. import fs from 'node:fs'
  3. import path from 'node:path'
  4. import { fileURLToPath } from 'node:url'
  5. // 获取当前文件的目录路径(替代 CommonJS 中的 __dirname)
  6. const __filename = fileURLToPath(import.meta.url)
  7. const __dirname = path.dirname(__filename)
  8. const manifest = {
  9. name: 'unibest',
  10. description: 'unibest - 最好的 uniapp 开发模板',
  11. versionName: '1.0.0',
  12. versionCode: '100',
  13. }
  14. const pages = {
  15. pages: [
  16. {
  17. path: 'pages/index/index',
  18. style: {
  19. navigationBarTitleText: 'uni-app',
  20. },
  21. },
  22. ],
  23. }
  24. // 使用修复后的 __dirname 来解析文件路径
  25. const manifestPath = path.resolve(__dirname, '../src/manifest.json')
  26. const pagesPath = path.resolve(__dirname, '../src/pages.json')
  27. // 确保 src 目录存在
  28. const srcDir = path.resolve(__dirname, '../src')
  29. if (!fs.existsSync(srcDir)) {
  30. fs.mkdirSync(srcDir, { recursive: true })
  31. }
  32. // 写入文件
  33. fs.writeFileSync(manifestPath, JSON.stringify(manifest, null, 2))
  34. fs.writeFileSync(pagesPath, JSON.stringify(pages, null, 2))