module.ts 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. /**
  2. * @Author HonorLee (dev@honorlee.me)
  3. * @Version 1.0 (2018-05-04)
  4. * @License MIT
  5. */
  6. export default class Module{
  7. public static init(){
  8. //定义全局Module载入语法糖
  9. (global as any).M = function(moduleName:string){
  10. if(!moduleName){
  11. LOGGER.error('Module name undefined!!');
  12. return null;
  13. }
  14. moduleName = moduleName.toLowerCase();
  15. // let ext = moduleName.includes('.js')?'':'.js';
  16. // let filePath = `${_MVCRootPath.module}/${moduleName}${ext}`
  17. const filePath = `${SYSTEM.MVC.PATH.MODULE}/${moduleName}`;
  18. try{
  19. FILE.statSync(filePath);
  20. return require(filePath);
  21. }catch(e:any){
  22. if(e.code!='ENOENT'){
  23. LOGGER.error('Load moduleName file error:');
  24. if(e.stack) LOGGER.error(e.stack);
  25. }else{
  26. LOGGER.error('No such module ['+moduleName+'],please check the moduleName file name,all letter must be lowercase');
  27. }
  28. return null;
  29. }
  30. }
  31. }
  32. }