config.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. 'use strict';
  2. const path = require('path');
  3. const dayjs = require('dayjs');
  4. const storage = require('./storage');
  5. const config = {
  6. log: {
  7. file: {
  8. fileName: path.normalize('./logs/electron-' + dayjs().format('YYYY-MM-DD') + '.log'),
  9. level: 'silly', // error, warn, info, verbose, debug, silly
  10. format: '[{y}-{m}-{d} {h}:{i}:{s}.{ms}] [{level}] {text}',
  11. maxSize: '1048576' // 1048576 (1mb) by default.
  12. }
  13. },
  14. windowsOption: {
  15. width: 980,
  16. height: 600,
  17. minWidth: 800,
  18. minHeight: 600,
  19. webPreferences: {
  20. //webSecurity: false,
  21. nodeIntegration: true,
  22. preload: path.join(__dirname, '../preload.js')
  23. },
  24. //frame: false,
  25. //titleBarStyle: 'hidden'
  26. },
  27. egg: {
  28. title: 'electron-egg',
  29. env: 'prod',
  30. port: 7068,
  31. hostname: '0.0.0.0',
  32. workers: 1
  33. },
  34. autoUpdate: {
  35. enable: false,
  36. options: {
  37. provider: 'generic', // or github, s3, bintray
  38. url: 'https://raw.githubusercontent.com/wallace5303/electron-egg/master/' // resource dir
  39. }
  40. }
  41. }
  42. exports.get = function (flag = '', env = 'prod') {
  43. console.log('[config] [get] flag:', flag);
  44. if (flag === 'log') {
  45. return config.log;
  46. }
  47. if (flag === 'windowsOption') {
  48. return config.windowsOption;
  49. }
  50. if (flag === 'webEgg') {
  51. return config.egg;
  52. }
  53. if (flag === 'egg') {
  54. const eggConfig = storage.getEggConfig();
  55. if (env === 'prod' && eggConfig.port) {
  56. config.egg.port = eggConfig.port;
  57. }
  58. return config.egg;
  59. }
  60. if (flag === 'autoUpdate') {
  61. return config.autoUpdate;
  62. }
  63. return {};
  64. };
  65. exports = module.exports;