mbler 0.1.1
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.
- package/bin/build.js +0 -0
- package/bin/mbler.js +14 -0
- package/bin/minify.js +155 -0
- package/lib/build/base.js +1 -0
- package/lib/build/build-g-config.json +12 -0
- package/lib/build/getModule.js +1 -0
- package/lib/build/index.js +1 -0
- package/lib/build/manifest.build.js +1 -0
- package/lib/build/mcVersion.js +1 -0
- package/lib/build/utils.js +1 -0
- package/lib/code-processor/c-handler-export.js +1 -0
- package/lib/code-processor/index.js +1 -0
- package/lib/code-processor/mtreehandler.js +1 -0
- package/lib/commander/index.js +1 -0
- package/lib/data/includes.json +13 -0
- package/lib/data/version.json +89 -0
- package/lib/git/clone.js +1 -0
- package/lib/git/index.js +1 -0
- package/lib/git/pull.js +1 -0
- package/lib/lang/__translate.js +1 -0
- package/lib/lang/en.js +1 -0
- package/lib/lang/index.js +1 -0
- package/lib/lang/zh.js +1 -0
- package/lib/loger/colors.js +1 -0
- package/lib/loger/index.js +1 -0
- package/lib/mcx/ast/index.js +1 -0
- package/lib/mcx/ast/prop.js +1 -0
- package/lib/mcx/ast/tag.js +1 -0
- package/lib/mcx/compile-component/lib.js +1 -0
- package/lib/mcx/compile-component/types.js +1 -0
- package/lib/mcx/compile-component/utils.js +1 -0
- package/lib/mcx/compile-mcx/_compile.js +602 -0
- package/lib/mcx/compile-mcx/compile.js +1 -0
- package/lib/mcx/compile-mcx/context.js +1 -0
- package/lib/mcx/compile-mcx/index.js +1 -0
- package/lib/mcx/compile-mcx/mcx/index.js +1 -0
- package/lib/mcx/compile-mcx/mcx/types.js +1 -0
- package/lib/mcx/compile-mcx/template/module.js +1 -0
- package/lib/mcx/compile-mcx/types.js +1 -0
- package/lib/mcx/compile-mcx/utils.node.js +1 -0
- package/lib/mcx/index.js +1 -0
- package/lib/mcx/test/index.js +1 -0
- package/lib/mcx/test.js +1 -0
- package/lib/mcx/types.js +1 -0
- package/lib/mcx/utils.js +1 -0
- package/lib/module-handler/index.js +1 -0
- package/lib/modules/contents.json +1 -0
- package/lib/modules/create-game/mbler.config.json +14 -0
- package/lib/modules/create-game/src/Runner/RunnerManager.js +1 -0
- package/lib/modules/create-game/src/Runner/scriptRunner.js +1 -0
- package/lib/modules/create-game/src/config.js +1 -0
- package/lib/modules/create-game/src/constants.js +1 -0
- package/lib/modules/create-game/src/createGameModule.js +1 -0
- package/lib/modules/create-game/src/gameComponent/common/autoStop.js +1 -0
- package/lib/modules/create-game/src/gameComponent/common/lazyLoader.js +1 -0
- package/lib/modules/create-game/src/gameComponent/common/stopWatch/onTimeEvent.js +1 -0
- package/lib/modules/create-game/src/gameComponent/common/stopWatch/stopWatch.js +1 -0
- package/lib/modules/create-game/src/gameComponent/common/stopWatch/tickEvent.js +1 -0
- package/lib/modules/create-game/src/gameComponent/common/timer/onTimeEvent.js +1 -0
- package/lib/modules/create-game/src/gameComponent/common/timer/tickEvent.js +1 -0
- package/lib/modules/create-game/src/gameComponent/common/timer/timer.js +1 -0
- package/lib/modules/create-game/src/gameComponent/gameComponent.js +1 -0
- package/lib/modules/create-game/src/gameComponent/index.js +1 -0
- package/lib/modules/create-game/src/gameComponent/player/blockInteractionBlocker.js +1 -0
- package/lib/modules/create-game/src/gameComponent/player/entityInteractionBlocker.js +1 -0
- package/lib/modules/create-game/src/gameComponent/player/healthIndicator.js +1 -0
- package/lib/modules/create-game/src/gameComponent/player/regionMonitor.js +1 -0
- package/lib/modules/create-game/src/gameComponent/player/respawn.js +1 -0
- package/lib/modules/create-game/src/gameComponent/player/spawnProtector.js +1 -0
- package/lib/modules/create-game/src/gameComponent/region/regionProtecter.js +1 -0
- package/lib/modules/create-game/src/gameComponent/region/regionTeamChooser.js +1 -0
- package/lib/modules/create-game/src/gameComponent/region/regionTeamCleaner.js +1 -0
- package/lib/modules/create-game/src/gameComponent/view/infoScoreboard.js +1 -0
- package/lib/modules/create-game/src/gameComponent/view/teamScoreboard.js +1 -0
- package/lib/modules/create-game/src/gameContext.js +1 -0
- package/lib/modules/create-game/src/gameEngine.js +1 -0
- package/lib/modules/create-game/src/gameEvent/eventManager.js +1 -0
- package/lib/modules/create-game/src/gameEvent/eventSignal.js +1 -0
- package/lib/modules/create-game/src/gameEvent/events/buttonPush.js +1 -0
- package/lib/modules/create-game/src/gameEvent/events/inSlot.js +1 -0
- package/lib/modules/create-game/src/gameEvent/events/interval.js +1 -0
- package/lib/modules/create-game/src/gameEvent/events/itemUse.js +1 -0
- package/lib/modules/create-game/src/gameEvent/events/onBlock.js +1 -0
- package/lib/modules/create-game/src/gameEvent/events/regionEvents.js +1 -0
- package/lib/modules/create-game/src/gameEvent/events/signClick.js +1 -0
- package/lib/modules/create-game/src/gameEvent/gameEvent.js +1 -0
- package/lib/modules/create-game/src/gameEvent/index.js +1 -0
- package/lib/modules/create-game/src/gameEvent/mapEventSignal.js +1 -0
- package/lib/modules/create-game/src/gameEvent/subscription.js +1 -0
- package/lib/modules/create-game/src/gamePlayer/gamePlayer.js +1 -0
- package/lib/modules/create-game/src/gamePlayer/groupBuilder.js +1 -0
- package/lib/modules/create-game/src/gamePlayer/groupSet.js +1 -0
- package/lib/modules/create-game/src/gamePlayer/index.js +1 -0
- package/lib/modules/create-game/src/gamePlayer/playerGroup.js +1 -0
- package/lib/modules/create-game/src/gamePlayer/playerManager.js +1 -0
- package/lib/modules/create-game/src/gameRegion/gameRegion.js +1 -0
- package/lib/modules/create-game/src/gameRegion/index.js +1 -0
- package/lib/modules/create-game/src/gameRegion/regionHelper.js +1 -0
- package/lib/modules/create-game/src/gameState/common/autoStop.js +1 -0
- package/lib/modules/create-game/src/gameState/gameState.js +1 -0
- package/lib/modules/create-game/src/gameState/index.js +1 -0
- package/lib/modules/create-game/src/gameState/types.js +1 -0
- package/lib/modules/create-game/src/gameStructure/gameStructure.js +1 -0
- package/lib/modules/create-game/src/main.js +1 -0
- package/lib/modules/create-game/src/system/gameCommand.js +1 -0
- package/lib/modules/create-game/src/system/gameManager.js +1 -0
- package/lib/modules/create-game/src/system/globalPlayerManager.js +1 -0
- package/lib/modules/create-game/src/utils/GameError.js +1 -0
- package/lib/modules/create-game/src/utils/algorithm.js +1 -0
- package/lib/modules/create-game/src/utils/chunk.js +1 -0
- package/lib/modules/create-game/src/utils/deferredObject.js +1 -0
- package/lib/modules/create-game/src/utils/duration.js +1 -0
- package/lib/modules/create-game/src/utils/func.js +1 -0
- package/lib/modules/create-game/src/utils/index.js +1 -0
- package/lib/modules/create-game/src/utils/interfaces.js +1 -0
- package/lib/modules/create-game/src/utils/logger.js +1 -0
- package/lib/modules/create-game/src/utils/random.js +1 -0
- package/lib/modules/create-game/src/utils/vanila-data.js +1 -0
- package/lib/modules/create-game/src/utils/vector.js +1 -0
- package/lib/modules/gameLib/mbler.config.json +16 -0
- package/lib/modules/gameLib/src/config.js +1 -0
- package/lib/modules/gameLib/src/data.js +1 -0
- package/lib/modules/gameLib/src/entity.js +1 -0
- package/lib/modules/gameLib/src/event.js +1 -0
- package/lib/modules/gameLib/src/index.js +1 -0
- package/lib/modules/gameLib/src/loger.js +1 -0
- package/lib/modules/gameLib/src/ui.js +1 -0
- package/lib/modules/gameLib/src/utils.js +1 -0
- package/lib/modules/gutils/mbler.config.json +12 -0
- package/lib/modules/gutils/src/index.js +1 -0
- package/lib/modules/innerDef.json +5 -0
- package/lib/runTemp/File.js +1 -0
- package/lib/runTemp/config.json +4 -0
- package/lib/runTemp/index.js +1 -0
- package/lib/runTemp/securityFile.js +1 -0
- package/lib/start/addPack.js +1 -0
- package/lib/start/clean.js +1 -0
- package/lib/start/create.js +1 -0
- package/lib/start/dev.js +1 -0
- package/lib/start/getResConfig.js +1 -0
- package/lib/start/incg.js +1 -0
- package/lib/start/index.js +1 -0
- package/lib/start/init.js +1 -0
- package/lib/start/rechce.js +1 -0
- package/lib/start/unaddPack.js +1 -0
- package/lib/start/unincg.js +1 -0
- package/lib/start/version.js +1 -0
- package/lib/utils/index.js +1 -0
- package/lib/uuid/index.js +1 -0
- package/package.json +1 -0
- package/test/2x sword/.cache__mbler__/config-hash.txt +1 -0
- package/test/2x sword/.cache__mbler__/package-hash.txt +1 -0
- package/test/2x sword/behavior/scripts/index.js +25 -0
- package/test/2x sword/mbler.config.json +12 -0
- package/test/2x sword/package.json +14 -0
- package/test/README.md +8 -0
- package/test/des/index.js +20 -0
- package/test/des/mbler.config.json +5 -0
- package/test/des/package.json +7 -0
- package/test/initializer/index.js +6 -0
- package/test/initializer/mbler.config.json +5 -0
- package/test/initializer/package.json +7 -0
- package/test/initializer/test.js +1 -0
- package/test/mbler-int/behavior/res/items/mang_one_int.json +22 -0
- package/test/mbler-int/behavior/res/pack_icon.png +0 -0
- package/test/mbler-int/behavior/res/recipes/mang_one_int.json +31 -0
- package/test/mbler-int/behavior/scripts/index.js +8 -0
- package/test/mbler-int/behavior/scripts/lib/event/index.js +20 -0
- package/test/mbler-int/behavior/scripts/lib/ui/Lore.js +19 -0
- package/test/mbler-int/behavior/scripts/lib/ui/baseUi.js +6 -0
- package/test/mbler-int/behavior/scripts/lib/ui/index.js +207 -0
- package/test/mbler-int/behavior/scripts/lib/utils/index.js +52 -0
- package/test/mbler-int/mbler.config.json +19 -0
- package/test/mbler-int/package.json +13 -0
- package/test/script-mbler/.cache__mbler__/config-hash.txt +1 -0
- package/test/script-mbler/.cache__mbler__/package-hash.txt +1 -0
- package/test/script-mbler/behavior/res/pack_icon.png +0 -0
- package/test/script-mbler/behavior/scripts/index.js +5 -0
- package/test/script-mbler/behavior/scripts/index.ts +6 -0
- package/test/script-mbler/mbler.config.json +15 -0
- package/test/script-mbler/package.json +16 -0
package/bin/build.js
ADDED
|
File without changes
|
package/bin/mbler.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @license MIT
|
|
5
|
+
* @description MCBE附加包开发工具
|
|
6
|
+
* @author github-Ruanhor
|
|
7
|
+
*/
|
|
8
|
+
const main = require('./../lib/start');
|
|
9
|
+
try {
|
|
10
|
+
new main(require('path').dirname(__dirname))
|
|
11
|
+
} catch (error) {
|
|
12
|
+
console.log("[runtime error]: " + error.stack);
|
|
13
|
+
process.exit(1)
|
|
14
|
+
}
|
package/bin/minify.js
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
const { execSync } = require('child_process');
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const { minify } = require('terser');
|
|
5
|
+
|
|
6
|
+
// 清理 dist 目录
|
|
7
|
+
fs.rmSync(path.join(__dirname, "../dist"), {
|
|
8
|
+
recursive: true,
|
|
9
|
+
force: true
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
// 编译 TypeScript
|
|
13
|
+
try {
|
|
14
|
+
execSync('tsc', {
|
|
15
|
+
stdio: 'inherit'
|
|
16
|
+
});
|
|
17
|
+
console.log('TypeScript 编译完成!');
|
|
18
|
+
} catch (error) {
|
|
19
|
+
console.error('TypeScript 编译失败:', error.message);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const distDir = path.resolve(__dirname, './../dist');
|
|
23
|
+
console.log(`🔍 扫描目录: ${distDir}`);
|
|
24
|
+
|
|
25
|
+
if (!fs.existsSync(distDir)) {
|
|
26
|
+
console.error('dist 目录不存在:', distDir);
|
|
27
|
+
process.exit(1);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const jsFiles = [];
|
|
31
|
+
const jsonFiles = [];
|
|
32
|
+
|
|
33
|
+
// 扫描编译后的 JS 文件
|
|
34
|
+
function scanDistDirectory(directory) {
|
|
35
|
+
const files = fs.readdirSync(directory);
|
|
36
|
+
files.forEach(file => {
|
|
37
|
+
const fullPath = path.join(directory, file);
|
|
38
|
+
const stat = fs.statSync(fullPath);
|
|
39
|
+
|
|
40
|
+
if (stat.isDirectory()) {
|
|
41
|
+
scanDistDirectory(fullPath); // 递归扫描子目录
|
|
42
|
+
} else if (file.endsWith('.js') && !file.endsWith('.min.js')) {
|
|
43
|
+
jsFiles.push(fullPath);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// 扫描源码中的 JSON 文件
|
|
49
|
+
function scanSrcJsonDirectory(directory) {
|
|
50
|
+
const files = fs.readdirSync(directory);
|
|
51
|
+
files.forEach(file => {
|
|
52
|
+
const fullPath = path.join(directory, file);
|
|
53
|
+
const stat = fs.statSync(fullPath);
|
|
54
|
+
|
|
55
|
+
if (stat.isDirectory()) {
|
|
56
|
+
scanSrcJsonDirectory(fullPath); // 递归扫描子目录
|
|
57
|
+
} else if (file.endsWith(".json")) {
|
|
58
|
+
// 计算对应的 dist 路径
|
|
59
|
+
const relativePath = path.relative(path.join(__dirname, "../src"), fullPath);
|
|
60
|
+
const distPath = path.join(distDir, "lib", relativePath);
|
|
61
|
+
jsonFiles.push({
|
|
62
|
+
srcPath: fullPath,
|
|
63
|
+
distPath: distPath
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
scanDistDirectory(distDir);
|
|
70
|
+
scanSrcJsonDirectory(path.join(__dirname, "../src"));
|
|
71
|
+
|
|
72
|
+
if (jsFiles.length === 0) {
|
|
73
|
+
console.log('没有找到需要压缩的文件');
|
|
74
|
+
process.exit(0);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
console.log(`${jsFiles.length} 个文件需要处理`);
|
|
78
|
+
|
|
79
|
+
async function processFiles() {
|
|
80
|
+
let successCount = 0;
|
|
81
|
+
let failCount = 0;
|
|
82
|
+
|
|
83
|
+
// 首先处理 JSON 文件复制
|
|
84
|
+
for (const jsonFile of jsonFiles) {
|
|
85
|
+
try {
|
|
86
|
+
console.log(`复制 JSON: ${jsonFile.srcPath} -> ${jsonFile.distPath}`);
|
|
87
|
+
|
|
88
|
+
try{ // 确保目标目录存在
|
|
89
|
+
await fs.promises.mkdir(path.dirname(jsonFile.distPath), { recursive: true });}catch{}
|
|
90
|
+
await fs.promises.copyFile(jsonFile.srcPath, jsonFile.distPath);
|
|
91
|
+
successCount++;
|
|
92
|
+
} catch (error) {
|
|
93
|
+
console.error(`处理失败 ${jsonFile.srcPath}:`, error.message);
|
|
94
|
+
failCount++;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// 然后处理 JS 文件压缩
|
|
99
|
+
for (const filePath of jsFiles) {
|
|
100
|
+
try {
|
|
101
|
+
// 处理 JS 文件压缩
|
|
102
|
+
const originalCode = fs.readFileSync(filePath, 'utf8');
|
|
103
|
+
const result = await minify(originalCode, {
|
|
104
|
+
compress: {
|
|
105
|
+
drop_console: false,
|
|
106
|
+
dead_code: true,
|
|
107
|
+
drop_debugger: true
|
|
108
|
+
},
|
|
109
|
+
mangle: true,
|
|
110
|
+
format: {
|
|
111
|
+
comments: false
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
if (result.error) {
|
|
116
|
+
throw new Error(result.error);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
fs.writeFileSync(filePath, result.code, 'utf8');
|
|
120
|
+
successCount++;
|
|
121
|
+
} catch (error) {
|
|
122
|
+
console.error(`处理失败 ${filePath}:`, error.message);
|
|
123
|
+
failCount++;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
console.log(`\n处理完成: 成功 ${successCount} 个, 失败 ${failCount} 个`);
|
|
128
|
+
// 复制其他必要文件
|
|
129
|
+
await Promise.all([
|
|
130
|
+
async function(){
|
|
131
|
+
const fileC = JSON.parse(await fs.promises.readFile(path.join(__dirname, "../package.json"), "utf-8"))
|
|
132
|
+
delete fileC.devDependencies
|
|
133
|
+
await fs.promises.writeFile(path.join(distDir, "package.json"), JSON.stringify(fileC))
|
|
134
|
+
}(),
|
|
135
|
+
fs.promises.cp(
|
|
136
|
+
path.join(__dirname, "../bin"),
|
|
137
|
+
path.join(__dirname, "../dist/bin"),
|
|
138
|
+
{ recursive: true, force: true }
|
|
139
|
+
),
|
|
140
|
+
fs.promises.cp(
|
|
141
|
+
path.join(__dirname, "../test"),
|
|
142
|
+
path.join(__dirname, "../dist/test"),
|
|
143
|
+
{ recursive: true, force: true }
|
|
144
|
+
)
|
|
145
|
+
]);
|
|
146
|
+
|
|
147
|
+
if (failCount > 0) {
|
|
148
|
+
process.exit(1);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
processFiles().catch(err => {
|
|
153
|
+
console.error('处理过程中出现错误:', err);
|
|
154
|
+
process.exit(1);
|
|
155
|
+
});
|
|
@@ -0,0 +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;
|
|
@@ -0,0 +1 @@
|
|
|
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};
|
|
@@ -0,0 +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"),index_js_5=__importDefault(require("./../mcx/index.js")),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 index_js_5.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;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,i,r,t){void 0===t&&(t=r);var n=Object.getOwnPropertyDescriptor(i,r);n&&!("get"in n?!i.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return i[r]}}),Object.defineProperty(e,t,n)}:function(e,i,r,t){void 0===t&&(t=r),e[t]=i[r]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(e,i){Object.defineProperty(e,"default",{enumerable:!0,value:i})}:function(e,i){e.default=i}),__importStar=this&&this.__importStar||function(){var e=function(i){return e=Object.getOwnPropertyNames||function(e){var i=[];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(i[i.length]=r);return i},e(i)};return function(i){if(i&&i.__esModule)return i;var r={};if(null!=i)for(var t=e(i),n=0;n<t.length;n++)"default"!==t[n]&&__createBinding(r,i,t[n]);return __setModuleDefault(r,i),r}}(),__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.ManiFest=void 0;const build_g_config_json_1=__importDefault(require("./build-g-config.json")),utils=__importStar(require("./../utils/index.js")),mcVersion_js_1=require("./mcVersion.js"),index_js_1=require("./../uuid/index.js"),path=__importStar(require("path")),config=build_g_config_json_1.default,isNonEmptyString=e=>"string"==typeof e&&e.trim().length>0;class ManiFest{data;constructor(e,i){this.data={format_version:2,header:{name:e.name,description:e.description,uuid:(0,index_js_1.fromString)(e.name,config[i].header),version:utils.ToArray(e.version),min_engine_version:utils.ToArray(e.mcVersion.toString())},modules:[{type:i,uuid:(0,index_js_1.fromString)(e.name,config[i].module),description:"From Mbler",version:utils.ToArray(e.version)}]},"data"===i&&e.script&&this.processScriptConfig(e,this.data)}processScriptConfig(e,i){const{script:r}=e;if(!r)return;let t=r.main||"index.js";if(t?.endsWith(".mcx")&&"mcx"===r.lang&&(t="index.js"),!isNonEmptyString(t))throw new Error("Script main entry is missing or invalid");i.dependencies||(i.dependencies=[]),i.dependencies.push({module_name:"@minecraft/server",version:mcVersion_js_1.mcVersionGeter.ToServer(e.mcVersion.toString(),Boolean(r.UseBeta))}),i.modules.push({type:"script",language:"javascript",entry:path.join("scripts",t).replace("\\","/ "),uuid:(0,index_js_1.fromString)(e.name,config.ScriptId),version:utils.ToArray(e.version)}),!0===r.ui&&i.dependencies.push({module_name:"@minecraft/server-ui",version:mcVersion_js_1.mcVersionGeter.ToServerUi(e.mcVersion.toString(),Boolean(r.UseBeta))}),i.capabilities=["script_eval"]}}exports.ManiFest=ManiFest;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.mcVersionGeter=void 0;const VERSION_TABLE=require("./../data/version.json").version,normalize=e=>String(e||"").trim(),parts=e=>normalize(e).split(".").slice(0,3).map(e=>parseInt(e,10)||0),compareVer=(e,r)=>{const t=parts(e),n=parts(r);for(let e=0;e<3;e++){const r=t[e],a=n[e];if(r&&a&&r!==a)return r>a?1:-1}return 0},findMatch=e=>{const r=normalize(e);for(const e of VERSION_TABLE){const[t,n]=e.range;if(compareVer(r,t)>=0&&compareVer(r,n)<=0)return{item:e,match:"exact",start:t,end:n}}const t=[...VERSION_TABLE].sort((e,r)=>compareVer(r.range[0],e.range[0]));for(const e of t)if(compareVer(r,e.range[0])>=0)return{item:e,match:"fallback",start:e.range[0],end:e.range[1]};const n=t[t.length-1];return{item:n,match:"oldest",start:n.range[0],end:n.range[1]}};exports.mcVersionGeter={ToServer(e,r=!1){const{item:t,match:n,start:a,end:o}=findMatch(e);return"exact"!==n&&console.warn(`⚠️ 使用兼容版本 ${a}-${o}(输入:${e})`),r?t.beta.server:t.format.server},ToServerUi(e,r=!1){const{item:t,match:n,start:a,end:o}=findMatch(e);return"exact"!==n&&console.warn(`⚠️ 使用兼容版本 ${a}-${o}(输入:${e})`),r?t.beta.server_ui:t.format.server_ui}};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";function next(e){process.stdout.write(`\r[${new Date}] ${e}`)}Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=next;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=default_1;const mtreehandler_1=__importDefault(require("./mtreehandler"));function default_1(e){return"string"!=typeof e?new mtreehandler_1.default(null):new mtreehandler_1.default(e)}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,r,i){void 0===i&&(i=r);var a=Object.getOwnPropertyDescriptor(t,r);a&&!("get"in a?!t.__esModule:a.writable||a.configurable)||(a={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,i,a)}:function(e,t,r,i){void 0===i&&(i=r),e[i]=t[r]}),__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 r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[t.length]=r);return t},e(t)};return function(t){if(t&&t.__esModule)return t;var r={};if(null!=t)for(var i=e(t),a=0;a<i.length;a++)"default"!==i[a]&&__createBinding(r,t,i[a]);return __setModuleDefault(r,t),r}}(),__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=processor;const fs=__importStar(require("fs/promises")),path=__importStar(require("path")),utils=__importStar(require("../utils/index.js")),c_handler_export_1=__importDefault(require("./c-handler-export")),terser_1=require("terser"),getModule_js_1=__importDefault(require("../build/getModule.js"));let gamelib_modules,forInscript=!1;async function replaceModuleImports(e,t,r,i){const a=(0,c_handler_export_1.default)(e);if(Array.isArray(t)){const s=a.get();if(s.length<1)return e;for(const e of t){const t=await gamelib_modules.getDir(e),o=(await utils.handlerPackage(t)).main,n=path.relative(path.dirname(r),path.join(i,"node_modules",path.basename(t),o)).split(path.sep).join("/"),c=s.find(t=>t.ModuleName===e);c&&a.set({ModuleName:`./${n}`,ImportItem:c.ImportItem})}}return a.generate()}async function processFile(e,t,r,i){try{const a=path.extname(e).slice(1),s=await fs.readFile(e,"utf-8");switch(a){case"js":let a=await replaceModuleImports(s,t,e,r);if(!0===i){const e=await(0,terser_1.minify)(a);e.code&&(a=e.code)}await fs.writeFile(e,a,"utf-8");break;case"json":let o=s;if(!0===i){const t=utils.JSONparse(s);o=JSON.stringify(t),forInscript&&await Promise.all([fs.writeFile(`${e}.js`,`export const data=${o}`),fs.rm(e,{recursive:!0,force:!0})])}break;case"map":case"ts":await fs.rm(e,{recursive:!0,force:!0})}}catch(t){console.log(e,t.message)}}async function processDir(e,t,r,i,a){const s=await fs.stat(e);gamelib_modules=await(0,getModule_js_1.default)(i);let o=!1;if(s.isDirectory()){const s=await fs.readdir(e);"scripts"===path.basename(e)&&(forInscript=!0,o=!0);for(const o of s)await processDir(path.join(e,o),t,r,i,a);forInscript&&o&&(forInscript=!1)}else s.isFile()?await processFile(e,t,r,a):console.warn(`跳过未知类型:${e}`)}async function processor(e,t){await processDir(e,t.modules||[],t.sourceDir,t.baseDir,t.minify)}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,r,i){void 0===i&&(i=r);var o=Object.getOwnPropertyDescriptor(t,r);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,i,o)}:function(e,t,r,i){void 0===i&&(i=r),e[i]=t[r]}),__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 r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[t.length]=r);return t},e(t)};return function(t){if(t&&t.__esModule)return t;var r={};if(null!=t)for(var i=e(t),o=0;o<i.length;o++)"default"!==i[o]&&__createBinding(r,t,i[o]);return __setModuleDefault(r,t),r}}(),__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0});const parser_1=require("@babel/parser"),traverse_1=__importDefault(require("@babel/traverse")),generator_1=__importDefault(require("@babel/generator")),types=__importStar(require("@babel/types"));class ImportManager{code;ast;imports;constructor(e){this.code=e,this.ast=null,this.imports=[],this._parse()}_parse(){this.code?(this.ast=(0,parser_1.parse)(this.code,{sourceType:"module"}),this._collectImports()):this.ast={program:{body:[]}}}_collectImports(){this.imports=[],(0,traverse_1.default)(this.ast,{ImportDeclaration:e=>{const t=e.node.source.value,r=e.node.specifiers.map(e=>"ImportDefaultSpecifier"===e.type?e.local.name:"ImportSpecifier"===e.type?"Identifier"==e.imported.type?e.imported.name:e.imported.value:"ImportNamespaceSpecifier"===e.type?"*"+e.local.name:null).filter(e=>null!==e);this.imports.push({moduleName:t,importItem:r})}})}has(e){return this.imports.some(t=>t.moduleName===e)}get(){return this.imports.map(e=>({ModuleName:e.moduleName,ImportItem:[...e.importItem]}))}set({ModuleName:e,ImportItem:t}){const r=this.imports.findIndex(r=>r.moduleName===e||r.importItem.some(e=>t.includes(e)));r>-1?this.imports[r]={moduleName:e,importItem:[...t]}:this.imports.push({moduleName:e,importItem:[...t]}),this._syncAST()}_syncAST(){(0,traverse_1.default)(this.ast,{ImportDeclaration(e){e.remove()}}),this.imports.forEach(e=>{const t=[];e.importItem.forEach(e=>{if("*"===e){const r=e.match(/\*\s+as\s+(\w+)/)||[];r&&t.push(types.importNamespaceSpecifier(types.identifier(r[1]||"")))}else e.endsWith("*")?t.push(types.importDefaultSpecifier(types.identifier(e.replace("*","")))):t.push(types.importSpecifier(types.identifier(e),types.identifier(e)))});const r=types.importDeclaration(t,types.stringLiteral(e.moduleName));this.ast.program.body.unshift(r)})}generate(){return(0,generator_1.default)(this.ast,{compact:!1}).code}}exports.default=ImportManager;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r);var s=Object.getOwnPropertyDescriptor(t,r);s&&!("get"in s?!t.__esModule:s.writable||s.configurable)||(s={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,s)}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),__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 r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[t.length]=r);return t},e(t)};return function(t){if(t&&t.__esModule)return t;var r={};if(null!=t)for(var n=e(t),s=0;s<n.length;s++)"default"!==n[s]&&__createBinding(r,t,n[s]);return __setModuleDefault(r,t),r}}();Object.defineProperty(exports,"__esModule",{value:!0}),exports.Input=void 0;const readline=__importStar(require("readline"));process.stdin.setRawMode(!0),readline.emitKeypressEvents(process.stdin);const promises=[],tasks=[];function handler(e,{ctrl:t,alt:r},n){const s=promises.find(n=>n.name===e&&n.ctrl===t&&n.alt===r);s&&(s.resolve(),promises.splice(promises.indexOf(s),1)),tasks.forEach(s=>s(e,t,r,n))}function click(e,{ctrl:t=!1,alt:r=!1}){return new Promise(n=>{promises.push({name:e,ctrl:t||!1,alt:r||!1,resolve:n})})}process.on("exit",e=>{process.stdout.write("[?25h")}),click("c",{ctrl:!0}).then(()=>process.exit(0));class Input{static render(e,t){return e.map((e,r)=>r===t?"[1m[32m"+e+"[0m":"[1m[33m"+e+"[0m").join(" ")}static select(e,t){let r=0,n=!1;console.log(`[2K[47m[1m[30m${e} (按 b 确认,n 键选择下一个) [0m[?25l`),console.log(Input.render(t,r)+"\n[1A");const s=()=>{n||(r++,r>=t.length&&(r=0),console.log(`[1A${Input.render(t,r)}\n[1A`),click("n",{ctrl:!1,alt:!1}).then(s))};return new Promise(e=>{click("n",{ctrl:!1,alt:!1}).then(s),click("b",{ctrl:!1,alt:!1}).then(()=>{n=!0,process.stdout.write("[?25h"),e(t[r])})})}static use(e){tasks.push(e)}}exports.Input=Input,process.stdin.on("keypress",(e,t)=>{handler(t?.name||"",{ctrl:Boolean(t?.ctrl),alt:Boolean(t?.alt)},e)});
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
{
|
|
2
|
+
"description": "版本表",
|
|
3
|
+
"version": [
|
|
4
|
+
{
|
|
5
|
+
"range": [
|
|
6
|
+
"1.21.130",
|
|
7
|
+
"1.21.139"
|
|
8
|
+
],
|
|
9
|
+
"format": {
|
|
10
|
+
"server": "2.4.0",
|
|
11
|
+
"server_ui": "2.0.0"
|
|
12
|
+
},
|
|
13
|
+
"beta": {
|
|
14
|
+
"server": "2.5.0-beta",
|
|
15
|
+
"server_ui": "2.1.0-beta"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"range": [
|
|
20
|
+
"1.21.120",
|
|
21
|
+
"1.21.129"
|
|
22
|
+
],
|
|
23
|
+
"format": {
|
|
24
|
+
"server": "2.3.0",
|
|
25
|
+
"server_ui": "2.0.0"
|
|
26
|
+
},
|
|
27
|
+
"beta": {
|
|
28
|
+
"server": "2.4.0-beta",
|
|
29
|
+
"server_ui": "2.1.0-beta"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"range": [
|
|
34
|
+
"1.21.110",
|
|
35
|
+
"1.21.119"
|
|
36
|
+
],
|
|
37
|
+
"format": {
|
|
38
|
+
"server": "2.2.0",
|
|
39
|
+
"server_ui": "2.0.0"
|
|
40
|
+
},
|
|
41
|
+
"beta": {
|
|
42
|
+
"server": "2.3.0-beta",
|
|
43
|
+
"server_ui": "2.1.0-beta"
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
"range": [
|
|
48
|
+
"1.21.90",
|
|
49
|
+
"1.21.109"
|
|
50
|
+
],
|
|
51
|
+
"format": {
|
|
52
|
+
"server": "2.1.0",
|
|
53
|
+
"server_ui": "2.0.0"
|
|
54
|
+
},
|
|
55
|
+
"beta": {
|
|
56
|
+
"server": "2.2.0-beta",
|
|
57
|
+
"server_ui": "2.1.0-beta"
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
"range": [
|
|
62
|
+
"1.21.70",
|
|
63
|
+
"1.21.89"
|
|
64
|
+
],
|
|
65
|
+
"format": {
|
|
66
|
+
"server": "1.19.0",
|
|
67
|
+
"server_ui": "1.3.0"
|
|
68
|
+
},
|
|
69
|
+
"beta": {
|
|
70
|
+
"server": "2.0.0-beta",
|
|
71
|
+
"server_ui": "2.0.0-beta"
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
"range": [
|
|
76
|
+
"1.21.60",
|
|
77
|
+
"1.21.69"
|
|
78
|
+
],
|
|
79
|
+
"format": {
|
|
80
|
+
"server": "1.17.0",
|
|
81
|
+
"server_ui": "1.3.0"
|
|
82
|
+
},
|
|
83
|
+
"beta": {
|
|
84
|
+
"server": "1.18.0-beta",
|
|
85
|
+
"server_ui": "1.4.0-beta"
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
]
|
|
89
|
+
}
|
package/lib/git/clone.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=gitClone;const child_process_1=require("child_process");function gitClone(e,r){return new Promise((o,s)=>{const t=(0,child_process_1.spawn)("git",["clone",e,r],{stdio:"inherit"});t.on("close",t=>{0===t?o(`Git 克隆成功: ${e} → ${r}`):s(new Error(` Git 克隆失败,退出码: ${t}`))}),t.on("error",e=>{s(new Error(`${e.message}`))})})}
|
package/lib/git/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0});const clone_js_1=__importDefault(require("./clone.js")),pull_js_1=__importDefault(require("./pull.js"));class GitRepo{static clone=clone_js_1.default;static pull=pull_js_1.default}exports.default=GitRepo;
|
package/lib/git/pull.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=gitPull;const child_process_1=require("child_process"),index_js_1=require("./../utils/index.js"),index_js_2=__importDefault(require("./../lang/index.js"));function gitPull(e){return new Promise((i,r)=>{async function o(){const o=(0,child_process_1.spawn)("git",["pull"],{cwd:e,stdio:"inherit"});o.on("close",e=>{0===e?i(!0):r(new Error(`❌ Git 拉取重试失败,退出码: ${e}`))}),o.on("error",e=>{r(new Error(`❌ 重试执行错误: ${e.message}`))})}(0,child_process_1.spawn)("git",["pull"],{cwd:e,stdio:"inherit"}).on("close",n=>{if(0===n)return console.log(`Git 拉取成功: ${e}`),void i(!0);let t="";const s=(0,child_process_1.spawn)("git",["pull"],{cwd:e,stdio:["ignore","pipe","pipe"]});s.stderr.on("data",e=>{t+=e.toString()}),s.on("close",async i=>{if(0!==i&&t.includes("dubious ownership")){const i=index_js_2.default.noGit,n=await(0,index_js_1.input)(i);"1"===n?(await runGitConfig(`--global --add safe.directory "${e}"`),o()):"2"===n?(await runGitConfig('--global --replace-all safe.directory "*"'),o()):r("3"===n?new Error("用户取消 Git 拉取"):new Error("无效的用户输入"))}else r(new Error(`❌ Git 拉取失败,退出码: ${i}\n错误信息: ${t}`))})})})}function runGitConfig(e){return new Promise((i,r)=>{const o=(0,child_process_1.spawn)("git",["config",...e.split(" ")],{stdio:"inherit"});o.on("close",e=>{0===e||console.warn(`执行 git config 失败(可能不影响后续操作),退出码: ${e}`),i(!0)}),o.on("error",e=>{i(!0)})})}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const fs=require("fs"),API="http://localhost:8000/translate",MAX_RETRY=5,DELAY=500;async function main(){const[,,t,e,n]=process.argv;t&&e&&n||(console.error("Usage: node translate-json.js zh_CN.json en_US.json en"),process.exit(1));const o=t=>new Promise(e=>setTimeout(e,t));function r(t,e="",n={}){for(const o in t){const s=e?`${e}.${o}`:o;"object"==typeof t[o]&&null!==t[o]?r(t[o],s,n):n[s]=String(t[o])}return n}async function s(t){if("object"==typeof t){const e={};for(let n in Object.keys(t)){const o=await s(t[n]);e[n]=o}return e}for(let e=1;e<=5;e++){try{const e=await fetch(API,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:t,to:n})}),o=await e.json();if(o?.status&&o.translatedText)return o.translatedText}catch{}console.warn(`⚠️ retry ${e}/5`),await o(500*e)}throw new Error("Translation failed after retries")}const a=require(`./${t}`),c=require(`./${e}`),i=r(a),l=r(c),f=Object.keys(i).filter(t=>!l[t]);console.log(`🔍 need translate: ${f.length}`);for(const t of f){const e=i[t];console.log(`🌐 ${t}: ${e}`);try{l[t]=Array.isArray(e)?e:await s(e),await o(500)}catch(n){console.error(`❌ failed: ${t}`),l[t]=e}}fs.writeFileSync(e,JSON.stringify(function(t){const e={};for(const n in t)n.split(".").reduce((e,o,r,s)=>(r===s.length-1?e[o]=t[n]:e[o]??={},e[o]),e);return e}(l),null,2))}main().then(()=>console.log("✅ done"));
|
package/lib/lang/en.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default={help:"MBLER\nMinecraft Bedrock Edition\nAddon Bulider In Nodejs\nnodejs build tools on bedrock version of minecraft\nSolve the problem of checking documents everywhere to configure api version\nUsage: node index.js [command]\n* You can also omit the node prefix after npm link link\nCommands: dev, install, build, init, version, -v, web_edit, clean, checkout, -c, -i, v, create, recache, lang\nHelp command:\n help\n Show help information\n The second parameter is the name of the command to be queried or empty\n Alias: -h, -help\n git https://github.com/RuanhoR/mbler/",config_invalid:"Non-GameLib projects",err_bulid:"Build error",uncommand:"Invalid command",s0:"Operation successful",noGit:"Git security restrictions detected\nGit is rejecting the operation because the directory might not belong to the current user or be in a system-protected path.\nPlease select a processing method:\n\n1: Only add the current directory to the trusted zone (recommended, safe)\n2: Globally trust all directories (not recommended, but convenient)\n3: Cancel operation",SameDes:"Dependencies with the same name",invalidConfig:"Invalid configuration",inited:"Already initialized",noGitRepo:"The requested git repository was not specified and the installation failed.",invalidDes:"invalid dependency",workPackV:"Current working directory package version:",cleanFinally:"Clean build successful",noCommandTip:"Do you want to express:",init:{name:"Project name:",desc:"Project description:",useMcVersion:"Supported minecraft versions:",useSapi:"Use Script API? (Y/N)",useTs:"Using TypeScript? (Y/N)",InputFormatErr:"It is not the correct version number in x.x.x format, please re-enter it.",main:"Main script path (such as ./index.js):",useUi:"Use UI? (Y/N)",ReInput:"Not meeting specifications. Try again:"},dev:{start:"Start monitoring the build in real time. The following is the first build.",start_d:"Start an incremental build",tip:"Listen for changes:"},installGit:{NoPackage:"This GIT repository does not contain a properly configured mbler",InstallFinally:"Installation completed",HadBeen:"There is already a dependent package with the same package name. Do you want to replace it? Y/N",SetContent:"Modifying index table"},vm:{shouldNotImp:"Importing a module is prohibited because it can be used in unsafe ways",runScriptErr:"Error running script, error stack"},build:{build_info_header:"--- Build information list ---",project_path:"Project path:",output_dir:"Output directory:",minify_enabled:"Enable compression:",build_time:"Build time:",build_success:"Build successfully. Time taken:",build_failed:"Build failed",config_invalid:"Invalid configuration",package_file_missing_fields:'Missing fields: required fields ["name","description","version","mcVersion"]',script_main_entry_missing:"script is enabled, but main entry file is not specified",subpack_folder_not_found:"{id} sub-package folder does not exist, packaging failed",subpack_processing_failed:"Subpackage {id} failed to process: {error}",includes_not_array:"includes.json is not an array, skip resource copying",ts_no_files:"No .ts files found, skipping TypeScript compilation",ts_diagnostics:"{file} ({line},{character}): {message}",ts_compilation_error:"Error compiling TypeScript",no_ts_files_skip:"No .ts files found, skipping TypeScript compilation",copying_subpack_script:"Subpackage script directory copied",copying_subpack_resources:"Copying subpackage other resources",removing_js_files:"Remove the .js files in the script directory",copying_compiled_ts:"Copy the compiled TypeScript file",minification_error:"Code compression failed",temp_mod_init:"Initialize temporary module directory",script_entry_required:"script is enabled but the main entry is not set",invalid_script_entry:"The main entry file is empty or invalid",module_copy_success:"Module copied to output directory",invalid_subpack_type:"subpack is not an object, skip processing",invalid_includes_type:"includes.json is not an array, skip resource copying",handle_includes_info:"Handle includes resource copy",minification_skipped:"includes.json is not an array, skips code compression",remove_js_files_info:"Remove compiled .js files (e.g. from ts)",process_minification:"Start code compression processing",copy_compiled_ts_only:"Copy only compiled ts files",temp_mod_usage:"Using a temporary directory to handle TypeScript compilation",build_failed_catch:"The build process terminated abnormally",error_message_log:"error message:",exit_with_code:"Process exits with code:",class_pri_locked:"Lock key attributes within a class",object_pri_enforced:"Setting object properties is not enumerable",no_resources:"Resource package resource not found, resource compilation skipped",ziped:"The zip compression is complete and you can directly import the game.\nThe mcaddon file is in:",tip_dist:"Packaging mode:"},buildBase:{npm_deps_skipped_no_json:"npm dependency not found, skip installation",build_time:"Build time",cannot_read_project_config:"Unable to read project configuration file",invalid_project_config_format:"Project configuration file format is invalid",starting_npm_install:"Start installing npm dependencies",npm_install_completed:"Dependency installation completed",npm_install_exit_code:"npm install exit code:",npm_install_error:"npmInstall error",calculating_sha1:"Calculate file SHA1 hash value",file_not_exist:"File does not exist",config_hash_stored:"Configuration hash stored",package_hash_stored:"Packet hash stored",config_changed:"Configuration has changed",package_changed:"Package has changed",saving_current_hash:"Save current hash to cache",removing_js_files:"Remove the .js files in the script directory",removing_js_error_ignored:"Remove .js file error, ignored",removing_npm_des:"Remove npm dependency description",module_not_included:"Module not included, skip deletion",recursive_remove_js:"Recursively remove Js files",reading_file_content:"Read file contents"},commands:{list:["dev","install","build","init","version","-v","web_edit","clean","checkout","-c","-i","v","create","recache","lang"],dev:"mblerdev\nMonitor files and repackage when modified",build:"mbler build\nPackage the project, package the mbler project into a standard mcbe behavior package, see the document for details on the mbler project",init:"mbler init\nInitialization path configuration file, created interactively from the command line, alias: -i",version:"mbler version [null | x.x.x]\nView or set the package version of the current working directory","-c":"$checkout","-i":"$init","-v":"$v",v:"mbler [v/-v]\nCheck the version of the mbler tool itself",checkout:"mbler [checkout/-c] [null | PATH]\nView (when the second parameter is null) or switch the working directory",web_edit:"mbler web_edit\nOpen the text editor of the local HTTP working directory. It is not recommended to use during development.",create:"mbler create [npm package name | git url | path]\nAfter downloading from the specified source (with cache), create the template package in the sandbox vm, similar to npm create",recache:"mbler recache\nreset cache",lang:"mbler lang [lang name]\nSet the language, such as mbler lang zh_CN\nThe current languages are\n 1. zh 中文\n 2. en English",install:"mbler install [modulesName[]]\nWhen installing a module, the modules declared in the configuration will be scanned."}};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.cleanFinally=cleanFinally,exports.s0=s0;const node_fs_1=__importDefault(require("node:fs")),zh_js_1=__importDefault(require("./zh.js")),en_js_1=__importDefault(require("./en.js")),node_path_1=__importDefault(require("node:path")),langs=["zh","en"],configPath=node_path_1.default.join(require("node:os").homedir(),".cache/mbler/.lang.db");class Lang{currenyLang="zh";init(){try{const e=node_fs_1.default.readFileSync(configPath,"utf-8").toString().trim();if("zh"!=e&&"en"!=e)throw new Error("[setup lang]: set lang error");this.currenyLang=e}catch{this.currenyLang="zh"}}set(e){return!!langs.includes(e)&&(node_fs_1.default.existsSync(configPath)||node_fs_1.default.mkdirSync(node_path_1.default.dirname(configPath),{recursive:!0}),node_fs_1.default.writeFileSync(configPath,e),this.currenyLang=e,!0)}async get(){try{return"zh"==this.currenyLang?zh_js_1.default:en_js_1.default}catch{return zh_js_1.default}}}let exp={};async function Export(e){const t=await e.get();Object.setPrototypeOf(exp,{...t,__internal:{class:e,set:t=>{e.set(t),Export(e)}}})}const lang=new Lang;function cleanFinally(e,t){throw new Error("Function not implemented.")}function s0(e){throw new Error("Function not implemented.")}lang.init(),Export(lang),exports.default=exp;
|
package/lib/lang/zh.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const cmdList=["dev","install","build","init","version","-v","web_edit","clean","checkout","-c","-i","v","create","recache","lang"];exports.default={help:`MBLER\nMinecraft Bedrock Edition\nAddon Bulider In Nodejs\n在基岩版我的世界上的 nodejs 构建工具\n解决到处查文档配置 api 版本的难题\n用法: node index.js [command]\n* 也可以 npm link 链接后省略 node 前缀\n命令 : ${cmdList.join(", ")}\n帮助命令 : \n help\n 显示帮助信息\n 第二个参数为要查询的命令名称或空\n 别名: -h, -help\n git https://github.com/RuanhoR/mbler/`,config_invalid:"非 GameLib 项目",err_bulid:"构建错误",uncommand:"无效的命令",s0:"操作成功 ",noGit:"\n检测到 Git 安全限制\nGit 拒绝操作,因为该目录可能不属于当前用户或位于系统保护路径。\n请选择处理方式:\n\n1 : 仅将当前目录加入可信区(推荐,安全)\n2 : 全局信任所有目录(不推荐,但方便)\n3 : 取消操作",SameDes:"同名的依赖",invalidConfig:"无效的配置",inited:"已经初始化过了",noGitRepo:"没有指定索取的git仓库,安装失败",invalidDes:"无效的依赖",workPackV:"当前工作目录包版本:",cleanFinally:"清理构建版本成功",noCommandTip:"你是否想表达 : ",init:{name:"项目名称 : ",desc:"项目描述 : ",useMcVersion:"支持的minecraft版本 : ",useSapi:"使用Script Api吗?(Y/N) ",useTs:"使用TypeScript吗?(Y/N) ",InputFormatErr:"不是正确的x.x.x格式版本号,重新输入\n ",main:"主脚本路径(如 ./index.js): ",useUi:"使用 UI 吗?(Y/N) ",ReInput:"不符合规范 重试:\n "},dev:{start:"开始即时监听构建 以下为第一次构建",start_d:"开始增量构建",tip:"监听到变化 : "},installGit:{NoPackage:"此 GIT 库未包含正确配置mbler",InstallFinally:"安装完成",HadBeen:"已有相同包名依赖包,是否替换? Y/N",SetContent:"正在修改索引表"},vm:{shouldNotImp:"禁止导入模块,因为该模块可以用于不安全举动",runScriptErr:"运行脚本出错,错误栈 "},build:{build_info_header:"--- 构建信息一览表 ---",project_path:"项目路径:",output_dir:"输出目录:",minify_enabled:"启用压缩:",build_time:"构建时间:",build_success:"构建成功 耗时 :",build_failed:"构建失败",config_invalid:"配置无效",package_file_missing_fields:`字段缺失:必需字段 ${JSON.stringify(["name","description","version","mcVersion"])}`,script_main_entry_missing:"启用了 script,但未指定 main 入口文件",subpack_folder_not_found:"{id} 子包文件夹不存在,打包失败",subpack_processing_failed:"子包 {id} 处理失败: {error}",includes_not_array:"includes.json 不是数组,跳过资源复制",ts_no_files:"未发现任何 .ts 文件,跳过 TypeScript 编译",ts_diagnostics:"{file} ({line},{character}): {message}",ts_compilation_error:"编译 TypeScript 时出错",no_ts_files_skip:"未发现任何 .ts 文件,跳过 TypeScript 编译",copying_subpack_script:"已复制子包脚本目录",copying_subpack_resources:"正在复制子包其他资源",removing_js_files:"移除脚本目录中的 .js 文件",copying_compiled_ts:"复制编译后的 TypeScript 文件",minification_error:"代码压缩失败",temp_mod_init:"初始化临时模块目录",script_entry_required:"script 启用但未设置 main 入口",invalid_script_entry:"main 入口文件为空或无效",module_copy_success:"模块已复制到输出目录",invalid_subpack_type:"subpack 不是对象,跳过处理",invalid_includes_type:"includes.json 不是数组,跳过资源复制",handle_includes_info:"处理 includes 资源拷贝",minification_skipped:"includes.json 非数组,跳过代码压缩",remove_js_files_info:"移除编译出的 .js 文件(如来自 ts)",process_minification:"开始代码压缩处理",copy_compiled_ts_only:"仅复制编译后的 ts 文件",temp_mod_usage:"使用临时目录处理 TypeScript 编译",build_failed_catch:"构建流程异常终止",error_message_log:"错误信息: ",exit_with_code:"进程退出,代码: ",class_pri_locked:"锁定类内关键属性",object_pri_enforced:"设置对象属性不可枚举",no_resources:"没找到资源包资源,跳过资源编译",ziped:"zip 压缩完成,你可以直接导入游戏啦\nmcaddon文件在 : ",tip_dist:"打包模式 :"},buildBase:{npm_deps_skipped_no_json:"没有找到npm依赖,跳过安装",build_time:"构建时间",cannot_read_project_config:"无法读取项目配置文件",invalid_project_config_format:"项目配置文件格式无效",starting_npm_install:"开始安装 npm 依赖",npm_install_completed:"依赖安装完成",npm_install_exit_code:"npm install 退出码:",npm_install_error:"npmInstall 错误",calculating_sha1:"计算文件 SHA1 哈希值",file_not_exist:"文件不存在",config_hash_stored:"配置哈希已存储",package_hash_stored:"包哈希已存储",config_changed:"配置已变更",package_changed:"包已变更",saving_current_hash:"保存当前哈希到缓存",removing_js_files:"移除脚本目录中的 .js 文件",removing_js_error_ignored:"移除 .js 文件错误,已忽略",removing_npm_des:"移除 npm 依赖描述",module_not_included:"模块未包含,跳过删除",recursive_remove_js:"递归移除 Js 文件",reading_file_content:"读取文件内容"},commands:{list:cmdList,dev:"mbler dev \n监听文件,在修改时重打包",build:"mbler build \n打包项目,把mbler项目打包成标准mcbe行为包,mbler项目介绍详见文档",init:"mbler init \n初始化路径的配置文件,以命令行交互式创建,别名: -i",version:"mbler version [null | x.x.x] \n查看或设置当前工作目录的包版本","-c":"$checkout","-i":"$init","-v":"$v",v:"mbler [v/-v] \n查看mbler工具本身的版本",checkout:"mbler [checkout/-c] [null | PATH]\n查看(当第二个参数为null时)或切换工作目录",web_edit:"mbler web_edit \n开启本地 HTTP 工作目录的文本编辑器,开发中不建议食用",create:"mbler create [npm package name | git url | path]\n从指定源下载后(有缓存)进行在沙盒vm内的创建模板包,类似npm create",recache:"mbler recache \n重置缓存",lang:"mbler lang [lang name] \n设置语言,如 mbler lang zh_CN\n目前语言有 \n 1. zh 中文 \n 2. en 英文",install:"mbler install [modulesName[]]\n安装模块,会顺便扫描配置中声明的模块"}};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.white=exports.cyan=exports.yellow=exports.red=exports.reset=void 0;const reset="[0m";exports.reset=reset;const red="[31m";exports.red=red;const yellow="[33m";exports.yellow=yellow;const cyan="[36m";exports.cyan=cyan;const white="[37m";exports.white=white;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,r,o){void 0===o&&(o=r);var i=Object.getOwnPropertyDescriptor(t,r);i&&!("get"in i?!t.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,o,i)}:function(e,t,r,o){void 0===o&&(o=r),e[o]=t[r]}),__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 r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[t.length]=r);return t},e(t)};return function(t){if(t&&t.__esModule)return t;var r={};if(null!=t)for(var o=e(t),i=0;i<o.length;i++)"default"!==o[i]&&__createBinding(r,t,o[i]);return __setModuleDefault(r,t),r}}(),__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0});const colors_js_1=require("./colors.js"),util_1=__importDefault(require("util")),utils=__importStar(require("./../utils/index.js")),LEVELS={ERROR:"ERROR",WARN:"WARN",INFO:"INFO",DEBUG:"DEBUG"},LEVEL_COLORS={[LEVELS.ERROR]:colors_js_1.red,[LEVELS.WARN]:colors_js_1.yellow,[LEVELS.INFO]:colors_js_1.white,[LEVELS.DEBUG]:colors_js_1.cyan};class Logger{[util_1.default.inspect.custom]=this.toString;#e(e,t,r,o){const i=(new Date).toISOString(),n=utils.toString(o);this.getConsole(t.toLowerCase(),`${r}[${t}] [${e}] ${i}: ${n} ${colors_js_1.reset}`)}getConsole(e,t){switch(e){case"error":console.error(t);break;case"info":default:console.info(t);break;case"warn":console.warn(t);break;case"debug":console.debug(t)}}e(e,...t){this.#e(e,LEVELS.ERROR,LEVEL_COLORS[LEVELS.ERROR],t)}w(e,...t){this.#e(e,LEVELS.WARN,LEVEL_COLORS[LEVELS.WARN],t)}i(e,...t){this.#e(e,LEVELS.INFO,LEVEL_COLORS[LEVELS.INFO],t)}d(e,...t){this.#e(e,LEVELS.DEBUG,LEVEL_COLORS[LEVELS.DEBUG],t)}toString(){return"[object Logger]"}}exports.default=new Logger;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var __importDefault=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(exports,"__esModule",{value:!0});const tag_js_1=__importDefault(require("./tag.js")),prop_js_1=__importDefault(require("./prop.js"));exports.default={tag:tag_js_1.default,prop:prop_js_1.default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Lexer=void 0,exports.default=PropParser;const STATUS=[0,1];class Lexer{code;constructor(e){this.code=e}*tokenize(){let e=STATUS[0],r="",t="",s=!1;for(const o of this.code)if(/\s/.test(o)){if("\n"===o){if(e===STATUS[1]&&r&&t){const e={key:r,value:this.HandlerValue(t),type:"PropChar"};yield e}r="",t="",s=!1,e=STATUS[0]}}else"="===o?e===STATUS[0]&&(e=STATUS[1],s=!0):e===STATUS[0]?r+=o:e===STATUS[1]&&(t+=o);if(r&&t){const e={key:r,value:this.HandlerValue(t),type:"PropChar"};yield e}}HandlerValue(e){try{const r=Number(e);if(!Number.isNaN(r))return r;if(["[","{"].includes(e.slice(0,1))&&["]","}"].includes(e.slice(-1)))return JSON.parse(e)}catch{}return e}}function PropParser(e){const r=new Lexer(e);return Array.from(r.tokenize())}exports.Lexer=Lexer;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});class Lexer{text;booleanProxyCache;constructor(t){this.text=t,this.booleanProxyCache=new WeakMap}get tokens(){return{[Symbol.iterator]:()=>this.tokenIterator()}}parseAttributes(t){const e={};let r="",n="",o=!0,a="",s=!1,l=null,i=!0;for(let c=0;c<t.length;c++){const h=t[c];if(i)if(" "===h||">"===h){if(a=r.trim(),r="",i=!1,">"===h)break}else r+=h;else if(s)h!==l||0!==n.length&&"\\"===n[n.length-1]?n+=h:(e[r.trim()]=n,r="",n="",o=!0,s=!1,l=null);else if("="===h&&o){o=!1,s=!0;const e=c+1,r=e<t.length?t[e]:" ";l='"'===r||"'"===r?r:null}else" "===h&&o&&r?(e[r.trim()]="true",r=""):o&&(r+=h)}return i?a=r.trim():r&&(e[r.trim()]=s?n.replace(/^["']/,"").replace(/["']$/,""):"true"),{name:a,arr:e}}*tagSplitIterator(){let t=!1,e="",r="";for(const n of this.text)if("<"===n){if(r){const t={data:r,type:"Content"};yield t,r=""}t=!0,e="<"}else if(">"===n){if(!t)throw new Error("未匹配的 '>'");e+=">",t=!1;const r=e.startsWith("</")?"TagEnd":"Tag",n={data:e,type:r};yield n,e=""}else t?e+=n:r+=n;if(r){const t={data:r,type:"Content"};yield t}}*tokenIterator(){const t=Array.from(this.tagSplitIterator());let e=null,r=0;for(let n=0;n<t.length;n++){const o=t[n];if(o)if("Tag"===o.type){const t=this.parseAttributes(o.data.slice(1,-1));e={start:o,name:t.name,arr:t.arr,content:null,end:null},r=n+1}else if("TagEnd"===o.type&&e){e.end=o;let a="";for(let e=r;e<n;e++){a+=t[e].data}const s={data:a,type:"TagContent"};e.content=s;const l={start:e.start,name:e.name,arr:e.arr,content:e.content,end:e.end};yield l,e=null}}}getBooleanCheckProxy(){if(!this.booleanProxyCache.has(this)){const t=new Map,e=new Proxy({},{get:(e,r)=>"string"==typeof r&&(t.get(r)||!1),set:(e,r,n)=>"string"==typeof r&&(t.set(r,Boolean(n)),!0)});this.booleanProxyCache.set(this,e)}return this.booleanProxyCache.get(this)}}class McxAst{text;constructor(t){this.text=t}getAST(){const t=new Lexer(this.text);return Array.from(t.tokens)}get data(){return this.getAST()}parseAST(){return this.getAST()}static generateCode(t){let e=`<${t.name}`;for(const[r,n]of Object.entries(t.arr))e+="true"===n?` ${r}`:` ${r}=${n}`;return e+=">",t.content&&(e+=t.content.data),e+=`</${t.name}>`,e}}exports.default=McxAst;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ItemComponent=void 0;class ItemComponent{#t;constructor(t){this.#t=t}toJSON(){if(!this.#t)throw new Error("[mcx component]: cannot read component");const t={format_version:"","minecraft:item":{components:{},description:{identifier:""}}};if("string"!=typeof this.#t.format||!/\d.\d.\d/.test(this.#t.format))throw new Error("[compile component]: no format");if(t.format_version=this.#t.format,"string"!=typeof this.#t.id||!/[a-zA-Z0-9_]:[a-zA-Z0-9_]/.test(this.#t.id))throw new Error("[compile component]:cno id");t["minecraft:item"].description.identifier=this.#t.id;const e=t["minecraft:item"].components;if("string"==typeof this.#t.name&&(e["minecraft:display_name"]={value:this.#t.name}),this.#t.components){const t=this.#t.components;"number"==typeof t.damage&&(e["minecraft:damage"]={value:t.damage}),"boolean"==typeof t.offHand&&t.offHand&&(e["minecraft:allow_off_hand"]={value:!0}),"boolean"==typeof t.DestroyInCreate&&(e["minecraft:can_destroy_in_creative"]={value:t.DestroyInCreate})}return t}setName(t){if("string"!=typeof t)throw new Error("[set error]: name type error");this.#t.name=t}setIcon(t){if("string"!=typeof t)throw new Error("[set error]: icon: type error");this.#t.components.icon=t}getName(){return this.#t.name}setId(t){if("string"!=typeof t)throw new Error("[set error]: id: type error");this.#t.id}getId(){}}exports.ItemComponent=ItemComponent,exports.default={Item:ItemComponent};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const normalize=r=>String(r||"").trim(),parts=r=>normalize(r).split(".").slice(0,3).map(r=>parseInt(r,10)||0),compareVar=(r,e)=>{const t=parts(r),s=parts(e);for(let r=0;r<3;r++){const e=t[r],a=s[r];if(e&&a&&e!==a)return e>a?1:-1}return 0};exports.default=compareVar;
|