@mafly/bdev-cli 1.0.1 → 1.0.3
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/README.md +3 -0
- package/dist/utils/mojang.js +57 -9
- package/dist/utils/wsserver.d.ts +5 -1
- package/dist/utils/wsserver.js +21 -6
- package/package.json +9 -1
package/README.md
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
# bdev
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/@mafly/bdev-cli)
|
|
4
|
+
[](./LICENSE)
|
|
5
|
+
|
|
3
6
|
A simple CLI tool for Minecraft Bedrock Edition addon development.
|
|
4
7
|
|
|
5
8
|
---
|
package/dist/utils/mojang.js
CHANGED
|
@@ -28,19 +28,55 @@ export function findMojangPath(customPath, projectDir = process.cwd()) {
|
|
|
28
28
|
}
|
|
29
29
|
const platform = os.platform();
|
|
30
30
|
if (platform === "win32") {
|
|
31
|
+
const appData = process.env.APPDATA || path.join(os.homedir(), "AppData", "Roaming");
|
|
31
32
|
const localAppData = process.env.LOCALAPPDATA ||
|
|
32
33
|
path.join(os.homedir(), "AppData", "Local");
|
|
34
|
+
// Modern Windows GDK Bedrock (Shared folder contains dev packs)
|
|
35
|
+
const gdkShared = path.join(appData, "Minecraft Bedrock", "Users", "Shared", "games", "com.mojang");
|
|
36
|
+
if (fs.existsSync(gdkShared)) {
|
|
37
|
+
return makeLocations(gdkShared, "retail");
|
|
38
|
+
}
|
|
39
|
+
const gdkPreviewShared = path.join(appData, "Minecraft Bedrock Preview", "Users", "Shared", "games", "com.mojang");
|
|
40
|
+
if (fs.existsSync(gdkPreviewShared)) {
|
|
41
|
+
return makeLocations(gdkPreviewShared, "preview");
|
|
42
|
+
}
|
|
43
|
+
// Classic UWP Retail
|
|
33
44
|
const retail = path.join(localAppData, "Packages", "Microsoft.MinecraftUWP_8wekyb3d8bbwe", "LocalState", "games", "com.mojang");
|
|
34
45
|
if (fs.existsSync(retail)) {
|
|
35
46
|
return makeLocations(retail, "retail");
|
|
36
47
|
}
|
|
48
|
+
// Classic UWP Preview
|
|
37
49
|
const preview = path.join(localAppData, "Packages", "Microsoft.MinecraftWindowsBeta_8wekyb3d8bbwe", "LocalState", "games", "com.mojang");
|
|
38
50
|
if (fs.existsSync(preview)) {
|
|
39
51
|
return makeLocations(preview, "preview");
|
|
40
52
|
}
|
|
41
53
|
}
|
|
42
|
-
// Check WSL
|
|
54
|
+
// Check Linux / Bedrock-on-linux / Proton / WSL
|
|
43
55
|
if (platform === "linux") {
|
|
56
|
+
// 1. Bedrock-on-Linux (Proton / Wine)
|
|
57
|
+
const bolBase = path.join(os.homedir(), ".local", "share", "bedrock-on-linux");
|
|
58
|
+
if (fs.existsSync(bolBase)) {
|
|
59
|
+
const profilesDir = path.join(bolBase, "profiles");
|
|
60
|
+
if (fs.existsSync(profilesDir)) {
|
|
61
|
+
try {
|
|
62
|
+
const profiles = fs.readdirSync(profilesDir);
|
|
63
|
+
for (const prof of profiles) {
|
|
64
|
+
const sharedPfx = path.join(profilesDir, prof, "compatdata", "pfx", "drive_c", "users", "steamuser", "AppData", "Roaming", "Minecraft Bedrock", "Users", "Shared", "games", "com.mojang");
|
|
65
|
+
if (fs.existsSync(sharedPfx)) {
|
|
66
|
+
return makeLocations(sharedPfx, "linux");
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
// ignore profile read errors
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
const defaultShared = path.join(bolBase, "compatdata", "pfx", "drive_c", "users", "steamuser", "AppData", "Roaming", "Minecraft Bedrock", "Users", "Shared", "games", "com.mojang");
|
|
75
|
+
if (fs.existsSync(defaultShared)) {
|
|
76
|
+
return makeLocations(defaultShared, "linux");
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
// 2. Check WSL
|
|
44
80
|
try {
|
|
45
81
|
const isWsl = Boolean(process.env.WSL_DISTRO_NAME) ||
|
|
46
82
|
fs.readFileSync("/proc/version", "utf-8").toLowerCase().includes("microsoft");
|
|
@@ -49,14 +85,14 @@ export function findMojangPath(customPath, projectDir = process.cwd()) {
|
|
|
49
85
|
if (fs.existsSync(mntCUsers)) {
|
|
50
86
|
const users = fs.readdirSync(mntCUsers);
|
|
51
87
|
for (const u of users) {
|
|
88
|
+
const gdk = path.join(mntCUsers, u, "AppData", "Roaming", "Minecraft Bedrock", "Users", "Shared", "games", "com.mojang");
|
|
89
|
+
if (fs.existsSync(gdk)) {
|
|
90
|
+
return makeLocations(gdk, "wsl");
|
|
91
|
+
}
|
|
52
92
|
const retail = path.join(mntCUsers, u, "AppData", "Local", "Packages", "Microsoft.MinecraftUWP_8wekyb3d8bbwe", "LocalState", "games", "com.mojang");
|
|
53
93
|
if (fs.existsSync(retail)) {
|
|
54
94
|
return makeLocations(retail, "wsl");
|
|
55
95
|
}
|
|
56
|
-
const preview = path.join(mntCUsers, u, "AppData", "Local", "Packages", "Microsoft.MinecraftWindowsBeta_8wekyb3d8bbwe", "LocalState", "games", "com.mojang");
|
|
57
|
-
if (fs.existsSync(preview)) {
|
|
58
|
-
return makeLocations(preview, "wsl");
|
|
59
|
-
}
|
|
60
96
|
}
|
|
61
97
|
}
|
|
62
98
|
}
|
|
@@ -64,7 +100,7 @@ export function findMojangPath(customPath, projectDir = process.cwd()) {
|
|
|
64
100
|
catch {
|
|
65
101
|
// Ignore read errors
|
|
66
102
|
}
|
|
67
|
-
// Native Linux
|
|
103
|
+
// 3. Native Linux mcpelauncher locations
|
|
68
104
|
const linuxMcpelauncherPaths = [
|
|
69
105
|
path.join(os.homedir(), ".var", "app", "io.mrarm.mcpelauncher", "data", "mcpelauncher", "games", "com.mojang"),
|
|
70
106
|
path.join(os.homedir(), ".local", "share", "mcpelauncher", "games", "com.mojang"),
|
|
@@ -78,10 +114,22 @@ export function findMojangPath(customPath, projectDir = process.cwd()) {
|
|
|
78
114
|
return null;
|
|
79
115
|
}
|
|
80
116
|
function makeLocations(root, type) {
|
|
117
|
+
// If pointing to a specific user XUID directory in Bedrock GDK (e.g. Users/<XUID>/games/com.mojang),
|
|
118
|
+
// Bedrock GDK only scans packs from Users/Shared/games/com.mojang.
|
|
119
|
+
let packsRoot = root;
|
|
120
|
+
try {
|
|
121
|
+
const sharedCandidate = path.resolve(root, "..", "..", "..", "Shared", "games", "com.mojang");
|
|
122
|
+
if (fs.existsSync(sharedCandidate)) {
|
|
123
|
+
packsRoot = sharedCandidate;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
catch {
|
|
127
|
+
// Ignore resolution errors
|
|
128
|
+
}
|
|
81
129
|
return {
|
|
82
|
-
root,
|
|
83
|
-
devBehaviorPacks: path.join(
|
|
84
|
-
devResourcePacks: path.join(
|
|
130
|
+
root: packsRoot,
|
|
131
|
+
devBehaviorPacks: path.join(packsRoot, "development_behavior_packs"),
|
|
132
|
+
devResourcePacks: path.join(packsRoot, "development_resource_packs"),
|
|
85
133
|
type,
|
|
86
134
|
};
|
|
87
135
|
}
|
package/dist/utils/wsserver.d.ts
CHANGED
|
@@ -2,11 +2,15 @@ export interface BedrockCommandRequest {
|
|
|
2
2
|
header: {
|
|
3
3
|
version: number;
|
|
4
4
|
requestId: string;
|
|
5
|
+
messageType: "commandRequest";
|
|
5
6
|
messagePurpose: "commandRequest";
|
|
6
7
|
};
|
|
7
8
|
body: {
|
|
8
|
-
commandLine: string;
|
|
9
9
|
version: number;
|
|
10
|
+
commandLine: string;
|
|
11
|
+
origin: {
|
|
12
|
+
type: "player";
|
|
13
|
+
};
|
|
10
14
|
};
|
|
11
15
|
}
|
|
12
16
|
export declare class BedrockHotReloadServer {
|
package/dist/utils/wsserver.js
CHANGED
|
@@ -35,13 +35,24 @@ export class BedrockHotReloadServer {
|
|
|
35
35
|
server.on("connection", (socket) => {
|
|
36
36
|
this.clients.add(socket);
|
|
37
37
|
logger.success(pc.green("Minecraft connected to WebSocket hot reload!"));
|
|
38
|
-
//
|
|
39
|
-
|
|
38
|
+
// Bedrock expects an event subscription to establish connection cleanly
|
|
39
|
+
const subscribePayload = {
|
|
40
|
+
header: {
|
|
41
|
+
version: 1,
|
|
42
|
+
requestId: uuidv4(),
|
|
43
|
+
messageType: "commandRequest",
|
|
44
|
+
messagePurpose: "subscribe",
|
|
45
|
+
},
|
|
46
|
+
body: {
|
|
47
|
+
eventName: "PlayerMessage",
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
socket.send(JSON.stringify(subscribePayload));
|
|
40
51
|
socket.on("message", (data) => {
|
|
41
52
|
try {
|
|
42
53
|
const res = JSON.parse(data.toString());
|
|
43
54
|
if (res?.body?.statusCode && res.body.statusCode !== 0) {
|
|
44
|
-
logger.warn(`Minecraft command
|
|
55
|
+
logger.warn(`Minecraft command response: ${res.body.statusMessage || "Error"}`);
|
|
45
56
|
}
|
|
46
57
|
}
|
|
47
58
|
catch {
|
|
@@ -65,15 +76,21 @@ export class BedrockHotReloadServer {
|
|
|
65
76
|
}
|
|
66
77
|
}
|
|
67
78
|
sendCommandToSocket(socket, commandLine) {
|
|
79
|
+
// Bedrock commandLine must NOT have a leading slash
|
|
80
|
+
const cleanCmd = commandLine.startsWith("/") ? commandLine.slice(1) : commandLine;
|
|
68
81
|
const payload = {
|
|
69
82
|
header: {
|
|
70
83
|
version: 1,
|
|
71
84
|
requestId: uuidv4(),
|
|
85
|
+
messageType: "commandRequest",
|
|
72
86
|
messagePurpose: "commandRequest",
|
|
73
87
|
},
|
|
74
88
|
body: {
|
|
75
|
-
commandLine,
|
|
76
89
|
version: 1,
|
|
90
|
+
commandLine: cleanCmd,
|
|
91
|
+
origin: {
|
|
92
|
+
type: "player",
|
|
93
|
+
},
|
|
77
94
|
},
|
|
78
95
|
};
|
|
79
96
|
socket.send(JSON.stringify(payload));
|
|
@@ -82,8 +99,6 @@ export class BedrockHotReloadServer {
|
|
|
82
99
|
if (this.clients.size === 0) {
|
|
83
100
|
return;
|
|
84
101
|
}
|
|
85
|
-
// Notify in game chat and execute reload command
|
|
86
|
-
this.sendCommand('tellraw @a {"rawtext":[{"text":"§e[bdev] Reloading scripts..."}]}');
|
|
87
102
|
this.sendCommand("reload");
|
|
88
103
|
}
|
|
89
104
|
get clientCount() {
|
package/package.json
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mafly/bdev-cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "Modern CLI tool for Minecraft Bedrock Edition Addon development",
|
|
5
5
|
"author": "Mafly",
|
|
6
6
|
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/Nekoplii/bdev.git"
|
|
10
|
+
},
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/Nekoplii/bdev/issues"
|
|
13
|
+
},
|
|
14
|
+
"homepage": "https://github.com/Nekoplii/bdev#readme",
|
|
7
15
|
"publishConfig": {
|
|
8
16
|
"access": "public"
|
|
9
17
|
},
|