@minecraft/creator-tools
Version:
Minecraft Creator Tools command line and libraries.
116 lines (115 loc) • 8.31 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.PackSizeInfoGeneratorTest = void 0;
const ProjectInfoItem_1 = __importDefault(require("./ProjectInfoItem"));
const IInfoItemData_1 = require("./IInfoItemData");
const StorageUtilities_1 = __importDefault(require("../storage/StorageUtilities"));
const ProjectInfoUtilities_1 = __importDefault(require("./ProjectInfoUtilities"));
var PackSizeInfoGeneratorTest;
(function (PackSizeInfoGeneratorTest) {
PackSizeInfoGeneratorTest[PackSizeInfoGeneratorTest["overallSize"] = 101] = "overallSize";
PackSizeInfoGeneratorTest[PackSizeInfoGeneratorTest["fileCount"] = 102] = "fileCount";
PackSizeInfoGeneratorTest[PackSizeInfoGeneratorTest["folderCount"] = 103] = "folderCount";
PackSizeInfoGeneratorTest[PackSizeInfoGeneratorTest["contentSize"] = 104] = "contentSize";
PackSizeInfoGeneratorTest[PackSizeInfoGeneratorTest["contentFileCount"] = 105] = "contentFileCount";
PackSizeInfoGeneratorTest[PackSizeInfoGeneratorTest["contentFolderCount"] = 106] = "contentFolderCount";
PackSizeInfoGeneratorTest[PackSizeInfoGeneratorTest["exceedsRecommendedAddonSize"] = 401] = "exceedsRecommendedAddonSize";
PackSizeInfoGeneratorTest[PackSizeInfoGeneratorTest["exceedsRecommendedPackageSize"] = 402] = "exceedsRecommendedPackageSize";
PackSizeInfoGeneratorTest[PackSizeInfoGeneratorTest["zipFileCouldNotBeProcessed"] = 410] = "zipFileCouldNotBeProcessed";
})(PackSizeInfoGeneratorTest || (exports.PackSizeInfoGeneratorTest = PackSizeInfoGeneratorTest = {}));
/**
* Calculates and validates pack size information including file and folder counts.
*
* @see {@link ../../public/data/forms/mctoolsval/packsize.form.json} for topic definitions
*/
class PackSizeInfoGenerator {
id = "PACKSIZE";
title = "Pack Size Information";
canAlwaysProcess = true;
performAddOnValidations = false;
summarize(info, infoSet) {
info.overallSize = infoSet.getFirstNumberDataValue(this.id, PackSizeInfoGeneratorTest.overallSize);
info.fileCounts = infoSet.getFirstNumberDataValue(this.id, PackSizeInfoGeneratorTest.fileCount);
info.folderCounts = infoSet.getFirstNumberDataValue(this.id, PackSizeInfoGeneratorTest.folderCount);
info.contentSize = infoSet.getFirstNumberDataValue(this.id, PackSizeInfoGeneratorTest.contentSize);
info.contentFileCounts = infoSet.getFirstNumberDataValue(this.id, PackSizeInfoGeneratorTest.contentFileCount);
info.contentFolderCounts = infoSet.getFirstNumberDataValue(this.id, PackSizeInfoGeneratorTest.contentFolderCount);
}
async generate(project, contentIndex) {
const genItems = [];
const results = {
size: 0,
fileCounts: 0,
folderCounts: 0,
contentSize: 0,
contentFileCounts: 0,
contentFolderCounts: 0,
};
await this.processFolder(project, await project.ensureProjectFolder(), genItems, contentIndex, results, 0, false);
genItems.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.featureAggregate, this.id, PackSizeInfoGeneratorTest.overallSize, ProjectInfoUtilities_1.default.getTitleFromEnum(PackSizeInfoGeneratorTest, PackSizeInfoGeneratorTest.overallSize), undefined, results.size));
genItems.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.featureAggregate, this.id, PackSizeInfoGeneratorTest.fileCount, ProjectInfoUtilities_1.default.getTitleFromEnum(PackSizeInfoGeneratorTest, PackSizeInfoGeneratorTest.fileCount), undefined, results.fileCounts));
genItems.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.featureAggregate, this.id, PackSizeInfoGeneratorTest.folderCount, ProjectInfoUtilities_1.default.getTitleFromEnum(PackSizeInfoGeneratorTest, PackSizeInfoGeneratorTest.folderCount), undefined, results.folderCounts));
genItems.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.featureAggregate, this.id, PackSizeInfoGeneratorTest.contentSize, ProjectInfoUtilities_1.default.getTitleFromEnum(PackSizeInfoGeneratorTest, PackSizeInfoGeneratorTest.contentSize), undefined, results.contentSize));
genItems.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.featureAggregate, this.id, PackSizeInfoGeneratorTest.contentFileCount, ProjectInfoUtilities_1.default.getTitleFromEnum(PackSizeInfoGeneratorTest, PackSizeInfoGeneratorTest.contentFileCount), undefined, results.contentFileCounts));
genItems.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.featureAggregate, this.id, PackSizeInfoGeneratorTest.contentFolderCount, ProjectInfoUtilities_1.default.getTitleFromEnum(PackSizeInfoGeneratorTest, PackSizeInfoGeneratorTest.contentFolderCount), undefined, results.contentFolderCounts));
if (this.performAddOnValidations && results.contentSize > 25000000) {
genItems.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.error, this.id, PackSizeInfoGeneratorTest.exceedsRecommendedAddonSize, ProjectInfoUtilities_1.default.getTitleFromEnum(PackSizeInfoGeneratorTest, PackSizeInfoGeneratorTest.exceedsRecommendedAddonSize), undefined, results.contentSize));
}
else if (!this.performAddOnValidations && results.contentSize > 250000000) {
genItems.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.error, this.id, PackSizeInfoGeneratorTest.exceedsRecommendedPackageSize, ProjectInfoUtilities_1.default.getTitleFromEnum(PackSizeInfoGeneratorTest, PackSizeInfoGeneratorTest.exceedsRecommendedPackageSize), undefined, results.contentSize));
}
return genItems;
}
async processFolder(project, folder, genItems, genContentIndex, results, depth, isInContent) {
if (!folder.isLoaded) {
await folder.load();
}
if (!isInContent && folder.files["manifest.json"]) {
isInContent = true;
}
for (const fileName in folder.files) {
const file = folder.files[fileName];
if (file) {
if (!file.isContentLoaded) {
await file.loadContent();
}
results.fileCounts++;
if (StorageUtilities_1.default.isContainerFile(file.fullPath)) {
let storageFolder = undefined;
storageFolder = await StorageUtilities_1.default.getFileStorageFolder(file);
if (storageFolder && typeof storageFolder !== "string") {
await this.processFolder(project, storageFolder, genItems, genContentIndex, results, depth + 1, isInContent);
}
else if (typeof storageFolder === "string") {
genItems.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.error, this.id, PackSizeInfoGeneratorTest.zipFileCouldNotBeProcessed, ProjectInfoUtilities_1.default.getTitleFromEnum(PackSizeInfoGeneratorTest, PackSizeInfoGeneratorTest.exceedsRecommendedPackageSize), undefined, file.errorStateMessage));
}
}
else {
if (isInContent) {
results.contentFileCounts++;
results.contentSize += file.coreContentLength;
}
results.size += file.coreContentLength;
}
}
}
if ((isInContent && depth < 15) || (!isInContent && depth < 8)) {
for (const folderName in folder.folders) {
const childFolder = folder.folders[folderName];
if (childFolder && !childFolder.errorStatus && childFolder.name) {
results.folderCounts++;
if (isInContent) {
results.contentFolderCounts++;
}
await this.processFolder(project, childFolder, genItems, genContentIndex, results, depth + 1, isInContent);
}
}
}
}
}
exports.default = PackSizeInfoGenerator;