12345678910111213141516171819202122232425262728293031 |
- /**
- * @Author HonorLee (dev@honorlee.me)
- * @Version 1.0 (2018-05-04)
- * @License MIT
- */
- export default class Module{
- public static init(){
- //定义全局Module载入语法糖
- (global as any).M = function(moduleName:string){
- if(!moduleName){
- LOGGER.error('Module name undefined!!');
- return null;
- }
- moduleName = moduleName.toLowerCase();
- const ext = moduleName.includes('.js')?'':'.js';
- const filePath = `${SYSTEM.MVC.PATH.MODULE}/${moduleName}${ext}`;
- try{
- FILE.statSync(filePath);
- return require(filePath);
- }catch(e:any){
- if(e.code!='ENOENT'){
- LOGGER.error('Load moduleName file error:');
- if(e.stack) LOGGER.error(e.stack);
- }else{
- LOGGER.error('No such module ['+moduleName+'],please check the moduleName file name,all letter must be lowercase');
- }
- return null;
- }
- }
- }
- }
|