postConfig.mjs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. 'latest.yml',
  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', //构建命令
  34. buildWebOutDir: '../../../release', //构建输出目录。相对于当前文件目录
  35. buildWebOptions: {
  36. skipFiles: [
  37. 'win-unpacked',
  38. 'builder-debug.yml',
  39. 'der-effective-config.yaml',
  40. ], //打包忽略文件,相对于 buildWebOutDir ,判断开头
  41. },
  42. buildWebOutVersionPath: '', //版本号输出目录,输出版本号至文件以供项目使用。相对于当前文件目录
  43. getCustomConfig: async (param, isApp, versionName) => {
  44. return {}//额外的自定义配置
  45. },
  46. /**
  47. * 自定义生成Web版本号的方法。
  48. * @param {Date} now 当前日期
  49. * @param {Number} lastTodaySubVersion 今天上传的之前版本数量
  50. * @returns
  51. */
  52. buildWebVersionGenerateCommand: async (now, lastTodaySubVersion) => {
  53. //生成Web版本号
  54. const version = `${now.getFullYear().toString().substring(2)}${pad(now.getMonth() + 1, 2)}${pad(now.getDate(), 2)}.${pad(lastTodaySubVersion, 2)}`;
  55. return version;
  56. },
  57. buildAppCallback: async (param, versionCode, versionName, lastTodaySubVersion) => {
  58. //构建App
  59. throw new Error('未实现buildAppCallback方法');
  60. },
  61. buildAppGetUploadFile: async (param, versionCode, versionName) => {
  62. //获取上传文件路径
  63. throw new Error('未实现buildAppGetUploadFile方法');
  64. },
  65. buildAppGetOSSFileName: async (param, versionCode, versionName) => {
  66. //生成OSS保存路径
  67. throw new Error('buildAppGetOSSFileName');
  68. },//构建命令
  69. buildAppOutDir: './dist', //构建输出目录。相对于当前文件目录
  70. buildAppGetVersion: async (versionName) => {
  71. //获取版本号
  72. throw new Error('未实现buildAppGetVersion方法');
  73. },
  74. }