mbler 0.1.1 → 0.1.3-alpha

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 (143) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +28 -0
  3. package/lib/build/base.js +297 -1
  4. package/lib/build/build-g-config.json +11 -11
  5. package/lib/build/getModule.js +182 -1
  6. package/lib/build/index.js +370 -1
  7. package/lib/build/manifest.build.js +103 -1
  8. package/lib/build/mcVersion.js +86 -1
  9. package/lib/build/utils.js +6 -1
  10. package/lib/code-processor/c-handler-export.js +12 -1
  11. package/lib/code-processor/index.js +141 -1
  12. package/lib/code-processor/mtreehandler.js +164 -1
  13. package/lib/commander/index.js +154 -1
  14. package/lib/data/includes.json +12 -12
  15. package/lib/git/clone.js +28 -1
  16. package/lib/git/index.js +12 -1
  17. package/lib/git/pull.js +100 -1
  18. package/lib/lang/__translate.js +93 -1
  19. package/lib/lang/en.js +128 -1
  20. package/lib/lang/index.js +78 -1
  21. package/lib/lang/zh.js +146 -1
  22. package/lib/loger/colors.js +13 -1
  23. package/lib/loger/index.js +136 -1
  24. package/lib/mcx/ast/index.js +11 -1
  25. package/lib/mcx/ast/prop.js +78 -1
  26. package/lib/mcx/ast/tag.js +246 -1
  27. package/lib/mcx/compile-component/lib.js +106 -1
  28. package/lib/mcx/compile-component/types.js +2 -1
  29. package/lib/mcx/compile-component/utils.js +26 -1
  30. package/lib/mcx/compile-mcx/_compile.js +1 -1
  31. package/lib/mcx/compile-mcx/compile.js +34 -1
  32. package/lib/mcx/compile-mcx/context.js +19 -1
  33. package/lib/mcx/compile-mcx/index.js +10 -1
  34. package/lib/mcx/compile-mcx/mcx/index.js +2 -1
  35. package/lib/mcx/compile-mcx/mcx/types.js +2 -1
  36. package/lib/mcx/compile-mcx/template/module.js +42 -1
  37. package/lib/mcx/compile-mcx/types.js +2 -1
  38. package/lib/mcx/compile-mcx/utils.node.js +207 -1
  39. package/lib/mcx/index.js +13 -1
  40. package/lib/mcx/test/index.js +7 -1
  41. package/lib/mcx/test.js +21 -1
  42. package/lib/mcx/types.js +2 -1
  43. package/lib/mcx/utils.js +86 -1
  44. package/lib/module-handler/index.js +482 -1
  45. package/lib/modules/create-game/src/Runner/RunnerManager.js +113 -1
  46. package/lib/modules/create-game/src/Runner/scriptRunner.js +70 -1
  47. package/lib/modules/create-game/src/config.js +27 -1
  48. package/lib/modules/create-game/src/constants.js +19 -1
  49. package/lib/modules/create-game/src/createGameModule.js +24 -1
  50. package/lib/modules/create-game/src/gameComponent/common/autoStop.js +38 -1
  51. package/lib/modules/create-game/src/gameComponent/common/lazyLoader.js +76 -1
  52. package/lib/modules/create-game/src/gameComponent/common/stopWatch/onTimeEvent.js +36 -1
  53. package/lib/modules/create-game/src/gameComponent/common/stopWatch/stopWatch.js +90 -1
  54. package/lib/modules/create-game/src/gameComponent/common/stopWatch/tickEvent.js +29 -1
  55. package/lib/modules/create-game/src/gameComponent/common/timer/onTimeEvent.js +36 -1
  56. package/lib/modules/create-game/src/gameComponent/common/timer/tickEvent.js +29 -1
  57. package/lib/modules/create-game/src/gameComponent/common/timer/timer.js +87 -1
  58. package/lib/modules/create-game/src/gameComponent/gameComponent.js +53 -1
  59. package/lib/modules/create-game/src/gameComponent/index.js +31 -1
  60. package/lib/modules/create-game/src/gameComponent/player/blockInteractionBlocker.js +40 -1
  61. package/lib/modules/create-game/src/gameComponent/player/entityInteractionBlocker.js +48 -1
  62. package/lib/modules/create-game/src/gameComponent/player/healthIndicator.js +48 -1
  63. package/lib/modules/create-game/src/gameComponent/player/regionMonitor.js +22 -1
  64. package/lib/modules/create-game/src/gameComponent/player/respawn.js +59 -1
  65. package/lib/modules/create-game/src/gameComponent/player/spawnProtector.js +69 -1
  66. package/lib/modules/create-game/src/gameComponent/region/regionProtecter.js +53 -1
  67. package/lib/modules/create-game/src/gameComponent/region/regionTeamChooser.js +71 -1
  68. package/lib/modules/create-game/src/gameComponent/region/regionTeamCleaner.js +20 -1
  69. package/lib/modules/create-game/src/gameComponent/view/infoScoreboard.js +77 -1
  70. package/lib/modules/create-game/src/gameComponent/view/teamScoreboard.js +83 -1
  71. package/lib/modules/create-game/src/gameContext.js +6 -1
  72. package/lib/modules/create-game/src/gameEngine.js +139 -1
  73. package/lib/modules/create-game/src/gameEvent/eventManager.js +108 -1
  74. package/lib/modules/create-game/src/gameEvent/eventSignal.js +28 -1
  75. package/lib/modules/create-game/src/gameEvent/events/buttonPush.js +41 -1
  76. package/lib/modules/create-game/src/gameEvent/events/inSlot.js +77 -1
  77. package/lib/modules/create-game/src/gameEvent/events/interval.js +51 -1
  78. package/lib/modules/create-game/src/gameEvent/events/itemUse.js +36 -1
  79. package/lib/modules/create-game/src/gameEvent/events/onBlock.js +106 -1
  80. package/lib/modules/create-game/src/gameEvent/events/regionEvents.js +105 -1
  81. package/lib/modules/create-game/src/gameEvent/events/signClick.js +45 -1
  82. package/lib/modules/create-game/src/gameEvent/gameEvent.js +54 -1
  83. package/lib/modules/create-game/src/gameEvent/index.js +20 -1
  84. package/lib/modules/create-game/src/gameEvent/mapEventSignal.js +101 -1
  85. package/lib/modules/create-game/src/gameEvent/subscription.js +17 -1
  86. package/lib/modules/create-game/src/gamePlayer/gamePlayer.js +102 -1
  87. package/lib/modules/create-game/src/gamePlayer/groupBuilder.js +38 -1
  88. package/lib/modules/create-game/src/gamePlayer/groupSet.js +96 -1
  89. package/lib/modules/create-game/src/gamePlayer/index.js +25 -1
  90. package/lib/modules/create-game/src/gamePlayer/playerGroup.js +145 -1
  91. package/lib/modules/create-game/src/gamePlayer/playerManager.js +57 -1
  92. package/lib/modules/create-game/src/gameRegion/gameRegion.js +229 -1
  93. package/lib/modules/create-game/src/gameRegion/index.js +43 -1
  94. package/lib/modules/create-game/src/gameRegion/regionHelper.js +79 -1
  95. package/lib/modules/create-game/src/gameState/common/autoStop.js +39 -1
  96. package/lib/modules/create-game/src/gameState/gameState.js +169 -1
  97. package/lib/modules/create-game/src/gameState/index.js +7 -1
  98. package/lib/modules/create-game/src/gameState/types.js +35 -1
  99. package/lib/modules/create-game/src/gameStructure/gameStructure.js +36 -1
  100. package/lib/modules/create-game/src/main.js +86 -1
  101. package/lib/modules/create-game/src/system/gameCommand.js +107 -1
  102. package/lib/modules/create-game/src/system/gameManager.js +124 -1
  103. package/lib/modules/create-game/src/system/globalPlayerManager.js +119 -1
  104. package/lib/modules/create-game/src/utils/GameError.js +31 -1
  105. package/lib/modules/create-game/src/utils/algorithm.js +95 -1
  106. package/lib/modules/create-game/src/utils/chunk.js +63 -1
  107. package/lib/modules/create-game/src/utils/deferredObject.js +27 -1
  108. package/lib/modules/create-game/src/utils/duration.js +25 -1
  109. package/lib/modules/create-game/src/utils/func.js +20 -1
  110. package/lib/modules/create-game/src/utils/index.js +52 -1
  111. package/lib/modules/create-game/src/utils/interfaces.js +2 -1
  112. package/lib/modules/create-game/src/utils/logger.js +47 -1
  113. package/lib/modules/create-game/src/utils/random.js +76 -1
  114. package/lib/modules/create-game/src/utils/vanila-data.js +123 -1
  115. package/lib/modules/create-game/src/utils/vector.js +96 -1
  116. package/lib/modules/gameLib/src/config.js +134 -1
  117. package/lib/modules/gameLib/src/data.js +77 -1
  118. package/lib/modules/gameLib/src/entity.js +256 -1
  119. package/lib/modules/gameLib/src/event.js +285 -1
  120. package/lib/modules/gameLib/src/index.js +20 -1
  121. package/lib/modules/gameLib/src/loger.js +21 -1
  122. package/lib/modules/gameLib/src/ui.js +209 -1
  123. package/lib/modules/gameLib/src/utils.js +122 -1
  124. package/lib/modules/gutils/src/index.js +22 -1
  125. package/lib/runTemp/File.js +54 -1
  126. package/lib/runTemp/index.js +137 -1
  127. package/lib/runTemp/securityFile.js +93 -1
  128. package/lib/start/addPack.js +3 -1
  129. package/lib/start/clean.js +84 -1
  130. package/lib/start/create.js +146 -1
  131. package/lib/start/dev.js +99 -1
  132. package/lib/start/getResConfig.js +3 -1
  133. package/lib/start/incg.js +3 -1
  134. package/lib/start/index.js +207 -1
  135. package/lib/start/init.js +125 -1
  136. package/lib/start/rechce.js +57 -1
  137. package/lib/start/unaddPack.js +3 -1
  138. package/lib/start/unincg.js +67 -1
  139. package/lib/start/version.js +73 -1
  140. package/lib/utils/index.js +298 -1
  141. package/lib/uuid/index.js +27 -1
  142. package/package.json +1 -1
  143. package/test/script-mbler/behavior/scripts/index.js +0 -5
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 RuanhoR
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # McBeBuilder - MBLER
2
+
3
+ #### 介绍
4
+ 一个针对Minecraft JavaScript API 的nodejs包,让你的附加包更简单
5
+ ### 安装
6
+ 确保你已经安装以下工具:
7
+ - Node.js 与 npm
8
+ - Git
9
+ 推荐使用 GitHub 仓库:
10
+ 从 [这里](https://github.com/RuanhoR/mbler/releases) 选择版本下载,到达这个目录(使用命令行cd),运行`npm link`
11
+ 也可使用 Gitee 的克隆链接或github镜像站,可能速度更快
12
+ 本项目目前迁移`typescript`,你也可以直接运行`tsc`进行构建
13
+
14
+ 安装成功后,你可以直接使用:
15
+ ```bash
16
+ # 获取版本
17
+ mbler -v
18
+ ```
19
+ 初始化目录配置文件
20
+ ```bash
21
+ mbler -c <项目路径>
22
+ mbler init
23
+ ```
24
+ ** 详细请看 : [文档](./docs) **
25
+
26
+ ### 发布平台
27
+ [github](https://github.com/RuanhoR/mbler)
28
+ [gitee](https://gitee.com/n304sc-haoran/mbler)
package/lib/build/base.js CHANGED
@@ -1 +1,297 @@
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";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.BaseBuild = void 0;
40
+ const promises_1 = __importDefault(require("fs/promises"));
41
+ const path_1 = __importDefault(require("path"));
42
+ const dayjs_1 = __importDefault(require("dayjs"));
43
+ const index_js_1 = __importDefault(require("./../lang/index.js"));
44
+ const index_js_2 = __importDefault(require("./../runTemp/index.js"));
45
+ const child_process_1 = require("child_process");
46
+ const manifest_build_js_1 = require("./manifest.build.js");
47
+ const node_os_1 = __importDefault(require("node:os"));
48
+ const time = () => (0, dayjs_1.default)().format('YYYY-MM-DD HH:mm:ss');
49
+ const utils_1 = __importDefault(require("./utils"));
50
+ const utils = __importStar(require("./../utils/index.js"));
51
+ // 这里是主Build的底类,用于提供工具,主Build负责将工具连起来,进行完整的构建
52
+ class BaseBuild {
53
+ static times = time();
54
+ outdir = "";
55
+ ResOutDir = null;
56
+ baseCwd = '';
57
+ cwd = '';
58
+ ResCwd = '';
59
+ d_data = null;
60
+ cacheDir = '';
61
+ dependencies = {};
62
+ Modules = [];
63
+ constructor() { }
64
+ async rmPackScriptScriptCache() {
65
+ await Promise.all([
66
+ this.rmNpmDes(),
67
+ promises_1.default.rm(path_1.default.join(this.outdir, 'scripts/package-lock.json'), {
68
+ recursive: true,
69
+ force: true
70
+ }).catch(() => { })
71
+ ]);
72
+ }
73
+ async processResources() {
74
+ if ((await utils.FileExsit(this.ResCwd)) && this.ResOutDir) {
75
+ await Promise.all((await promises_1.default.readdir(this.ResCwd)).map((dir) => utils.copy(path_1.default.join(this.ResCwd, dir), path_1.default.join(this.ResOutDir, dir))));
76
+ if (this.d_data == null)
77
+ throw new Error("[build error]: not load config when init");
78
+ const manifest = (new manifest_build_js_1.ManiFest(this.d_data, "resources")).data;
79
+ await this.writeFile(path_1.default.join(this.ResOutDir, "manifest.json"), JSON.stringify(manifest));
80
+ }
81
+ else {
82
+ (0, utils_1.default)(index_js_1.default.build.no_resources);
83
+ }
84
+ }
85
+ async processDist() {
86
+ if (process.env.MBLER_BUILD_MODULE === "dist") {
87
+ const temp = new index_js_2.default(path_1.default.join(node_os_1.default.tmpdir(), "mbler"));
88
+ await temp.init();
89
+ await Promise.all([
90
+ utils.copy(this.outdir, path_1.default.join(temp.dir, "behavior")),
91
+ (await utils.FileExsit(this.ResCwd)) ?
92
+ utils.copy(this.ResOutDir, path_1.default.join(temp.dir, "resources")) :
93
+ Promise.resolve()
94
+ ]);
95
+ let i = this.d_data?.outdir?.dist || "dist.mcaddon";
96
+ if (path_1.default.extname(i) !== ".mcaddon")
97
+ i += ".mcaddon";
98
+ const dir = path_1.default.join(this.baseCwd, i);
99
+ const v = require('./../../package.json');
100
+ await promises_1.default.writeFile(path_1.default.join(temp.dir, "behavior", ".mbler.build.info"), JSON.stringify({
101
+ mbler: {
102
+ version: v.version,
103
+ git: v.repository
104
+ },
105
+ time: BaseBuild.times
106
+ }));
107
+ await utils.zip([
108
+ temp.dir
109
+ ], dir);
110
+ await temp.remove();
111
+ (0, utils_1.default)(`${index_js_1.default.build.ziped} ${dir}`);
112
+ }
113
+ }
114
+ async loadPackageData() {
115
+ const data = await utils.GetData(this.baseCwd);
116
+ if (!data)
117
+ throw new Error(index_js_1.default.buildBase.cannot_read_project_config);
118
+ if (typeof data !== 'object' || data === null)
119
+ throw new Error(index_js_1.default.buildBase.invalid_project_config_format);
120
+ return data;
121
+ }
122
+ getCachePath(fileName) {
123
+ return path_1.default.join(this.cacheDir, fileName);
124
+ }
125
+ getOutputDir(dir, def) {
126
+ const outdir = dir;
127
+ return outdir ? path_1.default.join(this.baseCwd, outdir) : def;
128
+ }
129
+ async initNpmDes() {
130
+ const packager = JSON.parse(await promises_1.default.readFile(path_1.default.join(this.baseCwd, 'package.json'), "utf-8"));
131
+ const desLength = Object.keys(packager.dependencies || {}).length;
132
+ if (desLength < 1) {
133
+ (0, utils_1.default)(index_js_1.default.buildBase.npm_deps_skipped_no_json);
134
+ return;
135
+ }
136
+ await promises_1.default.writeFile(path_1.default.join(this.outdir, 'scripts/package.json'), JSON.stringify(packager));
137
+ await this.#npmInstall(path_1.default.join(this.outdir, 'scripts'));
138
+ }
139
+ #npmInstall(repo) {
140
+ return new Promise((resolve, reject) => {
141
+ (0, utils_1.default)(index_js_1.default.buildBase.starting_npm_install);
142
+ const processC = (0, child_process_1.spawn)('npm', ['install'], {
143
+ cwd: repo,
144
+ stdio: 'ignore'
145
+ });
146
+ processC.on('close', (code) => {
147
+ if (code === 0) {
148
+ (0, utils_1.default)(index_js_1.default.buildBase.npm_install_completed);
149
+ resolve(code);
150
+ }
151
+ else {
152
+ (0, utils_1.default)(index_js_1.default.buildBase.npm_install_exit_code + code);
153
+ resolve(code);
154
+ }
155
+ });
156
+ processC.on('error', (err) => {
157
+ (0, utils_1.default)(`${index_js_1.default.buildBase.npm_install_error} ${err.stack}`);
158
+ reject(err);
159
+ });
160
+ });
161
+ }
162
+ async getFileHash(filePath) {
163
+ if (!await utils.FileExsit(filePath))
164
+ return null;
165
+ const content = await promises_1.default.readFile(filePath);
166
+ const hashSum = (await import('crypto')).createHash('sha1');
167
+ hashSum.update(content);
168
+ return hashSum.digest('hex');
169
+ }
170
+ async chackConfigHash() {
171
+ const configPath = path_1.default.join(this.cwd, 'mbler.config.json');
172
+ const packagePath = path_1.default.join(this.cwd, 'package.json');
173
+ const configHashPath = this.getCachePath('config-hash.txt');
174
+ const packageHashPath = this.getCachePath('package-hash.txt');
175
+ const currentConfigHash = await this.getFileHash(configPath);
176
+ const currentPackageHash = await this.getFileHash(packagePath);
177
+ let configHashStored = null;
178
+ let packageHashStored = null;
179
+ if (await promises_1.default.access(configHashPath).then(() => true).catch(() => false)) {
180
+ configHashStored = await promises_1.default.readFile(configHashPath, "utf-8");
181
+ }
182
+ if (await promises_1.default.access(packageHashPath).then(() => true).catch(() => false)) {
183
+ packageHashStored = await promises_1.default.readFile(packageHashPath, "utf-8");
184
+ }
185
+ const configChanged = !currentConfigHash || currentConfigHash !== configHashStored;
186
+ const packageChanged = !currentPackageHash || currentPackageHash !== packageHashStored;
187
+ if (currentConfigHash) {
188
+ await promises_1.default.writeFile(configHashPath, currentConfigHash);
189
+ }
190
+ if (currentPackageHash) {
191
+ await promises_1.default.writeFile(packageHashPath, currentPackageHash);
192
+ }
193
+ return {
194
+ configChanged,
195
+ packageChanged
196
+ };
197
+ }
198
+ async removeJsFiles(dir) {
199
+ try {
200
+ for (const f of await promises_1.default.readdir(dir, {
201
+ withFileTypes: true
202
+ })) {
203
+ const full = path_1.default.join(dir, f.name);
204
+ if (full.includes('node_modules'))
205
+ continue;
206
+ if (f.isDirectory()) {
207
+ await this.removeJsFiles(full);
208
+ }
209
+ else if (f.isFile() && f.name.endsWith('.js')) {
210
+ try {
211
+ await promises_1.default.unlink(full);
212
+ }
213
+ catch (e) {
214
+ /* 忽略 unlink 错误 */
215
+ }
216
+ }
217
+ }
218
+ }
219
+ catch (err) { }
220
+ }
221
+ async rmNpmDes() {
222
+ const moduleDir = path_1.default.join(this.outdir, 'scripts/node_modules');
223
+ const modules = this.Modules || Object.keys(this.dependencies);
224
+ for (let file of await promises_1.default.readdir(moduleDir).catch(() => [])) {
225
+ if (!modules.includes(file))
226
+ await promises_1.default.rm(path_1.default.join(moduleDir, file), {
227
+ recursive: true,
228
+ force: true
229
+ }).catch(() => { });
230
+ }
231
+ }
232
+ async copyCompiledOnly(srcDir, destDir) {
233
+ try {
234
+ for (const ent of await promises_1.default.readdir(srcDir, {
235
+ withFileTypes: true
236
+ })) {
237
+ const srcFull = path_1.default.join(srcDir, ent.name);
238
+ const destFull = path_1.default.join(destDir, ent.name);
239
+ if (ent.isDirectory()) {
240
+ await promises_1.default.mkdir(destFull, {
241
+ recursive: true
242
+ }).catch(() => { });
243
+ await this.copyCompiledOnly(srcFull, destFull);
244
+ }
245
+ else if (ent.isFile()) {
246
+ const ext = path_1.default.extname(ent.name).toLowerCase();
247
+ if ([".js", ".json"].includes(ext)) {
248
+ await promises_1.default.mkdir(path_1.default.dirname(destFull), {
249
+ recursive: true
250
+ }).catch(() => { });
251
+ await promises_1.default.copyFile(srcFull, destFull).catch(() => {
252
+ // 文件可能被占用,忽略单个错误
253
+ });
254
+ }
255
+ }
256
+ }
257
+ }
258
+ catch (err) {
259
+ (0, utils_1.default)(`ERR: ${err && err.stack ? err.stack : err}`);
260
+ }
261
+ }
262
+ async getAllTsFiles(dir) {
263
+ const list = [];
264
+ try {
265
+ for (const f of await promises_1.default.readdir(dir, {
266
+ withFileTypes: true
267
+ })) {
268
+ const full = path_1.default.join(dir, f.name);
269
+ if (f.isDirectory()) {
270
+ const sub = await this.getAllTsFiles(full);
271
+ list.push(...sub);
272
+ }
273
+ else if (f.isFile() && f.name.endsWith('.ts')) {
274
+ list.push(full);
275
+ }
276
+ }
277
+ }
278
+ catch (err) { }
279
+ return list;
280
+ }
281
+ async writeFile(filePath, content) {
282
+ try {
283
+ await utils.waitGC();
284
+ await promises_1.default.mkdir(path_1.default.dirname(filePath), {
285
+ recursive: true
286
+ });
287
+ const data = typeof content === 'string' ? content : JSON.stringify(content, null, 2);
288
+ await promises_1.default.writeFile(filePath, data, 'utf-8');
289
+ }
290
+ catch (err) {
291
+ (0, utils_1.default)(`WRITE FILE ERR: ${filePath}`);
292
+ throw err;
293
+ }
294
+ await utils.waitGC();
295
+ }
296
+ }
297
+ exports.BaseBuild = BaseBuild;
@@ -1,12 +1,12 @@
1
1
  {
2
- "resources": {
3
- "header": "48793164",
4
- "module": "ab43f7cb"
5
- },
6
- "data": {
7
- "header": "7604691",
8
- "module": "bcd46f7a"
9
- },
10
- "ScriptId": "4654236ace4",
11
- "PackageFile": "mbler.config.json"
12
- }
2
+ "resources": {
3
+ "header": "48793164",
4
+ "module": "ab43f7cb"
5
+ },
6
+ "data": {
7
+ "header": "7604691",
8
+ "module": "bcd46f7a"
9
+ },
10
+ "ScriptId": "4654236ace4",
11
+ "PackageFile": "mbler.config.json"
12
+ }
@@ -1 +1,182 @@
1
- "use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(t,e,r,i){void 0===i&&(i=r);var n=Object.getOwnPropertyDescriptor(e,r);n&&!("get"in n?!e.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,n)}:function(t,e,r,i){void 0===i&&(i=r),t[i]=e[r]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),__importStar=this&&this.__importStar||function(){var t=function(e){return t=Object.getOwnPropertyNames||function(t){var e=[];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[e.length]=r);return e},t(e)};return function(e){if(e&&e.__esModule)return e;var r={};if(null!=e)for(var i=t(e),n=0;n<i.length;n++)"default"!==i[n]&&__createBinding(r,e,i[n]);return __setModuleDefault(r,e),r}}();const fs=__importStar(require("fs/promises")),path=__importStar(require("path")),utils=__importStar(require("./../utils/index.js")),dirCache=new Map;let cacheList=null;const normalize=t=>String(t||"").trim(),parts=t=>normalize(t).split(".").slice(0,3).map(t=>parseInt(t,10)||0),compareVer=(t,e)=>{const r=parts(t),i=parts(e);for(let t=0;t<3;t++){const e=r[t],n=i[t];if(e&&n&&e!==n)return e>n?1:-1}return 0},isValidVersionRange=(t,e)=>1===compareVer(e,t),isVersionInRange=(t,e,r)=>compareVer(t,e)>=0&&compareVer(t,r)<=0;class ModulePath{dir;innerList;cache;constructor(t){this.dir=t,this.innerList=new Array,this.cache=[]}async start(){this.cache=await this.#t(),this.innerList=JSON.parse((await fs.readFile(path.join(this.dir,"lib/modules/innerDef.json"),"utf-8")).toString())}getGit(t){for(const{name:e,git:r}of this.cache)if(e===t)return r;return null}getAll(){return cacheList||(cacheList=this.cache.map(t=>t.name),cacheList)}async getDir(t,e={}){if(!t)return null;const{gitUrl:r="",v:i="0.0.0"}=e;if(dirCache.has(t))return dirCache.get(t);for(const{name:e,git:n}of this.cache){if(!/^[a-zA-Z0-9\-]*$/.test(e))continue;if(e!==t)continue;if(r&&n!==r&&("inner"!==n||!this.innerList.includes(e)))continue;const s=path.join(this.dir,"lib/modules",e),a=await utils.GetData(s);if(a.mcVersion){Array.isArray(a.mcVersion)&&2===a.mcVersion.length||utils.Exit(`ERR - ${e} 模块的 mcVersion 配置格式错误,应为 [minVersion, maxVersion],如 ["1.0.0", "2.0.0"]`);const[t,r]=a.mcVersion;if(isValidVersionRange(t,r)||utils.Exit(`ERR - ${e} 模块 mcVersion 配置不正确:最高版本必须大于最低版本\n当前配置:min=${t}, max=${r}\n请联系开发者获取稳定版本`),!isVersionInRange(i,t,r))return{ERR:"V",message:`模块 "${e}" 不支持当前版本 v=${i},要求版本范围:[${t}, ${r}]`}}return dirCache.set(t,s),s}return null}async#t(){const t=path.join(this.dir,"lib/modules/contents.json");try{if(await this.#e(t)){const e=await fs.readFile(t,"utf8"),r=utils.JSONparse(e);return"object"==typeof r&&null!==r?r:[]}}catch(t){console.error("Failed to load contents.json:",t)}return[]}async#e(t){try{return await fs.access(t),!0}catch{return!1}}}module.exports=async t=>{const e=new ModulePath(t);return await e.start(),e};
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ const fs = __importStar(require("fs/promises"));
36
+ const path = __importStar(require("path"));
37
+ const utils = __importStar(require("./../utils/index.js"));
38
+ // 目录缓存
39
+ const dirCache = new Map();
40
+ let cacheList = null;
41
+ const normalize = (v) => {
42
+ return String(v || '').trim();
43
+ };
44
+ const parts = (v) => {
45
+ return normalize(v)
46
+ .split('.')
47
+ .slice(0, 3)
48
+ .map((n) => parseInt(n, 10) || 0);
49
+ };
50
+ // 比较版本号,返回 1 表示 a > b,-1 表示 a < b,0 表示相等
51
+ const compareVer = (a, b) => {
52
+ const A = parts(a);
53
+ const B = parts(b);
54
+ for (let i = 0; i < 3; i++) {
55
+ const a = A[i];
56
+ const b = B[i];
57
+ if (!a || !b)
58
+ continue;
59
+ if (a !== b)
60
+ return a > b ? 1 : -1;
61
+ }
62
+ return 0;
63
+ };
64
+ // 判断版本范围是否合法:min < max
65
+ const isValidVersionRange = (min, max) => {
66
+ return compareVer(max, min) === 1;
67
+ };
68
+ // 判断目标版本 v 是否在 [min, max] 范围内(闭区间)
69
+ const isVersionInRange = (v, min, max) => {
70
+ return compareVer(v, min) >= 0 && compareVer(v, max) <= 0;
71
+ };
72
+ // ModulePath 类定义
73
+ class ModulePath {
74
+ dir;
75
+ innerList;
76
+ cache;
77
+ constructor(dirname) {
78
+ this.dir = dirname;
79
+ this.innerList = new Array();
80
+ this.cache = [];
81
+ }
82
+ // 初始化:加载内容并读取 innerDef.json
83
+ async start() {
84
+ this.cache = await this.#loadContents();
85
+ this.innerList = JSON.parse((await fs.readFile(path.join(this.dir, 'lib/modules/innerDef.json'), "utf-8")).toString());
86
+ }
87
+ // 根据模块名称获取对应的 git 地址
88
+ getGit(Name) {
89
+ for (const { name, git } of this.cache) {
90
+ if (name === Name)
91
+ return git;
92
+ }
93
+ return null;
94
+ }
95
+ // 获取所有模块名称列表
96
+ getAll() {
97
+ if (cacheList)
98
+ return cacheList;
99
+ cacheList = this.cache.map((item) => item.name);
100
+ return cacheList;
101
+ }
102
+ // 根据包名查找模块所在目录,同时校验版本
103
+ async getDir(packageName, options = {}) {
104
+ if (!packageName)
105
+ return null;
106
+ const { gitUrl = '', v = "0.0.0" } = options;
107
+ // 先查缓存
108
+ if (dirCache.has(packageName)) {
109
+ return dirCache.get(packageName);
110
+ }
111
+ for (const { name, git } of this.cache) {
112
+ if (!/^[a-zA-Z0-9\-]*$/.test(name))
113
+ continue; // 只允许字母数字
114
+ if (name !== packageName)
115
+ continue;
116
+ // 如果指定了 gitUrl,需校验是否匹配,除非是 inner 且存在于 innerList
117
+ if (gitUrl) {
118
+ if (git !== gitUrl) {
119
+ if (!(git === 'inner' && this.innerList.includes(name))) {
120
+ continue; // 不匹配且不是合法的 inner 模块则跳过
121
+ }
122
+ }
123
+ }
124
+ const ddirPath = path.join(this.dir, 'lib/modules', name);
125
+ const packageJson = await utils.GetData(ddirPath);
126
+ // 如果有 mcVersion 配置,则进行版本校验
127
+ if (packageJson.mcVersion) {
128
+ // 校验 mcVersion 格式是否正确
129
+ if (!Array.isArray(packageJson.mcVersion) || packageJson.mcVersion.length !== 2) {
130
+ utils.Exit(`ERR - ${name} 模块的 mcVersion 配置格式错误,应为 [minVersion, maxVersion],如 ["1.0.0", "2.0.0"]`);
131
+ }
132
+ const [min, max] = packageJson.mcVersion;
133
+ // 校验版本范围是否合法:max 必须 > min
134
+ if (!isValidVersionRange(min, max)) {
135
+ utils.Exit(`ERR - ${name} 模块 mcVersion 配置不正确:最高版本必须大于最低版本\n当前配置:min=${min}, max=${max}\n请联系开发者获取稳定版本`);
136
+ }
137
+ // 校验传入的版本号 v 是否在 [min, max] 范围内
138
+ if (!isVersionInRange(v, min, max)) {
139
+ return {
140
+ ERR: "V",
141
+ message: `模块 "${name}" 不支持当前版本 v=${v},要求版本范围:[${min}, ${max}]`
142
+ };
143
+ }
144
+ }
145
+ // 所有校验通过,缓存并返回模块路径
146
+ dirCache.set(packageName, ddirPath);
147
+ return ddirPath;
148
+ }
149
+ // 没找到对应模块
150
+ return null;
151
+ }
152
+ // 读取 contents.json 文件内容
153
+ async #loadContents() {
154
+ const dataPath = path.join(this.dir, 'lib/modules/contents.json');
155
+ try {
156
+ if (await this.#fileExists(dataPath)) {
157
+ const content = await fs.readFile(dataPath, 'utf8');
158
+ const data = utils.JSONparse(content);
159
+ return (typeof data === 'object' && data !== null) ? data : [];
160
+ }
161
+ }
162
+ catch (err) {
163
+ console.error('Failed to load contents.json:', err);
164
+ }
165
+ return [];
166
+ }
167
+ // 检查文件是否存在
168
+ async #fileExists(filePath) {
169
+ try {
170
+ await fs.access(filePath);
171
+ return true;
172
+ }
173
+ catch {
174
+ return false;
175
+ }
176
+ }
177
+ }
178
+ module.exports = async (dirname) => {
179
+ const instance = new ModulePath(dirname);
180
+ await instance.start();
181
+ return instance;
182
+ };