helper.ts 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /**
  2. * @Author HonorLee (dev@honorlee.me)
  3. * @Version 1.0 (2018-05-04)
  4. * @License MIT
  5. */
  6. module.exports = {
  7. __construct:function(){
  8. (global as any).H = function(healperName:string){
  9. if(!healperName){
  10. LOGGER.error('Helper name undefined!!');
  11. return null;
  12. }
  13. healperName = healperName.toLowerCase();
  14. const ext = healperName.includes('.js')?'':'.js';
  15. let filePath = `${SYSTEM.PATH.Helper}/${healperName}${ext}`
  16. try{
  17. FILE.statSync(filePath);
  18. return require(filePath);
  19. }catch(e:any){
  20. if(e.code!='ENOENT'){
  21. LOGGER.error('Load help file error:');
  22. LOGGER.error(e.stack);
  23. return;
  24. }
  25. filePath = `${SYSTEM.PATH.CoreHelper}/${healperName}${ext}`
  26. try{
  27. FILE.statSync(filePath);
  28. return require(filePath);
  29. }catch(e:any){
  30. if(e.code!='ENOENT'){
  31. LOGGER.error('Load help file error:');
  32. LOGGER.error(e.stack);
  33. }else{
  34. LOGGER.error('No such helper ['+healperName+'],please check the helper file name,all letter must be lowercase');
  35. }
  36. return null;
  37. }
  38. }
  39. }
  40. }
  41. }