UNPKG

@minecraft/creator-tools

Version:

Minecraft Creator Tools command line and libraries.

57 lines (56 loc) 2.37 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const TestDefinition_1 = require("../tests/TestDefinition"); const MaxOrphanFileResults = 5; var CheckIntegrityTest; (function (CheckIntegrityTest) { CheckIntegrityTest["OrphanedFile"] = "OrphanedFile"; CheckIntegrityTest["UnexpectedManifest"] = "UnexpectedManifest"; })(CheckIntegrityTest || (CheckIntegrityTest = {})); const CheckIntegrityTests = { OrphanedFile: { id: 101, title: "Extraneous Files Or Folder", defaultMessage: "Project contains extraneous file or folder", }, UnexpectedManifest: { id: 102, title: "Unexpected Manifest Structure", defaultMessage: "Pack has an unexpected structure, multiple manifests detected. Nested manifests are not allowed.", }, }; /** * Validates project structure integrity including orphaned files and nested manifests. * * @see {@link ../../../public/data/forms/mctoolsval/prjint.form.json} for topic definitions */ class CheckProjectIntegrityGenerator { id = "PRJINT"; title = "Project Integrity"; canAlwaysProcess = true; generate(project) { const orphanResults = this.checkOrphanedFiles(project); const manifestResults = this.checkNestedManifests(project); const results = [...orphanResults, ...manifestResults]; return Promise.resolve(results); } checkOrphanedFiles(project) { //limit items to avoid spam, then get results const results = project.unknownFiles .slice(0, MaxOrphanFileResults) .map((file) => (0, TestDefinition_1.resultFromTest)(CheckIntegrityTests.OrphanedFile, { id: this.id, data: file.extendedPath })); return results; } checkNestedManifests(project) { const results = project.packs // get all manifests within each pack .map((pack) => [pack, pack.getPackItems().filter((item) => item.name === "manifest.json")]) // more than one manifest indicates an issue .filter(([_pack, manifests]) => manifests.length > 1) // get results .map(([pack]) => (0, TestDefinition_1.resultFromTest)(CheckIntegrityTests.UnexpectedManifest, { id: this.id, data: pack.name })); return results; } summarize() { } } exports.default = CheckProjectIntegrityGenerator;