main.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. await import(`${SYSTEM.PATH.App}/${SYSTEM.CONFIG.entrance}`);
  26. for(const module of SYSTEM.CONFIG.module){
  27. if(!module.enable) continue;
  28. const moduleName = module.name.toLowerCase();
  29. const modulePath = `${SYSTEM.PATH.Module}/${moduleName}/${moduleName}`;
  30. try{
  31. // eslint-disable-next-line @typescript-eslint/no-var-requires
  32. const MOD = require(modulePath);
  33. new MOD(module.option)
  34. LOGGER.info(`Module [${moduleName.toUpperCase()}] loaded`);
  35. }catch(e:any){
  36. LOGGER.error(`Module [${moduleName.toUpperCase()}] loaded error`);
  37. if(e.stack) LOGGER.error(e.stack);
  38. }
  39. }
  40. }
  41. })
  42. }else{
  43. LOGGER.error('Empty entrance option,please check Config.js');
  44. }