postConfig.mjs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import { readFileSync, existsSync } from 'node:fs';
  2. import { dirname } from 'node:path';
  3. import { fileURLToPath } from 'node:url';
  4. import { pad } from './utils.mjs';
  5. import path from 'node:path';
  6. import JSON5 from 'json5';
  7. //基础配置
  8. //========================================
  9. const __filename = fileURLToPath(import.meta.url);
  10. const __dirname = dirname(__filename);
  11. const localConfigPath = path.resolve(__dirname, './_localConfig.json');
  12. const localConfig = existsSync(localConfigPath) ? JSON.parse(readFileSync(localConfigPath, 'utf8')) : {};
  13. //提交更新配置
  14. //========================================
  15. export const config = {
  16. server: localConfig.updateServer || 'https://update-server1.imengyu.top/',
  17. submitKey: '',
  18. appId: 2,
  19. uploadWebConfig: {
  20. storageAction: 'override',
  21. storageProps: {
  22. overrideMode: 'overrideFiles',
  23. overrideFiles: [
  24. 'index.html',
  25. ],
  26. newFolderNameGenerateType: 'hash',
  27. },
  28. deprecateConfig: {
  29. indexFile: 'index.html',
  30. updateHtml: readFileSync(path.resolve(__dirname, './deprecate.html'), 'utf8')
  31. },
  32. },
  33. buildWebCommand: 'npm run build:h5', //构建命令
  34. buildWebOutDir: '../../../dist/build/h5', //构建输出目录。相对于当前文件目录
  35. buildWebOptions: {
  36. skipFiles: [
  37. ], //打包忽略文件,相对于 buildWebOutDir ,判断开头
  38. },
  39. buildWebOutVersionPath: '', //版本号输出目录,输出版本号至文件以供项目使用。相对于当前文件目录
  40. getCustomConfig: async (param, isApp, versionName) => {
  41. return {}//额外的自定义配置
  42. },
  43. /**
  44. * 自定义生成Web版本号的方法。
  45. * @param {Date} now 当前日期
  46. * @param {Number} lastTodaySubVersion 今天上传的之前版本数量
  47. * @returns
  48. */
  49. buildWebVersionGenerateCommand: async (now, lastTodaySubVersion) => {
  50. //生成Web版本号
  51. const version = `${now.getFullYear().toString().substring(2)}${pad(now.getMonth() + 1, 2)}${pad(now.getDate(), 2)}.${pad(lastTodaySubVersion, 2)}`;
  52. return version;
  53. },
  54. buildAppCallback: async (param, versionCode, versionName, lastTodaySubVersion) => {
  55. //构建App
  56. throw new Error('未实现buildAppCallback方法');
  57. },
  58. buildAppGetUploadFile: async (param, versionCode, versionName) => {
  59. //获取上传文件路径
  60. throw new Error('未实现buildAppGetUploadFile方法');
  61. },
  62. buildAppGetOSSFileName: async (param, versionCode, versionName) => {
  63. //生成OSS保存路径
  64. throw new Error('buildAppGetOSSFileName');
  65. },//构建命令
  66. buildAppOutDir: './dist', //构建输出目录。相对于当前文件目录
  67. buildAppGetVersion: async (versionName) => {
  68. //获取版本号
  69. throw new Error('未实现buildAppGetVersion方法');
  70. },
  71. }