"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Log_1 = require("../core/Log");
const Utilities_1 = require("../core/Utilities");
const BehaviorManifestDefinition_1 = require("../minecraft/BehaviorManifestDefinition");
const DesignManifestDefinition_1 = require("../minecraft/DesignManifestDefinition");
const MinecraftUtilities_1 = require("../minecraft/MinecraftUtilities");
const Pack_1 = require("../minecraft/Pack");
const ResourceManifestDefinition_1 = require("../minecraft/ResourceManifestDefinition");
const SkinManifestDefinition_1 = require("../minecraft/SkinManifestDefinition");
const StorageUtilities_1 = require("../storage/StorageUtilities");
const IProjectData_1 = require("./IProjectData");
const IProjectItemData_1 = require("./IProjectItemData");
const Project_1 = require("./Project");
class ProjectItemInference {
    static async inferProjectItemsFromFolder(project, folder, fileSystemPrefix, folderContext, variantLabel, isInWorld, rootFolder, depth, source, force, processingCallback) {
        if (project.projectFolder === null ||
            (folder.name.startsWith(".") && !folder.name.startsWith(".vscode") && !folder.name.startsWith(".mct"))) {
            Log_1.default.debugAlert("Could not process folder: " + folder.storageRelativePath);
            return;
        }
        if (processingCallback) {
            processingCallback("Scanning `" + folder.storageRelativePath + "` for Minecraft project items.");
        }
        await folder.load(force ? force : false);
        let parentFolder = folder.parentFolder;
        if (parentFolder === project.projectFolder.parentFolder) {
            parentFolder = null;
        }
        const folderPathCanon = StorageUtilities_1.default.canonicalizePath(StorageUtilities_1.default.getFolderPath(folder.storageRelativePath));
        const parentIsPacksRoot = parentFolder !== null &&
            parentFolder.name.indexOf("_packs") >= 0 &&
            (folderContext === Project_1.FolderContext.behaviorPack ||
                folderContext === Project_1.FolderContext.resourcePack ||
                folderContext === Project_1.FolderContext.skinPack);
        const lastUnderscore = folder.storageRelativePath.lastIndexOf("_");
        if (!variantLabel && lastUnderscore >= 0 && parentIsPacksRoot) {
            // vanilla stores folders like:
            // chemistry
            // chemistry_1.20.50
            // chemistry_1.20.60
            // unify version variants with their parent
            let potentialVersionSection = folder.storageRelativePath.substring(lastUnderscore + 1);
            if (potentialVersionSection.endsWith("/")) {
                potentialVersionSection = potentialVersionSection.substring(0, potentialVersionSection.length - 1);
            }
            if (Utilities_1.default.isNumericIsh(potentialVersionSection) && potentialVersionSection.indexOf(".") > 0) {
                variantLabel = potentialVersionSection;
            }
        }
        if (folderPathCanon.indexOf("/checkpoint_input") >= 0 ||
            folderPathCanon.indexOf("/metadata") >= 0 ||
            folderPathCanon.indexOf("/type_definitions") >= 0 ||
            folderPathCanon.indexOf("/typedefs") >= 0 ||
            folderPathCanon.indexOf("/script_modules/") >= 0 ||
            folderPathCanon.indexOf("/vanilladata_modules/") >= 0 ||
            folderPathCanon.indexOf("/engine_modules/") >= 0 ||
            folderPathCanon.indexOf("/command_modules/") >= 0) {
            folderContext = Project_1.FolderContext.typeDefs;
        }
        else if (folderPathCanon.indexOf("/data/") >= 0 || folderPathCanon.indexOf("/forms/") >= 0) {
            folderContext = Project_1.FolderContext.metaData;
        }
        else if (folderPathCanon.indexOf("/.vscode") >= 0) {
            folderContext = Project_1.FolderContext.vscodeFolder;
        }
        else if (folderPathCanon.indexOf("/.mct") >= 0) {
            folderContext = Project_1.FolderContext.mctoolsWorkingFolder;
        }
        else if (MinecraftUtilities_1.default.pathLooksLikeBehaviorPackName(folderPathCanon)) {
            folderContext = Project_1.FolderContext.behaviorPack;
        }
        else if (MinecraftUtilities_1.default.pathLooksLikeDesignPackName(folderPathCanon)) {
            folderContext = Project_1.FolderContext.designPack;
        }
        else if (MinecraftUtilities_1.default.pathLooksLikeSubPacksFolderName(folderPathCanon)) {
            // note this check must be above the .resourcePack check
            folderContext = Project_1.FolderContext.resourcePackSubPack;
        }
        else if (MinecraftUtilities_1.default.pathLooksLikeResourcePackName(folderPathCanon)) {
            folderContext = Project_1.FolderContext.resourcePack;
        }
        else if (MinecraftUtilities_1.default.pathLooksLikeSkinPackName(folderPathCanon) &&
            folderContext === Project_1.FolderContext.unknown) {
            folderContext = Project_1.FolderContext.skinPack;
        }
        else if (MinecraftUtilities_1.default.pathLooksLikePersonaPackName(folderPathCanon) &&
            folderContext === Project_1.FolderContext.unknown) {
            folderContext = Project_1.FolderContext.persona;
        }
        else if (MinecraftUtilities_1.default.pathLooksLikeWorldFolderName(folderPathCanon) &&
            folderContext === Project_1.FolderContext.unknown) {
            folderContext = Project_1.FolderContext.world;
            isInWorld = true;
        }
        else if ((folderPathCanon.indexOf("/docs/") >= 0 ||
            folderPathCanon.indexOf("/@minecraft/") >= 0 ||
            folderPathCanon.indexOf("/mojang-commands") >= 0) &&
            folderContext === Project_1.FolderContext.unknown) {
            folderContext = Project_1.FolderContext.docs;
            if (project.docsContainer === null) {
                project.docsContainer = folder.parentFolder;
            }
        }
        if (folderContext === Project_1.FolderContext.unknown &&
            (folder.files["manifest.json"] || folder.files["pack_manifest.json"]) &&
            !folder.files["level.dat"] &&
            !folder.files["levelname.txt"]) {
            for (const folderName in folder.folders) {
                if (folderName) {
                    if (folderName.toLowerCase() === "persona" || folderName.toLowerCase().startsWith("persona_")) {
                        folderContext = Project_1.FolderContext.persona;
                    }
                }
            }
        }
        if (folderContext === Project_1.FolderContext.unknown &&
            (folder.files["manifest.json"] || folder.files["pack_manifest.json"]) &&
            !folder.files["level.dat"] &&
            !folder.files["levelname.txt"]) {
            if (folder.folders["models"] ||
                folder.folders["textures"] ||
                folder.folders["lighting"] ||
                folder.folders["subpacks"] ||
                folder.folders["assets"] ||
                folder.folders["sounds"] ||
                folder.folders["texture_sets"] ||
                folder.folders["sounds"] ||
                folder.folders["ui"]) {
                folderContext = Project_1.FolderContext.resourcePack;
            }
            else if (MinecraftUtilities_1.default.pathLooksLikeResourcePackName(folder.fullPath)) {
                folderContext = Project_1.FolderContext.resourcePack;
            }
            else if (MinecraftUtilities_1.default.pathLooksLikeDesignPackName(folder.fullPath)) {
                folderContext = Project_1.FolderContext.designPack;
            }
            else {
                folderContext = Project_1.FolderContext.behaviorPack;
            }
        }
        if (folder.files["world_behavior_packs.json"] ||
            folder.files["world_resource_packs.json"] ||
            folder.files["levelname.txt"]) {
            if (folderContext === Project_1.FolderContext.unknown) {
                folderContext = Project_1.FolderContext.world;
            }
            if (folder.parentFolder && !project.worldContainer) {
                project.worldContainer = folder.parentFolder;
            }
        }
        for (const fileName in folder.files) {
            const canonFileName = StorageUtilities_1.default.canonicalizeName(fileName);
            // console.log("Considering " + canonFileName + " in folder " + folder.storageRelativePath);
            if (canonFileName !== "gulpfile.js" && canonFileName !== "package-lock.json") {
                const candidateFile = folder.files[fileName];
                if (candidateFile !== undefined) {
                    let pi = null;
                    let projectPath = undefined;
                    if (fileSystemPrefix.length > 0) {
                        projectPath = fileSystemPrefix + candidateFile.fullPath;
                        pi = project.getItemByProjectPath(projectPath);
                    }
                    else {
                        const frPath = candidateFile.getFolderRelativePath(rootFolder);
                        if (frPath !== undefined) {
                            projectPath = StorageUtilities_1.default.canonicalizePath(frPath);
                            pi = project.getItemByProjectPath(projectPath);
                        }
                    }
                    if ((pi === undefined || pi === null) && projectPath !== undefined) {
                        const fileExtension = candidateFile.type ? candidateFile.type.toLowerCase() : candidateFile.type;
                        const baseName = StorageUtilities_1.default.getBaseFromName(candidateFile.name);
                        const folderPath = StorageUtilities_1.default.canonicalizePath(StorageUtilities_1.default.getFolderPath(projectPath));
                        const folderPathLower = folderPath.toLowerCase();
                        const projectPathLower = projectPath.toLowerCase();
                        const isResourcePack = folderContext === Project_1.FolderContext.resourcePack || folderContext === Project_1.FolderContext.resourcePackSubPack;
                        if (canonFileName === "manifest.json" || canonFileName === "pack_manifest.json") {
                            if (folderContext === Project_1.FolderContext.world) {
                                project.defaultWorldFolder = folder;
                                project.worldContainer = parentFolder;
                            }
                            await candidateFile.loadContent(false);
                            let newPiType = IProjectItemData_1.ProjectItemType.unknown;
                            let tag = "";
                            if (folderContext === Project_1.FolderContext.behaviorPack) {
                                newPiType = IProjectItemData_1.ProjectItemType.behaviorPackManifestJson;
                                tag = "behaviorpackmanifest";
                            }
                            else if (folderContext === Project_1.FolderContext.resourcePack) {
                                newPiType = IProjectItemData_1.ProjectItemType.resourcePackManifestJson;
                                tag = "resourcepackmanifest";
                            }
                            else if (folderContext === Project_1.FolderContext.designPack) {
                                newPiType = IProjectItemData_1.ProjectItemType.designPackManifestJson;
                                tag = "designpackmanifest";
                            }
                            else if (folderContext === Project_1.FolderContext.skinPack) {
                                newPiType = IProjectItemData_1.ProjectItemType.skinPackManifestJson;
                                tag = "skinpackmanifest";
                            }
                            else if (folderContext === Project_1.FolderContext.persona) {
                                newPiType = IProjectItemData_1.ProjectItemType.personaManifestJson;
                                tag = "personapackmanifest";
                            }
                            else if (folderContext === Project_1.FolderContext.world) {
                                newPiType = IProjectItemData_1.ProjectItemType.worldTemplateManifestJson;
                                tag = "worldtemplatemanifest";
                            }
                            if (candidateFile.content !== undefined &&
                                candidateFile.content !== "" &&
                                !variantLabel &&
                                typeof candidateFile.content === "string") {
                                if (newPiType === IProjectItemData_1.ProjectItemType.behaviorPackManifestJson) {
                                    const bpManifest = await BehaviorManifestDefinition_1.default.ensureOnFile(candidateFile);
                                    if (bpManifest && bpManifest.id) {
                                        project.defaultBehaviorPackUniqueId = bpManifest.id;
                                        if (bpManifest.name) {
                                            project.title = bpManifest.name;
                                        }
                                        if (bpManifest.description) {
                                            project.description = bpManifest.description;
                                        }
                                        if (bpManifest.version) {
                                            project.defaultBehaviorPackVersion = bpManifest.version;
                                            if (bpManifest.version !== undefined && bpManifest.version.length === 3) {
                                                project.versionMajor = bpManifest.version[0];
                                                project.versionMinor = bpManifest.version[1];
                                                project.versionPatch = bpManifest.version[2];
                                            }
                                        }
                                        project.defaultBehaviorPackFolder = folder;
                                        project.behaviorPacksContainer = parentFolder;
                                        const scriptModuleId = bpManifest.getScriptModule()?.uuid;
                                        if (scriptModuleId) {
                                            project.defaultScriptModuleUniqueId = scriptModuleId;
                                        }
                                        project.ensurePackByFolder(folder, Pack_1.PackType.behavior);
                                    }
                                }
                                else if (newPiType === IProjectItemData_1.ProjectItemType.resourcePackManifestJson) {
                                    const rpManifest = await ResourceManifestDefinition_1.default.ensureOnFile(candidateFile);
                                    if (rpManifest && rpManifest.id) {
                                        project.defaultResourcePackUniqueId = rpManifest.id;
                                        if (rpManifest.name) {
                                            project.title = rpManifest.name;
                                        }
                                        if (rpManifest.description) {
                                            project.description = rpManifest.description;
                                        }
                                        if (rpManifest.version) {
                                            project.defaultResourcePackVersion = rpManifest.version;
                                            if (rpManifest.version !== undefined && rpManifest.version.length === 3) {
                                                project.versionMajor = rpManifest.version[0];
                                                project.versionMinor = rpManifest.version[1];
                                                project.versionPatch = rpManifest.version[2];
                                            }
                                        }
                                        project.defaultResourcePackFolder = folder;
                                        project.resourcePacksContainer = parentFolder;
                                        const subpacks = rpManifest.subpacks;
                                        if (subpacks) {
                                            for (const subpack of subpacks) {
                                                if (subpack.folder_name) {
                                                    const pv = project.ensureVariant(subpack.folder_name);
                                                    if (subpack.memory_tier) {
                                                        pv.memoryTier = subpack.memory_tier;
                                                    }
                                                    if (subpack.name) {
                                                        pv.title = subpack.name;
                                                    }
                                                }
                                            }
                                        }
                                        project.ensurePackByFolder(folder, Pack_1.PackType.resource);
                                    }
                                }
                                else if (newPiType === IProjectItemData_1.ProjectItemType.skinPackManifestJson) {
                                    const spManifest = await SkinManifestDefinition_1.default.ensureOnFile(candidateFile);
                                    if (spManifest) {
                                        if (spManifest.name) {
                                            project.title = spManifest.name;
                                        }
                                        if (spManifest.description) {
                                            project.description = spManifest.description;
                                        }
                                        project.defaultSkinPackFolder = folder;
                                        project.skinPacksContainer = parentFolder;
                                        project.ensurePackByFolder(folder, Pack_1.PackType.skin);
                                    }
                                }
                                else if (newPiType === IProjectItemData_1.ProjectItemType.designPackManifestJson) {
                                    const dpManifest = await DesignManifestDefinition_1.default.ensureOnFile(candidateFile);
                                    if (dpManifest) {
                                        if (dpManifest.name) {
                                            project.title = dpManifest.name;
                                        }
                                        if (dpManifest.description) {
                                            project.description = dpManifest.description;
                                        }
                                        project.defaultDesignPackFolder = folder;
                                        project.designPacksContainer = parentFolder;
                                        project.ensurePackByFolder(folder, Pack_1.PackType.design);
                                    }
                                }
                            }
                            // Log.assert(newPiType !== ProjectItemType.unknown, "Unknown manifest.json file found.");
                            project.ensureItemByProjectPath(projectPath, IProjectItemData_1.ProjectItemStorageType.singleFile, candidateFile.name, newPiType, folderContext, source, IProjectItemData_1.ProjectItemCreationType.normal, candidateFile, tag, isInWorld);
                        }
                        else if (projectPathLower.endsWith("/scripts/index.js")) {
                            await candidateFile.loadContent();
                            let creationType = IProjectItemData_1.ProjectItemCreationType.normal;
                            if (candidateFile.content === undefined ||
                                candidateFile.content === "" ||
                                (typeof candidateFile.content === "string" &&
                                    candidateFile.content.indexOf(Project_1.AUTOGENERATED_CONTENT_TOKEN) >= 0)) {
                                creationType = IProjectItemData_1.ProjectItemCreationType.generated;
                            }
                            project.ensureItemByTag("jsindex", "index.js", IProjectItemData_1.ProjectItemType.catalogIndexJs, projectPath, IProjectItemData_1.ProjectItemStorageType.singleFile, creationType, candidateFile, isInWorld);
                        }
                        else if (projectPathLower.endsWith(".mctp.json") &&
                            folderContext === Project_1.FolderContext.mctoolsWorkingFolder) {
                            project.ensureItemByProjectPath(projectPath, IProjectItemData_1.ProjectItemStorageType.singleFile, candidateFile.name, IProjectItemData_1.ProjectItemType.mcToolsProjectPreferences, folderContext, source, IProjectItemData_1.ProjectItemCreationType.normal, candidateFile, undefined, isInWorld);
                        }
                        else if (projectPathLower.endsWith("tasks.json") && folderContext === Project_1.FolderContext.vscodeFolder) {
                            project.ensureItemByProjectPath(projectPath, IProjectItemData_1.ProjectItemStorageType.singleFile, candidateFile.name, IProjectItemData_1.ProjectItemType.vsCodeTasksJson, folderContext, source, IProjectItemData_1.ProjectItemCreationType.normal, candidateFile, undefined, isInWorld);
                        }
                        else if (projectPathLower.endsWith("launch.json") && folderContext === Project_1.FolderContext.vscodeFolder) {
                            project.ensureItemByProjectPath(projectPath, IProjectItemData_1.ProjectItemStorageType.singleFile, candidateFile.name, IProjectItemData_1.ProjectItemType.vsCodeLaunchJson, folderContext, source, IProjectItemData_1.ProjectItemCreationType.normal, candidateFile, undefined, isInWorld);
                        }
                        else if (projectPathLower.endsWith("settings.json") && folderContext === Project_1.FolderContext.vscodeFolder) {
                            project.ensureItemByProjectPath(projectPath, IProjectItemData_1.ProjectItemStorageType.singleFile, candidateFile.name, IProjectItemData_1.ProjectItemType.vsCodeSettingsJson, folderContext, source, IProjectItemData_1.ProjectItemCreationType.normal, candidateFile, undefined, isInWorld);
                        }
                        else if (projectPathLower.endsWith("extensions.json") && folderContext === Project_1.FolderContext.vscodeFolder) {
                            project.ensureItemByProjectPath(projectPath, IProjectItemData_1.ProjectItemStorageType.singleFile, candidateFile.name, IProjectItemData_1.ProjectItemType.vsCodeExtensionsJson, folderContext, source, IProjectItemData_1.ProjectItemCreationType.normal, candidateFile, undefined, isInWorld);
                        }
                        else if (projectPathLower.endsWith("/tick.json")) {
                            project.ensureItemByProjectPath(projectPath, IProjectItemData_1.ProjectItemStorageType.singleFile, candidateFile.name, IProjectItemData_1.ProjectItemType.tickJson, folderContext, source, IProjectItemData_1.ProjectItemCreationType.normal, candidateFile, undefined, isInWorld);
                        }
                        else if (fileExtension === "mcstructure") {
                            project.ensureItemByProjectPath(projectPath, IProjectItemData_1.ProjectItemStorageType.singleFile, candidateFile.name, IProjectItemData_1.ProjectItemType.structure, folderContext, source, IProjectItemData_1.ProjectItemCreationType.normal, candidateFile, undefined, isInWorld);
                        }
                        else if (fileExtension === "mcfunction") {
                            project.ensureItemByProjectPath(projectPath, IProjectItemData_1.ProjectItemStorageType.singleFile, candidateFile.name, IProjectItemData_1.ProjectItemType.MCFunction, folderContext, source, IProjectItemData_1.ProjectItemCreationType.normal, candidateFile, undefined, isInWorld);
                        }
                        else if (fileExtension === "material") {
                            project.ensureItemByProjectPath(projectPath, IProjectItemData_1.ProjectItemStorageType.singleFile, candidateFile.name, IProjectItemData_1.ProjectItemType.material, folderContext, source, IProjectItemData_1.ProjectItemCreationType.normal, candidateFile, undefined, isInWorld);
                        }
                        else if (fileExtension === "vertex") {
                            project.ensureItemByProjectPath(projectPath, IProjectItemData_1.ProjectItemStorageType.singleFile, candidateFile.name, IProjectItemData_1.ProjectItemType.materialVertex, folderContext, source, IProjectItemData_1.ProjectItemCreationType.normal, candidateFile, undefined, isInWorld);
                        }
                        else if (fileExtension === "fragment") {
                            project.ensureItemByProjectPath(projectPath, IProjectItemData_1.ProjectItemStorageType.singleFile, candidateFile.name, IProjectItemData_1.ProjectItemType.materialFragment, folderContext, source, IProjectItemData_1.ProjectItemCreationType.normal, candidateFile, undefined, isInWorld);
                        }
                        else if (fileExtension === "geometry") {
                            project.ensureItemByProjectPath(projectPath, IProjectItemData_1.ProjectItemStorageType.singleFile, candidateFile.name, IProjectItemData_1.ProjectItemType.materialGeometry, folderContext, source, IProjectItemData_1.ProjectItemCreationType.normal, candidateFile, undefined, isInWorld);
                        }
                        else if (canonFileName === "level.dat" &&
                            fileSystemPrefix.indexOf(".mcworld") < 0 && // don't create a project item if we're inside of a mcworld/mctemplate since that broader item has a link already
                            fileSystemPrefix.indexOf(".mctemplate") < 0 &&
                            folderContext !== Project_1.FolderContext.behaviorPack) {
                            isInWorld = true;
                            project.ensureItemByProjectPath(folderPath, IProjectItemData_1.ProjectItemStorageType.folder, candidateFile.name, IProjectItemData_1.ProjectItemType.worldFolder, folderContext, source, IProjectItemData_1.ProjectItemCreationType.normal, candidateFile, undefined, isInWorld);
                        }
                        else if (canonFileName === "just.config.ts") {
                            project.ensureItemByProjectPath(projectPath, IProjectItemData_1.ProjectItemStorageType.singleFile, candidateFile.name, IProjectItemData_1.ProjectItemType.justConfigTs, folderContext, source, IProjectItemData_1.ProjectItemCreationType.normal, candidateFile, undefined, isInWorld);
                        }
                        else if (canonFileName === "eslint.config.mjs") {
                            project.ensureItemByProjectPath(projectPath, IProjectItemData_1.ProjectItemStorageType.singleFile, candidateFile.name, IProjectItemData_1.ProjectItemType.esLintConfigMjs, folderContext, source, IProjectItemData_1.ProjectItemCreationType.normal, candidateFile, undefined, isInWorld);
                        }
                        else if (fileExtension === "js") {
                            project.ensureItemByProjectPath(projectPath, IProjectItemData_1.ProjectItemStorageType.singleFile, candidateFile.name, IProjectItemData_1.ProjectItemType.js, folderContext, source, IProjectItemData_1.ProjectItemCreationType.normal, candidateFile, undefined, isInWorld);
                        }
                        else if (fileExtension === "ts") {
                            project.ensureItemByProjectPath(projectPath, IProjectItemData_1.ProjectItemStorageType.singleFile, candidateFile.name, IProjectItemData_1.ProjectItemType.ts, folderContext, source, IProjectItemData_1.ProjectItemCreationType.normal, candidateFile, undefined, isInWorld);
                        }
                        else if (fileExtension === "mcworld") {
                            project.ensureItemByProjectPath(projectPath, IProjectItemData_1.ProjectItemStorageType.singleFile, candidateFile.name, IProjectItemData_1.ProjectItemType.MCWorld, folderContext, source, IProjectItemData_1.ProjectItemCreationType.normal, candidateFile, undefined, isInWorld);
                            await project.inferProjectItemsFromZipFile(projectPath, candidateFile, force);
                        }
                        else if (fileExtension === "mcproject") {
                            project.ensureItemByProjectPath(projectPath, IProjectItemData_1.ProjectItemStorageType.singleFile, candidateFile.name, IProjectItemData_1.ProjectItemType.MCProject, folderContext, source, IProjectItemData_1.ProjectItemCreationType.normal, candidateFile, undefined, isInWorld);
                            await project.inferProjectItemsFromZipFile(projectPath, candidateFile, force);
                        }
                        else if (fileExtension === "mctemplate") {
                            project.ensureItemByProjectPath(projectPath, IProjectItemData_1.ProjectItemStorageType.singleFile, candidateFile.name, IProjectItemData_1.ProjectItemType.MCTemplate, folderContext, source, IProjectItemData_1.ProjectItemCreationType.normal, candidateFile, undefined, isInWorld);
                            await project.inferProjectItemsFromZipFile(projectPath, candidateFile, force);
                        }
                        else if (fileExtension === "mcaddon") {
                            project.ensureItemByProjectPath(projectPath, IProjectItemData_1.ProjectItemStorageType.singleFile, candidateFile.name, IProjectItemData_1.ProjectItemType.MCAddon, folderContext, source, IProjectItemData_1.ProjectItemCreationType.normal, candidateFile, undefined, isInWorld);
                            await project.inferProjectItemsFromZipFile(projectPath, candidateFile, force);
                        }
                        else if (fileExtension === "mcpack") {
                            project.ensureItemByProjectPath(projectPath, IProjectItemData_1.ProjectItemStorageType.singleFile, candidateFile.name, IProjectItemData_1.ProjectItemType.MCPack, folderContext, source, IProjectItemData_1.ProjectItemCreationType.normal, candidateFile, undefined, isInWorld);
                            await project.inferProjectItemsFromZipFile(projectPath, candidateFile, force);
                        }
                        else if (fileExtension === "zip") {
                            project.ensureItemByProjectPath(projectPath, IProjectItemData_1.ProjectItemStorageType.singleFile, candidateFile.name, IProjectItemData_1.ProjectItemType.zip, folderContext, source, IProjectItemData_1.ProjectItemCreationType.normal, candidateFile, undefined, isInWorld);
                            await project.inferProjectItemsFromZipFile(projectPath, candidateFile, force);
                        }
                        else if (fileExtension === "png" ||
                            fileExtension === "jpg" ||
                            fileExtension === "gif" ||
                            fileExtension === "psd" ||
                            fileExtension === "jpeg" ||
                            fileExtension === "tga") {
                            let imageType = IProjectItemData_1.ProjectItemType.image;
                            if (folderPathLower.indexOf("/marketing art/") >= 0) {
                                imageType = IProjectItemData_1.ProjectItemType.marketingAssetImage;
                            }
                            else if (folderPathLower.indexOf("/store art/") >= 0) {
                                imageType = IProjectItemData_1.ProjectItemType.storeAssetImage;
                            }
                            else if (folderPathLower.indexOf("/textures/ui/") >= 0) {
                                imageType = IProjectItemData_1.ProjectItemType.uiTexture;
                            }
                            else if (folderPathLower.indexOf("/design_textures/") >= 0) {
                                imageType = IProjectItemData_1.ProjectItemType.designTexture;
                            }
                            else if (folderPathLower.indexOf("/textures/") >= 0 || folderContext === Project_1.FolderContext.skinPack) {
                                imageType = IProjectItemData_1.ProjectItemType.texture;
                            }
                            else if (baseName === "pack_icon" || folder.files["manifest.json"]) {
                                imageType = IProjectItemData_1.ProjectItemType.packIconImage;
                            }
                            project.ensureItemByProjectPath(projectPath, IProjectItemData_1.ProjectItemStorageType.singleFile, candidateFile.name, imageType, folderContext, source, IProjectItemData_1.ProjectItemCreationType.normal, candidateFile, undefined, isInWorld);
                        }
                        else if (fileExtension === "ogg" ||
                            fileExtension === "flac" ||
                            fileExtension === "mp3" ||
                            fileExtension === "wav") {
                            project.ensureItemByProjectPath(projectPath, IProjectItemData_1.ProjectItemStorageType.singleFile, candidateFile.name, IProjectItemData_1.ProjectItemType.audio, folderContext, source, IProjectItemData_1.ProjectItemCreationType.normal, candidateFile, undefined, isInWorld);
                        }
                        else if (fileExtension === "env" && baseName === "") {
                            project.ensureItemByProjectPath(projectPath, IProjectItemData_1.ProjectItemStorageType.singleFile, candidateFile.name, IProjectItemData_1.ProjectItemType.env, folderContext, source, IProjectItemData_1.ProjectItemCreationType.normal, candidateFile, undefined, isInWorld);
                        }
                        else if (fileExtension === "lang") {
                            project.ensureItemByProjectPath(projectPath, IProjectItemData_1.ProjectItemStorageType.singleFile, candidateFile.name, IProjectItemData_1.ProjectItemType.lang, folderContext, source, IProjectItemData_1.ProjectItemCreationType.normal, candidateFile, undefined, isInWorld);
                        }
                        else if (fileExtension === "json") {
                            let newJsonType = IProjectItemData_1.ProjectItemType.unknownJson;
                            let itemName = candidateFile.name;
                            if (folderContext === Project_1.FolderContext.behaviorPack && folderPathLower.indexOf("/loot_tables/") >= 0) {
                                newJsonType = IProjectItemData_1.ProjectItemType.lootTableBehavior;
                            }
                            else if (folderContext === Project_1.FolderContext.behaviorPack && folderPathLower.indexOf("/dialogue/") >= 0) {
                                newJsonType = IProjectItemData_1.ProjectItemType.dialogueBehaviorJson;
                            }
                            else if (folderContext === Project_1.FolderContext.behaviorPack && folderPathLower.indexOf("/recipes/") >= 0) {
                                newJsonType = IProjectItemData_1.ProjectItemType.recipeBehavior;
                            }
                            else if (folderContext === Project_1.FolderContext.behaviorPack &&
                                folderPathLower.indexOf("/spawn_rules/") >= 0) {
                                newJsonType = IProjectItemData_1.ProjectItemType.spawnRuleBehavior;
                            }
                            else if (folderContext === Project_1.FolderContext.behaviorPack &&
                                folderPathLower.indexOf("/cameras/") >= 0 &&
                                folderPathLower.indexOf("aim_assist_preset") >= 0) {
                                newJsonType = IProjectItemData_1.ProjectItemType.aimAssistPresetJson;
                            }
                            else if (folderContext === Project_1.FolderContext.behaviorPack &&
                                folderPathLower.indexOf("/aim_assist/categories/") >= 0) {
                                newJsonType = IProjectItemData_1.ProjectItemType.aimAssistCategoryJson;
                            }
                            else if (folderContext === Project_1.FolderContext.behaviorPack &&
                                folderPathLower.indexOf("/aim_assist/presets/") >= 0) {
                                newJsonType = IProjectItemData_1.ProjectItemType.aimAssistPresetJson;
                            }
                            else if (folderContext === Project_1.FolderContext.behaviorPack &&
                                folderPathLower.indexOf("/behavior_trees/") >= 0) {
                                newJsonType = IProjectItemData_1.ProjectItemType.behaviorTreeJson;
                            }
                            else if (folderPathLower.indexOf("/spawn_groups/") >= 0) {
                                newJsonType = IProjectItemData_1.ProjectItemType.spawnGroupJson;
                            }
                            else if (isResourcePack && folderPathLower.indexOf("/atmospherics/") >= 0) {
                                newJsonType = IProjectItemData_1.ProjectItemType.atmosphericsJson;
                            }
                            else if (isResourcePack && folderPathLower.indexOf("/point_lights/") >= 0) {
                                newJsonType = IProjectItemData_1.ProjectItemType.pointLightsJson;
                            }
                            else if (isResourcePack && folderPathLower.indexOf("/color_grading/") >= 0) {
                                newJsonType = IProjectItemData_1.ProjectItemType.colorGradingJson;
                            }
                            else if (folderContext === Project_1.FolderContext.behaviorPack && folderPathLower.indexOf("/cameras/") >= 0) {
                                newJsonType = IProjectItemData_1.ProjectItemType.cameraBehaviorJson;
                            }
                            else if (folderContext === Project_1.FolderContext.resourcePack && folderPathLower.indexOf("/cameras/") >= 0) {
                                newJsonType = IProjectItemData_1.ProjectItemType.cameraResourceJson;
                            }
                            else if (folderContext === Project_1.FolderContext.behaviorPack && folderPathLower.indexOf("/trading/") >= 0) {
                                newJsonType = IProjectItemData_1.ProjectItemType.tradingBehaviorJson;
                            }
                            else if (folderContext === Project_1.FolderContext.behaviorPack &&
                                folderPathLower.indexOf("/animation_controllers/") >= 0) {
                                newJsonType = IProjectItemData_1.ProjectItemType.animationControllerBehaviorJson;
                            }
                            else if (folderContext === Project_1.FolderContext.behaviorPack && folderPathLower.indexOf("/animations/") >= 0) {
                                newJsonType = IProjectItemData_1.ProjectItemType.animationBehaviorJson;
                            }
                            else if (isResourcePack &&
                                (folderPathLower.indexOf("/models/") >= 0 ||
                                    baseName.endsWith(".geo") ||
                                    baseName.endsWith(".geometry"))) {
                                newJsonType = IProjectItemData_1.ProjectItemType.modelGeometryJson;
                            }
                            else if (baseName.endsWith(".mci")) {
                                newJsonType = IProjectItemData_1.ProjectItemType.contentIndexJson;
                            }
                            else if (baseName.endsWith(".mcr")) {
                                newJsonType = IProjectItemData_1.ProjectItemType.contentReportJson;
                            }
                            else if (folderContext === Project_1.FolderContext.behaviorPack && folderPathLower.indexOf("/dimension/") >= 0) {
                                newJsonType = IProjectItemData_1.ProjectItemType.dimensionJson;
                            }
                            else if ((folderContext === Project_1.FolderContext.behaviorPack || folderContext === Project_1.FolderContext.unknown) &&
                                folderPathLower.indexOf("/features/") >= 0) {
                                newJsonType = IProjectItemData_1.ProjectItemType.featureBehavior;
                            }
                            else if ((folderContext === Project_1.FolderContext.behaviorPack || folderContext === Project_1.FolderContext.unknown) &&
                                folderPathLower.indexOf("/feature_rules/") >= 0) {
                                newJsonType = IProjectItemData_1.ProjectItemType.featureRuleBehavior;
                            }
                            else if (isResourcePack && folderPathLower.indexOf("/animation_controllers/") >= 0) {
                                newJsonType = IProjectItemData_1.ProjectItemType.animationControllerResourceJson;
                            }
                            else if (isResourcePack && folderPathLower.indexOf("/animations/") >= 0) {
                                newJsonType = IProjectItemData_1.ProjectItemType.animationResourceJson;
                            }
                            else if (folderPathLower.indexOf("/attachables/") >= 0) {
                                newJsonType = IProjectItemData_1.ProjectItemType.attachableResourceJson;
                            }
                            else if (isResourcePack && folderPathLower.indexOf("/fogs/") >= 0) {
                                newJsonType = IProjectItemData_1.ProjectItemType.fogResourceJson;
                            }
                            else if (isResourcePack && folderPathLower.indexOf("/particles/") >= 0) {
                                newJsonType = IProjectItemData_1.ProjectItemType.particleJson;
                            }
                            else if (isResourcePack && folderPathLower.indexOf("/render_controllers/") >= 0) {
                                newJsonType = IProjectItemData_1.ProjectItemType.renderControllerJson;
                            }
                            else if (isResourcePack && folderPathLower.indexOf("/block_culling/") >= 0) {
                                newJsonType = IProjectItemData_1.ProjectItemType.blockCulling;
                            }
                            else if (folderContext === Project_1.FolderContext.behaviorPack &&
                                projectPathLower.indexOf("/item_catalog/crafting_item_catalog") >= 0) {
                                newJsonType = IProjectItemData_1.ProjectItemType.craftingItemCatalog;
                            }
                            else if (isResourcePack &&
                                (projectPathLower.endsWith("terrain_texture.json") ||
                                    projectPathLower.endsWith("terrain_textures.json"))) {
                                newJsonType = IProjectItemData_1.ProjectItemType.terrainTextureCatalogResourceJson;
                            }
                            else if (isResourcePack && projectPathLower.endsWith("_global_variables.json")) {
                                newJsonType = IProjectItemData_1.ProjectItemType.globalVariablesJson;
                            }
                            else if (isResourcePack && projectPathLower.endsWith("flipbook_textures.json")) {
                                newJsonType = IProjectItemData_1.ProjectItemType.flipbookTexturesJson;
                            }
                            else if (isResourcePack &&
                                (projectPathLower.endsWith("item_texture.json") || projectPathLower.endsWith("item_textures.json"))) {
                                newJsonType = IProjectItemData_1.ProjectItemType.itemTextureJson;
                            }
                            else if (baseName === "contents") {
                                newJsonType = IProjectItemData_1.ProjectItemType.contentsJson;
                            }
                            else if (folderContext === Project_1.FolderContext.skinPack && projectPathLower.endsWith("skins.json")) {
                                newJsonType = IProjectItemData_1.ProjectItemType.skinCatalogJson;
                            }
                            else if (isResourcePack && folderPathLower.indexOf("/materials/") >= 0) {
                                newJsonType = IProjectItemData_1.ProjectItemType.materialSetJson;
                            }
                            else if (isResourcePack &&
                                folderPathLower.indexOf("/sounds/") >= 0 &&
                                baseName === "sound_definitions") {
                                newJsonType = IProjectItemData_1.ProjectItemType.soundDefinitionCatalog;
                            }
                            else if (isResourcePack &&
                                folderPathLower.indexOf("/sounds/") >= 0 &&
                                baseName === "music_definitions") {
                                newJsonType = IProjectItemData_1.ProjectItemType.musicDefinitionJson;
                            }
                            else if (folderPathLower.indexOf("/texts/") >= 0 || baseName === "languages") {
                                newJsonType = IProjectItemData_1.ProjectItemType.languagesCatalogResourceJson;
                            }
                            else if (isResourcePack && folderPathLower.indexOf("/textures/ui/") >= 0) {
                                newJsonType = IProjectItemData_1.ProjectItemType.ninesliceJson;
                            }
                            else if (isResourcePack && folderPathLower.indexOf("/texture_sets/") >= 0) {
                                newJsonType = IProjectItemData_1.ProjectItemType.textureSetJson;
                            }
                            else if (isResourcePack && folderPathLower.indexOf("/lighting/") >= 0) {
                                newJsonType = IProjectItemData_1.ProjectItemType.lightingJson;
                            }
                            else if (isResourcePack && folderPathLower.indexOf("/point_lights/") >= 0) {
                                newJsonType = IProjectItemData_1.ProjectItemType.lightingJson;
                            }
                            else if (isResourcePack && folderPathLower.indexOf("/pbr/") >= 0) {
                                newJsonType = IProjectItemData_1.ProjectItemType.pbrJson;
                            }
                            else if (isResourcePack && folderPathLower.indexOf("/water/") >= 0) {
                                newJsonType = IProjectItemData_1.ProjectItemType.waterJson;
                            }
                            else if (isResourcePack && folderPathLower.indexOf("/shadows/") >= 0) {
                                newJsonType = IProjectItemData_1.ProjectItemType.shadowsJson;
                            }
                            else if (folderContext === Project_1.FolderContext.behaviorPack &&
                                folderPathLower.indexOf("/worldgen/jigsaw_structures/") >= 0) {
                                newJsonType = IProjectItemData_1.ProjectItemType.jigsawStructure;
                            }
                            else if (folderContext === Project_1.FolderContext.behaviorPack &&
                                folderPathLower.indexOf("/worldgen/structure_sets/") >= 0) {
                                newJsonType = IProjectItemData_1.ProjectItemType.jigsawStructureSet;
                            }
                            else if (folderContext === Project_1.FolderContext.behaviorPack &&
                                folderPathLower.indexOf("/worldgen/template_pools/") >= 0) {
                                newJsonType = IProjectItemData_1.ProjectItemType.jigsawTemplatePool;
                            }
                            else if (folderContext === Project_1.FolderContext.behaviorPack &&
                                folderPathLower.indexOf("/worldgen/processors/") >= 0) {
                                newJsonType = IProjectItemData_1.ProjectItemType.jigsawProcessorList;
                            }
                            else if (isResourcePack && folderPathLower.indexOf("/ui/") >= 0) {
                                newJsonType = IProjectItemData_1.ProjectItemType.uiJson;
                            }
                            else if (folderContext === Project_1.FolderContext.docs && baseName === "example_files") {
                                newJsonType = IProjectItemData_1.ProjectItemType.fileListArrayJson;
                            }
                            else if (isResourcePack && baseName === "biomes_client") {
                                newJsonType = IProjectItemData_1.ProjectItemType.biomesClientResource;
                            }
                            else if (isResourcePack && folderPathLower.indexOf("/biomes/") >= 0) {
                                newJsonType = IProjectItemData_1.ProjectItemType.biomeResource;
                            }
                            else if (folderPathLower.indexOf("/biomes/") >= 0) {
                                newJsonType = IProjectItemData_1.ProjectItemType.biomeBehavior;
                            }
                            else if (isResourcePack && baseName === "blocks") {
                                newJsonType = IProjectItemData_1.ProjectItemType.blocksCatalogResourceJson;
                            }
                            else if (isResourcePack &&
                                (projectPathLower.endsWith("texture_list.json") || projectPathLower.endsWith("textures_list.json"))) {
                                newJsonType = IProjectItemData_1.ProjectItemType.textureListJson;
                            }
                            else if (isResourcePack && projectPathLower.endsWith("texture_set.json")) {
                                newJsonType = IProjectItemData_1.ProjectItemType.textureSetJson;
                            }
                            else if (isResourcePack && folderPathLower.indexOf("/items/") >= 0) {
                                newJsonType = IProjectItemData_1.ProjectItemType.itemTypeLegacyResource;
                            }
                            else if (isResourcePack && baseName === "sounds") {
                                newJsonType = IProjectItemData_1.ProjectItemType.soundCatalog;
                            }
                            else if (baseName === "education") {
                                newJsonType = IProjectItemData_1.ProjectItemType.educationJson;
                            }
                            else if (baseName === "world_behavior_packs") {
                                newJsonType = IProjectItemData_1.ProjectItemType.behaviorPackListJson;
                            }
                            else if (baseName === "world_resource_packs") {
                                newJsonType = IProjectItemData_1.ProjectItemType.resourcePackListJson;
                            }
                            else if (baseName === "world_behavior_pack_history") {
                                newJsonType = IProjectItemData_1.ProjectItemType.behaviorPackHistoryListJson;
                            }
                            else if (baseName === "world_resource_pack_history") {
                                newJsonType = IProjectItemData_1.ProjectItemType.resourcePackHistoryListJson;
                            }
                            else if (baseName === "tsconfig") {
                                newJsonType = IProjectItemData_1.ProjectItemType.tsconfigJson;
                            }
                            else if (baseName === "docfx") {
                                newJsonType = IProjectItemData_1.ProjectItemType.docfxJson;
                            }
                            else if (baseName === "jsdoc") {
                                newJsonType = IProjectItemData_1.ProjectItemType.jsdocJson;
                            }
                            else if (baseName === "jsconfig") {
                                newJsonType = IProjectItemData_1.ProjectItemType.jsconfigJson;
                            }
                            else if (baseName === "package") {
                                newJsonType = IProjectItemData_1.ProjectItemType.packageJson;
                            }
                            else if (baseName === "package.lock") {
                                newJsonType = IProjectItemData_1.ProjectItemType.packageLockJson;
                            }
                            else if (baseName === ".prettierrc") {
                                newJsonType = IProjectItemData_1.ProjectItemType.prettierRcJson;
                            }
                            else if (folderPathLower.indexOf("/persona/") >= 0) {
                                newJsonType = IProjectItemData_1.ProjectItemType.personaJson;
                            }
                            else if (folderPathLower.indexOf("/sdl_layouts/") >= 0) {
                                newJsonType = IProjectItemData_1.ProjectItemType.sdlLayout;
                            }
                            else if (folderPathLower.indexOf("/renderer/") >= 0) {
                                newJsonType = IProjectItemData_1.ProjectItemType.rendererJson;
                            }
                            else if (folderPathLower.indexOf("/sdl_layouts/") >= 0) {
                                newJsonType = IProjectItemData_1.ProjectItemType.sdlLayout;
                            }
                            else if (baseName === "splashes") {
                                newJsonType = IProjectItemData_1.ProjectItemType.splashesJson;
                            }
                            else if (baseName === "loading_messages") {
                                newJsonType = IProjectItemData_1.ProjectItemType.loadingMessagesJson;
                            }
                            else if (isResourcePack && baseName === "font_metadata") {
                                newJsonType = IProjectItemData_1.ProjectItemType.fontMetadataJson;
                            }
                            else if (isResourcePack && baseName === "emoticons") {
                                newJsonType = IProjectItemData_1.ProjectItemType.emoticonsJson;
                            }
                            else if (folderContext === Project_1.FolderContext.skinPack && baseName === "geometry") {
                                newJsonType = IProjectItemData_1.ProjectItemType.skinPackGeometryJson;
                            }
                            else if (baseName === "texture_backwards_compatibility_mapping") {
                                newJsonType = IProjectItemData_1.ProjectItemType.skinPackTextureBackCompatJson;
                            }
                            else if (baseName === "uniforms") {
                                newJsonType = IProjectItemData_1.ProjectItemType.uniformsJson;
                            }
                            else if (folderContext === Project_1.FolderContext.docs && baseName === "info") {
                                newJsonType = IProjectItemData_1.ProjectItemType.docInfoJson;
                                project.role = IProjectData_1.ProjectRole.documentation;
                                itemName = StorageUtilities_1.default.getLeafName(folderPath);
                            }
                            else if (isResourcePack && folderPathLower.indexOf("/textures/") >= 0) {
                                newJsonType = IProjectItemData_1.ProjectItemType.ninesliceJson;
                            }
                            else if (folderContext === Project_1.FolderContext.docs &&
                                (baseName === "_example_files" || baseName === "example_files")) {
                                newJsonType = IProjectItemData_1.ProjectItemType.fileListArrayJson;
                                project.role = IProjectData_1.ProjectRole.documentation;
                                itemName = StorageUtilities_1.default.getLeafName(folderPath);
                            }
                            else if (folderContext === Project_1.FolderContext.typeDefs && folderPathLower.indexOf("/command_modules") >= 0) {
                                newJsonType = IProjectItemData_1.ProjectItemType.commandSetDefinitionJson;
                                project.role = IProjectData_1.ProjectRole.documentation;
                            }
                            else if ((folderContext === Project_1.FolderContext.metaData && folderPathLower.indexOf("/forms") >= 0) ||
                                projectPathLower.endsWith(".form.json")) {
                                newJsonType = IProjectItemData_1.ProjectItemType.dataForm;
                                project.role = IProjectData_1.ProjectRole.meta;
                            }
                            else if (folderContext === Project_1.FolderContext.typeDefs && folderPathLower.indexOf("/script_modules") >= 0) {
                                newJsonType = IProjectItemData_1.ProjectItemType.scriptTypesJson;
                                project.role = IProjectData_1.ProjectRole.documentation;
                            }
                            else if (folderContext === Project_1.FolderContext.typeDefs &&
                                folderPathLower.indexOf("/vanilladata_modules") >= 0) {
                                newJsonType = IProjectItemData_1.ProjectItemType.vanillaDataJson;
                                project.role = IProjectData_1.ProjectRole.documentation;
                            }
                            else if (folderContext === Project_1.FolderContext.typeDefs && folderPathLower.indexOf("/engine_modules") >= 0) {
                                newJsonType = IProjectItemData_1.ProjectItemType.engineOrderingJson;
                                project.role = IProjectData_1.ProjectRole.documentation;
                            }
                            // these need to be near the bottom since URL segments like /items/, /blocks/, /entities etc. could theoretically be used in loot_tables, etc. and that should take precedence in detection
                            else if (folderContext === Project_1.FolderContext.behaviorPack && folderPathLower.indexOf("/items/") >= 0) {
                                newJsonType = IProjectItemData_1.ProjectItemType.itemTypeBehavior;
                            }
                            else if (folderContext === Project_1.FolderContext.behaviorPack && folderPathLower.indexOf("/blocks/") >= 0) {
                                newJsonType = IProjectItemData_1.ProjectItemType.blockTypeBehavior;
                            }
                            else if (isResourcePack &&
                                (folderPathLower.indexOf("/entities/") >= 0 || folderPathLower.indexOf("/entity/") >= 0)) {
                                newJsonType = IProjectItemData_1.ProjectItemType.entityTypeResource;
                            }
                            else if (folderContext === Project_1.FolderContext.behaviorPack &&
                                (folderPathLower.indexOf("/entities/") >= 0 || folderPathLower.indexOf("/entity/") >= 0)) {
                                newJsonType = IProjectItemData_1.ProjectItemType.entityTypeBehavior;
                            }
                            else {
                                // Log.debugAlert("General JSON file found: " + projectPath);
                            }
                            project.ensureItemByProjectPath(projectPath, IProjectItemData_1.ProjectItemStorageType.singleFile, itemName, newJsonType, folderContext, source, IProjectItemData_1.ProjectItemCreationType.normal, candidateFile, undefined, isInWorld);
                        }
                    }
                    else if (pi && projectPath !== undefined) {
                        if (pi.itemType === IProjectItemData_1.ProjectItemType.MCWorld ||
                            pi.itemType === IProjectItemData_1.ProjectItemType.MCProject ||
                            pi.itemType === IProjectItemData_1.ProjectItemType.MCTemplate ||
                            pi.itemType === IProjectItemData_1.ProjectItemType.MCAddon ||
                            pi.itemType === IProjectItemData_1.ProjectItemType.MCPack ||
                            pi.itemType === IProjectItemData_1.ProjectItemType.zip) {
                            await project.inferProjectItemsFromZipFile(projectPath, candidateFile, force);
                        }
                    }
                }
            }
        }
        for (const folderName in folder.folders) {
            const childFolder = folder.folders[folderName];
            if (childFolder && !childFolder.errorStatus) {
                const name = StorageUtilities_1.default.canonicalizeName(folderName);
                if (name === "build" || name === "out" || name === "dist") {
                    project.distBuildFolder = folder;
                }
                else if (name === "lib") {
                    project.libFolder = folder;
                }
                else if (name === "project_item_data" && folderContext === Project_1.FolderContext.designPack) {
                    if (!project.projectItemAccessoryFolder) {
                        project.projectItemAccessoryFolder = folder;
                    }
                }
                else if ((name.startsWith(".mct") || name.startsWith(".vscode") || !name.startsWith(".")) && // disallow any "." folders, except for .mct or .vscode
                    name !== "project_item_data" &&
                    name !== "node_modules" &&
                    !childFolder.canIgnore &&
                    (folderContext !== Project_1.FolderContext.unknown || depth < 4) &&
                    depth < 10) {
                    if (childFolder !== undefined) {
                        await ProjectItemInference.inferProjectItemsFromFolder(project, childFolder, fileSystemPrefix, folderContext, variantLabel, isInWorld, rootFolder, depth + 1, source, force, processingCallback);
                    }
                }
            }
        }
    }
}
exports.default = ProjectItemInference;

//# sourceMappingURL=../maps/app/ProjectItemInference.js.map
