UNPKG

@minecraft/creator-tools

Version:

Minecraft Creator Tools command line and libraries.

64 lines (63 loc) 3 kB
"use strict"; // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.validateCommand = exports.ValidateCommand = void 0; const IToolCommand_1 = require("../IToolCommand"); const IProjectInfoData_1 = require("../../../info/IProjectInfoData"); const IInfoItemData_1 = require("../../../info/IInfoItemData"); const ProjectInfoSet_1 = __importDefault(require("../../../info/ProjectInfoSet")); class ValidateCommand extends IToolCommand_1.ToolCommandBase { metadata = { name: "validate", description: "Run inspector validation on the current project and print a summary", aliases: ["val"], category: "Validation", requiresProject: true, isWriteCommand: false, examples: ["/validate", "/val"], }; async execute(context, _args, _flags) { if (!context.project) { context.output.error("No active project — open a project before running /validate."); return this.error("NO_PROJECT", "No active project"); } const project = context.project; try { context.output.info(`Validating project '${project.name}'...`); const infoSet = new ProjectInfoSet_1.default(project, IProjectInfoData_1.ProjectInfoSuite.defaultInDevelopment); await infoSet.generateForProject(); const errors = infoSet.getCountByType(IInfoItemData_1.InfoItemType.error); const warnings = infoSet.getCountByType(IInfoItemData_1.InfoItemType.warning); const recommendations = infoSet.getCountByType(IInfoItemData_1.InfoItemType.recommendation); const internal = infoSet.getCountByType(IInfoItemData_1.InfoItemType.internalProcessingError); const summary = `errors=${errors} warnings=${warnings} recommendations=${recommendations}`; if (errors > 0 || internal > 0) { context.output.error(`Validation: ${summary}`); } else if (warnings > 0) { context.output.warn(`Validation: ${summary}`); } else { context.output.success(`Validation: ${summary}`); } return this.success(summary, { errors, warnings, recommendations, internalProcessingErrors: internal, projectName: project.name, }); } catch (error) { const message = error instanceof Error ? error.message : String(error); context.output.error(`Validation failed: ${message}`); return this.error("VALIDATE_ERROR", `Failed to validate project: ${message}`); } } } exports.ValidateCommand = ValidateCommand; exports.validateCommand = new ValidateCommand();