core.ts 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // 系统进程ID
  2. SYSTEM.ID = (Math.ceil(Math.random()*61439+4096)).toString(16).toUpperCase();
  3. //系统目录配置
  4. SYSTEM.PATH = {
  5. App : SYSTEM.ROOTPATH + '/app',
  6. System : SYSTEM.ROOTPATH + '/system',
  7. Module : SYSTEM.ROOTPATH + '/system/module',
  8. CoreLib : SYSTEM.ROOTPATH + '/system/lib/core',
  9. ExtraLib : SYSTEM.ROOTPATH + '/system/lib/extra',
  10. CoreHelper : SYSTEM.ROOTPATH + '/system/lib/helper',
  11. Library : SYSTEM.ROOTPATH + '/lib',
  12. Helper : SYSTEM.ROOTPATH + '/lib/helper',
  13. Temp : SYSTEM.ROOTPATH + '/temp',
  14. Session : SYSTEM.ROOTPATH + '/temp/session',
  15. Log : SYSTEM.ROOTPATH + '/log'
  16. }
  17. //全局扩展库
  18. const Global = (global as any);
  19. Global.FILE = require('fs-extra');
  20. Global.FILE.walkSync = require('klaw-sync');
  21. Global.PATH = require('path');
  22. Global.REQUEST = require('request');
  23. Global.Moment = require('moment');
  24. //自动载入系统目录运行库
  25. let CoreLibFiles = FILE.readdirSync(SYSTEM.PATH.CoreLib);
  26. // console.log(CoreLibFiles)
  27. CoreLibFiles.forEach((filename:string)=>{
  28. const nameWithOutMimeType = (filename.split('.')[0]).toUpperCase();
  29. let coreClass;
  30. try {
  31. coreClass = require(SYSTEM.PATH.CoreLib + '/' + filename);
  32. }catch(e){
  33. console.log('[Core] Core library file ['+filename+'] load error!');
  34. console.log(e);
  35. Global.Tracer.error('[Core] Core library file ['+filename+'] load error!');
  36. }
  37. // if(!coreClass) return;
  38. if(coreClass.hasOwnProperty && coreClass.hasOwnProperty('_name') && coreClass['_name']){
  39. Global[coreClass['_name']] = coreClass;
  40. }else{
  41. Global[nameWithOutMimeType] = coreClass;
  42. }
  43. if(typeof coreClass == 'object' && coreClass.hasOwnProperty && coreClass.hasOwnProperty('__construct')) coreClass['__construct']();
  44. });
  45. CoreLibFiles = null;
  46. //检查并自动创建文件目录
  47. Object.keys(SYSTEM.PATH).forEach((path)=>{
  48. try{
  49. FILE.statSync(SYSTEM.PATH[path]);
  50. }catch(e){
  51. FILE.mkdirsSync(SYSTEM.PATH[path]);
  52. }
  53. });