postConfig.mjs 2.8 KB

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