mbler 0.1.3-alpha-r2 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (146) hide show
  1. package/bin/mbler.js +0 -0
  2. package/lib/build/base.d.ts +34 -0
  3. package/lib/build/base.js +1 -1
  4. package/lib/build/getModule.d.ts +24 -0
  5. package/lib/build/index.d.ts +29 -0
  6. package/lib/build/index.js +1 -1
  7. package/lib/build/manifest.build.d.ts +52 -0
  8. package/lib/build/mcVersion.d.ts +6 -0
  9. package/lib/build/utils.d.ts +1 -0
  10. package/lib/code-processor/c-handler-export.d.ts +2 -0
  11. package/lib/code-processor/index.d.ts +8 -0
  12. package/lib/code-processor/mtreehandler.d.ts +19 -0
  13. package/lib/commander/index.d.ts +24 -0
  14. package/lib/git/clone.d.ts +7 -0
  15. package/lib/git/index.d.ts +6 -0
  16. package/lib/git/pull.d.ts +6 -0
  17. package/lib/lang/__translate.d.ts +1 -0
  18. package/lib/lang/en.d.ts +141 -0
  19. package/lib/lang/index.d.ts +2 -0
  20. package/lib/lang/zh.d.ts +127 -0
  21. package/lib/loger/colors.d.ts +6 -0
  22. package/lib/loger/index.d.ts +36 -0
  23. package/lib/module-handler/index.d.ts +65 -0
  24. package/lib/modules/create-game/src/Runner/RunnerManager.d.ts +34 -0
  25. package/lib/modules/create-game/src/Runner/scriptRunner.d.ts +17 -0
  26. package/lib/modules/create-game/src/config.d.ts +16 -0
  27. package/lib/modules/create-game/src/constants.d.ts +6 -0
  28. package/lib/modules/create-game/src/gameComponent/common/autoStop.d.ts +6 -0
  29. package/lib/modules/create-game/src/gameComponent/common/lazyLoader.d.ts +13 -0
  30. package/lib/modules/create-game/src/gameComponent/common/stopWatch/onTimeEvent.d.ts +10 -0
  31. package/lib/modules/create-game/src/gameComponent/common/stopWatch/stopWatch.d.ts +26 -0
  32. package/lib/modules/create-game/src/gameComponent/common/stopWatch/tickEvent.d.ts +10 -0
  33. package/lib/modules/create-game/src/gameComponent/common/timer/onTimeEvent.d.ts +10 -0
  34. package/lib/modules/create-game/src/gameComponent/common/timer/tickEvent.d.ts +10 -0
  35. package/lib/modules/create-game/src/gameComponent/common/timer/timer.d.ts +23 -0
  36. package/lib/modules/create-game/src/gameComponent/gameComponent.d.ts +20 -0
  37. package/lib/modules/create-game/src/gameComponent/index.d.ts +13 -0
  38. package/lib/modules/create-game/src/gameComponent/player/blockInteractionBlocker.d.ts +7 -0
  39. package/lib/modules/create-game/src/gameComponent/player/entityInteractionBlocker.d.ts +7 -0
  40. package/lib/modules/create-game/src/gameComponent/player/healthIndicator.d.ts +10 -0
  41. package/lib/modules/create-game/src/gameComponent/player/regionMonitor.d.ts +6 -0
  42. package/lib/modules/create-game/src/gameComponent/player/respawn.d.ts +5 -0
  43. package/lib/modules/create-game/src/gameComponent/player/spawnProtector.d.ts +10 -0
  44. package/lib/modules/create-game/src/gameComponent/region/regionProtecter.d.ts +6 -0
  45. package/lib/modules/create-game/src/gameComponent/region/regionTeamChooser.d.ts +8 -0
  46. package/lib/modules/create-game/src/gameComponent/region/regionTeamCleaner.d.ts +5 -0
  47. package/lib/modules/create-game/src/gameComponent/view/infoScoreboard.d.ts +12 -0
  48. package/lib/modules/create-game/src/gameComponent/view/teamScoreboard.d.ts +12 -0
  49. package/lib/modules/create-game/src/gameContext.d.ts +2 -0
  50. package/lib/modules/create-game/src/gameEngine.d.ts +38 -0
  51. package/lib/modules/create-game/src/gameEvent/eventManager.d.ts +19 -0
  52. package/lib/modules/create-game/src/gameEvent/eventSignal.d.ts +8 -0
  53. package/lib/modules/create-game/src/gameEvent/events/buttonPush.d.ts +14 -0
  54. package/lib/modules/create-game/src/gameEvent/events/inSlot.d.ts +17 -0
  55. package/lib/modules/create-game/src/gameEvent/events/interval.d.ts +13 -0
  56. package/lib/modules/create-game/src/gameEvent/events/itemUse.d.ts +14 -0
  57. package/lib/modules/create-game/src/gameEvent/events/onBlock.d.ts +22 -0
  58. package/lib/modules/create-game/src/gameEvent/events/regionEvents.d.ts +18 -0
  59. package/lib/modules/create-game/src/gameEvent/events/signClick.d.ts +17 -0
  60. package/lib/modules/create-game/src/gameEvent/gameEvent.d.ts +30 -0
  61. package/lib/modules/create-game/src/gameEvent/index.d.ts +4 -0
  62. package/lib/modules/create-game/src/gameEvent/mapEventSignal.d.ts +22 -0
  63. package/lib/modules/create-game/src/gameEvent/subscription.d.ts +8 -0
  64. package/lib/modules/create-game/src/gamePlayer/gamePlayer.d.ts +41 -0
  65. package/lib/modules/create-game/src/gamePlayer/groupBuilder.d.ts +16 -0
  66. package/lib/modules/create-game/src/gamePlayer/groupSet.d.ts +35 -0
  67. package/lib/modules/create-game/src/gamePlayer/index.d.ts +5 -0
  68. package/lib/modules/create-game/src/gamePlayer/playerGroup.d.ts +46 -0
  69. package/lib/modules/create-game/src/gamePlayer/playerManager.d.ts +18 -0
  70. package/lib/modules/create-game/src/gameRegion/gameRegion.d.ts +96 -0
  71. package/lib/modules/create-game/src/gameRegion/index.d.ts +3 -0
  72. package/lib/modules/create-game/src/gameRegion/regionHelper.d.ts +10 -0
  73. package/lib/modules/create-game/src/gameState/common/autoStop.d.ts +6 -0
  74. package/lib/modules/create-game/src/gameState/gameState.d.ts +58 -0
  75. package/lib/modules/create-game/src/gameState/index.d.ts +2 -0
  76. package/lib/modules/create-game/src/gameState/types.d.ts +13 -0
  77. package/lib/modules/create-game/src/gameStructure/gameStructure.d.ts +20 -0
  78. package/lib/modules/create-game/src/main.d.ts +28 -0
  79. package/lib/modules/create-game/src/system/gameCommand.d.ts +1 -0
  80. package/lib/modules/create-game/src/system/gameManager.d.ts +24 -0
  81. package/lib/modules/create-game/src/system/globalPlayerManager.d.ts +24 -0
  82. package/lib/modules/create-game/src/utils/GameError.d.ts +9 -0
  83. package/lib/modules/create-game/src/utils/algorithm.d.ts +9 -0
  84. package/lib/modules/create-game/src/utils/chunk.d.ts +38 -0
  85. package/lib/modules/create-game/src/utils/deferredObject.d.ts +4 -0
  86. package/lib/modules/create-game/src/utils/duration.d.ts +11 -0
  87. package/lib/modules/create-game/src/utils/func.d.ts +6 -0
  88. package/lib/modules/create-game/src/utils/index.d.ts +9 -0
  89. package/lib/modules/create-game/src/utils/interfaces.d.ts +1 -0
  90. package/lib/modules/create-game/src/utils/logger.d.ts +15 -0
  91. package/lib/modules/create-game/src/utils/random.d.ts +20 -0
  92. package/lib/modules/create-game/src/utils/vanila-data.d.ts +9 -0
  93. package/lib/modules/create-game/src/utils/vector.d.ts +75 -0
  94. package/lib/modules/gameLib/src/config.d.ts +140 -0
  95. package/lib/modules/gameLib/src/data.d.ts +76 -0
  96. package/lib/modules/gameLib/src/entity.d.ts +79 -0
  97. package/lib/modules/gameLib/src/event.d.ts +73 -0
  98. package/lib/modules/gameLib/src/index.d.ts +76 -0
  99. package/lib/modules/gameLib/src/loger.d.ts +10 -0
  100. package/lib/modules/gameLib/src/ui.d.ts +39 -0
  101. package/lib/modules/gameLib/src/utils.d.ts +16 -0
  102. package/lib/modules/gutils/src/index.d.ts +3 -0
  103. package/lib/runTemp/File.d.ts +9 -0
  104. package/lib/runTemp/index.d.ts +16 -0
  105. package/lib/runTemp/securityFile.d.ts +9 -0
  106. package/lib/start/addPack.d.ts +2 -0
  107. package/lib/start/clean.d.ts +10 -0
  108. package/lib/start/create.d.ts +2 -0
  109. package/lib/start/dev.d.ts +2 -0
  110. package/lib/start/dev.js +1 -1
  111. package/lib/start/getResConfig.d.ts +2 -0
  112. package/lib/start/incg.d.ts +2 -0
  113. package/lib/start/index.d.ts +1 -0
  114. package/lib/start/init.d.ts +9 -0
  115. package/lib/start/init.js +1 -1
  116. package/lib/start/rechce.d.ts +2 -0
  117. package/lib/start/unaddPack.d.ts +2 -0
  118. package/lib/start/unincg.d.ts +2 -0
  119. package/lib/start/version.d.ts +9 -0
  120. package/lib/utils/index.d.ts +43 -0
  121. package/lib/uuid/index.d.ts +7 -0
  122. package/package.json +1 -49
  123. package/lib/mcx/ast/index.js +0 -1
  124. package/lib/mcx/ast/prop.js +0 -1
  125. package/lib/mcx/ast/tag.js +0 -1
  126. package/lib/mcx/compile-component/lib.js +0 -1
  127. package/lib/mcx/compile-component/types.js +0 -1
  128. package/lib/mcx/compile-component/utils.js +0 -1
  129. package/lib/mcx/compile-mcx/compile.js +0 -1
  130. package/lib/mcx/compile-mcx/compiler/bundler.js +0 -1
  131. package/lib/mcx/compile-mcx/compiler/compileData.js +0 -1
  132. package/lib/mcx/compile-mcx/compiler/compileMain.js +0 -1
  133. package/lib/mcx/compile-mcx/compiler/index.js +0 -1
  134. package/lib/mcx/compile-mcx/compiler/utils.js +0 -1
  135. package/lib/mcx/compile-mcx/context.js +0 -1
  136. package/lib/mcx/compile-mcx/index.js +0 -1
  137. package/lib/mcx/compile-mcx/mcx/index.js +0 -1
  138. package/lib/mcx/compile-mcx/mcx/types.js +0 -1
  139. package/lib/mcx/compile-mcx/template/module.js +0 -1
  140. package/lib/mcx/compile-mcx/types.js +0 -1
  141. package/lib/mcx/compile-mcx/utils.node.js +0 -1
  142. package/lib/mcx/index.js +0 -1
  143. package/lib/mcx/test/index.js +0 -1
  144. package/lib/mcx/test.js +0 -1
  145. package/lib/mcx/types.js +0 -1
  146. package/lib/mcx/utils.js +0 -1
package/bin/mbler.js CHANGED
File without changes
@@ -0,0 +1,34 @@
1
+ import type { MblerConfigData } from "./../types.js";
2
+ import type { BuildData } from "./index.js";
3
+ export declare abstract class BaseBuild {
4
+ #private;
5
+ [x: string]: any;
6
+ static times: string;
7
+ outdir: string;
8
+ ResOutDir: string | null;
9
+ baseCwd: string;
10
+ cwd: string;
11
+ ResCwd: string;
12
+ d_data: BuildData | null;
13
+ cacheDir: string;
14
+ dependencies: Record<string, string>;
15
+ Modules: string[];
16
+ protected constructor();
17
+ rmPackScriptScriptCache(): Promise<void>;
18
+ processResources(): Promise<void>;
19
+ processDist(): Promise<void>;
20
+ loadPackageData(): Promise<MblerConfigData>;
21
+ getCachePath(fileName: string): string;
22
+ getOutputDir(dir: string | null | undefined, def: string): string;
23
+ initNpmDes(_this?: any): Promise<void>;
24
+ getFileHash(filePath: string): Promise<string | null>;
25
+ chackConfigHash(): Promise<{
26
+ configChanged: boolean;
27
+ packageChanged: boolean;
28
+ }>;
29
+ removeJsFiles(dir: string): Promise<void>;
30
+ rmNpmDes(): Promise<void>;
31
+ copyCompiledOnly(srcDir: string, destDir: string): Promise<void>;
32
+ getAllTsFiles(dir: string): Promise<string[]>;
33
+ writeFile(filePath: string, content: string | object): Promise<void>;
34
+ }
package/lib/build/base.js CHANGED
@@ -1 +1 @@
1
- "use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,i,a){void 0===a&&(a=i);var s=Object.getOwnPropertyDescriptor(t,i);s&&!("get"in s?!t.__esModule:s.writable||s.configurable)||(s={enumerable:!0,get:function(){return t[i]}}),Object.defineProperty(e,a,s)}:function(e,t,i,a){void 0===a&&(a=i),e[a]=t[i]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),__importStar=this&&this.__importStar||function(){var e=function(t){return e=Object.getOwnPropertyNames||function(e){var t=[];for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[t.length]=i);return t},e(t)};return function(t){if(t&&t.__esModule)return t;var i={};if(null!=t)for(var a=e(t),s=0;s<a.length;s++)"default"!==a[s]&&__createBinding(i,t,a[s]);return __setModuleDefault(i,t),i}}(),__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.BaseBuild=void 0;const promises_1=__importDefault(require("fs/promises")),path_1=__importDefault(require("path")),dayjs_1=__importDefault(require("dayjs")),index_js_1=__importDefault(require("./../lang/index.js")),index_js_2=__importDefault(require("./../runTemp/index.js")),child_process_1=require("child_process"),manifest_build_js_1=require("./manifest.build.js"),node_os_1=__importDefault(require("node:os")),time=()=>(0,dayjs_1.default)().format("YYYY-MM-DD HH:mm:ss"),utils_1=__importDefault(require("./utils")),utils=__importStar(require("./../utils/index.js"));class BaseBuild{static times=time();outdir="";ResOutDir=null;baseCwd="";cwd="";ResCwd="";d_data=null;cacheDir="";dependencies={};Modules=[];constructor(){}async rmPackScriptScriptCache(){await Promise.all([this.rmNpmDes(),promises_1.default.rm(path_1.default.join(this.outdir,"scripts/package-lock.json"),{recursive:!0,force:!0}).catch(()=>{})])}async processResources(){if(await utils.FileExsit(this.ResCwd)&&this.ResOutDir){if(await Promise.all((await promises_1.default.readdir(this.ResCwd)).map(e=>utils.copy(path_1.default.join(this.ResCwd,e),path_1.default.join(this.ResOutDir,e)))),null==this.d_data)throw new Error("[build error]: not load config when init");const e=new manifest_build_js_1.ManiFest(this.d_data,"resources").data;await this.writeFile(path_1.default.join(this.ResOutDir,"manifest.json"),JSON.stringify(e))}else(0,utils_1.default)(index_js_1.default.build.no_resources)}async processDist(){if("dist"===process.env.MBLER_BUILD_MODULE){const e=new index_js_2.default(path_1.default.join(node_os_1.default.tmpdir(),"mbler"));await e.init(),await Promise.all([utils.copy(this.outdir,path_1.default.join(e.dir,"behavior")),await utils.FileExsit(this.ResCwd)?utils.copy(this.ResOutDir,path_1.default.join(e.dir,"resources")):Promise.resolve()]);let t=this.d_data?.outdir?.dist||"dist.mcaddon";".mcaddon"!==path_1.default.extname(t)&&(t+=".mcaddon");const i=path_1.default.join(this.baseCwd,t),a=require("./../../package.json");await promises_1.default.writeFile(path_1.default.join(e.dir,"behavior",".mbler.build.info"),JSON.stringify({mbler:{version:a.version,git:a.repository},time:BaseBuild.times})),await utils.zip([e.dir],i),await e.remove(),(0,utils_1.default)(`${index_js_1.default.build.ziped} ${i}`)}}async loadPackageData(){const e=await utils.GetData(this.baseCwd);if(!e)throw new Error(index_js_1.default.buildBase.cannot_read_project_config);if("object"!=typeof e||null===e)throw new Error(index_js_1.default.buildBase.invalid_project_config_format);return e}getCachePath(e){return path_1.default.join(this.cacheDir,e)}getOutputDir(e,t){const i=e;return i?path_1.default.join(this.baseCwd,i):t}async initNpmDes(){const e=JSON.parse(await promises_1.default.readFile(path_1.default.join(this.baseCwd,"package.json"),"utf-8"));Object.keys(e.dependencies||{}).length<1?(0,utils_1.default)(index_js_1.default.buildBase.npm_deps_skipped_no_json):(await promises_1.default.writeFile(path_1.default.join(this.outdir,"scripts/package.json"),JSON.stringify(e)),await this.#e(path_1.default.join(this.outdir,"scripts")))}#e(e){return new Promise((t,i)=>{(0,utils_1.default)(index_js_1.default.buildBase.starting_npm_install);const a=(0,child_process_1.spawn)("npm",["install"],{cwd:e,stdio:"ignore"});a.on("close",e=>{0===e?((0,utils_1.default)(index_js_1.default.buildBase.npm_install_completed),t(e)):((0,utils_1.default)(index_js_1.default.buildBase.npm_install_exit_code+e),t(e))}),a.on("error",e=>{(0,utils_1.default)(`${index_js_1.default.buildBase.npm_install_error} ${e.stack}`),i(e)})})}async getFileHash(e){if(!await utils.FileExsit(e))return null;const t=await promises_1.default.readFile(e),i=(await import("crypto")).createHash("sha1");return i.update(t),i.digest("hex")}async chackConfigHash(){const e=path_1.default.join(this.cwd,"mbler.config.json"),t=path_1.default.join(this.cwd,"package.json"),i=this.getCachePath("config-hash.txt"),a=this.getCachePath("package-hash.txt"),s=await this.getFileHash(e),r=await this.getFileHash(t);let l=null,n=null;await promises_1.default.access(i).then(()=>!0).catch(()=>!1)&&(l=await promises_1.default.readFile(i,"utf-8")),await promises_1.default.access(a).then(()=>!0).catch(()=>!1)&&(n=await promises_1.default.readFile(a,"utf-8"));const o=!s||s!==l,d=!r||r!==n;return s&&await promises_1.default.writeFile(i,s),r&&await promises_1.default.writeFile(a,r),{configChanged:o,packageChanged:d}}async removeJsFiles(e){try{for(const t of await promises_1.default.readdir(e,{withFileTypes:!0})){const i=path_1.default.join(e,t.name);if(!i.includes("node_modules"))if(t.isDirectory())await this.removeJsFiles(i);else if(t.isFile()&&t.name.endsWith(".js"))try{await promises_1.default.unlink(i)}catch(e){}}}catch(e){}}async rmNpmDes(){const e=path_1.default.join(this.outdir,"scripts/node_modules"),t=this.Modules||Object.keys(this.dependencies);for(let i of await promises_1.default.readdir(e).catch(()=>[]))t.includes(i)||await promises_1.default.rm(path_1.default.join(e,i),{recursive:!0,force:!0}).catch(()=>{})}async copyCompiledOnly(e,t){try{for(const i of await promises_1.default.readdir(e,{withFileTypes:!0})){const a=path_1.default.join(e,i.name),s=path_1.default.join(t,i.name);if(i.isDirectory())await promises_1.default.mkdir(s,{recursive:!0}).catch(()=>{}),await this.copyCompiledOnly(a,s);else if(i.isFile()){const e=path_1.default.extname(i.name).toLowerCase();[".js",".json"].includes(e)&&(await promises_1.default.mkdir(path_1.default.dirname(s),{recursive:!0}).catch(()=>{}),await promises_1.default.copyFile(a,s).catch(()=>{}))}}}catch(e){(0,utils_1.default)(`ERR: ${e&&e.stack?e.stack:e}`)}}async getAllTsFiles(e){const t=[];try{for(const i of await promises_1.default.readdir(e,{withFileTypes:!0})){const a=path_1.default.join(e,i.name);if(i.isDirectory()){const e=await this.getAllTsFiles(a);t.push(...e)}else i.isFile()&&i.name.endsWith(".ts")&&t.push(a)}}catch(e){}return t}async writeFile(e,t){try{await utils.waitGC(),await promises_1.default.mkdir(path_1.default.dirname(e),{recursive:!0});const i="string"==typeof t?t:JSON.stringify(t,null,2);await promises_1.default.writeFile(e,i,"utf-8")}catch(t){throw(0,utils_1.default)(`WRITE FILE ERR: ${e}`),t}await utils.waitGC()}}exports.BaseBuild=BaseBuild;
1
+ "use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,i,a){void 0===a&&(a=i);var s=Object.getOwnPropertyDescriptor(t,i);s&&!("get"in s?!t.__esModule:s.writable||s.configurable)||(s={enumerable:!0,get:function(){return t[i]}}),Object.defineProperty(e,a,s)}:function(e,t,i,a){void 0===a&&(a=i),e[a]=t[i]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),__importStar=this&&this.__importStar||function(){var e=function(t){return e=Object.getOwnPropertyNames||function(e){var t=[];for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[t.length]=i);return t},e(t)};return function(t){if(t&&t.__esModule)return t;var i={};if(null!=t)for(var a=e(t),s=0;s<a.length;s++)"default"!==a[s]&&__createBinding(i,t,a[s]);return __setModuleDefault(i,t),i}}(),__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.BaseBuild=void 0;const promises_1=__importDefault(require("fs/promises")),path_1=__importDefault(require("path")),dayjs_1=__importDefault(require("dayjs")),index_js_1=__importDefault(require("./../lang/index.js")),index_js_2=__importDefault(require("./../runTemp/index.js")),child_process_1=require("child_process"),manifest_build_js_1=require("./manifest.build.js"),node_os_1=__importDefault(require("node:os")),time=()=>(0,dayjs_1.default)().format("YYYY-MM-DD HH:mm:ss"),utils_1=__importDefault(require("./utils")),utils=__importStar(require("./../utils/index.js"));class BaseBuild{static times=time();outdir="";ResOutDir=null;baseCwd="";cwd="";ResCwd="";d_data=null;cacheDir="";dependencies={};Modules=[];constructor(){}async rmPackScriptScriptCache(){await Promise.all([this.rmNpmDes(),promises_1.default.rm(path_1.default.join(this.outdir,"scripts/package-lock.json"),{recursive:!0,force:!0}).catch(()=>{})])}async processResources(){if(await utils.FileExsit(this.ResCwd)&&this.ResOutDir){if(await Promise.all((await promises_1.default.readdir(this.ResCwd)).map(e=>utils.copy(path_1.default.join(this.ResCwd,e),path_1.default.join(this.ResOutDir,e)))),null==this.d_data)throw new Error("[build error]: not load config when init");const e=new manifest_build_js_1.ManiFest(this.d_data,"resources").data;await this.writeFile(path_1.default.join(this.ResOutDir,"manifest.json"),JSON.stringify(e))}else(0,utils_1.default)(index_js_1.default.build.no_resources)}async processDist(){if("dist"===process.env.MBLER_BUILD_MODULE){const e=new index_js_2.default(path_1.default.join(node_os_1.default.tmpdir(),"mbler"));await e.init(),await Promise.all([utils.copy(this.outdir,path_1.default.join(e.dir,"behavior")),await utils.FileExsit(this.ResCwd)?utils.copy(this.ResOutDir,path_1.default.join(e.dir,"resources")):Promise.resolve()]);let t=this.d_data?.outdir?.dist||"dist.mcaddon";".mcaddon"!==path_1.default.extname(t)&&(t+=".mcaddon");const i=path_1.default.join(this.baseCwd,t),a=require("./../../package.json");await promises_1.default.writeFile(path_1.default.join(e.dir,"behavior",".mbler.build.info"),JSON.stringify({mbler:{version:a.version,git:a.repository},time:BaseBuild.times})),await utils.zip([e.dir],i),await e.remove(),(0,utils_1.default)(`${index_js_1.default.build.ziped} ${i}`)}}async loadPackageData(){const e=await utils.GetData(this.baseCwd);if(!e)throw new Error(index_js_1.default.buildBase.cannot_read_project_config);if("object"!=typeof e||null===e)throw new Error(index_js_1.default.buildBase.invalid_project_config_format);return e}getCachePath(e){return path_1.default.join(this.cacheDir,e)}getOutputDir(e,t){const i=e;return i?path_1.default.join(this.baseCwd,i):t}async initNpmDes(e=this){const t=JSON.parse(await promises_1.default.readFile(path_1.default.join(e.baseCwd,"package.json"),"utf-8"));Object.keys(t.dependencies||{}).length;await promises_1.default.writeFile(path_1.default.join(e.outdir,"scripts/package.json"),JSON.stringify(t)),await this.#e(path_1.default.join(e.outdir,"scripts"))}#e(e){return new Promise((t,i)=>{const a=(0,child_process_1.spawn)("npm",["install"],{cwd:e,stdio:"ignore"});a.on("close",e=>{0===e?((0,utils_1.default)(index_js_1.default.buildBase.npm_install_completed),t(e)):((0,utils_1.default)(index_js_1.default.buildBase.npm_install_exit_code+e),t(e))}),a.on("error",e=>{(0,utils_1.default)(`${index_js_1.default.buildBase.npm_install_error} ${e.stack}`),i(e)})})}async getFileHash(e){if(!await utils.FileExsit(e))return null;const t=await promises_1.default.readFile(e),i=(await import("crypto")).createHash("sha1");return i.update(t),i.digest("hex")}async chackConfigHash(){const e=path_1.default.join(this.cwd,"mbler.config.json"),t=path_1.default.join(this.cwd,"package.json"),i=this.getCachePath("config-hash.txt"),a=this.getCachePath("package-hash.txt"),s=await this.getFileHash(e),r=await this.getFileHash(t);let l=null,o=null;await promises_1.default.access(i).then(()=>!0).catch(()=>!1)&&(l=await promises_1.default.readFile(i,"utf-8")),await promises_1.default.access(a).then(()=>!0).catch(()=>!1)&&(o=await promises_1.default.readFile(a,"utf-8"));const n=!s||s!==l,d=!r||r!==o;return s&&await promises_1.default.writeFile(i,s),r&&await promises_1.default.writeFile(a,r),{configChanged:n,packageChanged:d}}async removeJsFiles(e){try{for(const t of await promises_1.default.readdir(e,{withFileTypes:!0})){const i=path_1.default.join(e,t.name);if(!i.includes("node_modules"))if(t.isDirectory())await this.removeJsFiles(i);else if(t.isFile()&&t.name.endsWith(".js"))try{await promises_1.default.unlink(i)}catch(e){}}}catch(e){}}async rmNpmDes(){const e=path_1.default.join(this.outdir,"scripts/node_modules"),t=this.Modules||Object.keys(this.dependencies),i=[];for(let a of await promises_1.default.readdir(e).catch(()=>[]))t.includes(a)||"@mbler/mcx"===a||i.push(promises_1.default.rm(path_1.default.join(e,a),{recursive:!0,force:!0}).catch(()=>{}));await Promise.all(i)}async copyCompiledOnly(e,t){try{for(const i of await promises_1.default.readdir(e,{withFileTypes:!0})){const a=path_1.default.join(e,i.name),s=path_1.default.join(t,i.name);if(i.isDirectory())await promises_1.default.mkdir(s,{recursive:!0}).catch(()=>{}),await this.copyCompiledOnly(a,s);else if(i.isFile()){const e=path_1.default.extname(i.name).toLowerCase();[".js",".json"].includes(e)&&(await promises_1.default.mkdir(path_1.default.dirname(s),{recursive:!0}).catch(()=>{}),await promises_1.default.copyFile(a,s).catch(()=>{}))}}}catch(e){(0,utils_1.default)(`ERR: ${e&&e.stack?e.stack:e}`)}}async getAllTsFiles(e){const t=[];try{for(const i of await promises_1.default.readdir(e,{withFileTypes:!0})){const a=path_1.default.join(e,i.name);if(i.isDirectory()){const e=await this.getAllTsFiles(a);t.push(...e)}else i.isFile()&&i.name.endsWith(".ts")&&t.push(a)}}catch(e){}return t}async writeFile(e,t){try{await utils.waitGC(),await promises_1.default.mkdir(path_1.default.dirname(e),{recursive:!0});const i="string"==typeof t?t:JSON.stringify(t,null,2);await promises_1.default.writeFile(e,i,"utf-8")}catch(t){throw(0,utils_1.default)(`WRITE FILE ERR: ${e}`),t}await utils.waitGC()}}exports.BaseBuild=BaseBuild;
@@ -0,0 +1,24 @@
1
+ interface ModuleCacheItem {
2
+ name: string;
3
+ git: string;
4
+ }
5
+ interface ModuleVersionInfo {
6
+ ERR: string;
7
+ message: string;
8
+ }
9
+ declare class ModulePath {
10
+ #private;
11
+ dir: string;
12
+ innerList: string[];
13
+ cache: ModuleCacheItem[];
14
+ constructor(dirname: string);
15
+ start(): Promise<void>;
16
+ getGit(Name: string): string | null;
17
+ getAll(): string[];
18
+ getDir(packageName: string, options?: {
19
+ gitUrl?: string;
20
+ v?: string;
21
+ }): Promise<string | null | ModuleVersionInfo>;
22
+ }
23
+ declare const _default: (dirname: string) => Promise<ModulePath>;
24
+ export = _default;
@@ -0,0 +1,29 @@
1
+ import { BaseBuild } from './base.js';
2
+ import type { MblerConfigData } from './../types.js';
3
+ export interface BuildData extends MblerConfigData {
4
+ ResDes?: {
5
+ name: string;
6
+ version: string;
7
+ };
8
+ subpack?: Record<string, string>;
9
+ minify?: boolean;
10
+ }
11
+ export default class Build extends BaseBuild {
12
+ #private;
13
+ [x: string]: any;
14
+ baseDir: string;
15
+ baseModDir: string;
16
+ gamelibModule: any;
17
+ constructor(buildPath: string, baseDir: string);
18
+ build(): Promise<void>;
19
+ start(): Promise<void>;
20
+ writeManifest(data: BuildData): Promise<void>;
21
+ buildManifest(data: BuildData): Promise<any>;
22
+ processResourceDependencies(data: BuildData, manifest: any): void;
23
+ handleScripts(data: BuildData): Promise<void>;
24
+ processSubpacks(data: BuildData): Promise<void>;
25
+ compileTypeScriptUnified(): Promise<void>;
26
+ handlerMod(modules: Record<string, string>, processed?: Set<string>): Promise<string[]>;
27
+ handleIncludes(): Promise<void> | undefined;
28
+ processMinification(data: BuildData): Promise<void>;
29
+ }
@@ -1 +1 @@
1
- "use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,i,s){void 0===s&&(s=i);var a=Object.getOwnPropertyDescriptor(t,i);a&&!("get"in a?!t.__esModule:a.writable||a.configurable)||(a={enumerable:!0,get:function(){return t[i]}}),Object.defineProperty(e,s,a)}:function(e,t,i,s){void 0===s&&(s=i),e[s]=t[i]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),__importStar=this&&this.__importStar||function(){var e=function(t){return e=Object.getOwnPropertyNames||function(e){var t=[];for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[t.length]=i);return t},e(t)};return function(t){if(t&&t.__esModule)return t;var i={};if(null!=t)for(var s=e(t),a=0;a<s.length;a++)"default"!==s[a]&&__createBinding(i,t,s[a]);return __setModuleDefault(i,t),i}}(),__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0});const fs=__importStar(require("fs/promises")),path=__importStar(require("path")),ts=__importStar(require("typescript")),index_js_1=__importDefault(require("./../lang/index.js")),index_js_2=require("./../uuid/index.js"),index_js_3=__importDefault(require("./../code-processor/index.js")),utils=__importStar(require("./../utils/index.js")),getModule_js_1=__importDefault(require("./getModule.js")),includes_json_1=__importDefault(require("./../data/includes.json")),clean_js_1=__importDefault(require("./../start/clean.js")),index_js_4=__importDefault(require("./../runTemp/index.js")),base_js_1=require("./base.js"),manifest_build_js_1=require("./manifest.build.js"),mcx_core_1=__importDefault(require("@mbler/mcx-core")),node_os_1=__importDefault(require("node:os")),utils_1=__importDefault(require("./utils"));class Build extends base_js_1.BaseBuild{baseDir;baseModDir;gamelibModule;constructor(e,t){super(),e||utils.Exit(index_js_1.default.build.config_invalid),this.baseDir=t,this.baseCwd=path.isAbsolute(e)?e:path.join(t,e),this.cwd=path.join(this.baseCwd,"behavior"),this.ResOutDir=null,this.ResCwd=path.join(this.baseCwd,"resources"),this.dependencies={},this.gamelibModule=null,this.baseModDir=path.join(this.baseDir,"lib/modules"),this.#e(["baseModDir","baseDir"]),this.#t(["outdir","dependencies","gamelibModule","cwd","ResCwd","baseModDir","baseCwd"]),this.cacheDir=path.join(this.baseCwd,".cache__mbler__")}#e(e){if(Array.isArray(e))for(let t of e)Object.defineProperty(this,t,{enumerable:!1,writable:!1})}#t(e){if(Array.isArray(e))for(let t of e)Object.defineProperty(this,t,{enumerable:!1})}async#i(){try{await fs.mkdir(this.cacheDir,{recursive:!0})}catch(e){if("EEXIST"!==e.code)throw e}}build(){return this.start().catch(e=>{const t=utils.toString(e);(0,utils_1.default)(index_js_1.default.build.error_message_log+t)})}async start(){const e=Date.now();await this.#i();const{configChanged:t,packageChanged:i}=await this.chackConfigHash(),s=new clean_js_1.default(this.baseCwd,this.baseDir);await s.run(),await utils.waitGC();const a=await this.loadPackageData();this.d_data=a,this.outdir=this.getOutputDir(a.outdir?.behavior,path.join(this.baseCwd,"dist/dep")),this.ResOutDir=this.getOutputDir(a.outdir?.resources,path.join(this.baseCwd,"dist/res"));const r=["name","description","version","mcVersion"];if(!utils.hasKeys(a,r,r.length))throw new Error(`${index_js_1.default.build.package_file} 字段缺失:必需字段 ${JSON.stringify(r)}`);switch(this.gamelibModule=await(0,getModule_js_1.default)(this.baseDir),console.log(index_js_1.default.build.build_info_header),console.table({[index_js_1.default.build.project_path]:this.baseCwd,[index_js_1.default.build.output_dir]:JSON.stringify(a.outdir),[index_js_1.default.build.minify_enabled]:Boolean(a.minify),[index_js_1.default.build.build_time]:Build.times,[index_js_1.default.build.tip_dist]:process.env.MBLER_BUILD_MODULE||"dev"}),await Promise.all([this.writeManifest(a),this.handleScripts(a),this.handleIncludes(),this.processSubpacks(a)]),a.script?.lang||""){case"ts":await this.compileTypeScriptUnified();break;case"mcx":await mcx_core_1.default.load({ProjectDir:path.join(this.cwd,"scripts"),config:{useTS:!0},output:path.join(this.outdir,"scripts"),moduleList:this.Modules,main:path.join(this.cwd,a.script?.main||"index.js"),cacheDir:this.cacheDir,moduleDir:path.join(this.outdir,"scripts/node_modules"),isCache:!0})}await Promise.all([this.processMinification(a),this.processResources()]),await this.processDist(),console.log(`${index_js_1.default.build.build_success} ${(Date.now()-e)/1e3}`)}async writeManifest(e){const t=await this.buildManifest(e);await this.writeFile(path.join(this.outdir,"manifest.json"),t)}async buildManifest(e){const t=new manifest_build_js_1.ManiFest(e,"data").data,i=e.subpack||{};return"object"==typeof e.ResDes&&this.processResourceDependencies(e,t),"object"==typeof e.subpack&&Object.keys(e.subpack).length>0&&(t.subpack=Object.keys(e.subpack).map(e=>({folder_name:e,name:i[e]||"",memory_tier:1}))),t}processResourceDependencies(e,t){const{name:i="unknown",version:s}=e.ResDes||{};s&&utils.isVerison(s)&&t.dependencies.push({name:(0,index_js_2.fromString)(i),version:utils.ToArray(s)})}async handleScripts(e){if(!e.script||"object"!=typeof e.script)return;const t=path.join(this.cwd,"scripts"),i=path.join(this.outdir,"scripts");await utils.FileExsit(t)&&(await utils.copy(t,i),this.dependencies=e.script.dependencies||{},await this.initNpmDes(),Object.keys(this.dependencies).length>0&&(this.Modules=await this.handlerMod(this.dependencies,new Set)))}async processSubpacks(e){if("object"!=typeof e.subpack)return;const t=this.outdir,i=new Build(this.cwd,this.baseDir);for(let[s,a]of Object.entries(e.subpack))try{const e=path.join(this.cwd,"subpacks",s),a=path.join(t,"subpacks",s);if(await fs.mkdir(a,{recursive:!0}),!await utils.FileExsit(e)){(0,utils_1.default)(index_js_1.default.build.subpack_folder_not_found.replace("{id}",s));continue}const r=path.join(e,"scripts"),n=path.join(a,"scripts");await utils.FileExsit(r)&&await utils.copy(r,n),i.cwd=e,i.outdir=a,await i.handleIncludes()}catch(e){(0,utils_1.default)(index_js_1.default.build.error_processing_subpack.replace("{id}",s).replace("{error}",e.stack))}}async compileTypeScriptUnified(){const e=new index_js_4.default(path.join(node_os_1.default.tmpdir(),"mbler"));await e.init();const t=e.dir;try{const e=await this.getAllTsFiles(this.outdir);if(!e||0===e.length)return void(0,utils_1.default)(index_js_1.default.build.ts_no_files);let i={compilerOptions:{target:"esnext",module:"esnext",moduleResolution:"NodeNext",esModuleInterop:!0,verbatimModuleSyntax:!1,allowSyntheticDefaultImports:!0,outDir:t,rootDir:this.outdir,strict:!0,allowJs:!0,sourceMap:!1,incremental:!0,tsBuildInfoFile:path.join(this.cacheDir,"tsbuildinfo")},include:["**/*.ts"]};await utils.FileExsit(path.join(this.baseCwd,"tsconfig.json"))&&(i=JSON.parse(await fs.readFile(path.join(this.baseCwd,"tsconfig.json"),"utf-8")));const s=ts.parseJsonConfigFileContent(i,ts.sys,this.outdir,void 0,"tsconfig.json"),a=ts.createProgram({rootNames:e,options:s.options}),r=a.emit();ts.getPreEmitDiagnostics(a).concat(r.diagnostics).forEach(e=>{const t=ts.flattenDiagnosticMessageText(e.messageText,"\n");if(e.file){const{line:i,character:s}=e.file.getLineAndCharacterOfPosition(e.start);(0,utils_1.default)(index_js_1.default.build.ts_diagnostics.replace("{file}",e.file.fileName).replace("{line}",(i+1).toString()).replace("{character}",(s+1).toString()).replace("{message}",t))}else(0,utils_1.default)(t)}),await this.removeJsFiles(path.join(this.outdir,"scripts")),await this.copyCompiledOnly(t,this.outdir),(0,utils_1.default)(index_js_1.default.build.ts_compilation_error+" 完成")}catch(e){throw(0,utils_1.default)(index_js_1.default.build.ts_compilation_error+e.stack),e}finally{await e.remove()}}async handlerMod(e,t=new Set){const i=this.gamelibModule.getAll(),s=path.join(this.outdir,"scripts/node_modules");let a={};for(const[r,n]of Object.entries(e)){if(!i.includes(r)||t.has(r))continue;const e=await this.gamelibModule.getDir(r,{gitUrl:n,v:this.d_data.mcVersion});if(!e||!await utils.FileExsit(e))continue;const o=await utils.handlerPackage(e,{des:Array.from(t)});o.des&&Object.assign(a,o.des),await utils.copy(e,path.join(s,r)),await utils.waitGC(),t.add(r)}return Object.keys(a).length>0&&await this.handlerMod(a,t),Array.from(t)}handleIncludes(){if(!Array.isArray(includes_json_1.default))return;const e=includes_json_1.default.filter(e=>"string"==typeof e).map(async e=>{const t=path.join(this.cwd,"res",e),i=path.join(this.outdir,e);await utils.FileExsit(t)&&await utils.copy(t,i)});return Promise.all(e)}async processMinification(e){try{if(!Array.isArray(includes_json_1.default))return void(0,utils_1.default)(index_js_1.default.build.includes_not_array);await(0,index_js_3.default)(this.outdir,{modules:this.Modules,sourceDir:path.join(this.outdir,"scripts"),baseDir:this.baseDir,minify:Boolean(e.minify)}),await utils.waitGC()}catch(e){(0,utils_1.default)(index_js_1.default.build.minification_error+e)}}}exports.default=Build;
1
+ "use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,i,s){void 0===s&&(s=i);var a=Object.getOwnPropertyDescriptor(t,i);a&&!("get"in a?!t.__esModule:a.writable||a.configurable)||(a={enumerable:!0,get:function(){return t[i]}}),Object.defineProperty(e,s,a)}:function(e,t,i,s){void 0===s&&(s=i),e[s]=t[i]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),__importStar=this&&this.__importStar||function(){var e=function(t){return e=Object.getOwnPropertyNames||function(e){var t=[];for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[t.length]=i);return t},e(t)};return function(t){if(t&&t.__esModule)return t;var i={};if(null!=t)for(var s=e(t),a=0;a<s.length;a++)"default"!==s[a]&&__createBinding(i,t,s[a]);return __setModuleDefault(i,t),i}}(),__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0});const fs=__importStar(require("fs/promises")),path=__importStar(require("path")),ts=__importStar(require("typescript")),index_js_1=__importDefault(require("./../lang/index.js")),index_js_2=require("./../uuid/index.js"),index_js_3=__importDefault(require("./../code-processor/index.js")),utils=__importStar(require("./../utils/index.js")),getModule_js_1=__importDefault(require("./getModule.js")),includes_json_1=__importDefault(require("./../data/includes.json")),clean_js_1=__importDefault(require("./../start/clean.js")),index_js_4=__importDefault(require("./../runTemp/index.js")),base_js_1=require("./base.js"),manifest_build_js_1=require("./manifest.build.js"),mcx_core_1=__importDefault(require("@mbler/mcx-core")),node_os_1=__importDefault(require("node:os")),utils_1=__importDefault(require("./utils"));class Build extends base_js_1.BaseBuild{baseDir;baseModDir;gamelibModule;constructor(e,t){super(),e||utils.Exit(index_js_1.default.build.config_invalid),this.baseDir=t,this.baseCwd=path.isAbsolute(e)?e:path.join(t,e),this.cwd=path.join(this.baseCwd,"behavior"),this.ResOutDir=null,this.ResCwd=path.join(this.baseCwd,"resources"),this.dependencies={},this.gamelibModule=null,this.baseModDir=path.join(this.baseDir,"lib/modules"),this.#e(["baseModDir","baseDir"]),this.#t(["outdir","dependencies","gamelibModule","cwd","ResCwd","baseModDir","baseCwd"]),this.cacheDir=path.join(this.baseCwd,".cache__mbler__")}#e(e){if(Array.isArray(e))for(let t of e)Object.defineProperty(this,t,{enumerable:!1,writable:!1})}#t(e){if(Array.isArray(e))for(let t of e)Object.defineProperty(this,t,{enumerable:!1})}async#i(){try{await fs.mkdir(this.cacheDir,{recursive:!0})}catch(e){if("EEXIST"!==e.code)throw e}}build(){return this.start().catch(e=>{const t=utils.toString(e);(0,utils_1.default)(index_js_1.default.build.error_message_log+t)})}async start(){const e=Date.now();await this.#i();const{configChanged:t,packageChanged:i}=await this.chackConfigHash(),s=new clean_js_1.default(this.baseCwd,this.baseDir);await s.run(),await utils.waitGC();const a=await this.loadPackageData();this.d_data=a,this.outdir=this.getOutputDir(a.outdir?.behavior,path.join(this.baseCwd,"dist/dep")),this.ResOutDir=this.getOutputDir(a.outdir?.resources,path.join(this.baseCwd,"dist/res"));const r=["name","description","version","mcVersion"];if(!utils.hasKeys(a,r,r.length))throw new Error(`${index_js_1.default.build.package_file} 字段缺失:必需字段 ${JSON.stringify(r)}`);switch(this.gamelibModule=await(0,getModule_js_1.default)(this.baseDir),console.log(index_js_1.default.build.build_info_header),console.table({[index_js_1.default.build.project_path]:this.baseCwd,[index_js_1.default.build.output_dir]:JSON.stringify(a.outdir),[index_js_1.default.build.minify_enabled]:Boolean(a.minify),[index_js_1.default.build.build_time]:Build.times,[index_js_1.default.build.tip_dist]:process.env.MBLER_BUILD_MODULE||"dev"}),await Promise.all([this.writeManifest(a),this.handleScripts(a),this.handleIncludes(),this.processSubpacks(a)]),a.script?.lang&&(0,utils_1.default)("对特定语言进行处理:"+a.script.lang),a.script?.lang||""){case"ts":await this.compileTypeScriptUnified();break;case"mcx":this.initNpmDes({baseCwd:this.baseCwd,outdir:this.cwd}),await mcx_core_1.default.load({ProjectDir:path.join(this.baseCwd),config:{},output:path.join(this.outdir,"scripts"),main:path.join(this.cwd,"scripts",a.script?.main||"index.js"),moduleDir:path.join(this.outdir,"scripts/node_modules")});break;default:console.error("无效的语言设置")}await Promise.all([this.processMinification(a),this.processResources()]),await this.processDist(),console.log(`${index_js_1.default.build.build_success} ${(Date.now()-e)/1e3}`)}async writeManifest(e){const t=await this.buildManifest(e);await this.writeFile(path.join(this.outdir,"manifest.json"),t)}async buildManifest(e){const t=new manifest_build_js_1.ManiFest(e,"data").data,i=e.subpack||{};return"object"==typeof e.ResDes&&this.processResourceDependencies(e,t),"object"==typeof e.subpack&&Object.keys(e.subpack).length>0&&(t.subpack=Object.keys(e.subpack).map(e=>({folder_name:e,name:i[e]||"",memory_tier:1}))),t}processResourceDependencies(e,t){const{name:i="unknown",version:s}=e.ResDes||{};s&&utils.isVerison(s)&&t.dependencies.push({name:(0,index_js_2.fromString)(i),version:utils.ToArray(s)})}async handleScripts(e){if(!e.script||"object"!=typeof e.script)return;const t=path.join(this.cwd,"scripts"),i=path.join(this.outdir,"scripts");await utils.FileExsit(t)&&(await utils.copy(t,i),this.dependencies=e.script.dependencies||{},await this.initNpmDes(),Object.keys(this.dependencies).length>0&&(this.Modules=await this.handlerMod(this.dependencies,new Set)))}async processSubpacks(e){if("object"!=typeof e.subpack)return;const t=this.outdir,i=new Build(this.cwd,this.baseDir);for(let[s,a]of Object.entries(e.subpack))try{const e=path.join(this.cwd,"subpacks",s),a=path.join(t,"subpacks",s);if(await fs.mkdir(a,{recursive:!0}),!await utils.FileExsit(e)){(0,utils_1.default)(index_js_1.default.build.subpack_folder_not_found.replace("{id}",s));continue}const r=path.join(e,"scripts"),n=path.join(a,"scripts");await utils.FileExsit(r)&&await utils.copy(r,n),i.cwd=e,i.outdir=a,await i.handleIncludes()}catch(e){(0,utils_1.default)(index_js_1.default.build.error_processing_subpack.replace("{id}",s).replace("{error}",e.stack))}}async compileTypeScriptUnified(){const e=new index_js_4.default(path.join(node_os_1.default.tmpdir(),"mbler"));await e.init();const t=e.dir;try{const e=await this.getAllTsFiles(this.outdir);if(!e||0===e.length)return void(0,utils_1.default)(index_js_1.default.build.ts_no_files);let i={compilerOptions:{target:"esnext",module:"esnext",moduleResolution:"NodeNext",esModuleInterop:!0,verbatimModuleSyntax:!1,allowSyntheticDefaultImports:!0,outDir:t,rootDir:this.outdir,strict:!0,allowJs:!0,sourceMap:!1,incremental:!0,tsBuildInfoFile:path.join(this.cacheDir,"tsbuildinfo")},include:["**/*.ts"]};await utils.FileExsit(path.join(this.baseCwd,"tsconfig.json"))&&(i=JSON.parse(await fs.readFile(path.join(this.baseCwd,"tsconfig.json"),"utf-8")));const s=ts.parseJsonConfigFileContent(i,ts.sys,this.outdir,void 0,"tsconfig.json"),a=ts.createProgram({rootNames:e,options:s.options}),r=a.emit();ts.getPreEmitDiagnostics(a).concat(r.diagnostics).forEach(e=>{const t=ts.flattenDiagnosticMessageText(e.messageText,"\n");if(e.file){const{line:i,character:s}=e.file.getLineAndCharacterOfPosition(e.start);(0,utils_1.default)(index_js_1.default.build.ts_diagnostics.replace("{file}",e.file.fileName).replace("{line}",(i+1).toString()).replace("{character}",(s+1).toString()).replace("{message}",t))}else(0,utils_1.default)(t)}),await this.removeJsFiles(path.join(this.outdir,"scripts")),await this.copyCompiledOnly(t,this.outdir),(0,utils_1.default)(index_js_1.default.build.ts_compilation_error+" 完成")}catch(e){throw(0,utils_1.default)(index_js_1.default.build.ts_compilation_error+e.stack),e}finally{await e.remove()}}async handlerMod(e,t=new Set){const i=this.gamelibModule.getAll(),s=path.join(this.outdir,"scripts/node_modules");let a={};for(const[r,n]of Object.entries(e)){if(!i.includes(r)||t.has(r))continue;const e=await this.gamelibModule.getDir(r,{gitUrl:n,v:this.d_data.mcVersion});if(!e||!await utils.FileExsit(e))continue;const o=await utils.handlerPackage(e,{des:Array.from(t)});o.des&&Object.assign(a,o.des),await utils.copy(e,path.join(s,r)),await utils.waitGC(),t.add(r)}return Object.keys(a).length>0&&await this.handlerMod(a,t),Array.from(t)}handleIncludes(){if(!Array.isArray(includes_json_1.default))return;const e=includes_json_1.default.filter(e=>"string"==typeof e).map(async e=>{const t=path.join(this.cwd,"res",e),i=path.join(this.outdir,e);await utils.FileExsit(t)&&await utils.copy(t,i)});return Promise.all(e)}async processMinification(e){try{if(!Array.isArray(includes_json_1.default))return void(0,utils_1.default)(index_js_1.default.build.includes_not_array);await(0,index_js_3.default)(this.outdir,{modules:this.Modules,sourceDir:path.join(this.outdir,"scripts"),baseDir:this.baseDir,minify:Boolean(e.minify)}),await utils.waitGC()}catch(e){(0,utils_1.default)(index_js_1.default.build.minification_error+e)}}}exports.default=Build;
@@ -0,0 +1,52 @@
1
+ import type { BuildData } from './index';
2
+ interface MblerConfig {
3
+ name: string;
4
+ description: string;
5
+ version: string;
6
+ mcVersion: string;
7
+ ResDes?: {
8
+ name?: string;
9
+ version?: string;
10
+ };
11
+ subpack?: Record<string, string>;
12
+ script?: {
13
+ main?: string;
14
+ lang?: string;
15
+ UseBeta?: boolean;
16
+ ui?: boolean;
17
+ };
18
+ }
19
+ interface ManifestData {
20
+ format_version: number;
21
+ header: {
22
+ name: string;
23
+ description: string;
24
+ uuid: string;
25
+ version: number[];
26
+ min_engine_version: number[];
27
+ };
28
+ modules: Array<{
29
+ type: string;
30
+ uuid: string;
31
+ description?: string;
32
+ version: number[];
33
+ language?: string;
34
+ entry?: string;
35
+ }>;
36
+ dependencies?: Array<{
37
+ module_name: string;
38
+ version: string;
39
+ }>;
40
+ subpack?: Array<{
41
+ folder_name: string;
42
+ name: string;
43
+ memory_tier: number;
44
+ }>;
45
+ capabilities?: string[];
46
+ }
47
+ export declare class ManiFest {
48
+ data: ManifestData;
49
+ constructor(MblerConfig: MblerConfig | BuildData, type: string);
50
+ processScriptConfig(data: MblerConfig | BuildData, manifest: ManifestData): void;
51
+ }
52
+ export {};
@@ -0,0 +1,6 @@
1
+ interface McVersionGeter {
2
+ ToServer(version: string, useBeta?: boolean): string;
3
+ ToServerUi(version: string, useBeta?: boolean): string;
4
+ }
5
+ export declare const mcVersionGeter: McVersionGeter;
6
+ export {};
@@ -0,0 +1 @@
1
+ export default function next(tip: string): void;
@@ -0,0 +1,2 @@
1
+ import ImportManager from './mtreehandler';
2
+ export default function (text: string | null): ImportManager;
@@ -0,0 +1,8 @@
1
+ interface ProcessOptions {
2
+ modules?: string[];
3
+ sourceDir: string;
4
+ baseDir: string;
5
+ minify?: boolean;
6
+ }
7
+ export default function processor(targetDir: string, options: ProcessOptions): Promise<void>;
8
+ export {};
@@ -0,0 +1,19 @@
1
+ export default class ImportManager {
2
+ private code;
3
+ private ast;
4
+ private imports;
5
+ constructor(code: string | null);
6
+ private _parse;
7
+ private _collectImports;
8
+ has(moduleName: string): boolean;
9
+ get(): Array<{
10
+ ModuleName: string;
11
+ ImportItem: string[];
12
+ }>;
13
+ set({ ModuleName, ImportItem }: {
14
+ ModuleName: string;
15
+ ImportItem: string[];
16
+ }): void;
17
+ private _syncAST;
18
+ generate(): string;
19
+ }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * 工具类:提供控制台交互功能,比如高亮菜单渲染、交互式选择等
3
+ */
4
+ export declare class Input {
5
+ /**
6
+ * 渲染一个字符串数组,高亮当前选中的项
7
+ * @param arr 菜单项数组
8
+ * @param index 当前选中索引
9
+ * @returns 格式化后的字符串
10
+ */
11
+ static render(arr: string[], index: number): string;
12
+ /**
13
+ * 提供一个交互式菜单选择器
14
+ * @param tip 提示文本
15
+ * @param arr 选项数组
16
+ * @returns 用户选中的选项内容(Promise<string>)
17
+ */
18
+ static select(tip: string, arr: string[]): Promise<any>;
19
+ /**
20
+ * 注册一个全局任务,每次按键都会被调用
21
+ * @param task 回调函数
22
+ */
23
+ static use(task: (name: string, ctrl: boolean, alt: boolean, raw: string) => void): void;
24
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * 克隆 Git 仓库
3
+ * @param {string} repoUrl - Git 仓库地址
4
+ * @param {string} targetDir - 本地目标目录(如 './my-project')
5
+ * @returns {Promise<void>}
6
+ */
7
+ export default function gitClone(repoUrl: string, targetDir: string): Promise<unknown>;
@@ -0,0 +1,6 @@
1
+ import clone from "./clone.js";
2
+ import pull from "./pull.js";
3
+ export default class GitRepo {
4
+ static clone: typeof clone;
5
+ static pull: typeof pull;
6
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * 拉取 Git 仓库
3
+ * @param {string} repoDir - 本地 Git 仓库目录(如 './my-project')
4
+ * @returns {Promise<void>}
5
+ */
6
+ export default function gitPull(repoDir: string): Promise<boolean>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,141 @@
1
+ declare const _default: {
2
+ help: string;
3
+ config_invalid: string;
4
+ err_bulid: string;
5
+ uncommand: string;
6
+ s0: string;
7
+ noGit: string;
8
+ SameDes: string;
9
+ invalidConfig: string;
10
+ inited: string;
11
+ noGitRepo: string;
12
+ invalidDes: string;
13
+ workPackV: string;
14
+ cleanFinally: string;
15
+ noCommandTip: string;
16
+ init: {
17
+ name: string;
18
+ desc: string;
19
+ useMcVersion: string;
20
+ useSapi: string;
21
+ useTs: string;
22
+ InputFormatErr: string;
23
+ main: string;
24
+ useUi: string;
25
+ ReInput: string;
26
+ };
27
+ dev: {
28
+ start: string;
29
+ start_d: string;
30
+ tip: string;
31
+ };
32
+ installGit: {
33
+ NoPackage: string;
34
+ InstallFinally: string;
35
+ HadBeen: string;
36
+ SetContent: string;
37
+ };
38
+ vm: {
39
+ shouldNotImp: string;
40
+ runScriptErr: string;
41
+ };
42
+ build: {
43
+ build_info_header: string;
44
+ project_path: string;
45
+ output_dir: string;
46
+ minify_enabled: string;
47
+ build_time: string;
48
+ build_success: string;
49
+ build_failed: string;
50
+ config_invalid: string;
51
+ package_file_missing_fields: string;
52
+ script_main_entry_missing: string;
53
+ subpack_folder_not_found: string;
54
+ subpack_processing_failed: string;
55
+ includes_not_array: string;
56
+ ts_no_files: string;
57
+ ts_diagnostics: string;
58
+ ts_compilation_error: string;
59
+ no_ts_files_skip: string;
60
+ copying_subpack_script: string;
61
+ copying_subpack_resources: string;
62
+ removing_js_files: string;
63
+ copying_compiled_ts: string;
64
+ minification_error: string;
65
+ temp_mod_init: string;
66
+ script_entry_required: string;
67
+ invalid_script_entry: string;
68
+ module_copy_success: string;
69
+ invalid_subpack_type: string;
70
+ invalid_includes_type: string;
71
+ handle_includes_info: string;
72
+ minification_skipped: string;
73
+ remove_js_files_info: string;
74
+ process_minification: string;
75
+ copy_compiled_ts_only: string;
76
+ temp_mod_usage: string;
77
+ build_failed_catch: string;
78
+ error_message_log: string;
79
+ exit_with_code: string;
80
+ class_pri_locked: string;
81
+ object_pri_enforced: string;
82
+ no_resources: string;
83
+ ziped: string;
84
+ tip_dist: string;
85
+ };
86
+ buildBase: {
87
+ npm_deps_skipped_no_json: string;
88
+ build_time: string;
89
+ cannot_read_project_config: string;
90
+ invalid_project_config_format: string;
91
+ starting_npm_install: string;
92
+ npm_install_completed: string;
93
+ npm_install_exit_code: string;
94
+ npm_install_error: string;
95
+ calculating_sha1: string;
96
+ file_not_exist: string;
97
+ config_hash_stored: string;
98
+ package_hash_stored: string;
99
+ config_changed: string;
100
+ package_changed: string;
101
+ saving_current_hash: string;
102
+ removing_js_files: string;
103
+ removing_js_error_ignored: string;
104
+ removing_npm_des: string;
105
+ module_not_included: string;
106
+ recursive_remove_js: string;
107
+ reading_file_content: string;
108
+ };
109
+ commands: {
110
+ list: {
111
+ "0": string;
112
+ "1": string;
113
+ "2": string;
114
+ "3": string;
115
+ "4": string;
116
+ "5": string;
117
+ "6": string;
118
+ "7": string;
119
+ "8": string;
120
+ "9": string;
121
+ "10": string;
122
+ "11": string;
123
+ "12": string;
124
+ "13": string;
125
+ };
126
+ dev: string;
127
+ build: string;
128
+ init: string;
129
+ version: string;
130
+ "-c": string;
131
+ "-i": string;
132
+ "-v": string;
133
+ v: string;
134
+ checkout: string;
135
+ create: string;
136
+ recache: string;
137
+ lang: string;
138
+ install: string;
139
+ };
140
+ };
141
+ export default _default;
@@ -0,0 +1,2 @@
1
+ declare let exp: any;
2
+ export default exp;
@@ -0,0 +1,127 @@
1
+ declare const _default: {
2
+ help: string;
3
+ config_invalid: string;
4
+ err_bulid: string;
5
+ uncommand: string;
6
+ s0: string;
7
+ noGit: string;
8
+ SameDes: string;
9
+ invalidConfig: string;
10
+ inited: string;
11
+ noGitRepo: string;
12
+ invalidDes: string;
13
+ workPackV: string;
14
+ cleanFinally: string;
15
+ noCommandTip: string;
16
+ init: {
17
+ name: string;
18
+ desc: string;
19
+ useMcVersion: string;
20
+ useSapi: string;
21
+ useTs: string;
22
+ InputFormatErr: string;
23
+ main: string;
24
+ useUi: string;
25
+ ReInput: string;
26
+ };
27
+ dev: {
28
+ start: string;
29
+ start_d: string;
30
+ tip: string;
31
+ };
32
+ installGit: {
33
+ NoPackage: string;
34
+ InstallFinally: string;
35
+ HadBeen: string;
36
+ SetContent: string;
37
+ };
38
+ vm: {
39
+ shouldNotImp: string;
40
+ runScriptErr: string;
41
+ };
42
+ build: {
43
+ build_info_header: string;
44
+ project_path: string;
45
+ output_dir: string;
46
+ minify_enabled: string;
47
+ build_time: string;
48
+ build_success: string;
49
+ build_failed: string;
50
+ config_invalid: string;
51
+ package_file_missing_fields: string;
52
+ script_main_entry_missing: string;
53
+ subpack_folder_not_found: string;
54
+ subpack_processing_failed: string;
55
+ includes_not_array: string;
56
+ ts_no_files: string;
57
+ ts_diagnostics: string;
58
+ ts_compilation_error: string;
59
+ no_ts_files_skip: string;
60
+ copying_subpack_script: string;
61
+ copying_subpack_resources: string;
62
+ removing_js_files: string;
63
+ copying_compiled_ts: string;
64
+ minification_error: string;
65
+ temp_mod_init: string;
66
+ script_entry_required: string;
67
+ invalid_script_entry: string;
68
+ module_copy_success: string;
69
+ invalid_subpack_type: string;
70
+ invalid_includes_type: string;
71
+ handle_includes_info: string;
72
+ minification_skipped: string;
73
+ remove_js_files_info: string;
74
+ process_minification: string;
75
+ copy_compiled_ts_only: string;
76
+ temp_mod_usage: string;
77
+ build_failed_catch: string;
78
+ error_message_log: string;
79
+ exit_with_code: string;
80
+ class_pri_locked: string;
81
+ object_pri_enforced: string;
82
+ no_resources: string;
83
+ ziped: string;
84
+ tip_dist: string;
85
+ };
86
+ buildBase: {
87
+ npm_deps_skipped_no_json: string;
88
+ build_time: string;
89
+ cannot_read_project_config: string;
90
+ invalid_project_config_format: string;
91
+ starting_npm_install: string;
92
+ npm_install_completed: string;
93
+ npm_install_exit_code: string;
94
+ npm_install_error: string;
95
+ calculating_sha1: string;
96
+ file_not_exist: string;
97
+ config_hash_stored: string;
98
+ package_hash_stored: string;
99
+ config_changed: string;
100
+ package_changed: string;
101
+ saving_current_hash: string;
102
+ removing_js_files: string;
103
+ removing_js_error_ignored: string;
104
+ removing_npm_des: string;
105
+ module_not_included: string;
106
+ recursive_remove_js: string;
107
+ reading_file_content: string;
108
+ };
109
+ commands: {
110
+ list: string[];
111
+ dev: string;
112
+ build: string;
113
+ init: string;
114
+ version: string;
115
+ "-c": string;
116
+ "-i": string;
117
+ "-v": string;
118
+ v: string;
119
+ checkout: string;
120
+ web_edit: string;
121
+ create: string;
122
+ recache: string;
123
+ lang: string;
124
+ install: string;
125
+ };
126
+ };
127
+ export default _default;
@@ -0,0 +1,6 @@
1
+ declare const reset = "\u001B[0m";
2
+ declare const red = "\u001B[31m";
3
+ declare const yellow = "\u001B[33m";
4
+ declare const cyan = "\u001B[36m";
5
+ declare const white = "\u001B[37m";
6
+ export { reset, red, yellow, cyan, white };
@@ -0,0 +1,36 @@
1
+ import util from 'util';
2
+ declare class Logger {
3
+ #private;
4
+ [util.inspect.custom]: () => string;
5
+ getConsole(type: string, t: string): void;
6
+ /**
7
+ * 错误日志
8
+ * @param {string} tag - 日志标签
9
+ * @param {...*} msgs - 日志内容
10
+ */
11
+ e(tag: string, ...msgs: any[]): void;
12
+ /**
13
+ * 警告日志
14
+ * @param {string} tag - 日志标签
15
+ * @param {...*} msgs - 日志内容
16
+ */
17
+ w(tag: string, ...msgs: any[]): void;
18
+ /**
19
+ * 信息日志
20
+ * @param {string} tag - 日志标签
21
+ * @param {...*} msgs - 日志内容
22
+ */
23
+ i(tag: string, ...msgs: any[]): void;
24
+ /**
25
+ * 调试日志
26
+ * @param {string} tag - 日志标签
27
+ * @param {...*} msgs - 日志内容
28
+ */
29
+ d(tag: string, ...msgs: any[]): void;
30
+ /**
31
+ * @returns {string}
32
+ */
33
+ toString(): string;
34
+ }
35
+ declare const _default: Logger;
36
+ export default _default;