main.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /**
  2. * SugarNode-TS
  3. * This is a fast-easy framework with a lot syntactic-sugar for node developers.
  4. * It is the 3rd version from my own develop framework,which had been used for some commercial projects,even some high concurrency iot projects.
  5. * And now i decide to port it to TS version.
  6. *
  7. * @Author HonorLee (dev@honorlee.me)
  8. * @Version 1.0 (2022-06-25)
  9. * @License MIT
  10. */
  11. /*
  12. * Entry File
  13. * DO NOT CHANGE ANYTHING IN THIS FILE!
  14. */
  15. (global as any).SYSTEM = {};
  16. SYSTEM.ROOTPATH = __dirname;
  17. require("./config");
  18. require('./system/core');
  19. if(SYSTEM.CONFIG.entrance){
  20. FILE.stat(`${SYSTEM.PATH.App}/${SYSTEM.CONFIG.entrance}`,async (err:Error,stats:any)=>{
  21. if(err || !stats.isFile()){
  22. LOGGER.error(`Wrong entrance file: ${SYSTEM.CONFIG.entrance}`);
  23. LOGGER.error(`Entrance Error: ${err}`);
  24. }else{
  25. for(const module of SYSTEM.CONFIG.module){
  26. if(!module.enable) continue;
  27. const moduleName = module.name.toLowerCase();
  28. const modulePath = `${SYSTEM.PATH.Module}/${moduleName}/${moduleName}`;
  29. try{
  30. // eslint-disable-next-line @typescript-eslint/no-var-requires
  31. const MOD = require(modulePath);
  32. new MOD(module.option)
  33. LOGGER.info(`Module [${moduleName.toUpperCase()}] loaded`);
  34. }catch(e:any){
  35. LOGGER.error(`Module [${moduleName.toUpperCase()}] loaded error`);
  36. if(e.stack) LOGGER.error(e.stack);
  37. }
  38. }
  39. await import(`${SYSTEM.PATH.App}/${SYSTEM.CONFIG.entrance}`);
  40. }
  41. })
  42. }else{
  43. LOGGER.error('Empty entrance option,please check Config.js');
  44. }
  45. process.on('uncaughtException',(err)=>{
  46. LOGGER.error(err.stack as string);
  47. })