config.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. const file = require('./utils/file')
  2. const { logger, fileLogger } = require("./utils/logger");
  3. const fs = require('fs');
  4. const path = require('path');
  5. /**
  6. * 配置
  7. * */
  8. let rustConfig = {}
  9. function init() {
  10. /**
  11. * 1. 检查目录
  12. * */
  13. getConfig()
  14. logger.info('--配置 检查完成');
  15. }
  16. function getConfig() {
  17. const configFilePath = path.join(__dirname, './utils/node.json');
  18. // 使用 fs 模块同步地读取 JSON 文件的内容
  19. try {
  20. // 读取文件内容
  21. const rawContent = fs.readFileSync(configFilePath, 'utf8');
  22. // 解析 JSON 内容为 JavaScript 对象
  23. const config = JSON.parse(rawContent);
  24. rustConfig = config.rustConfig
  25. // 现在可以访问 config 对象中的数据了
  26. logger.info('配置文件内容:',rawContent);
  27. } catch (error) {
  28. // 如果有错误发生,比如文件不存在或者 JSON 格式不正确,打印错误信息
  29. logger.error('读取配置文件时出错:', error);
  30. }
  31. }
  32. function getRustConfig(){
  33. return rustConfig
  34. }
  35. // 检查目录,与文件
  36. function checkConfig(id) {
  37. var appPath = path + "/" + id
  38. //1. 检查目录
  39. file.checkPath(appPath)
  40. //2. 检查文件
  41. for (var i in fileArray) {
  42. if (file.checkFilePath(appPath + "/" + fileArray[i])) {
  43. } else {
  44. //不存在,需要下载,比对版本号等
  45. }
  46. }
  47. }
  48. module.exports = {
  49. init,
  50. checkConfig,
  51. getRustConfig
  52. }