mcaddon-generator 1.0.0
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/addon_files/BP/manifest.json +27 -0
- package/addon_files/BP/pack_icon.png +0 -0
- package/addon_files/BP/scripts/output/main.js +4 -0
- package/addon_files/BP/scripts/source/main.ts +5 -0
- package/addon_files/RP/manifest.json +27 -0
- package/addon_files/RP/pack_icon.png +0 -0
- package/package.json +21 -0
- package/scripts/output/commands/create/createBP.js +33 -0
- package/scripts/output/commands/create/createPack.js +34 -0
- package/scripts/output/commands/create/createRP.js +14 -0
- package/scripts/output/commands/create/main.js +82 -0
- package/scripts/output/commands/pack.js +55 -0
- package/scripts/output/index.js +45 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"format_version": 3,
|
|
3
|
+
"header": {
|
|
4
|
+
"name": "",
|
|
5
|
+
"description": "",
|
|
6
|
+
"min_engine_version": {},
|
|
7
|
+
"version": "1.0.0",
|
|
8
|
+
"uuid": ""
|
|
9
|
+
},
|
|
10
|
+
"metadata": {
|
|
11
|
+
"authors": [
|
|
12
|
+
],
|
|
13
|
+
"generated_with": {
|
|
14
|
+
"mcaddon": [
|
|
15
|
+
"1.0.0"
|
|
16
|
+
]
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"modules": [
|
|
20
|
+
{
|
|
21
|
+
"type": "data",
|
|
22
|
+
"description": "Allows the addition of blocks, items, and entities into your addon",
|
|
23
|
+
"version": "1.0.0",
|
|
24
|
+
"uuid": ""
|
|
25
|
+
}
|
|
26
|
+
]
|
|
27
|
+
}
|
|
Binary file
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"format_version": 3,
|
|
3
|
+
"header": {
|
|
4
|
+
"name": "",
|
|
5
|
+
"description": "",
|
|
6
|
+
"min_engine_version": {},
|
|
7
|
+
"version": "1.0.0",
|
|
8
|
+
"uuid": ""
|
|
9
|
+
},
|
|
10
|
+
"metadata": {
|
|
11
|
+
"authors": [
|
|
12
|
+
],
|
|
13
|
+
"generated_with": {
|
|
14
|
+
"mcaddon": [
|
|
15
|
+
"1.0.0"
|
|
16
|
+
]
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"modules": [
|
|
20
|
+
{
|
|
21
|
+
"type": "resources",
|
|
22
|
+
"description": "Allows the addition of textures, models, sounds, and more into your addon",
|
|
23
|
+
"version": "1.0.0",
|
|
24
|
+
"uuid": ""
|
|
25
|
+
}
|
|
26
|
+
]
|
|
27
|
+
}
|
|
Binary file
|
package/package.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "mcaddon-generator",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Enables creators to be more efficient in creating and packaging their addons",
|
|
5
|
+
"license": "ISC",
|
|
6
|
+
"author": "AngrySalt",
|
|
7
|
+
"type": "commonjs",
|
|
8
|
+
"main": "scripts/output/index.js",
|
|
9
|
+
"keywords": [
|
|
10
|
+
"minecraft"
|
|
11
|
+
],
|
|
12
|
+
"bin": {
|
|
13
|
+
"mcaddon": "scripts/output/index.js"
|
|
14
|
+
},
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"@types/node": "^25.5.2",
|
|
17
|
+
"commander": "^14.0.3",
|
|
18
|
+
"uuid": "^13.0.0",
|
|
19
|
+
"zip-a-folder": "^6.1.0"
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CreateBP = CreateBP;
|
|
4
|
+
const node_crypto_1 = require("node:crypto");
|
|
5
|
+
const path = require("node:path");
|
|
6
|
+
const createPack_1 = require("./createPack");
|
|
7
|
+
const __1 = require("../..");
|
|
8
|
+
const BASE_BP_FOLDER = path.join(createPack_1.addonFilesFolder, "BP");
|
|
9
|
+
function CreateBP(bpUUID, rpUUID, args, destinationDirectory) {
|
|
10
|
+
var _a;
|
|
11
|
+
const base_manifest = require(path.join(BASE_BP_FOLDER, "manifest.json"));
|
|
12
|
+
let manifest = (0, createPack_1.ApplySharedManifestInfo)(base_manifest, args, bpUUID, (args.rp && rpUUID) || undefined);
|
|
13
|
+
if (args.script) {
|
|
14
|
+
manifest.modules.push({
|
|
15
|
+
type: "script",
|
|
16
|
+
language: "javascript",
|
|
17
|
+
entry: "scripts/output/main.js",
|
|
18
|
+
description: "Allows you to add scripts that can interact with your minecraft world through APIs",
|
|
19
|
+
uuid: (0, node_crypto_1.randomUUID)(),
|
|
20
|
+
version: "1.0.0"
|
|
21
|
+
});
|
|
22
|
+
manifest.dependencies = (_a = manifest.dependencies) !== null && _a !== void 0 ? _a : [];
|
|
23
|
+
manifest.dependencies.push({
|
|
24
|
+
module_name: "@minecraft/server",
|
|
25
|
+
version: args.script_version
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
const filePath = (0, __1.GetPackFolder)(destinationDirectory, __1.PackType.BP, args);
|
|
29
|
+
(0, createPack_1.SavePackFiles)(manifest, BASE_BP_FOLDER, filePath, args.script == false ?
|
|
30
|
+
((source) => !(source.endsWith("scripts") || source.endsWith("package.json") || source.endsWith("tsconfig.json")))
|
|
31
|
+
: undefined);
|
|
32
|
+
return filePath;
|
|
33
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addonFilesFolder = void 0;
|
|
4
|
+
exports.ApplySharedManifestInfo = ApplySharedManifestInfo;
|
|
5
|
+
exports.SavePackFiles = SavePackFiles;
|
|
6
|
+
const node_crypto_1 = require("node:crypto");
|
|
7
|
+
const path = require("node:path");
|
|
8
|
+
const filesystem = require("node:fs");
|
|
9
|
+
function FormatVersionNumber(args, version) {
|
|
10
|
+
return args.format_version == 3 ? version : version.split(".").map(parseFloat);
|
|
11
|
+
}
|
|
12
|
+
function ApplySharedManifestInfo(manifest, args, uuid, dependentId) {
|
|
13
|
+
manifest.header.name = args.name;
|
|
14
|
+
manifest.header.description = args.description;
|
|
15
|
+
manifest.header.uuid = uuid;
|
|
16
|
+
manifest.header.min_engine_version = FormatVersionNumber(args, args.engine_version);
|
|
17
|
+
manifest.modules[0].uuid = (0, node_crypto_1.randomUUID)();
|
|
18
|
+
if (dependentId) {
|
|
19
|
+
manifest.dependencies = [{
|
|
20
|
+
uuid: dependentId,
|
|
21
|
+
version: "1.0.0"
|
|
22
|
+
}];
|
|
23
|
+
}
|
|
24
|
+
manifest.metadata.authors.push(args.author);
|
|
25
|
+
return manifest;
|
|
26
|
+
}
|
|
27
|
+
exports.addonFilesFolder = path.join(__dirname, "..", "..", "..", "..", "addon_files");
|
|
28
|
+
function SavePackFiles(manifest, sourceDirectory, directory, filter) {
|
|
29
|
+
filesystem.cpSync(sourceDirectory, directory, { recursive: true, filter });
|
|
30
|
+
filesystem.writeFile(path.join(directory, "manifest.json"), JSON.stringify(manifest, undefined, 4), (e) => {
|
|
31
|
+
if (e)
|
|
32
|
+
console.error(`Error when writing BP manifest file: ${e}`);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CreateRP = CreateRP;
|
|
4
|
+
const path = require("node:path");
|
|
5
|
+
const createPack_1 = require("./createPack");
|
|
6
|
+
const __1 = require("../..");
|
|
7
|
+
const BASE_RP_FOLDER = path.join(createPack_1.addonFilesFolder, "RP");
|
|
8
|
+
function CreateRP(rpUUID, bpUUID, args, destinationDirectory) {
|
|
9
|
+
const base_manifest = require(path.join(BASE_RP_FOLDER, "manifest.json"));
|
|
10
|
+
const manifest = (0, createPack_1.ApplySharedManifestInfo)(base_manifest, args, rpUUID, bpUUID);
|
|
11
|
+
const filePath = (0, __1.GetPackFolder)(destinationDirectory, __1.PackType.RP, args);
|
|
12
|
+
(0, createPack_1.SavePackFiles)(manifest, BASE_RP_FOLDER, filePath);
|
|
13
|
+
return filePath;
|
|
14
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.CreateCommand = void 0;
|
|
13
|
+
const commander_1 = require("commander");
|
|
14
|
+
const node_process_1 = require("node:process");
|
|
15
|
+
const node_crypto_1 = require("node:crypto");
|
|
16
|
+
const createBP_1 = require("./createBP");
|
|
17
|
+
const createRP_1 = require("./createRP");
|
|
18
|
+
const path = require("node:path");
|
|
19
|
+
const filesystem = require("node:fs");
|
|
20
|
+
const readline = require("node:readline");
|
|
21
|
+
const __1 = require("../..");
|
|
22
|
+
let rl;
|
|
23
|
+
function AskQuestion(question, defaultAnswer) {
|
|
24
|
+
question += `? (${defaultAnswer}): `;
|
|
25
|
+
return new Promise((r) => {
|
|
26
|
+
rl.question(question, (answer) => r(answer.length > 0 ? answer : defaultAnswer));
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
function ExecuteCreateCommand(args) {
|
|
30
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
if (args.beta)
|
|
32
|
+
args.script_version = "beta";
|
|
33
|
+
(0, __1.AssertArgs)(args.preview && args.here, "--preview or --here must be false");
|
|
34
|
+
(0, __1.AssertArgs)(!(args.bp === true || args.rp === true), "Must either output a BP file, a RP file, or both. Cannot do neither");
|
|
35
|
+
rl = readline.createInterface({ input: node_process_1.stdin, output: node_process_1.stdout });
|
|
36
|
+
if (!args.name)
|
|
37
|
+
args.name = yield AskQuestion("name", "PACK_NAME");
|
|
38
|
+
if (!args.description)
|
|
39
|
+
args.description = yield AskQuestion("description", "pack.description");
|
|
40
|
+
if (!args.author)
|
|
41
|
+
args.author = yield AskQuestion("author", "");
|
|
42
|
+
rl.close();
|
|
43
|
+
let bpUUID = (0, node_crypto_1.randomUUID)();
|
|
44
|
+
let rpUUID = (0, node_crypto_1.randomUUID)();
|
|
45
|
+
const destinationDirectory = (0, __1.GetTargetDirectory)(args);
|
|
46
|
+
if (!filesystem.existsSync(destinationDirectory)) {
|
|
47
|
+
console.error(`${destinationDirectory} doesn't exist!`);
|
|
48
|
+
(0, node_process_1.exit)(1);
|
|
49
|
+
}
|
|
50
|
+
const workspaceData = {
|
|
51
|
+
folders: [],
|
|
52
|
+
settings: {}
|
|
53
|
+
};
|
|
54
|
+
if (args.bp)
|
|
55
|
+
workspaceData.folders.push({ path: (0, createBP_1.CreateBP)(bpUUID, rpUUID, args, destinationDirectory) });
|
|
56
|
+
if (args.rp)
|
|
57
|
+
workspaceData.folders.push({ path: (0, createRP_1.CreateRP)(rpUUID, bpUUID, args, destinationDirectory) });
|
|
58
|
+
if (!args.vscode)
|
|
59
|
+
return;
|
|
60
|
+
filesystem.writeFileSync(path.join(process.cwd(), `${args.name}.code-workspace`), JSON.stringify(workspaceData, undefined, 4));
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
exports.CreateCommand = new commander_1.Command("create")
|
|
64
|
+
.description("Used to create both BPs and RPs for MCBE")
|
|
65
|
+
.option("--name, -n <NAME>", "Set the name used for both packs")
|
|
66
|
+
.option("--description, -d <DESCRIPTION>", "Set the description used for both packs")
|
|
67
|
+
.option("--author, -a <AUTHOR>", "Specify the author of the project")
|
|
68
|
+
.option("--bp [VALUE]", "Whether or not to create a behavior pack", true)
|
|
69
|
+
.option("--no-bp")
|
|
70
|
+
.option("--rp [VALUE]", "Whether or not to create a resource pack", true)
|
|
71
|
+
.option("--no-rp")
|
|
72
|
+
.option("--here, -h", "Output the packs into the current directory. By default the pack files will go into your minecraft development folders", false)
|
|
73
|
+
.option("--preview, -p", "Will output your packs into the preview version of the game", false)
|
|
74
|
+
.option("--script [VALUE]", "Whether or not to use the script api", true)
|
|
75
|
+
.option("--no-script")
|
|
76
|
+
.option("--script_version <VERSION>", "What version to use for the @minecraft/server api", "2.6.0")
|
|
77
|
+
.option("--beta, -b", "Shorthand for --script_version beta", false)
|
|
78
|
+
.option("--engine_version, -v <VERSION>", "The minimum engine version", "1.26.0")
|
|
79
|
+
.option("--format_version <VERSION>", "The format_version of the manifest", parseInt, 3)
|
|
80
|
+
.option("--vscode [VALUE]", "Whether or not to output a vscode workspace file in the current directory", true)
|
|
81
|
+
.option("--no-vscode")
|
|
82
|
+
.action(ExecuteCreateCommand);
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.PACK_COMMAND = void 0;
|
|
13
|
+
const commander_1 = require("commander");
|
|
14
|
+
const index_1 = require("../index");
|
|
15
|
+
const path = require("node:path");
|
|
16
|
+
const filesystem = require("node:fs");
|
|
17
|
+
const node_process_1 = require("node:process");
|
|
18
|
+
const zip_a_folder_1 = require("zip-a-folder");
|
|
19
|
+
exports.PACK_COMMAND = new commander_1.Command()
|
|
20
|
+
.name("pack")
|
|
21
|
+
.description("Packs up your existing pack to be downloaded and imported by other players")
|
|
22
|
+
.requiredOption("--name, -n <NAME>", "The name of your pack(s)")
|
|
23
|
+
.option("--here, -h [VALUE]", "Look for files in the current directory", false)
|
|
24
|
+
.option("--preview, -p", "Look for files in the Minecraft Preview directory", false)
|
|
25
|
+
.action((args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
26
|
+
(0, index_1.AssertArgs)(args.here && args.preview, "Either --preview or --here must be false");
|
|
27
|
+
const directory = (0, index_1.GetTargetDirectory)(args);
|
|
28
|
+
const bpFolder = (0, index_1.GetPackFolder)(directory, index_1.PackType.BP, args);
|
|
29
|
+
const rpFolder = (0, index_1.GetPackFolder)(directory, index_1.PackType.RP, args);
|
|
30
|
+
const newDirectory = path.join(process.cwd(), args.name);
|
|
31
|
+
const hasBp = filesystem.existsSync(bpFolder);
|
|
32
|
+
const hasRp = filesystem.existsSync(rpFolder);
|
|
33
|
+
if (!(hasBp || hasRp)) {
|
|
34
|
+
console.error("Couldn't find neither a BP or a RP");
|
|
35
|
+
(0, node_process_1.exit)(1);
|
|
36
|
+
}
|
|
37
|
+
if (filesystem.existsSync(newDirectory)) {
|
|
38
|
+
console.error("Folder with addon name already exists!");
|
|
39
|
+
(0, node_process_1.exit)(1);
|
|
40
|
+
}
|
|
41
|
+
if (hasBp) {
|
|
42
|
+
const newBpDirectory = path.join(newDirectory, "BP");
|
|
43
|
+
filesystem.cpSync(bpFolder, newBpDirectory, { recursive: true });
|
|
44
|
+
// Optimize the BP by removing un-needed files
|
|
45
|
+
const targetFiles = filesystem.globSync([path.join(newBpDirectory, "package.json"), path.join(newBpDirectory, "**", "tsconfig.json"), path.join(newBpDirectory, "scripts", "source"), path.join(newBpDirectory, "**", "*.ts")]);
|
|
46
|
+
targetFiles.forEach(filePath => {
|
|
47
|
+
if (filesystem.existsSync(filePath))
|
|
48
|
+
filesystem.rmSync(filePath, { recursive: true });
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
if (hasRp)
|
|
52
|
+
filesystem.cpSync(rpFolder, path.join(newDirectory, "RP"), { recursive: true });
|
|
53
|
+
yield (0, zip_a_folder_1.zip)(newDirectory, newDirectory + ".mcaddon");
|
|
54
|
+
filesystem.rmSync(newDirectory, { recursive: true });
|
|
55
|
+
}));
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
#! /usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.PackType = void 0;
|
|
5
|
+
exports.GetTargetDirectory = GetTargetDirectory;
|
|
6
|
+
exports.GetPackFolder = GetPackFolder;
|
|
7
|
+
exports.AssertArgs = AssertArgs;
|
|
8
|
+
const commander_1 = require("commander");
|
|
9
|
+
const main_1 = require("./commands/create/main");
|
|
10
|
+
const node_process_1 = require("node:process");
|
|
11
|
+
const path = require("node:path");
|
|
12
|
+
const os = require("node:os");
|
|
13
|
+
const pack_1 = require("./commands/pack");
|
|
14
|
+
const program = new commander_1.Command("mcaddon")
|
|
15
|
+
.description("Enables more efficient creation in MCBE addons")
|
|
16
|
+
.version("1.0.0")
|
|
17
|
+
.helpCommand(true)
|
|
18
|
+
.action(() => {
|
|
19
|
+
program.help();
|
|
20
|
+
});
|
|
21
|
+
function GetTargetDirectory({ here, preview }) {
|
|
22
|
+
const userDirectory = os.homedir();
|
|
23
|
+
const currentDirectory = process.cwd();
|
|
24
|
+
const minecraftDirectory = path.join(userDirectory, "AppData", "Roaming", "Minecraft Bedrock", "Users", "Shared", "games", "com.mojang");
|
|
25
|
+
const previewDirectory = path.join(userDirectory, "AppData", "Roaming", "Minecraft Bedrock Preview", "Users", "Shared", "games", "com.mojang");
|
|
26
|
+
return here ? currentDirectory : preview ? previewDirectory : minecraftDirectory;
|
|
27
|
+
}
|
|
28
|
+
var PackType;
|
|
29
|
+
(function (PackType) {
|
|
30
|
+
PackType["BP"] = "BP";
|
|
31
|
+
PackType["RP"] = "RP";
|
|
32
|
+
})(PackType || (exports.PackType = PackType = {}));
|
|
33
|
+
function GetPackFolder(directory, packType, { name, here }) {
|
|
34
|
+
const nameNoSpaces = name.replace(" ", "") + packType;
|
|
35
|
+
return here ? path.join(directory, nameNoSpaces) : path.join(directory, packType == PackType.BP ? "development_behavior_packs" : "development_resource_packs", nameNoSpaces);
|
|
36
|
+
}
|
|
37
|
+
function AssertArgs(condition, errorMsg) {
|
|
38
|
+
if (condition) {
|
|
39
|
+
console.error(errorMsg);
|
|
40
|
+
(0, node_process_1.exit)(9);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
program.addCommand(pack_1.PACK_COMMAND);
|
|
44
|
+
program.addCommand(main_1.CreateCommand);
|
|
45
|
+
program.parse();
|