mbler 0.1.3-alpha → 0.1.3-alpha-r2
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 -21
- package/README.md +15 -6
- package/bin/mbler.js +12 -12
- package/bin/minify.js +58 -44
- package/lib/build/base.js +1 -297
- package/lib/build/build-g-config.json +12 -12
- package/lib/build/getModule.js +1 -182
- package/lib/build/index.js +1 -370
- package/lib/build/manifest.build.js +1 -103
- package/lib/build/mcVersion.js +1 -86
- package/lib/build/utils.js +1 -6
- package/lib/code-processor/c-handler-export.js +1 -12
- package/lib/code-processor/index.js +1 -141
- package/lib/code-processor/mtreehandler.js +1 -164
- package/lib/commander/index.js +1 -154
- package/lib/data/includes.json +13 -13
- package/lib/data/version.json +88 -88
- package/lib/git/clone.js +1 -28
- package/lib/git/index.js +1 -12
- package/lib/git/pull.js +1 -100
- package/lib/lang/__translate.js +1 -93
- package/lib/lang/en.js +1 -128
- package/lib/lang/index.js +1 -78
- package/lib/lang/zh.js +1 -146
- package/lib/loger/colors.js +1 -13
- package/lib/loger/index.js +1 -136
- package/lib/mcx/ast/index.js +1 -11
- package/lib/mcx/ast/prop.js +1 -78
- package/lib/mcx/ast/tag.js +1 -246
- package/lib/mcx/compile-component/lib.js +1 -106
- package/lib/mcx/compile-component/types.js +1 -2
- package/lib/mcx/compile-component/utils.js +1 -26
- package/lib/mcx/compile-mcx/compile.js +1 -34
- package/lib/mcx/compile-mcx/compiler/bundler.js +1 -0
- package/lib/mcx/compile-mcx/compiler/compileData.js +1 -0
- package/lib/mcx/compile-mcx/compiler/compileMain.js +1 -0
- package/lib/mcx/compile-mcx/compiler/index.js +1 -0
- package/lib/mcx/compile-mcx/compiler/utils.js +1 -0
- package/lib/mcx/compile-mcx/context.js +1 -19
- package/lib/mcx/compile-mcx/index.js +1 -10
- package/lib/mcx/compile-mcx/mcx/index.js +1 -2
- package/lib/mcx/compile-mcx/mcx/types.js +1 -2
- package/lib/mcx/compile-mcx/template/module.js +1 -42
- package/lib/mcx/compile-mcx/types.js +1 -2
- package/lib/mcx/compile-mcx/utils.node.js +1 -207
- package/lib/mcx/index.js +1 -13
- package/lib/mcx/test/index.js +1 -7
- package/lib/mcx/test.js +1 -21
- package/lib/mcx/types.js +1 -2
- package/lib/mcx/utils.js +1 -86
- package/lib/module-handler/index.js +1 -482
- package/lib/modules/create-game/mbler.config.json +13 -13
- package/lib/modules/create-game/src/Runner/RunnerManager.js +1 -113
- package/lib/modules/create-game/src/Runner/scriptRunner.js +1 -70
- package/lib/modules/create-game/src/config.js +1 -27
- package/lib/modules/create-game/src/constants.js +1 -19
- package/lib/modules/create-game/src/createGameModule.js +1 -24
- package/lib/modules/create-game/src/gameComponent/common/autoStop.js +1 -38
- package/lib/modules/create-game/src/gameComponent/common/lazyLoader.js +1 -76
- package/lib/modules/create-game/src/gameComponent/common/stopWatch/onTimeEvent.js +1 -36
- package/lib/modules/create-game/src/gameComponent/common/stopWatch/stopWatch.js +1 -90
- package/lib/modules/create-game/src/gameComponent/common/stopWatch/tickEvent.js +1 -29
- package/lib/modules/create-game/src/gameComponent/common/timer/onTimeEvent.js +1 -36
- package/lib/modules/create-game/src/gameComponent/common/timer/tickEvent.js +1 -29
- package/lib/modules/create-game/src/gameComponent/common/timer/timer.js +1 -87
- package/lib/modules/create-game/src/gameComponent/gameComponent.js +1 -53
- package/lib/modules/create-game/src/gameComponent/index.js +1 -31
- package/lib/modules/create-game/src/gameComponent/player/blockInteractionBlocker.js +1 -40
- package/lib/modules/create-game/src/gameComponent/player/entityInteractionBlocker.js +1 -48
- package/lib/modules/create-game/src/gameComponent/player/healthIndicator.js +1 -48
- package/lib/modules/create-game/src/gameComponent/player/regionMonitor.js +1 -22
- package/lib/modules/create-game/src/gameComponent/player/respawn.js +1 -59
- package/lib/modules/create-game/src/gameComponent/player/spawnProtector.js +1 -69
- package/lib/modules/create-game/src/gameComponent/region/regionProtecter.js +1 -53
- package/lib/modules/create-game/src/gameComponent/region/regionTeamChooser.js +1 -71
- package/lib/modules/create-game/src/gameComponent/region/regionTeamCleaner.js +1 -20
- package/lib/modules/create-game/src/gameComponent/view/infoScoreboard.js +1 -77
- package/lib/modules/create-game/src/gameComponent/view/teamScoreboard.js +1 -83
- package/lib/modules/create-game/src/gameContext.js +1 -6
- package/lib/modules/create-game/src/gameEngine.js +1 -139
- package/lib/modules/create-game/src/gameEvent/eventManager.js +1 -108
- package/lib/modules/create-game/src/gameEvent/eventSignal.js +1 -28
- package/lib/modules/create-game/src/gameEvent/events/buttonPush.js +1 -41
- package/lib/modules/create-game/src/gameEvent/events/inSlot.js +1 -77
- package/lib/modules/create-game/src/gameEvent/events/interval.js +1 -51
- package/lib/modules/create-game/src/gameEvent/events/itemUse.js +1 -36
- package/lib/modules/create-game/src/gameEvent/events/onBlock.js +1 -106
- package/lib/modules/create-game/src/gameEvent/events/regionEvents.js +1 -105
- package/lib/modules/create-game/src/gameEvent/events/signClick.js +1 -45
- package/lib/modules/create-game/src/gameEvent/gameEvent.js +1 -54
- package/lib/modules/create-game/src/gameEvent/index.js +1 -20
- package/lib/modules/create-game/src/gameEvent/mapEventSignal.js +1 -101
- package/lib/modules/create-game/src/gameEvent/subscription.js +1 -17
- package/lib/modules/create-game/src/gamePlayer/gamePlayer.js +1 -102
- package/lib/modules/create-game/src/gamePlayer/groupBuilder.js +1 -38
- package/lib/modules/create-game/src/gamePlayer/groupSet.js +1 -96
- package/lib/modules/create-game/src/gamePlayer/index.js +1 -25
- package/lib/modules/create-game/src/gamePlayer/playerGroup.js +1 -145
- package/lib/modules/create-game/src/gamePlayer/playerManager.js +1 -57
- package/lib/modules/create-game/src/gameRegion/gameRegion.js +1 -229
- package/lib/modules/create-game/src/gameRegion/index.js +1 -43
- package/lib/modules/create-game/src/gameRegion/regionHelper.js +1 -79
- package/lib/modules/create-game/src/gameState/common/autoStop.js +1 -39
- package/lib/modules/create-game/src/gameState/gameState.js +1 -169
- package/lib/modules/create-game/src/gameState/index.js +1 -7
- package/lib/modules/create-game/src/gameState/types.js +1 -35
- package/lib/modules/create-game/src/gameStructure/gameStructure.js +1 -36
- package/lib/modules/create-game/src/main.js +1 -86
- package/lib/modules/create-game/src/system/gameCommand.js +1 -107
- package/lib/modules/create-game/src/system/gameManager.js +1 -124
- package/lib/modules/create-game/src/system/globalPlayerManager.js +1 -119
- package/lib/modules/create-game/src/utils/GameError.js +1 -31
- package/lib/modules/create-game/src/utils/algorithm.js +1 -95
- package/lib/modules/create-game/src/utils/chunk.js +1 -63
- package/lib/modules/create-game/src/utils/deferredObject.js +1 -27
- package/lib/modules/create-game/src/utils/duration.js +1 -25
- package/lib/modules/create-game/src/utils/func.js +1 -20
- package/lib/modules/create-game/src/utils/index.js +1 -52
- package/lib/modules/create-game/src/utils/interfaces.js +1 -2
- package/lib/modules/create-game/src/utils/logger.js +1 -47
- package/lib/modules/create-game/src/utils/random.js +1 -76
- package/lib/modules/create-game/src/utils/vanila-data.js +1 -123
- package/lib/modules/create-game/src/utils/vector.js +1 -96
- package/lib/modules/gameLib/mbler.config.json +15 -15
- package/lib/modules/gameLib/src/config.js +1 -134
- package/lib/modules/gameLib/src/data.js +1 -77
- package/lib/modules/gameLib/src/entity.js +1 -256
- package/lib/modules/gameLib/src/event.js +1 -285
- package/lib/modules/gameLib/src/index.js +1 -20
- package/lib/modules/gameLib/src/loger.js +1 -21
- package/lib/modules/gameLib/src/ui.js +1 -209
- package/lib/modules/gameLib/src/utils.js +1 -122
- package/lib/modules/gutils/mbler.config.json +11 -11
- package/lib/modules/gutils/src/index.js +1 -22
- package/lib/modules/innerDef.json +4 -4
- package/lib/runTemp/File.js +1 -54
- package/lib/runTemp/config.json +3 -3
- package/lib/runTemp/index.js +1 -137
- package/lib/runTemp/securityFile.js +1 -93
- package/lib/start/addPack.js +1 -3
- package/lib/start/clean.js +1 -84
- package/lib/start/create.js +1 -146
- package/lib/start/dev.js +1 -99
- package/lib/start/getResConfig.js +1 -3
- package/lib/start/incg.js +1 -3
- package/lib/start/index.js +1 -207
- package/lib/start/init.js +1 -125
- package/lib/start/rechce.js +1 -57
- package/lib/start/unaddPack.js +1 -3
- package/lib/start/unincg.js +1 -67
- package/lib/start/version.js +1 -73
- package/lib/utils/index.js +1 -298
- package/lib/uuid/index.js +1 -27
- package/package.json +49 -1
- package/test/2x sword/behavior/scripts/index.js +24 -24
- package/test/2x sword/mbler.config.json +11 -11
- package/test/2x sword/package.json +13 -13
- package/test/README.md +7 -7
- package/test/des/index.js +19 -19
- package/test/des/mbler.config.json +4 -4
- package/test/des/package.json +6 -6
- package/test/initializer/index.js +5 -5
- package/test/initializer/mbler.config.json +4 -4
- package/test/initializer/package.json +6 -6
- package/test/mbler-int/behavior/res/items/mang_one_int.json +21 -21
- package/test/mbler-int/behavior/scripts/index.js +7 -7
- package/test/mbler-int/behavior/scripts/lib/event/index.js +19 -19
- package/test/mbler-int/behavior/scripts/lib/ui/Lore.js +18 -18
- package/test/mbler-int/behavior/scripts/lib/ui/baseUi.js +6 -6
- package/test/mbler-int/behavior/scripts/lib/ui/index.js +206 -206
- package/test/mbler-int/behavior/scripts/lib/utils/index.js +51 -51
- package/test/mbler-int/mbler.config.json +18 -18
- package/test/mbler-int/package.json +12 -12
- package/test/script-mbler/behavior/scripts/index.js +5 -0
- package/test/script-mbler/behavior/scripts/index.ts +5 -5
- package/test/script-mbler/mbler.config.json +14 -14
- package/test/script-mbler/package.json +15 -15
- package/lib/mcx/compile-mcx/_compile.js +0 -602
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025 RuanhoR
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 RuanhoR
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
# McBeBuilder - MBLER
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
### 提示
|
|
3
|
+
最近一次提交, 我们办了一件大事...
|
|
4
|
+
- 把 mcx 这个模块移到新仓库,用npm引用
|
|
5
|
+
- 你会看到大量代码被删除,并不是放弃开发,而是迁移
|
|
6
|
+
- 新仓库 https://github.com/RuanhoR/mcx-core
|
|
7
|
+
### 介绍
|
|
8
|
+
一个针对Minecraft JavaScript API 的nodejs包,让你的附加包版本管理更简单
|
|
5
9
|
### 安装
|
|
6
10
|
确保你已经安装以下工具:
|
|
7
11
|
- Node.js 与 npm
|
|
@@ -10,7 +14,7 @@
|
|
|
10
14
|
从 [这里](https://github.com/RuanhoR/mbler/releases) 选择版本下载,到达这个目录(使用命令行cd),运行`npm link`
|
|
11
15
|
也可使用 Gitee 的克隆链接或github镜像站,可能速度更快
|
|
12
16
|
本项目目前迁移`typescript`,你也可以直接运行`tsc`进行构建
|
|
13
|
-
|
|
17
|
+
- npm `npm install -g mbler`
|
|
14
18
|
安装成功后,你可以直接使用:
|
|
15
19
|
```bash
|
|
16
20
|
# 获取版本
|
|
@@ -21,8 +25,13 @@ mbler -v
|
|
|
21
25
|
mbler -c <项目路径>
|
|
22
26
|
mbler init
|
|
23
27
|
```
|
|
24
|
-
** 详细请看 : [文档](
|
|
28
|
+
** 详细请看 : [文档](https://mbler-docs.ruanhor.dpdns.org/) **
|
|
25
29
|
|
|
26
30
|
### 发布平台
|
|
27
31
|
[github](https://github.com/RuanhoR/mbler)
|
|
28
|
-
[gitee](https://gitee.com/n304sc-haoran/mbler)
|
|
32
|
+
[gitee](https://gitee.com/n304sc-haoran/mbler)
|
|
33
|
+
|
|
34
|
+
## 文档
|
|
35
|
+
[中文](https://zh.mbler-docs.ruanhor.dpdns.org/)
|
|
36
|
+
[英文](https://mbler-docs.ruanhor.dpdns.org/)
|
|
37
|
+
|
package/bin/mbler.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
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)
|
|
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
14
|
}
|
package/bin/minify.js
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
const { execSync } = require(
|
|
2
|
-
const fs = require(
|
|
3
|
-
const path = require(
|
|
4
|
-
const { minify } = require(
|
|
1
|
+
const { execSync } = require("child_process");
|
|
2
|
+
const fs = require("fs");
|
|
3
|
+
const path = require("path");
|
|
4
|
+
const { minify } = require("terser");
|
|
5
5
|
|
|
6
6
|
// 清理 dist 目录
|
|
7
7
|
fs.rmSync(path.join(__dirname, "../dist"), {
|
|
8
8
|
recursive: true,
|
|
9
|
-
force: true
|
|
9
|
+
force: true,
|
|
10
10
|
});
|
|
11
11
|
|
|
12
12
|
// 编译 TypeScript
|
|
13
13
|
try {
|
|
14
|
-
execSync(
|
|
15
|
-
stdio:
|
|
14
|
+
execSync("tsc", {
|
|
15
|
+
stdio: "inherit",
|
|
16
16
|
});
|
|
17
|
-
console.log(
|
|
17
|
+
console.log("TypeScript 编译完成!");
|
|
18
18
|
} catch (error) {
|
|
19
|
-
console.error(
|
|
19
|
+
console.error("TypeScript 编译失败:", error.message);
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
const distDir = path.resolve(__dirname,
|
|
23
|
-
console.log(
|
|
22
|
+
const distDir = path.resolve(__dirname, "./../dist");
|
|
23
|
+
console.log(distDir);
|
|
24
24
|
|
|
25
25
|
if (!fs.existsSync(distDir)) {
|
|
26
|
-
console.error(
|
|
26
|
+
console.error("dist 目录不存在:", distDir);
|
|
27
27
|
process.exit(1);
|
|
28
28
|
}
|
|
29
29
|
|
|
@@ -33,13 +33,13 @@ const jsonFiles = [];
|
|
|
33
33
|
// 扫描编译后的 JS 文件
|
|
34
34
|
function scanDistDirectory(directory) {
|
|
35
35
|
const files = fs.readdirSync(directory);
|
|
36
|
-
files.forEach(file => {
|
|
36
|
+
files.forEach((file) => {
|
|
37
37
|
const fullPath = path.join(directory, file);
|
|
38
38
|
const stat = fs.statSync(fullPath);
|
|
39
39
|
|
|
40
40
|
if (stat.isDirectory()) {
|
|
41
41
|
scanDistDirectory(fullPath); // 递归扫描子目录
|
|
42
|
-
} else if (file.endsWith(
|
|
42
|
+
} else if (file.endsWith(".js") && !file.endsWith(".min.js")) {
|
|
43
43
|
jsFiles.push(fullPath);
|
|
44
44
|
}
|
|
45
45
|
});
|
|
@@ -48,7 +48,7 @@ function scanDistDirectory(directory) {
|
|
|
48
48
|
// 扫描源码中的 JSON 文件
|
|
49
49
|
function scanSrcJsonDirectory(directory) {
|
|
50
50
|
const files = fs.readdirSync(directory);
|
|
51
|
-
files.forEach(file => {
|
|
51
|
+
files.forEach((file) => {
|
|
52
52
|
const fullPath = path.join(directory, file);
|
|
53
53
|
const stat = fs.statSync(fullPath);
|
|
54
54
|
|
|
@@ -56,11 +56,14 @@ function scanSrcJsonDirectory(directory) {
|
|
|
56
56
|
scanSrcJsonDirectory(fullPath); // 递归扫描子目录
|
|
57
57
|
} else if (file.endsWith(".json")) {
|
|
58
58
|
// 计算对应的 dist 路径
|
|
59
|
-
const relativePath = path.relative(
|
|
59
|
+
const relativePath = path.relative(
|
|
60
|
+
path.join(__dirname, "../src"),
|
|
61
|
+
fullPath,
|
|
62
|
+
);
|
|
60
63
|
const distPath = path.join(distDir, "lib", relativePath);
|
|
61
64
|
jsonFiles.push({
|
|
62
65
|
srcPath: fullPath,
|
|
63
|
-
distPath: distPath
|
|
66
|
+
distPath: distPath,
|
|
64
67
|
});
|
|
65
68
|
}
|
|
66
69
|
});
|
|
@@ -70,12 +73,12 @@ scanDistDirectory(distDir);
|
|
|
70
73
|
scanSrcJsonDirectory(path.join(__dirname, "../src"));
|
|
71
74
|
|
|
72
75
|
if (jsFiles.length === 0) {
|
|
73
|
-
console.log(
|
|
76
|
+
console.log("没有找到需要压缩的文件");
|
|
74
77
|
process.exit(0);
|
|
75
78
|
}
|
|
76
79
|
|
|
77
80
|
console.log(`${jsFiles.length} 个文件需要处理`);
|
|
78
|
-
|
|
81
|
+
processFiles()
|
|
79
82
|
async function processFiles() {
|
|
80
83
|
let successCount = 0;
|
|
81
84
|
let failCount = 0;
|
|
@@ -84,9 +87,13 @@ async function processFiles() {
|
|
|
84
87
|
for (const jsonFile of jsonFiles) {
|
|
85
88
|
try {
|
|
86
89
|
console.log(`复制 JSON: ${jsonFile.srcPath} -> ${jsonFile.distPath}`);
|
|
87
|
-
|
|
88
|
-
try{
|
|
89
|
-
|
|
90
|
+
|
|
91
|
+
try {
|
|
92
|
+
// 确保目标目录存在
|
|
93
|
+
await fs.promises.mkdir(path.dirname(jsonFile.distPath), {
|
|
94
|
+
recursive: true,
|
|
95
|
+
});
|
|
96
|
+
} catch {}
|
|
90
97
|
await fs.promises.copyFile(jsonFile.srcPath, jsonFile.distPath);
|
|
91
98
|
successCount++;
|
|
92
99
|
} catch (error) {
|
|
@@ -99,24 +106,24 @@ try{ // 确保目标目录存在
|
|
|
99
106
|
for (const filePath of jsFiles) {
|
|
100
107
|
try {
|
|
101
108
|
// 处理 JS 文件压缩
|
|
102
|
-
const originalCode = fs.readFileSync(filePath,
|
|
109
|
+
const originalCode = fs.readFileSync(filePath, "utf8");
|
|
103
110
|
const result = await minify(originalCode, {
|
|
104
111
|
compress: {
|
|
105
112
|
drop_console: false,
|
|
106
113
|
dead_code: true,
|
|
107
|
-
drop_debugger: true
|
|
114
|
+
drop_debugger: true,
|
|
108
115
|
},
|
|
109
116
|
mangle: true,
|
|
110
117
|
format: {
|
|
111
|
-
comments: false
|
|
112
|
-
}
|
|
118
|
+
comments: false,
|
|
119
|
+
},
|
|
113
120
|
});
|
|
114
121
|
|
|
115
122
|
if (result.error) {
|
|
116
123
|
throw new Error(result.error);
|
|
117
124
|
}
|
|
118
125
|
|
|
119
|
-
fs.writeFileSync(filePath, result.code,
|
|
126
|
+
fs.writeFileSync(filePath, result.code, "utf8");
|
|
120
127
|
successCount++;
|
|
121
128
|
} catch (error) {
|
|
122
129
|
console.error(`处理失败 ${filePath}:`, error.message);
|
|
@@ -127,29 +134,36 @@ try{ // 确保目标目录存在
|
|
|
127
134
|
console.log(`\n处理完成: 成功 ${successCount} 个, 失败 ${failCount} 个`);
|
|
128
135
|
// 复制其他必要文件
|
|
129
136
|
await Promise.all([
|
|
130
|
-
async function(){
|
|
131
|
-
const fileC = JSON.parse(
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
137
|
+
(async function () {
|
|
138
|
+
const fileC = JSON.parse(
|
|
139
|
+
await fs.promises.readFile(
|
|
140
|
+
path.join(__dirname, "../package.json"),
|
|
141
|
+
"utf-8",
|
|
142
|
+
),
|
|
143
|
+
);
|
|
144
|
+
delete fileC.devDependencies;
|
|
145
|
+
await fs.promises.writeFile(
|
|
146
|
+
path.join(distDir, "package.json"),
|
|
147
|
+
JSON.stringify(fileC),
|
|
148
|
+
);
|
|
149
|
+
})(),
|
|
135
150
|
fs.promises.cp(
|
|
136
151
|
path.join(__dirname, "../bin"),
|
|
137
152
|
path.join(__dirname, "../dist/bin"),
|
|
138
|
-
{ recursive: true, force: true }
|
|
153
|
+
{ recursive: true, force: true },
|
|
139
154
|
),
|
|
140
155
|
fs.promises.cp(
|
|
141
156
|
path.join(__dirname, "../test"),
|
|
142
157
|
path.join(__dirname, "../dist/test"),
|
|
143
|
-
{ recursive: true, force: true }
|
|
144
|
-
)
|
|
158
|
+
{ recursive: true, force: true },
|
|
159
|
+
),
|
|
160
|
+
fs.promises.cp(
|
|
161
|
+
path.join(__dirname, "../README.md"),
|
|
162
|
+
path.join(__dirname, "../dist/README.md"),
|
|
163
|
+
),
|
|
164
|
+
fs.promises.cp(
|
|
165
|
+
path.join(__dirname, "../LICENSE"),
|
|
166
|
+
path.join(__dirname, "../dist/LICENSE"),
|
|
167
|
+
),
|
|
145
168
|
]);
|
|
146
|
-
|
|
147
|
-
if (failCount > 0) {
|
|
148
|
-
process.exit(1);
|
|
149
|
-
}
|
|
150
169
|
}
|
|
151
|
-
|
|
152
|
-
processFiles().catch(err => {
|
|
153
|
-
console.error('处理过程中出现错误:', err);
|
|
154
|
-
process.exit(1);
|
|
155
|
-
});
|
package/lib/build/base.js
CHANGED
|
@@ -1,297 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.BaseBuild = void 0;
|
|
40
|
-
const promises_1 = __importDefault(require("fs/promises"));
|
|
41
|
-
const path_1 = __importDefault(require("path"));
|
|
42
|
-
const dayjs_1 = __importDefault(require("dayjs"));
|
|
43
|
-
const index_js_1 = __importDefault(require("./../lang/index.js"));
|
|
44
|
-
const index_js_2 = __importDefault(require("./../runTemp/index.js"));
|
|
45
|
-
const child_process_1 = require("child_process");
|
|
46
|
-
const manifest_build_js_1 = require("./manifest.build.js");
|
|
47
|
-
const node_os_1 = __importDefault(require("node:os"));
|
|
48
|
-
const time = () => (0, dayjs_1.default)().format('YYYY-MM-DD HH:mm:ss');
|
|
49
|
-
const utils_1 = __importDefault(require("./utils"));
|
|
50
|
-
const utils = __importStar(require("./../utils/index.js"));
|
|
51
|
-
// 这里是主Build的底类,用于提供工具,主Build负责将工具连起来,进行完整的构建
|
|
52
|
-
class BaseBuild {
|
|
53
|
-
static times = time();
|
|
54
|
-
outdir = "";
|
|
55
|
-
ResOutDir = null;
|
|
56
|
-
baseCwd = '';
|
|
57
|
-
cwd = '';
|
|
58
|
-
ResCwd = '';
|
|
59
|
-
d_data = null;
|
|
60
|
-
cacheDir = '';
|
|
61
|
-
dependencies = {};
|
|
62
|
-
Modules = [];
|
|
63
|
-
constructor() { }
|
|
64
|
-
async rmPackScriptScriptCache() {
|
|
65
|
-
await Promise.all([
|
|
66
|
-
this.rmNpmDes(),
|
|
67
|
-
promises_1.default.rm(path_1.default.join(this.outdir, 'scripts/package-lock.json'), {
|
|
68
|
-
recursive: true,
|
|
69
|
-
force: true
|
|
70
|
-
}).catch(() => { })
|
|
71
|
-
]);
|
|
72
|
-
}
|
|
73
|
-
async processResources() {
|
|
74
|
-
if ((await utils.FileExsit(this.ResCwd)) && this.ResOutDir) {
|
|
75
|
-
await Promise.all((await promises_1.default.readdir(this.ResCwd)).map((dir) => utils.copy(path_1.default.join(this.ResCwd, dir), path_1.default.join(this.ResOutDir, dir))));
|
|
76
|
-
if (this.d_data == null)
|
|
77
|
-
throw new Error("[build error]: not load config when init");
|
|
78
|
-
const manifest = (new manifest_build_js_1.ManiFest(this.d_data, "resources")).data;
|
|
79
|
-
await this.writeFile(path_1.default.join(this.ResOutDir, "manifest.json"), JSON.stringify(manifest));
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
(0, utils_1.default)(index_js_1.default.build.no_resources);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
async processDist() {
|
|
86
|
-
if (process.env.MBLER_BUILD_MODULE === "dist") {
|
|
87
|
-
const temp = new index_js_2.default(path_1.default.join(node_os_1.default.tmpdir(), "mbler"));
|
|
88
|
-
await temp.init();
|
|
89
|
-
await Promise.all([
|
|
90
|
-
utils.copy(this.outdir, path_1.default.join(temp.dir, "behavior")),
|
|
91
|
-
(await utils.FileExsit(this.ResCwd)) ?
|
|
92
|
-
utils.copy(this.ResOutDir, path_1.default.join(temp.dir, "resources")) :
|
|
93
|
-
Promise.resolve()
|
|
94
|
-
]);
|
|
95
|
-
let i = this.d_data?.outdir?.dist || "dist.mcaddon";
|
|
96
|
-
if (path_1.default.extname(i) !== ".mcaddon")
|
|
97
|
-
i += ".mcaddon";
|
|
98
|
-
const dir = path_1.default.join(this.baseCwd, i);
|
|
99
|
-
const v = require('./../../package.json');
|
|
100
|
-
await promises_1.default.writeFile(path_1.default.join(temp.dir, "behavior", ".mbler.build.info"), JSON.stringify({
|
|
101
|
-
mbler: {
|
|
102
|
-
version: v.version,
|
|
103
|
-
git: v.repository
|
|
104
|
-
},
|
|
105
|
-
time: BaseBuild.times
|
|
106
|
-
}));
|
|
107
|
-
await utils.zip([
|
|
108
|
-
temp.dir
|
|
109
|
-
], dir);
|
|
110
|
-
await temp.remove();
|
|
111
|
-
(0, utils_1.default)(`${index_js_1.default.build.ziped} ${dir}`);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
async loadPackageData() {
|
|
115
|
-
const data = await utils.GetData(this.baseCwd);
|
|
116
|
-
if (!data)
|
|
117
|
-
throw new Error(index_js_1.default.buildBase.cannot_read_project_config);
|
|
118
|
-
if (typeof data !== 'object' || data === null)
|
|
119
|
-
throw new Error(index_js_1.default.buildBase.invalid_project_config_format);
|
|
120
|
-
return data;
|
|
121
|
-
}
|
|
122
|
-
getCachePath(fileName) {
|
|
123
|
-
return path_1.default.join(this.cacheDir, fileName);
|
|
124
|
-
}
|
|
125
|
-
getOutputDir(dir, def) {
|
|
126
|
-
const outdir = dir;
|
|
127
|
-
return outdir ? path_1.default.join(this.baseCwd, outdir) : def;
|
|
128
|
-
}
|
|
129
|
-
async initNpmDes() {
|
|
130
|
-
const packager = JSON.parse(await promises_1.default.readFile(path_1.default.join(this.baseCwd, 'package.json'), "utf-8"));
|
|
131
|
-
const desLength = Object.keys(packager.dependencies || {}).length;
|
|
132
|
-
if (desLength < 1) {
|
|
133
|
-
(0, utils_1.default)(index_js_1.default.buildBase.npm_deps_skipped_no_json);
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
await promises_1.default.writeFile(path_1.default.join(this.outdir, 'scripts/package.json'), JSON.stringify(packager));
|
|
137
|
-
await this.#npmInstall(path_1.default.join(this.outdir, 'scripts'));
|
|
138
|
-
}
|
|
139
|
-
#npmInstall(repo) {
|
|
140
|
-
return new Promise((resolve, reject) => {
|
|
141
|
-
(0, utils_1.default)(index_js_1.default.buildBase.starting_npm_install);
|
|
142
|
-
const processC = (0, child_process_1.spawn)('npm', ['install'], {
|
|
143
|
-
cwd: repo,
|
|
144
|
-
stdio: 'ignore'
|
|
145
|
-
});
|
|
146
|
-
processC.on('close', (code) => {
|
|
147
|
-
if (code === 0) {
|
|
148
|
-
(0, utils_1.default)(index_js_1.default.buildBase.npm_install_completed);
|
|
149
|
-
resolve(code);
|
|
150
|
-
}
|
|
151
|
-
else {
|
|
152
|
-
(0, utils_1.default)(index_js_1.default.buildBase.npm_install_exit_code + code);
|
|
153
|
-
resolve(code);
|
|
154
|
-
}
|
|
155
|
-
});
|
|
156
|
-
processC.on('error', (err) => {
|
|
157
|
-
(0, utils_1.default)(`${index_js_1.default.buildBase.npm_install_error} ${err.stack}`);
|
|
158
|
-
reject(err);
|
|
159
|
-
});
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
async getFileHash(filePath) {
|
|
163
|
-
if (!await utils.FileExsit(filePath))
|
|
164
|
-
return null;
|
|
165
|
-
const content = await promises_1.default.readFile(filePath);
|
|
166
|
-
const hashSum = (await import('crypto')).createHash('sha1');
|
|
167
|
-
hashSum.update(content);
|
|
168
|
-
return hashSum.digest('hex');
|
|
169
|
-
}
|
|
170
|
-
async chackConfigHash() {
|
|
171
|
-
const configPath = path_1.default.join(this.cwd, 'mbler.config.json');
|
|
172
|
-
const packagePath = path_1.default.join(this.cwd, 'package.json');
|
|
173
|
-
const configHashPath = this.getCachePath('config-hash.txt');
|
|
174
|
-
const packageHashPath = this.getCachePath('package-hash.txt');
|
|
175
|
-
const currentConfigHash = await this.getFileHash(configPath);
|
|
176
|
-
const currentPackageHash = await this.getFileHash(packagePath);
|
|
177
|
-
let configHashStored = null;
|
|
178
|
-
let packageHashStored = null;
|
|
179
|
-
if (await promises_1.default.access(configHashPath).then(() => true).catch(() => false)) {
|
|
180
|
-
configHashStored = await promises_1.default.readFile(configHashPath, "utf-8");
|
|
181
|
-
}
|
|
182
|
-
if (await promises_1.default.access(packageHashPath).then(() => true).catch(() => false)) {
|
|
183
|
-
packageHashStored = await promises_1.default.readFile(packageHashPath, "utf-8");
|
|
184
|
-
}
|
|
185
|
-
const configChanged = !currentConfigHash || currentConfigHash !== configHashStored;
|
|
186
|
-
const packageChanged = !currentPackageHash || currentPackageHash !== packageHashStored;
|
|
187
|
-
if (currentConfigHash) {
|
|
188
|
-
await promises_1.default.writeFile(configHashPath, currentConfigHash);
|
|
189
|
-
}
|
|
190
|
-
if (currentPackageHash) {
|
|
191
|
-
await promises_1.default.writeFile(packageHashPath, currentPackageHash);
|
|
192
|
-
}
|
|
193
|
-
return {
|
|
194
|
-
configChanged,
|
|
195
|
-
packageChanged
|
|
196
|
-
};
|
|
197
|
-
}
|
|
198
|
-
async removeJsFiles(dir) {
|
|
199
|
-
try {
|
|
200
|
-
for (const f of await promises_1.default.readdir(dir, {
|
|
201
|
-
withFileTypes: true
|
|
202
|
-
})) {
|
|
203
|
-
const full = path_1.default.join(dir, f.name);
|
|
204
|
-
if (full.includes('node_modules'))
|
|
205
|
-
continue;
|
|
206
|
-
if (f.isDirectory()) {
|
|
207
|
-
await this.removeJsFiles(full);
|
|
208
|
-
}
|
|
209
|
-
else if (f.isFile() && f.name.endsWith('.js')) {
|
|
210
|
-
try {
|
|
211
|
-
await promises_1.default.unlink(full);
|
|
212
|
-
}
|
|
213
|
-
catch (e) {
|
|
214
|
-
/* 忽略 unlink 错误 */
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
catch (err) { }
|
|
220
|
-
}
|
|
221
|
-
async rmNpmDes() {
|
|
222
|
-
const moduleDir = path_1.default.join(this.outdir, 'scripts/node_modules');
|
|
223
|
-
const modules = this.Modules || Object.keys(this.dependencies);
|
|
224
|
-
for (let file of await promises_1.default.readdir(moduleDir).catch(() => [])) {
|
|
225
|
-
if (!modules.includes(file))
|
|
226
|
-
await promises_1.default.rm(path_1.default.join(moduleDir, file), {
|
|
227
|
-
recursive: true,
|
|
228
|
-
force: true
|
|
229
|
-
}).catch(() => { });
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
async copyCompiledOnly(srcDir, destDir) {
|
|
233
|
-
try {
|
|
234
|
-
for (const ent of await promises_1.default.readdir(srcDir, {
|
|
235
|
-
withFileTypes: true
|
|
236
|
-
})) {
|
|
237
|
-
const srcFull = path_1.default.join(srcDir, ent.name);
|
|
238
|
-
const destFull = path_1.default.join(destDir, ent.name);
|
|
239
|
-
if (ent.isDirectory()) {
|
|
240
|
-
await promises_1.default.mkdir(destFull, {
|
|
241
|
-
recursive: true
|
|
242
|
-
}).catch(() => { });
|
|
243
|
-
await this.copyCompiledOnly(srcFull, destFull);
|
|
244
|
-
}
|
|
245
|
-
else if (ent.isFile()) {
|
|
246
|
-
const ext = path_1.default.extname(ent.name).toLowerCase();
|
|
247
|
-
if ([".js", ".json"].includes(ext)) {
|
|
248
|
-
await promises_1.default.mkdir(path_1.default.dirname(destFull), {
|
|
249
|
-
recursive: true
|
|
250
|
-
}).catch(() => { });
|
|
251
|
-
await promises_1.default.copyFile(srcFull, destFull).catch(() => {
|
|
252
|
-
// 文件可能被占用,忽略单个错误
|
|
253
|
-
});
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
catch (err) {
|
|
259
|
-
(0, utils_1.default)(`ERR: ${err && err.stack ? err.stack : err}`);
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
async getAllTsFiles(dir) {
|
|
263
|
-
const list = [];
|
|
264
|
-
try {
|
|
265
|
-
for (const f of await promises_1.default.readdir(dir, {
|
|
266
|
-
withFileTypes: true
|
|
267
|
-
})) {
|
|
268
|
-
const full = path_1.default.join(dir, f.name);
|
|
269
|
-
if (f.isDirectory()) {
|
|
270
|
-
const sub = await this.getAllTsFiles(full);
|
|
271
|
-
list.push(...sub);
|
|
272
|
-
}
|
|
273
|
-
else if (f.isFile() && f.name.endsWith('.ts')) {
|
|
274
|
-
list.push(full);
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
catch (err) { }
|
|
279
|
-
return list;
|
|
280
|
-
}
|
|
281
|
-
async writeFile(filePath, content) {
|
|
282
|
-
try {
|
|
283
|
-
await utils.waitGC();
|
|
284
|
-
await promises_1.default.mkdir(path_1.default.dirname(filePath), {
|
|
285
|
-
recursive: true
|
|
286
|
-
});
|
|
287
|
-
const data = typeof content === 'string' ? content : JSON.stringify(content, null, 2);
|
|
288
|
-
await promises_1.default.writeFile(filePath, data, 'utf-8');
|
|
289
|
-
}
|
|
290
|
-
catch (err) {
|
|
291
|
-
(0, utils_1.default)(`WRITE FILE ERR: ${filePath}`);
|
|
292
|
-
throw err;
|
|
293
|
-
}
|
|
294
|
-
await utils.waitGC();
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
exports.BaseBuild = BaseBuild;
|
|
1
|
+
"use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,i,a){void 0===a&&(a=i);var s=Object.getOwnPropertyDescriptor(t,i);s&&!("get"in s?!t.__esModule:s.writable||s.configurable)||(s={enumerable:!0,get:function(){return t[i]}}),Object.defineProperty(e,a,s)}:function(e,t,i,a){void 0===a&&(a=i),e[a]=t[i]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),__importStar=this&&this.__importStar||function(){var e=function(t){return e=Object.getOwnPropertyNames||function(e){var t=[];for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[t.length]=i);return t},e(t)};return function(t){if(t&&t.__esModule)return t;var i={};if(null!=t)for(var a=e(t),s=0;s<a.length;s++)"default"!==a[s]&&__createBinding(i,t,a[s]);return __setModuleDefault(i,t),i}}(),__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.BaseBuild=void 0;const promises_1=__importDefault(require("fs/promises")),path_1=__importDefault(require("path")),dayjs_1=__importDefault(require("dayjs")),index_js_1=__importDefault(require("./../lang/index.js")),index_js_2=__importDefault(require("./../runTemp/index.js")),child_process_1=require("child_process"),manifest_build_js_1=require("./manifest.build.js"),node_os_1=__importDefault(require("node:os")),time=()=>(0,dayjs_1.default)().format("YYYY-MM-DD HH:mm:ss"),utils_1=__importDefault(require("./utils")),utils=__importStar(require("./../utils/index.js"));class BaseBuild{static times=time();outdir="";ResOutDir=null;baseCwd="";cwd="";ResCwd="";d_data=null;cacheDir="";dependencies={};Modules=[];constructor(){}async rmPackScriptScriptCache(){await Promise.all([this.rmNpmDes(),promises_1.default.rm(path_1.default.join(this.outdir,"scripts/package-lock.json"),{recursive:!0,force:!0}).catch(()=>{})])}async processResources(){if(await utils.FileExsit(this.ResCwd)&&this.ResOutDir){if(await Promise.all((await promises_1.default.readdir(this.ResCwd)).map(e=>utils.copy(path_1.default.join(this.ResCwd,e),path_1.default.join(this.ResOutDir,e)))),null==this.d_data)throw new Error("[build error]: not load config when init");const e=new manifest_build_js_1.ManiFest(this.d_data,"resources").data;await this.writeFile(path_1.default.join(this.ResOutDir,"manifest.json"),JSON.stringify(e))}else(0,utils_1.default)(index_js_1.default.build.no_resources)}async processDist(){if("dist"===process.env.MBLER_BUILD_MODULE){const e=new index_js_2.default(path_1.default.join(node_os_1.default.tmpdir(),"mbler"));await e.init(),await Promise.all([utils.copy(this.outdir,path_1.default.join(e.dir,"behavior")),await utils.FileExsit(this.ResCwd)?utils.copy(this.ResOutDir,path_1.default.join(e.dir,"resources")):Promise.resolve()]);let t=this.d_data?.outdir?.dist||"dist.mcaddon";".mcaddon"!==path_1.default.extname(t)&&(t+=".mcaddon");const i=path_1.default.join(this.baseCwd,t),a=require("./../../package.json");await promises_1.default.writeFile(path_1.default.join(e.dir,"behavior",".mbler.build.info"),JSON.stringify({mbler:{version:a.version,git:a.repository},time:BaseBuild.times})),await utils.zip([e.dir],i),await e.remove(),(0,utils_1.default)(`${index_js_1.default.build.ziped} ${i}`)}}async loadPackageData(){const e=await utils.GetData(this.baseCwd);if(!e)throw new Error(index_js_1.default.buildBase.cannot_read_project_config);if("object"!=typeof e||null===e)throw new Error(index_js_1.default.buildBase.invalid_project_config_format);return e}getCachePath(e){return path_1.default.join(this.cacheDir,e)}getOutputDir(e,t){const i=e;return i?path_1.default.join(this.baseCwd,i):t}async initNpmDes(){const e=JSON.parse(await promises_1.default.readFile(path_1.default.join(this.baseCwd,"package.json"),"utf-8"));Object.keys(e.dependencies||{}).length<1?(0,utils_1.default)(index_js_1.default.buildBase.npm_deps_skipped_no_json):(await promises_1.default.writeFile(path_1.default.join(this.outdir,"scripts/package.json"),JSON.stringify(e)),await this.#e(path_1.default.join(this.outdir,"scripts")))}#e(e){return new Promise((t,i)=>{(0,utils_1.default)(index_js_1.default.buildBase.starting_npm_install);const a=(0,child_process_1.spawn)("npm",["install"],{cwd:e,stdio:"ignore"});a.on("close",e=>{0===e?((0,utils_1.default)(index_js_1.default.buildBase.npm_install_completed),t(e)):((0,utils_1.default)(index_js_1.default.buildBase.npm_install_exit_code+e),t(e))}),a.on("error",e=>{(0,utils_1.default)(`${index_js_1.default.buildBase.npm_install_error} ${e.stack}`),i(e)})})}async getFileHash(e){if(!await utils.FileExsit(e))return null;const t=await promises_1.default.readFile(e),i=(await import("crypto")).createHash("sha1");return i.update(t),i.digest("hex")}async chackConfigHash(){const e=path_1.default.join(this.cwd,"mbler.config.json"),t=path_1.default.join(this.cwd,"package.json"),i=this.getCachePath("config-hash.txt"),a=this.getCachePath("package-hash.txt"),s=await this.getFileHash(e),r=await this.getFileHash(t);let l=null,n=null;await promises_1.default.access(i).then(()=>!0).catch(()=>!1)&&(l=await promises_1.default.readFile(i,"utf-8")),await promises_1.default.access(a).then(()=>!0).catch(()=>!1)&&(n=await promises_1.default.readFile(a,"utf-8"));const o=!s||s!==l,d=!r||r!==n;return s&&await promises_1.default.writeFile(i,s),r&&await promises_1.default.writeFile(a,r),{configChanged:o,packageChanged:d}}async removeJsFiles(e){try{for(const t of await promises_1.default.readdir(e,{withFileTypes:!0})){const i=path_1.default.join(e,t.name);if(!i.includes("node_modules"))if(t.isDirectory())await this.removeJsFiles(i);else if(t.isFile()&&t.name.endsWith(".js"))try{await promises_1.default.unlink(i)}catch(e){}}}catch(e){}}async rmNpmDes(){const e=path_1.default.join(this.outdir,"scripts/node_modules"),t=this.Modules||Object.keys(this.dependencies);for(let i of await promises_1.default.readdir(e).catch(()=>[]))t.includes(i)||await promises_1.default.rm(path_1.default.join(e,i),{recursive:!0,force:!0}).catch(()=>{})}async copyCompiledOnly(e,t){try{for(const i of await promises_1.default.readdir(e,{withFileTypes:!0})){const a=path_1.default.join(e,i.name),s=path_1.default.join(t,i.name);if(i.isDirectory())await promises_1.default.mkdir(s,{recursive:!0}).catch(()=>{}),await this.copyCompiledOnly(a,s);else if(i.isFile()){const e=path_1.default.extname(i.name).toLowerCase();[".js",".json"].includes(e)&&(await promises_1.default.mkdir(path_1.default.dirname(s),{recursive:!0}).catch(()=>{}),await promises_1.default.copyFile(a,s).catch(()=>{}))}}}catch(e){(0,utils_1.default)(`ERR: ${e&&e.stack?e.stack:e}`)}}async getAllTsFiles(e){const t=[];try{for(const i of await promises_1.default.readdir(e,{withFileTypes:!0})){const a=path_1.default.join(e,i.name);if(i.isDirectory()){const e=await this.getAllTsFiles(a);t.push(...e)}else i.isFile()&&i.name.endsWith(".ts")&&t.push(a)}}catch(e){}return t}async writeFile(e,t){try{await utils.waitGC(),await promises_1.default.mkdir(path_1.default.dirname(e),{recursive:!0});const i="string"==typeof t?t:JSON.stringify(t,null,2);await promises_1.default.writeFile(e,i,"utf-8")}catch(t){throw(0,utils_1.default)(`WRITE FILE ERR: ${e}`),t}await utils.waitGC()}}exports.BaseBuild=BaseBuild;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"resources": {
|
|
3
|
+
"header": "48793164",
|
|
4
|
+
"module": "ab43f7cb"
|
|
5
|
+
},
|
|
6
|
+
"data": {
|
|
7
|
+
"header": "7604691",
|
|
8
|
+
"module": "bcd46f7a"
|
|
9
|
+
},
|
|
10
|
+
"ScriptId": "4654236ace4",
|
|
11
|
+
"PackageFile": "mbler.config.json"
|
|
12
|
+
}
|