"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const EslintConfig_1 = require("../devproject/EslintConfig");
const JustConfig_1 = require("../devproject/JustConfig");
const NpmPackageDefinition_1 = require("../devproject/NpmPackageDefinition");
const IProjectItemData_1 = require("./IProjectItemData");
const Project_1 = require("./Project");
class ProjectStandard {
    static async ensureIsStandard(project) {
        await project.ensureProjectFolder();
        if (project.projectFolder) {
            const justFile = await project.projectFolder.getFileFromRelativePath("/just.config.ts");
            if (justFile && (await justFile.exists())) {
                justFile.setContent(JustConfig_1.default.getDefaultContent());
                justFile.saveContent();
            }
            const eslintFile = await project.projectFolder.getFileFromRelativePath("/eslint.config.mjs");
            if (eslintFile && (await eslintFile.exists())) {
                eslintFile.setContent(EslintConfig_1.default.getDefaultContent());
                eslintFile.saveContent();
            }
            const packageJson = await project.projectFolder.getFileFromRelativePath("/package.json");
            if (packageJson && (await packageJson.exists())) {
                project.ensureItemByProjectPath("/package.json", IProjectItemData_1.ProjectItemStorageType.singleFile, "package.json", IProjectItemData_1.ProjectItemType.packageJson, Project_1.FolderContext.unknown, undefined, IProjectItemData_1.ProjectItemCreationType.generated);
            }
        }
        const itemsCopy = project.getItemsCopy();
        for (let i = 0; i < itemsCopy.length; i++) {
            const item = itemsCopy[i];
            if (item.itemType === IProjectItemData_1.ProjectItemType.justConfigTs && item.primaryFile) {
                item.creationType = IProjectItemData_1.ProjectItemCreationType.generated;
                const justConfig = await JustConfig_1.default.ensureOnFile(item.primaryFile);
                if (justConfig) {
                    justConfig.ensureDefault();
                    await justConfig.save();
                }
            }
            else if (item.itemType === IProjectItemData_1.ProjectItemType.esLintConfigMjs && item.primaryFile) {
                item.creationType = IProjectItemData_1.ProjectItemCreationType.generated;
                const eslintConfig = await EslintConfig_1.default.ensureOnFile(item.primaryFile);
                if (eslintConfig) {
                    eslintConfig.ensureDefault();
                    await eslintConfig.save();
                }
            }
            else if (item.itemType === IProjectItemData_1.ProjectItemType.packageJson && item.primaryFile) {
                item.creationType = IProjectItemData_1.ProjectItemCreationType.generated;
                const packageJson = await NpmPackageDefinition_1.default.ensureOnFile(item.primaryFile);
                if (packageJson) {
                    await packageJson.ensureStandardContent();
                    await packageJson.save();
                }
            }
        }
    }
}
exports.default = ProjectStandard;

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