@minecraft/creator-tools
Version:
Minecraft Creator Tools command line and libraries.
108 lines (106 loc) • 7.45 kB
JavaScript
;
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
exports.PackSizeInfoGeneratorTest = void 0;
const ProjectInfoItem_1 = require("./ProjectInfoItem");
const IInfoItemData_1 = require("./IInfoItemData");
const StorageUtilities_1 = require("../storage/StorageUtilities");
const ProjectInfoUtilities_1 = require("./ProjectInfoUtilities");
var PackSizeInfoGeneratorTest;
(function (PackSizeInfoGeneratorTest) {
PackSizeInfoGeneratorTest[PackSizeInfoGeneratorTest["overallSize"] = 1] = "overallSize";
PackSizeInfoGeneratorTest[PackSizeInfoGeneratorTest["fileCount"] = 2] = "fileCount";
PackSizeInfoGeneratorTest[PackSizeInfoGeneratorTest["folderCount"] = 3] = "folderCount";
PackSizeInfoGeneratorTest[PackSizeInfoGeneratorTest["contentSize"] = 4] = "contentSize";
PackSizeInfoGeneratorTest[PackSizeInfoGeneratorTest["contentFileCount"] = 5] = "contentFileCount";
PackSizeInfoGeneratorTest[PackSizeInfoGeneratorTest["contentFolderCount"] = 6] = "contentFolderCount";
PackSizeInfoGeneratorTest[PackSizeInfoGeneratorTest["exceedsRecommendedAddonSize"] = 401] = "exceedsRecommendedAddonSize";
PackSizeInfoGeneratorTest[PackSizeInfoGeneratorTest["exceedsRecommendedPackageSize"] = 402] = "exceedsRecommendedPackageSize";
})(PackSizeInfoGeneratorTest = exports.PackSizeInfoGeneratorTest || (exports.PackSizeInfoGeneratorTest = {}));
class PackSizeInfoGenerator {
constructor() {
this.id = "PACKSIZE";
this.title = "Pack Size Information";
this.canAlwaysProcess = true;
this.performAddOnValidations = false;
}
getTopicData(topicId) {
return {
title: ProjectInfoUtilities_1.default.getTitleFromEnum(PackSizeInfoGeneratorTest, topicId),
};
}
summarize(info, infoSet) {
info.overallSize = infoSet.getFirstNumberValue(this.id, PackSizeInfoGeneratorTest.overallSize);
info.fileCounts = infoSet.getFirstNumberValue(this.id, PackSizeInfoGeneratorTest.fileCount);
info.folderCounts = infoSet.getFirstNumberValue(this.id, PackSizeInfoGeneratorTest.folderCount);
info.contentSize = infoSet.getFirstNumberValue(this.id, PackSizeInfoGeneratorTest.contentSize);
info.contentFileCounts = infoSet.getFirstNumberValue(this.id, PackSizeInfoGeneratorTest.contentFileCount);
info.contentFolderCounts = infoSet.getFirstNumberValue(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) {
await folder.load();
if (!isInContent && folder.files["manifest.json"]) {
isInContent = true;
}
for (const fileName in folder.files) {
const file = folder.files[fileName];
if (file) {
await file.loadContent();
results.fileCounts++;
if (StorageUtilities_1.default.isContainerFile(file.fullPath)) {
const storageFolder = await StorageUtilities_1.default.getFileStorageFolder(file);
if (storageFolder) {
await this.processFolder(project, storageFolder, genItems, genContentIndex, results, depth + 1, isInContent);
}
}
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;
//# sourceMappingURL=../maps/info/PackSizeInfoGenerator.js.map