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.
- package/LICENSE +21 -0
- package/README.md +28 -0
- package/lib/build/base.js +297 -1
- package/lib/build/build-g-config.json +11 -11
- package/lib/build/getModule.js +182 -1
- package/lib/build/index.js +370 -1
- package/lib/build/manifest.build.js +103 -1
- package/lib/build/mcVersion.js +86 -1
- package/lib/build/utils.js +6 -1
- package/lib/code-processor/c-handler-export.js +12 -1
- package/lib/code-processor/index.js +141 -1
- package/lib/code-processor/mtreehandler.js +164 -1
- package/lib/commander/index.js +154 -1
- package/lib/data/includes.json +12 -12
- package/lib/git/clone.js +28 -1
- package/lib/git/index.js +12 -1
- package/lib/git/pull.js +100 -1
- package/lib/lang/__translate.js +93 -1
- package/lib/lang/en.js +128 -1
- package/lib/lang/index.js +78 -1
- package/lib/lang/zh.js +146 -1
- package/lib/loger/colors.js +13 -1
- package/lib/loger/index.js +136 -1
- package/lib/mcx/ast/index.js +11 -1
- package/lib/mcx/ast/prop.js +78 -1
- package/lib/mcx/ast/tag.js +246 -1
- package/lib/mcx/compile-component/lib.js +106 -1
- package/lib/mcx/compile-component/types.js +2 -1
- package/lib/mcx/compile-component/utils.js +26 -1
- package/lib/mcx/compile-mcx/_compile.js +1 -1
- package/lib/mcx/compile-mcx/compile.js +34 -1
- package/lib/mcx/compile-mcx/context.js +19 -1
- package/lib/mcx/compile-mcx/index.js +10 -1
- package/lib/mcx/compile-mcx/mcx/index.js +2 -1
- package/lib/mcx/compile-mcx/mcx/types.js +2 -1
- package/lib/mcx/compile-mcx/template/module.js +42 -1
- package/lib/mcx/compile-mcx/types.js +2 -1
- package/lib/mcx/compile-mcx/utils.node.js +207 -1
- package/lib/mcx/index.js +13 -1
- package/lib/mcx/test/index.js +7 -1
- package/lib/mcx/test.js +21 -1
- package/lib/mcx/types.js +2 -1
- package/lib/mcx/utils.js +86 -1
- package/lib/module-handler/index.js +482 -1
- package/lib/modules/create-game/src/Runner/RunnerManager.js +113 -1
- package/lib/modules/create-game/src/Runner/scriptRunner.js +70 -1
- package/lib/modules/create-game/src/config.js +27 -1
- package/lib/modules/create-game/src/constants.js +19 -1
- package/lib/modules/create-game/src/createGameModule.js +24 -1
- package/lib/modules/create-game/src/gameComponent/common/autoStop.js +38 -1
- package/lib/modules/create-game/src/gameComponent/common/lazyLoader.js +76 -1
- package/lib/modules/create-game/src/gameComponent/common/stopWatch/onTimeEvent.js +36 -1
- package/lib/modules/create-game/src/gameComponent/common/stopWatch/stopWatch.js +90 -1
- package/lib/modules/create-game/src/gameComponent/common/stopWatch/tickEvent.js +29 -1
- package/lib/modules/create-game/src/gameComponent/common/timer/onTimeEvent.js +36 -1
- package/lib/modules/create-game/src/gameComponent/common/timer/tickEvent.js +29 -1
- package/lib/modules/create-game/src/gameComponent/common/timer/timer.js +87 -1
- package/lib/modules/create-game/src/gameComponent/gameComponent.js +53 -1
- package/lib/modules/create-game/src/gameComponent/index.js +31 -1
- package/lib/modules/create-game/src/gameComponent/player/blockInteractionBlocker.js +40 -1
- package/lib/modules/create-game/src/gameComponent/player/entityInteractionBlocker.js +48 -1
- package/lib/modules/create-game/src/gameComponent/player/healthIndicator.js +48 -1
- package/lib/modules/create-game/src/gameComponent/player/regionMonitor.js +22 -1
- package/lib/modules/create-game/src/gameComponent/player/respawn.js +59 -1
- package/lib/modules/create-game/src/gameComponent/player/spawnProtector.js +69 -1
- package/lib/modules/create-game/src/gameComponent/region/regionProtecter.js +53 -1
- package/lib/modules/create-game/src/gameComponent/region/regionTeamChooser.js +71 -1
- package/lib/modules/create-game/src/gameComponent/region/regionTeamCleaner.js +20 -1
- package/lib/modules/create-game/src/gameComponent/view/infoScoreboard.js +77 -1
- package/lib/modules/create-game/src/gameComponent/view/teamScoreboard.js +83 -1
- package/lib/modules/create-game/src/gameContext.js +6 -1
- package/lib/modules/create-game/src/gameEngine.js +139 -1
- package/lib/modules/create-game/src/gameEvent/eventManager.js +108 -1
- package/lib/modules/create-game/src/gameEvent/eventSignal.js +28 -1
- package/lib/modules/create-game/src/gameEvent/events/buttonPush.js +41 -1
- package/lib/modules/create-game/src/gameEvent/events/inSlot.js +77 -1
- package/lib/modules/create-game/src/gameEvent/events/interval.js +51 -1
- package/lib/modules/create-game/src/gameEvent/events/itemUse.js +36 -1
- package/lib/modules/create-game/src/gameEvent/events/onBlock.js +106 -1
- package/lib/modules/create-game/src/gameEvent/events/regionEvents.js +105 -1
- package/lib/modules/create-game/src/gameEvent/events/signClick.js +45 -1
- package/lib/modules/create-game/src/gameEvent/gameEvent.js +54 -1
- package/lib/modules/create-game/src/gameEvent/index.js +20 -1
- package/lib/modules/create-game/src/gameEvent/mapEventSignal.js +101 -1
- package/lib/modules/create-game/src/gameEvent/subscription.js +17 -1
- package/lib/modules/create-game/src/gamePlayer/gamePlayer.js +102 -1
- package/lib/modules/create-game/src/gamePlayer/groupBuilder.js +38 -1
- package/lib/modules/create-game/src/gamePlayer/groupSet.js +96 -1
- package/lib/modules/create-game/src/gamePlayer/index.js +25 -1
- package/lib/modules/create-game/src/gamePlayer/playerGroup.js +145 -1
- package/lib/modules/create-game/src/gamePlayer/playerManager.js +57 -1
- package/lib/modules/create-game/src/gameRegion/gameRegion.js +229 -1
- package/lib/modules/create-game/src/gameRegion/index.js +43 -1
- package/lib/modules/create-game/src/gameRegion/regionHelper.js +79 -1
- package/lib/modules/create-game/src/gameState/common/autoStop.js +39 -1
- package/lib/modules/create-game/src/gameState/gameState.js +169 -1
- package/lib/modules/create-game/src/gameState/index.js +7 -1
- package/lib/modules/create-game/src/gameState/types.js +35 -1
- package/lib/modules/create-game/src/gameStructure/gameStructure.js +36 -1
- package/lib/modules/create-game/src/main.js +86 -1
- package/lib/modules/create-game/src/system/gameCommand.js +107 -1
- package/lib/modules/create-game/src/system/gameManager.js +124 -1
- package/lib/modules/create-game/src/system/globalPlayerManager.js +119 -1
- package/lib/modules/create-game/src/utils/GameError.js +31 -1
- package/lib/modules/create-game/src/utils/algorithm.js +95 -1
- package/lib/modules/create-game/src/utils/chunk.js +63 -1
- package/lib/modules/create-game/src/utils/deferredObject.js +27 -1
- package/lib/modules/create-game/src/utils/duration.js +25 -1
- package/lib/modules/create-game/src/utils/func.js +20 -1
- package/lib/modules/create-game/src/utils/index.js +52 -1
- package/lib/modules/create-game/src/utils/interfaces.js +2 -1
- package/lib/modules/create-game/src/utils/logger.js +47 -1
- package/lib/modules/create-game/src/utils/random.js +76 -1
- package/lib/modules/create-game/src/utils/vanila-data.js +123 -1
- package/lib/modules/create-game/src/utils/vector.js +96 -1
- package/lib/modules/gameLib/src/config.js +134 -1
- package/lib/modules/gameLib/src/data.js +77 -1
- package/lib/modules/gameLib/src/entity.js +256 -1
- package/lib/modules/gameLib/src/event.js +285 -1
- package/lib/modules/gameLib/src/index.js +20 -1
- package/lib/modules/gameLib/src/loger.js +21 -1
- package/lib/modules/gameLib/src/ui.js +209 -1
- package/lib/modules/gameLib/src/utils.js +122 -1
- package/lib/modules/gutils/src/index.js +22 -1
- package/lib/runTemp/File.js +54 -1
- package/lib/runTemp/index.js +137 -1
- package/lib/runTemp/securityFile.js +93 -1
- package/lib/start/addPack.js +3 -1
- package/lib/start/clean.js +84 -1
- package/lib/start/create.js +146 -1
- package/lib/start/dev.js +99 -1
- package/lib/start/getResConfig.js +3 -1
- package/lib/start/incg.js +3 -1
- package/lib/start/index.js +207 -1
- package/lib/start/init.js +125 -1
- package/lib/start/rechce.js +57 -1
- package/lib/start/unaddPack.js +3 -1
- package/lib/start/unincg.js +67 -1
- package/lib/start/version.js +73 -1
- package/lib/utils/index.js +298 -1
- package/lib/uuid/index.js +27 -1
- package/package.json +1 -1
- package/test/script-mbler/behavior/scripts/index.js +0 -5
package/lib/build/index.js
CHANGED
|
@@ -1 +1,370 @@
|
|
|
1
|
-
"use strict";
|
|
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
|
+
const fs = __importStar(require("fs/promises"));
|
|
40
|
+
const path = __importStar(require("path"));
|
|
41
|
+
const ts = __importStar(require("typescript"));
|
|
42
|
+
const index_js_1 = __importDefault(require("./../lang/index.js"));
|
|
43
|
+
const index_js_2 = require("./../uuid/index.js");
|
|
44
|
+
const index_js_3 = __importDefault(require("./../code-processor/index.js"));
|
|
45
|
+
const utils = __importStar(require("./../utils/index.js"));
|
|
46
|
+
const getModule_js_1 = __importDefault(require("./getModule.js"));
|
|
47
|
+
const includes_json_1 = __importDefault(require("./../data/includes.json"));
|
|
48
|
+
const clean_js_1 = __importDefault(require("./../start/clean.js"));
|
|
49
|
+
const index_js_4 = __importDefault(require("./../runTemp/index.js"));
|
|
50
|
+
const base_js_1 = require("./base.js");
|
|
51
|
+
const manifest_build_js_1 = require("./manifest.build.js");
|
|
52
|
+
const index_js_5 = __importDefault(require("./../mcx/index.js"));
|
|
53
|
+
const node_os_1 = __importDefault(require("node:os"));
|
|
54
|
+
const utils_1 = __importDefault(require("./utils"));
|
|
55
|
+
// 构建主类
|
|
56
|
+
class Build extends base_js_1.BaseBuild {
|
|
57
|
+
baseDir;
|
|
58
|
+
baseModDir;
|
|
59
|
+
gamelibModule;
|
|
60
|
+
constructor(buildPath, baseDir) {
|
|
61
|
+
super();
|
|
62
|
+
if (!buildPath)
|
|
63
|
+
utils.Exit(index_js_1.default.build.config_invalid);
|
|
64
|
+
this.baseDir = baseDir;
|
|
65
|
+
this.baseCwd = path.isAbsolute(buildPath) ?
|
|
66
|
+
buildPath :
|
|
67
|
+
path.join(baseDir, buildPath);
|
|
68
|
+
this.cwd = path.join(this.baseCwd, "behavior");
|
|
69
|
+
this.ResOutDir = null;
|
|
70
|
+
this.ResCwd = path.join(this.baseCwd, "resources");
|
|
71
|
+
this.dependencies = {};
|
|
72
|
+
this.gamelibModule = null;
|
|
73
|
+
this.baseModDir = path.join(this.baseDir, 'lib/modules');
|
|
74
|
+
// 锁定属性
|
|
75
|
+
this.#ObjectPri(['baseModDir', 'baseDir']);
|
|
76
|
+
this.#ObjectPriEn(["outdir", "dependencies", "gamelibModule", "cwd", "ResCwd", "baseModDir", "baseCwd"]);
|
|
77
|
+
this.cacheDir = path.join(this.baseCwd, '.cache__mbler__');
|
|
78
|
+
}
|
|
79
|
+
#ObjectPri(list) {
|
|
80
|
+
if (!Array.isArray(list))
|
|
81
|
+
return;
|
|
82
|
+
for (let item of list) {
|
|
83
|
+
Object.defineProperty(this, item, {
|
|
84
|
+
enumerable: false,
|
|
85
|
+
writable: false
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
// 私有:设置不可枚举属性
|
|
90
|
+
#ObjectPriEn(list) {
|
|
91
|
+
if (!Array.isArray(list))
|
|
92
|
+
return;
|
|
93
|
+
for (let item of list) {
|
|
94
|
+
Object.defineProperty(this, item, {
|
|
95
|
+
enumerable: false
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
// 确保缓存目录存在
|
|
100
|
+
async #ensureCacheDir() {
|
|
101
|
+
try {
|
|
102
|
+
await fs.mkdir(this.cacheDir, {
|
|
103
|
+
recursive: true
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
catch (err) {
|
|
107
|
+
// 如果目录已存在,忽略错误
|
|
108
|
+
if (err.code !== 'EEXIST') {
|
|
109
|
+
throw err;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
// 构建入口
|
|
114
|
+
build() {
|
|
115
|
+
return this.start().catch(err => {
|
|
116
|
+
const errorMsg = utils.toString(err);
|
|
117
|
+
(0, utils_1.default)(index_js_1.default.build.error_message_log + errorMsg);
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
async start() {
|
|
121
|
+
const startTime = Date.now();
|
|
122
|
+
await this.#ensureCacheDir();
|
|
123
|
+
const { configChanged, packageChanged } = await this.chackConfigHash();
|
|
124
|
+
const clean = new clean_js_1.default(this.baseCwd, this.baseDir);
|
|
125
|
+
await clean.run();
|
|
126
|
+
await utils.waitGC();
|
|
127
|
+
const data = await this.loadPackageData();
|
|
128
|
+
this.d_data = data;
|
|
129
|
+
this.outdir = this.getOutputDir(data.outdir?.behavior, path.join(this.baseCwd, "dist/dep"));
|
|
130
|
+
this.ResOutDir = this.getOutputDir(data.outdir?.resources, path.join(this.baseCwd, "dist/res"));
|
|
131
|
+
const requiredKeys = ['name', 'description', 'version', 'mcVersion'];
|
|
132
|
+
if (!utils.hasKeys(data, requiredKeys, requiredKeys.length))
|
|
133
|
+
throw new Error(`${index_js_1.default.build.package_file} 字段缺失:必需字段 ${JSON.stringify(requiredKeys)}`);
|
|
134
|
+
this.gamelibModule = await (0, getModule_js_1.default)(this.baseDir);
|
|
135
|
+
console.log(index_js_1.default.build.build_info_header);
|
|
136
|
+
console.table({
|
|
137
|
+
[index_js_1.default.build.project_path]: this.baseCwd,
|
|
138
|
+
[index_js_1.default.build.output_dir]: JSON.stringify(data.outdir),
|
|
139
|
+
[index_js_1.default.build.minify_enabled]: Boolean(data.minify),
|
|
140
|
+
[index_js_1.default.build.build_time]: Build.times,
|
|
141
|
+
[index_js_1.default.build.tip_dist]: process.env.MBLER_BUILD_MODULE || "dev"
|
|
142
|
+
});
|
|
143
|
+
// 并发处理资源、脚本、子包、includes
|
|
144
|
+
await Promise.all([
|
|
145
|
+
this.writeManifest(data),
|
|
146
|
+
this.handleScripts(data),
|
|
147
|
+
this.handleIncludes(),
|
|
148
|
+
this.processSubpacks(data)
|
|
149
|
+
]);
|
|
150
|
+
switch (data.script?.lang || "") {
|
|
151
|
+
case "ts": // TypeScript 编译
|
|
152
|
+
await this.compileTypeScriptUnified();
|
|
153
|
+
break;
|
|
154
|
+
case "mcx":
|
|
155
|
+
await index_js_5.default.load({
|
|
156
|
+
ProjectDir: path.join(this.cwd, "scripts"),
|
|
157
|
+
config: {
|
|
158
|
+
useTS: true
|
|
159
|
+
},
|
|
160
|
+
output: path.join(this.outdir, "scripts"),
|
|
161
|
+
moduleList: this.Modules,
|
|
162
|
+
main: path.join(this.cwd, data.script?.main || "index.js"),
|
|
163
|
+
cacheDir: this.cacheDir,
|
|
164
|
+
moduleDir: path.join(this.outdir, "scripts/node_modules"),
|
|
165
|
+
isCache: true
|
|
166
|
+
});
|
|
167
|
+
break;
|
|
168
|
+
}
|
|
169
|
+
await Promise.all([this.processMinification(data),
|
|
170
|
+
// 资源包处理
|
|
171
|
+
this.processResources()
|
|
172
|
+
]);
|
|
173
|
+
await this.processDist();
|
|
174
|
+
// 最终完成
|
|
175
|
+
console.log(`${index_js_1.default.build.build_success} ${(Date.now() - startTime) / 1000}`);
|
|
176
|
+
}
|
|
177
|
+
async writeManifest(data) {
|
|
178
|
+
const manifest = await this.buildManifest(data);
|
|
179
|
+
await this.writeFile(path.join(this.outdir, 'manifest.json'), manifest);
|
|
180
|
+
}
|
|
181
|
+
async buildManifest(data) {
|
|
182
|
+
const manifest = (new manifest_build_js_1.ManiFest(data, "data")).data;
|
|
183
|
+
const subpack = data.subpack || {};
|
|
184
|
+
if (typeof data.ResDes === 'object')
|
|
185
|
+
this.processResourceDependencies(data, manifest);
|
|
186
|
+
if (typeof data.subpack === 'object' && Object.keys(data.subpack).length > 0) {
|
|
187
|
+
manifest.subpack = Object.keys(data.subpack).map(id => ({
|
|
188
|
+
folder_name: id,
|
|
189
|
+
name: subpack[id] || "",
|
|
190
|
+
memory_tier: 1
|
|
191
|
+
}));
|
|
192
|
+
}
|
|
193
|
+
return manifest;
|
|
194
|
+
}
|
|
195
|
+
processResourceDependencies(data, manifest) {
|
|
196
|
+
const { name = 'unknown', version } = data.ResDes || {};
|
|
197
|
+
if (version && utils.isVerison(version)) {
|
|
198
|
+
manifest.dependencies.push({
|
|
199
|
+
name: (0, index_js_2.fromString)(name),
|
|
200
|
+
version: utils.ToArray(version)
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
async handleScripts(data) {
|
|
205
|
+
if (!data.script || typeof data.script !== 'object')
|
|
206
|
+
return;
|
|
207
|
+
const scriptsDir = path.join(this.cwd, 'scripts');
|
|
208
|
+
const outScripts = path.join(this.outdir, 'scripts');
|
|
209
|
+
if (!(await utils.FileExsit(scriptsDir)))
|
|
210
|
+
return;
|
|
211
|
+
// 复制主包脚本
|
|
212
|
+
await utils.copy(scriptsDir, outScripts);
|
|
213
|
+
this.dependencies = data.script.dependencies || {};
|
|
214
|
+
await this.initNpmDes();
|
|
215
|
+
if (Object.keys(this.dependencies).length > 0) {
|
|
216
|
+
this.Modules = await this.handlerMod(this.dependencies, new Set());
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
async processSubpacks(data) {
|
|
220
|
+
if (typeof data.subpack !== 'object')
|
|
221
|
+
return;
|
|
222
|
+
const outdir = this.outdir;
|
|
223
|
+
const content = new Build(this.cwd, this.baseDir);
|
|
224
|
+
for (let [id, title] of Object.entries(data.subpack)) {
|
|
225
|
+
try {
|
|
226
|
+
const subpackPath = path.join(this.cwd, 'subpacks', id);
|
|
227
|
+
const outSubpack = path.join(outdir, 'subpacks', id);
|
|
228
|
+
await fs.mkdir(outSubpack, {
|
|
229
|
+
recursive: true
|
|
230
|
+
});
|
|
231
|
+
if (!(await utils.FileExsit(subpackPath))) {
|
|
232
|
+
(0, utils_1.default)(index_js_1.default.build.subpack_folder_not_found.replace('{id}', id));
|
|
233
|
+
continue;
|
|
234
|
+
}
|
|
235
|
+
const subScriptDir = path.join(subpackPath, 'scripts');
|
|
236
|
+
const outSubScriptDir = path.join(outSubpack, 'scripts');
|
|
237
|
+
if (await utils.FileExsit(subScriptDir)) {
|
|
238
|
+
await utils.copy(subScriptDir, outSubScriptDir);
|
|
239
|
+
}
|
|
240
|
+
// 复制子包其他资源
|
|
241
|
+
content.cwd = subpackPath;
|
|
242
|
+
content.outdir = outSubpack;
|
|
243
|
+
await content.handleIncludes();
|
|
244
|
+
}
|
|
245
|
+
catch (err) {
|
|
246
|
+
(0, utils_1.default)(index_js_1.default.build.error_processing_subpack.replace('{id}', id).replace('{error}', err.stack));
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
async compileTypeScriptUnified() {
|
|
251
|
+
const tempMod = new index_js_4.default(path.join(node_os_1.default.tmpdir(), "mbler"));
|
|
252
|
+
await tempMod.init();
|
|
253
|
+
const tempDir = tempMod.dir;
|
|
254
|
+
try {
|
|
255
|
+
const rootFiles = await this.getAllTsFiles(this.outdir);
|
|
256
|
+
if (!rootFiles || rootFiles.length === 0) {
|
|
257
|
+
(0, utils_1.default)(index_js_1.default.build.ts_no_files);
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
let tsConfigJson = {
|
|
261
|
+
compilerOptions: {
|
|
262
|
+
target: "esnext",
|
|
263
|
+
module: "esnext",
|
|
264
|
+
moduleResolution: "NodeNext",
|
|
265
|
+
esModuleInterop: true,
|
|
266
|
+
verbatimModuleSyntax: false,
|
|
267
|
+
allowSyntheticDefaultImports: true,
|
|
268
|
+
outDir: tempDir,
|
|
269
|
+
rootDir: this.outdir,
|
|
270
|
+
strict: true,
|
|
271
|
+
allowJs: true,
|
|
272
|
+
sourceMap: false,
|
|
273
|
+
incremental: true, // 启用增量编译
|
|
274
|
+
tsBuildInfoFile: path.join(this.cacheDir, 'tsbuildinfo') // 指定缓存文件
|
|
275
|
+
},
|
|
276
|
+
include: ["**/*.ts"]
|
|
277
|
+
};
|
|
278
|
+
if (await utils.FileExsit(path.join(this.baseCwd, "tsconfig.json")))
|
|
279
|
+
tsConfigJson = JSON.parse(await fs.readFile(path.join(this.baseCwd, "tsconfig.json"), "utf-8"));
|
|
280
|
+
const parsed = ts.parseJsonConfigFileContent(tsConfigJson, ts.sys, this.outdir, undefined, "tsconfig.json");
|
|
281
|
+
const program = ts.createProgram({
|
|
282
|
+
rootNames: rootFiles,
|
|
283
|
+
options: parsed.options
|
|
284
|
+
});
|
|
285
|
+
const emitResult = program.emit();
|
|
286
|
+
const allDiagnostics = ts
|
|
287
|
+
.getPreEmitDiagnostics(program)
|
|
288
|
+
.concat(emitResult.diagnostics);
|
|
289
|
+
allDiagnostics.forEach(d => {
|
|
290
|
+
const msg = ts.flattenDiagnosticMessageText(d.messageText, "\n");
|
|
291
|
+
if (d.file) {
|
|
292
|
+
const { line, character } = d.file.getLineAndCharacterOfPosition(d.start);
|
|
293
|
+
(0, utils_1.default)(index_js_1.default.build.ts_diagnostics.replace('{file}', d.file.fileName).replace('{line}', (line + 1).toString()).replace('{character}', (character + 1).toString()).replace('{message}', msg));
|
|
294
|
+
}
|
|
295
|
+
else {
|
|
296
|
+
(0, utils_1.default)(msg);
|
|
297
|
+
}
|
|
298
|
+
});
|
|
299
|
+
await this.removeJsFiles(path.join(this.outdir, 'scripts'));
|
|
300
|
+
await this.copyCompiledOnly(tempDir, this.outdir);
|
|
301
|
+
(0, utils_1.default)(index_js_1.default.build.ts_compilation_error + " 完成");
|
|
302
|
+
}
|
|
303
|
+
catch (err) {
|
|
304
|
+
(0, utils_1.default)(index_js_1.default.build.ts_compilation_error + err.stack);
|
|
305
|
+
throw err;
|
|
306
|
+
}
|
|
307
|
+
finally {
|
|
308
|
+
await tempMod.remove();
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
async handlerMod(modules, processed = new Set()) {
|
|
312
|
+
const allModules = this.gamelibModule.getAll();
|
|
313
|
+
const scriptOutDir = path.join(this.outdir, 'scripts/node_modules');
|
|
314
|
+
let nextDeps = {};
|
|
315
|
+
for (const [packageName, gitRepo] of Object.entries(modules)) {
|
|
316
|
+
if (!allModules.includes(packageName) || processed.has(packageName))
|
|
317
|
+
continue;
|
|
318
|
+
const srcDir = await this.gamelibModule.getDir(packageName, {
|
|
319
|
+
gitUrl: gitRepo,
|
|
320
|
+
v: this.d_data.mcVersion
|
|
321
|
+
});
|
|
322
|
+
if (!srcDir || !(await utils.FileExsit(srcDir)))
|
|
323
|
+
continue;
|
|
324
|
+
const pkg = await utils.handlerPackage(srcDir, {
|
|
325
|
+
des: Array.from(processed)
|
|
326
|
+
});
|
|
327
|
+
if (pkg.des)
|
|
328
|
+
Object.assign(nextDeps, pkg.des);
|
|
329
|
+
await utils.copy(srcDir, path.join(scriptOutDir, packageName));
|
|
330
|
+
await utils.waitGC();
|
|
331
|
+
processed.add(packageName);
|
|
332
|
+
}
|
|
333
|
+
if (Object.keys(nextDeps).length > 0)
|
|
334
|
+
await this.handlerMod(nextDeps, processed);
|
|
335
|
+
return Array.from(processed);
|
|
336
|
+
}
|
|
337
|
+
handleIncludes() {
|
|
338
|
+
if (!Array.isArray(includes_json_1.default))
|
|
339
|
+
return;
|
|
340
|
+
const copyOperations = includes_json_1.default
|
|
341
|
+
.filter(item => typeof item === 'string')
|
|
342
|
+
.map(async (item) => {
|
|
343
|
+
const src = path.join(this.cwd, 'res', item);
|
|
344
|
+
const dest = path.join(this.outdir, item);
|
|
345
|
+
if (await utils.FileExsit(src)) {
|
|
346
|
+
await utils.copy(src, dest);
|
|
347
|
+
}
|
|
348
|
+
});
|
|
349
|
+
return Promise.all(copyOperations);
|
|
350
|
+
}
|
|
351
|
+
async processMinification(data) {
|
|
352
|
+
try {
|
|
353
|
+
if (!Array.isArray(includes_json_1.default)) {
|
|
354
|
+
(0, utils_1.default)(index_js_1.default.build.includes_not_array);
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
357
|
+
await (0, index_js_3.default)(this.outdir, {
|
|
358
|
+
modules: this.Modules,
|
|
359
|
+
sourceDir: path.join(this.outdir, 'scripts'),
|
|
360
|
+
baseDir: this.baseDir,
|
|
361
|
+
minify: Boolean(data.minify)
|
|
362
|
+
});
|
|
363
|
+
await utils.waitGC();
|
|
364
|
+
}
|
|
365
|
+
catch (err) {
|
|
366
|
+
(0, utils_1.default)(index_js_1.default.build.minification_error + err);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
exports.default = Build;
|
|
@@ -1 +1,103 @@
|
|
|
1
|
-
"use strict";
|
|
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.ManiFest = void 0;
|
|
40
|
+
const build_g_config_json_1 = __importDefault(require("./build-g-config.json"));
|
|
41
|
+
const utils = __importStar(require("./../utils/index.js"));
|
|
42
|
+
const mcVersion_js_1 = require("./mcVersion.js");
|
|
43
|
+
const index_js_1 = require("./../uuid/index.js");
|
|
44
|
+
const path = __importStar(require("path"));
|
|
45
|
+
const config = build_g_config_json_1.default;
|
|
46
|
+
const isNonEmptyString = (str) => typeof str === 'string' && str.trim().length > 0;
|
|
47
|
+
class ManiFest {
|
|
48
|
+
data;
|
|
49
|
+
constructor(MblerConfig, type) {
|
|
50
|
+
this.data = {
|
|
51
|
+
format_version: 2,
|
|
52
|
+
header: {
|
|
53
|
+
name: MblerConfig.name,
|
|
54
|
+
description: MblerConfig.description,
|
|
55
|
+
uuid: (0, index_js_1.fromString)(MblerConfig.name, config[type].header),
|
|
56
|
+
version: utils.ToArray(MblerConfig.version),
|
|
57
|
+
min_engine_version: utils.ToArray(MblerConfig.mcVersion.toString()),
|
|
58
|
+
},
|
|
59
|
+
modules: [{
|
|
60
|
+
type: type,
|
|
61
|
+
uuid: (0, index_js_1.fromString)(MblerConfig.name, config[type].module),
|
|
62
|
+
description: `From Mbler`,
|
|
63
|
+
version: utils.ToArray(MblerConfig.version),
|
|
64
|
+
}]
|
|
65
|
+
};
|
|
66
|
+
if (type === "data" && MblerConfig.script)
|
|
67
|
+
this.processScriptConfig(MblerConfig, this.data);
|
|
68
|
+
}
|
|
69
|
+
processScriptConfig(data, manifest) {
|
|
70
|
+
const { script } = data;
|
|
71
|
+
if (!script)
|
|
72
|
+
return;
|
|
73
|
+
let entry = script.main || "index.js";
|
|
74
|
+
// 如果是mcx,直接设为index.js,因为mcxLoad类会聚集mcx文件和其他文件将其编译输出到index.js
|
|
75
|
+
if (entry?.endsWith(".mcx") && script.lang === "mcx")
|
|
76
|
+
entry = "index.js";
|
|
77
|
+
if (!isNonEmptyString(entry))
|
|
78
|
+
throw new Error('Script main entry is missing or invalid');
|
|
79
|
+
if (!manifest.dependencies)
|
|
80
|
+
manifest.dependencies = [];
|
|
81
|
+
manifest.dependencies.push({
|
|
82
|
+
module_name: '@minecraft/server',
|
|
83
|
+
version: mcVersion_js_1.mcVersionGeter.ToServer(data.mcVersion.toString(), Boolean(script.UseBeta))
|
|
84
|
+
});
|
|
85
|
+
manifest.modules.push({
|
|
86
|
+
type: 'script',
|
|
87
|
+
language: 'javascript',
|
|
88
|
+
entry: path.join("scripts", entry).replace("\\", "/ "),
|
|
89
|
+
uuid: (0, index_js_1.fromString)(data.name, config.ScriptId),
|
|
90
|
+
version: utils.ToArray(data.version),
|
|
91
|
+
});
|
|
92
|
+
if (script.ui === true) {
|
|
93
|
+
manifest.dependencies.push({
|
|
94
|
+
module_name: '@minecraft/server-ui',
|
|
95
|
+
version: mcVersion_js_1.mcVersionGeter.ToServerUi(data.mcVersion.toString(), Boolean(script.UseBeta))
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
;
|
|
99
|
+
manifest.capabilities = ['script_eval'];
|
|
100
|
+
}
|
|
101
|
+
;
|
|
102
|
+
}
|
|
103
|
+
exports.ManiFest = ManiFest;
|
package/lib/build/mcVersion.js
CHANGED
|
@@ -1 +1,86 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mcVersionGeter = void 0;
|
|
4
|
+
// 版本资源表
|
|
5
|
+
const VERSION_TABLE = require('./../data/version.json').version;
|
|
6
|
+
// 转字符串
|
|
7
|
+
const normalize = (v) => {
|
|
8
|
+
return String(v || '')
|
|
9
|
+
.trim();
|
|
10
|
+
};
|
|
11
|
+
const parts = (v) => {
|
|
12
|
+
return normalize(v)
|
|
13
|
+
.split('.')
|
|
14
|
+
.slice(0, 3)
|
|
15
|
+
.map((n) => parseInt(n, 10) || 0);
|
|
16
|
+
};
|
|
17
|
+
const compareVer = (a, b) => {
|
|
18
|
+
const A = parts(a);
|
|
19
|
+
const B = parts(b);
|
|
20
|
+
for (let i = 0; i < 3; i++) {
|
|
21
|
+
const a = A[i];
|
|
22
|
+
const b = B[i];
|
|
23
|
+
if (!a || !b)
|
|
24
|
+
continue;
|
|
25
|
+
if (a !== b)
|
|
26
|
+
return a > b ? 1 : -1;
|
|
27
|
+
}
|
|
28
|
+
return 0;
|
|
29
|
+
};
|
|
30
|
+
const findMatch = (version) => {
|
|
31
|
+
const v = normalize(version);
|
|
32
|
+
for (const item of VERSION_TABLE) {
|
|
33
|
+
// 遍历查找
|
|
34
|
+
const [start, end] = item.range;
|
|
35
|
+
if (compareVer(v, start) >= 0 && compareVer(v, end) <= 0) {
|
|
36
|
+
return {
|
|
37
|
+
item,
|
|
38
|
+
match: 'exact',
|
|
39
|
+
start,
|
|
40
|
+
end
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const sorted = [
|
|
45
|
+
...VERSION_TABLE
|
|
46
|
+
].sort((a, b) => compareVer(b.range[0], a.range[0]));
|
|
47
|
+
for (const item of sorted) {
|
|
48
|
+
if (compareVer(v, item.range[0]) >= 0) {
|
|
49
|
+
return {
|
|
50
|
+
item,
|
|
51
|
+
match: 'fallback',
|
|
52
|
+
start: item.range[0],
|
|
53
|
+
end: item.range[1]
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
const last = sorted[sorted.length - 1];
|
|
58
|
+
return {
|
|
59
|
+
item: last,
|
|
60
|
+
match: 'oldest',
|
|
61
|
+
start: last.range[0],
|
|
62
|
+
end: last.range[1]
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
exports.mcVersionGeter = {
|
|
66
|
+
/**
|
|
67
|
+
* @param version Minecraft版本号
|
|
68
|
+
* @param useBeta 是否返回Beta版本
|
|
69
|
+
*/
|
|
70
|
+
ToServer(version, useBeta = false) {
|
|
71
|
+
const { item, match, start, end } = findMatch(version);
|
|
72
|
+
if (match !== 'exact')
|
|
73
|
+
console.warn(`⚠️ 使用兼容版本 ${start}-${end}(输入:${version})`);
|
|
74
|
+
return useBeta ? item.beta.server : item.format.server;
|
|
75
|
+
},
|
|
76
|
+
/**
|
|
77
|
+
* @param version Minecraft版本号
|
|
78
|
+
* @param useBeta 是否返回Beta版本
|
|
79
|
+
*/
|
|
80
|
+
ToServerUi(version, useBeta = false) {
|
|
81
|
+
const { item, match, start, end } = findMatch(version);
|
|
82
|
+
if (match !== 'exact')
|
|
83
|
+
console.warn(`⚠️ 使用兼容版本 ${start}-${end}(输入:${version})`);
|
|
84
|
+
return useBeta ? item.beta.server_ui : item.format.server_ui;
|
|
85
|
+
}
|
|
86
|
+
};
|
package/lib/build/utils.js
CHANGED
|
@@ -1 +1,6 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = next;
|
|
4
|
+
function next(tip) {
|
|
5
|
+
process.stdout.write(`\r[${new Date}] ${tip}`);
|
|
6
|
+
}
|
|
@@ -1 +1,12 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.default = default_1;
|
|
7
|
+
const mtreehandler_1 = __importDefault(require("./mtreehandler"));
|
|
8
|
+
function default_1(text) {
|
|
9
|
+
if (typeof text !== 'string')
|
|
10
|
+
return new mtreehandler_1.default(null);
|
|
11
|
+
return new mtreehandler_1.default(text);
|
|
12
|
+
}
|