bedrock-development
Version:
APIs for creating and editing files related to Minecraft Bedrock development.
35 lines (34 loc) • 1.56 kB
JavaScript
var _a;
import { Option } from "commander";
import { setFiles } from "../../file_manager.js";
import { MCFunction } from "../../types/index.js";
import { implementConfig } from "../../utils.js";
import { CommandMap } from "../command_map.js";
CommandMap.addCommand("root.new.function", {
parent: (_a = CommandMap.getCommandEntry("root.new")) === null || _a === void 0 ? void 0 : _a.command,
commandOptions(command) {
command
.name("function")
.description('creates new bedrock functions')
.argument('<names...>', 'function names as "foo/bar"')
.addOption(new Option('-c, --commands [function commands...]', 'the commands in the function'))
.option('-d, --description <description>', 'the description of the function, used as a comment')
.option('-s, --source <source>', 'where is this function called from, used as a comment')
.option('-o, --origin <origin>', 'who is @s within this function, used as a comment');
},
commandAction: triggerCreateNewFunction,
});
function triggerCreateNewFunction(names, options) {
implementConfig();
const description = options.description;
const source = options.source;
const selector = options.origin;
names.forEach((name) => {
if (!name.endsWith('.mcfunction')) {
name += ".mcfunction";
}
const mcfunction = new MCFunction(name);
mcfunction.addCommand(options.commands, { description, source, selector });
setFiles(mcfunction.files);
});
}