@minecraft/creator-tools
Version:
Minecraft Creator Tools command line and libraries.
90 lines (89 loc) • 4.77 kB
JavaScript
;
// 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.PathLengthFileGeneratorTest = void 0;
const ProjectInfoItem_1 = __importDefault(require("./ProjectInfoItem"));
const IInfoItemData_1 = require("./IInfoItemData");
const StorageUtilities_1 = require("../storage/StorageUtilities");
var PathLengthFileGeneratorTest;
(function (PathLengthFileGeneratorTest) {
PathLengthFileGeneratorTest[PathLengthFileGeneratorTest["filePathExceeds8DirectorySegments"] = 102] = "filePathExceeds8DirectorySegments";
PathLengthFileGeneratorTest[PathLengthFileGeneratorTest["filePathExceedsCharacterLength"] = 103] = "filePathExceedsCharacterLength";
PathLengthFileGeneratorTest[PathLengthFileGeneratorTest["filePathContainsNonLowercaseLetters"] = 104] = "filePathContainsNonLowercaseLetters";
})(PathLengthFileGeneratorTest || (exports.PathLengthFileGeneratorTest = PathLengthFileGeneratorTest = {}));
/**
* Validates file path lengths and naming conventions.
*
* @see {@link ../../public/data/forms/mctoolsval/pathlength.form.json} for topic definitions
*/
class PathLengthFileGenerator {
id = "PATHLENGTH";
title = "Path Length";
canAlwaysProcess = true;
summarize(info, infoSet) { }
async generate(project, file, contentIndex) {
const items = [];
let path = file.storageRelativePath;
let pathSub = path;
pathSub = pathSub.replace("/Content/", "/content/");
pathSub = pathSub.replace("/Marketing Art/", "/marketing art/");
pathSub = pathSub.replace("/Store Art/", "/store art/");
// we don't want to check the marketing art or store art folders, as they are not part of the content
if (pathSub.indexOf("/marketing art/") >= 0 || pathSub.indexOf("/store art/") >= 0) {
return items;
}
if (pathSub.startsWith("/content/")) {
pathSub = pathSub.substring(9);
}
let packsIndex = pathSub.indexOf("_packs/");
if (packsIndex > 0) {
packsIndex = pathSub.indexOf("/", packsIndex + 7);
if (packsIndex >= 0) {
pathSub = pathSub.substring(packsIndex);
}
}
else {
// else, try to find the first subfolder after the second slash
packsIndex = pathSub.indexOf("/", 2);
if (packsIndex >= 0) {
pathSub = pathSub.substring(packsIndex + 1);
}
}
if (pathSub.toLowerCase() !== pathSub &&
!pathSub.startsWith("/marketing art/") &&
!pathSub.startsWith("/store art/") &&
!pathSub.endsWith(".lang") &&
pathSub.indexOf("/texts/") < 0 &&
pathSub.indexOf("/scripts/") < 0) {
items.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.recommendation, this.id, PathLengthFileGeneratorTest.filePathContainsNonLowercaseLetters, `File path contains non-lowercase letters`, project.getItemByExtendedOrProjectPath(file.extendedPath), pathSub));
}
for (const hint of StorageUtilities_1.PackContainerFolderHints) {
const hintIndex = path.toLowerCase().indexOf("/" + hint + "/");
if (hintIndex >= 0) {
path = path.substring(hintIndex + hint.length + 2);
}
}
for (const hint of StorageUtilities_1.PackFolderHints) {
if (path.toLowerCase().startsWith("/" + hint + "/")) {
path = path.substring(hint.length + 2);
}
if (path.toLowerCase().startsWith(hint + "/")) {
path = path.substring(hint.length + 1);
}
}
const fSlashSegments = path.split("/");
const bSlashSegments = path.split("\\");
if (fSlashSegments.length > 9 || bSlashSegments.length > 9) {
items.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.error, this.id, PathLengthFileGeneratorTest.filePathExceeds8DirectorySegments, `File path contains 8 or more directory segments, and may not run on all devices`, project.getItemByExtendedOrProjectPath(file.extendedPath), path));
}
if (path.length > 100) {
items.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.error, this.id, PathLengthFileGeneratorTest.filePathExceedsCharacterLength, `File path contains more than 100 characters, and may not run on all devices`, project.getItemByExtendedOrProjectPath(file.extendedPath), path));
}
return items;
}
}
exports.default = PathLengthFileGenerator;