UNPKG

@minecraft/creator-tools

Version:

Minecraft Creator Tools command line and libraries.

47 lines (46 loc) 2.61 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.ValidGeneratorTest = void 0; const ProjectInfoItem_1 = __importDefault(require("./ProjectInfoItem")); const IInfoItemData_1 = require("./IInfoItemData"); const StorageUtilities_1 = __importDefault(require("../storage/StorageUtilities")); var ValidGeneratorTest; (function (ValidGeneratorTest) { ValidGeneratorTest[ValidGeneratorTest["nonCompliantJson"] = 102] = "nonCompliantJson"; ValidGeneratorTest[ValidGeneratorTest["emptyJson"] = 103] = "emptyJson"; ValidGeneratorTest[ValidGeneratorTest["jsonNotString"] = 104] = "jsonNotString"; })(ValidGeneratorTest || (exports.ValidGeneratorTest = ValidGeneratorTest = {})); /** * Validates file contents for JSON compliance and format correctness. * * @see {@link ../../public/data/forms/mctoolsval/valfile.form.json} for topic definitions */ class ValidFileGenerator { id = "VALFILE"; title = "Valid files"; summarize(info, infoSet) { } async generate(project, file, contentIndex) { const items = []; if (StorageUtilities_1.default.getMimeType(file) === "application/json") { if (!file.isString) { items.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.error, this.id, ValidGeneratorTest.jsonNotString, `JSON file is not a string`, project.getItemByExtendedOrProjectPath(file.extendedPath), file.content ? file.content.length + " bytes" : "unloadable")); } else if (!file.content || file.content?.length < 2) { items.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.error, this.id, ValidGeneratorTest.emptyJson, `JSON file is empty`, project.getItemByExtendedOrProjectPath(file.extendedPath), file.content ? file.content.length + " characters" : "unloadable")); } else { StorageUtilities_1.default.getJsonObject(file); if (file.isInErrorState) { items.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.error, this.id, ValidGeneratorTest.nonCompliantJson, `JSON file is not JSON compliant`, project.getItemByExtendedOrProjectPath(file.extendedPath), file.errorStateMessage ? file.errorStateMessage : "unparseable")); } } } return items; } } exports.default = ValidFileGenerator;