CfgUtil.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. let fs = require('fire-fs');
  2. let path = require('fire-path');
  3. let electron = require('electron');
  4. module.exports = {
  5. cfgData: {
  6. excelRootPath: null, // excel根路径
  7. jsFileName: null,
  8. jsonAllFileName: null,
  9. isMergeJson: null,
  10. isFormatJsCode: null,
  11. isFormatJson: null,
  12. isExportJson: null,
  13. isExportJs: null,
  14. isExportClient: null,
  15. isExportServer: null,
  16. },
  17. initCfg(cb) {
  18. let configFilePath = this._getAppCfgPath();
  19. let b = fs.existsSync(configFilePath);
  20. // Editor.info("cfg path: " + configFilePath, b);
  21. if (b) {
  22. fs.readFile(configFilePath, 'utf-8', function (err, data) {
  23. if (!err) {
  24. let saveData = JSON.parse(data.toString());
  25. self.cfgData = saveData;
  26. if (cb) {
  27. cb(saveData);
  28. }
  29. }
  30. }.bind(self));
  31. } else {
  32. if (cb) {
  33. cb(null);
  34. }
  35. }
  36. },
  37. saveCfgByData(data) {
  38. this.cfgData.excelRootPath = data.excelRootPath;
  39. this.cfgData.jsFileName = data.jsFileName;
  40. this.cfgData.jsonAllFileName = data.jsonAllFileName;
  41. this.cfgData.isMergeJson = data.isMergeJson;
  42. this.cfgData.isMergeJavaScript = data.isMergeJavaScript;
  43. this.cfgData.isFormatJsCode = data.isFormatJsCode;
  44. this.cfgData.isFormatJson = data.isFormatJson;
  45. this.cfgData.isExportJson = data.isExportJson;
  46. this.cfgData.isExportJs = data.isExportJs;
  47. this.cfgData.isExportClient = data.isExportClient;
  48. this.cfgData.isExportServer = data.isExportServer;
  49. this.cfgData.importProjectCfgPath = data.importProjectCfgPath;
  50. this._save();
  51. },
  52. _save() {
  53. let savePath = this._getAppCfgPath();
  54. fs.writeFileSync(savePath, JSON.stringify(this.cfgData));
  55. Editor.info("save ok!");
  56. },
  57. _getAppCfgPath() {
  58. // let userDataPath = null;
  59. // if (electron.remote) {
  60. // userDataPath = electron.remote.app.getPath('userData');
  61. // } else {
  62. // userDataPath = electron.app.getPath('userData');
  63. // }
  64. // let tar = Editor.libraryPath;
  65. // tar = tar.replace(/\\/g, '-');
  66. // tar = tar.replace(/:/g, '-');
  67. // tar = tar.replace(/\//g, '-');
  68. // return path.join(userDataPath, "excel-fucker-" + tar + ".json");
  69. // 配置文件保存在settings目录
  70. let cfgFile = `excel-killer-configuration.json`;
  71. let cfgPath = path.join(Editor.Project.path, 'settings', cfgFile);
  72. return cfgPath;
  73. },
  74. };