"use strict";
var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __generator = (this && this.__generator) || function (thisArg, body) {
    var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
    return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
    function verb(n) { return function (v) { return step([n, v]); }; }
    function step(op) {
        if (f) throw new TypeError("Generator is already executing.");
        while (g && (g = 0, op[0] && (_ = 0)), _) try {
            if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
            if (y = 0, t) op = [op[0] & 2, t.value];
            switch (op[0]) {
                case 0: case 1: t = op; break;
                case 4: _.label++; return { value: op[1], done: false };
                case 5: _.label++; y = op[1]; op = [0]; continue;
                case 7: op = _.ops.pop(); _.trys.pop(); continue;
                default:
                    if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
                    if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
                    if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
                    if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
                    if (t[2]) _.ops.pop();
                    _.trys.pop(); continue;
            }
            op = body.call(thisArg, _);
        } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
        if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
    }
};
var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
    if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
        if (ar || !(i in from)) {
            if (!ar) ar = Array.prototype.slice.call(from, 0, i);
            ar[i] = from[i];
        }
    }
    return to.concat(ar || Array.prototype.slice.call(from));
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.generateSplashScreen = exports.validateSplashScreenGenerator = exports.generateAppIcons = exports.validateAppIconGenerator = exports.generateFromTemplate = exports.updateGenerators = exports.showGeneratorHelp = exports.runGenerator = void 0;
var ejs = require("ejs");
var gluegun_1 = require("gluegun");
var sharp = require("sharp");
var YAML = require("yaml");
var pretty_1 = require("./pretty");
var NEW_LINE = gluegun_1.filesystem.eol;
function runGenerator(toolbox, generateFunc, generator) {
    var parameters = toolbox.parameters;
    (0, pretty_1.p)();
    if (parameters.options.help || parameters.options.list) {
        // show help or list generators
        showGeneratorHelp(toolbox);
    }
    else if (parameters.options.update) {
        // update with fresh generators
        updateGenerators(toolbox);
    }
    else {
        if (generator) {
            var isValid = validateGenerator(generator);
            if (!isValid)
                return;
        }
        else {
            // catch-all, just show help
            showGeneratorHelp(toolbox);
            return;
        }
        generateFunc(toolbox);
    }
}
exports.runGenerator = runGenerator;
function validateGenerator(generator) {
    var generators = installedGenerators();
    if (!generators.includes(generator)) {
        (0, pretty_1.warning)("\u26A0\uFE0F  Generator \"".concat(generator, "\" isn't installed."));
        (0, pretty_1.p)();
        if (availableGenerators().includes(generator)) {
            (0, pretty_1.direction)("Install the generator with:");
            (0, pretty_1.p)();
            (0, pretty_1.command)("npx ignite-cli generate ".concat(generator, " --update"));
            (0, pretty_1.p)();
            (0, pretty_1.direction)("... and then try again!");
        }
        else {
            (0, pretty_1.direction)("Check your spelling and try again");
        }
        return false;
    }
    return true;
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
function showGeneratorHelp(toolbox) {
    (0, pretty_1.igniteHeading)();
    (0, pretty_1.heading)("Ignite Generators");
    (0, pretty_1.p)();
    (0, pretty_1.p)("When you create a new app with Ignite CLI, it will install several generator");
    (0, pretty_1.p)("templates in the project folder under the `ignite/templates` folder.");
    (0, pretty_1.p)();
    (0, pretty_1.heading)("Commands");
    (0, pretty_1.p)();
    (0, pretty_1.command)("--list  ", "List installed generators", ["npx ignite-cli --list"]);
    (0, pretty_1.command)("--update", "Update installed generators. You can also use the 'npx ignite-cli update X' format", [
        "npx ignite-cli --update",
        "npx ignite-cli model --update",
        "npx ignite-cli update model",
        "npx ignite-cli update --all",
    ]);
    (0, pretty_1.warning)("          ⚠️  this erases any customizations you've made!");
    (0, pretty_1.p)();
    (0, pretty_1.heading)("Options");
    (0, pretty_1.p)();
    (0, pretty_1.command)("--dir", "Override front matter or default path for generated files", [
        "npx ignite-cli g model Episodes --dir src/models",
    ]);
    (0, pretty_1.command)("--case", "Formats the generated filename", [
        "npx ignite-cli g model episode --case=auto",
        "npx ignite-cli g model episode --case=pascal",
        "npx ignite-cli g model episode --case=kebab",
        "npx ignite-cli g model episode --case=snake",
        "npx ignite-cli g model episode --case=none",
    ]);
    (0, pretty_1.p)();
    (0, pretty_1.heading)("Installed generators");
    (0, pretty_1.p)();
    showGenerators();
}
exports.showGeneratorHelp = showGeneratorHelp;
function showGenerators() {
    if (!isIgniteProject()) {
        (0, pretty_1.warning)("⚠️  Not in an Ignite project root. Go to your Ignite project root to see generators.");
        return;
    }
    var generators = installedGenerators();
    var longestGen = generators.reduce(function (c, g) { return Math.max(c, g.length); }, 0);
    generators.forEach(function (g) {
        if (g === "app-icon") {
            // specialty app-icon generator
            (0, pretty_1.command)(g.padEnd(longestGen), "generates app-icons", [
                "npx ignite-cli ".concat(g, " all|ios|android|expo"),
            ]);
        }
        else if (g === "splash-screen") {
            // specialty splash-screen generator
            (0, pretty_1.command)(g.padEnd(longestGen), "generates splash-screen", [
                "npx ignite-cli ".concat(g, " \"#191015\" [--android-size=180 --ios-size=212]"),
            ]);
        }
        else {
            // standard generators
            (0, pretty_1.command)(g.padEnd(longestGen), "generates a ".concat(g), ["npx ignite-cli ".concat(g, " Demo")]);
        }
    });
}
function updateGenerators(toolbox) {
    var parameters = toolbox.parameters;
    if (!isIgniteProject()) {
        (0, pretty_1.warning)("⚠️  Not in an Ignite project root. Go to your Ignite project root to see generators.");
        return;
    }
    var generatorsToUpdate;
    if (parameters.first) {
        // only update the specified one
        generatorsToUpdate = [parameters.first];
    }
    else {
        // update any available generators
        generatorsToUpdate = availableGenerators();
    }
    var changes = installGenerators(generatorsToUpdate);
    var distinct = function (val, index, self) { return self.indexOf(val) === index; };
    var allGenerators = changes.concat(generatorsToUpdate).filter(distinct).sort();
    (0, pretty_1.heading)("Updated ".concat(changes.length, " generator").concat(changes.length === 1 ? "" : "s"));
    allGenerators.forEach(function (g) {
        if (changes.includes(g)) {
            (0, pretty_1.heading)("  ".concat(g, " - updated"));
        }
        else {
            (0, pretty_1.p)("  ".concat(g, " - no changes"));
        }
    });
}
exports.updateGenerators = updateGenerators;
function isIgniteProject() {
    return gluegun_1.filesystem.exists("./ignite") === "dir";
}
function cwd() {
    return process.cwd();
}
function igniteDir() {
    return gluegun_1.filesystem.path(cwd(), "ignite");
}
function appDir() {
    return gluegun_1.filesystem.path(cwd(), "app");
}
function templatesDir() {
    return gluegun_1.filesystem.path(igniteDir(), "templates");
}
function frontMatter(contents) {
    var _a;
    var parts = contents.split("---".concat(NEW_LINE));
    if (parts.length === 1 || parts.length === 3) {
        return {
            data: parts[1] ? YAML.parse(parts[1]) : {},
            content: (_a = parts[2]) !== null && _a !== void 0 ? _a : parts[0],
        };
    }
    else {
        return {};
    }
}
/**
 * Handles patching files via front matter config
 */
function handlePatches(data) {
    var _a;
    return __awaiter(this, void 0, void 0, function () {
        var patches, _i, patches_1, patch, patchPath, skip, patchOpts;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    patches = (_a = data.patches) !== null && _a !== void 0 ? _a : [];
                    if (data.patch)
                        patches.push(data.patch);
                    _i = 0, patches_1 = patches;
                    _b.label = 1;
                case 1:
                    if (!(_i < patches_1.length)) return [3 /*break*/, 10];
                    patch = patches_1[_i];
                    patchPath = patch.path, skip = patch.skip, patchOpts = __rest(patch, ["path", "skip"]);
                    if (!(patchPath && !skip)) return [3 /*break*/, 9];
                    if (!patchOpts.append) return [3 /*break*/, 3];
                    return [4 /*yield*/, gluegun_1.patching.append(patchPath, patchOpts.append)];
                case 2:
                    _b.sent();
                    _b.label = 3;
                case 3:
                    if (!patchOpts.prepend) return [3 /*break*/, 5];
                    return [4 /*yield*/, gluegun_1.patching.prepend(patchPath, patchOpts.prepend)];
                case 4:
                    _b.sent();
                    _b.label = 5;
                case 5:
                    if (!patchOpts.replace) return [3 /*break*/, 7];
                    return [4 /*yield*/, gluegun_1.patching.replace(patchPath, patchOpts.replace, patchOpts.insert)];
                case 6:
                    _b.sent();
                    _b.label = 7;
                case 7: return [4 /*yield*/, gluegun_1.patching.patch(patchPath, patchOpts)];
                case 8:
                    _b.sent();
                    _b.label = 9;
                case 9:
                    _i++;
                    return [3 /*break*/, 1];
                case 10: return [2 /*return*/];
            }
        });
    });
}
/**
 * Finds generator templates installed in the current project
 */
function installedGenerators() {
    var subdirectories = gluegun_1.filesystem.subdirectories, separator = gluegun_1.filesystem.separator;
    var generators = subdirectories(templatesDir()).map(function (g) { return g.split(separator).slice(-1)[0]; });
    return generators;
}
/**
 * Generates something using a template
 */
function generateFromTemplate(generator, options) {
    var _a, _b;
    return __awaiter(this, void 0, void 0, function () {
        var find, path, dir, separator, pascalCase, kebabCase, pluralize, camelCase, snakeCase, pascalCaseName, kebabCaseName, camelCaseName, snakeCaseName, written, overwritten, exists, props, templateDir, files, formattedName, _i, files_1, templateFilename, filename, templateContents, _c, frontMatterData, content, defaultDestinationDir, overrideDestinationDir, destinationDir, destinationPath, isFileExist;
        return __generator(this, function (_d) {
            switch (_d.label) {
                case 0:
                    find = gluegun_1.filesystem.find, path = gluegun_1.filesystem.path, dir = gluegun_1.filesystem.dir, separator = gluegun_1.filesystem.separator;
                    pascalCase = gluegun_1.strings.pascalCase, kebabCase = gluegun_1.strings.kebabCase, pluralize = gluegun_1.strings.pluralize, camelCase = gluegun_1.strings.camelCase, snakeCase = gluegun_1.strings.snakeCase;
                    pascalCaseName = pascalCase(options.name);
                    kebabCaseName = kebabCase(options.name);
                    camelCaseName = camelCase(options.name);
                    snakeCaseName = snakeCase(options.name);
                    written = [];
                    overwritten = [];
                    exists = [];
                    props = __assign({ camelCaseName: camelCaseName, kebabCaseName: kebabCaseName, pascalCaseName: pascalCaseName, snakeCaseName: snakeCaseName }, options);
                    templateDir = path(templatesDir(), generator);
                    files = find(templateDir, { matching: "*" });
                    formattedName = pascalCaseName;
                    switch (options.case) {
                        case "camel":
                            formattedName = camelCaseName;
                            break;
                        case "kebab":
                            formattedName = kebabCaseName;
                            break;
                        case "snake":
                            formattedName = snakeCaseName;
                            break;
                        case "none":
                            formattedName = options.originalName;
                            break;
                        case "auto":
                        default:
                            formattedName = pascalCaseName;
                            break;
                    }
                    _i = 0, files_1 = files;
                    _d.label = 1;
                case 1:
                    if (!(_i < files_1.length)) return [3 /*break*/, 5];
                    templateFilename = files_1[_i];
                    filename = templateFilename.split(separator).slice(-1)[0].replace("NAME", formattedName);
                    // strip the .ejs
                    if (filename.endsWith(".ejs")) {
                        filename = filename.slice(0, -4);
                    }
                    templateContents = gluegun_1.filesystem.read(templateFilename);
                    // render ejs
                    if (templateFilename.endsWith(".ejs")) {
                        templateContents = ejs.render(templateContents, { props: __assign(__assign({}, props), { filename: filename }) });
                    }
                    _c = frontMatter(templateContents), frontMatterData = _c.data, content = _c.content;
                    if (!content) {
                        (0, pretty_1.warning)("⚠️  Unable to parse front matter. Please check your delimiters.");
                        return [2 /*return*/, { written: written, exists: exists, overwritten: overwritten }];
                    }
                    defaultDestinationDir = path(appDir(), pluralize(generator), options.subdirectory) // e.g. app/components, app/screens, app/models
                    ;
                    overrideDestinationDir = (_a = options.dir) !== null && _a !== void 0 ? _a : frontMatterData.destinationDir // cli dir takes priority over front matter dir
                    ;
                    destinationDir = overrideDestinationDir
                        ? path(cwd(), overrideDestinationDir)
                        : defaultDestinationDir;
                    destinationPath = path(destinationDir, (_b = frontMatterData.filename) !== null && _b !== void 0 ? _b : filename);
                    isFileExist = gluegun_1.filesystem.exists(destinationPath);
                    if (!!isFileExist) return [3 /*break*/, 3];
                    return [4 /*yield*/, handlePatches(frontMatterData)
                        // ensure destination folder exists
                    ];
                case 2:
                    _d.sent();
                    _d.label = 3;
                case 3:
                    // ensure destination folder exists
                    dir(destinationDir);
                    // check if file exist or not and check of overwrite property
                    if (isFileExist) {
                        if (props.overwrite) {
                            gluegun_1.filesystem.write(destinationPath, content);
                            overwritten.push(destinationPath);
                        }
                        else {
                            exists.push(destinationPath);
                        }
                    }
                    else {
                        gluegun_1.filesystem.write(destinationPath, content);
                        written.push(destinationPath);
                    }
                    _d.label = 4;
                case 4:
                    _i++;
                    return [3 /*break*/, 1];
                case 5: return [2 /*return*/, { written: written, exists: exists, overwritten: overwritten }];
            }
        });
    });
}
exports.generateFromTemplate = generateFromTemplate;
/**
 * Ignite cli root directory
 */
function igniteCliRootDir() {
    return gluegun_1.filesystem.path(__filename, "..", "..", "..");
}
/**
 * Directory where we can find Ignite CLI generator templates
 */
function sourceDirectory() {
    return gluegun_1.filesystem.path(igniteCliRootDir(), "boilerplate", "ignite", "templates");
}
/**
 * Finds generator templates in Ignite CLI
 */
function availableGenerators() {
    var subdirectories = gluegun_1.filesystem.subdirectories, separator = gluegun_1.filesystem.separator;
    return subdirectories(sourceDirectory()).map(function (g) { return g.split(separator).slice(-1)[0]; });
}
/**
 * Copies over generators (specific generators, or all) from Ignite CLI to the project
 * ignite/templates folder.
 */
function installGenerators(generators) {
    var path = gluegun_1.filesystem.path, find = gluegun_1.filesystem.find, copy = gluegun_1.filesystem.copy, dir = gluegun_1.filesystem.dir, cwd = gluegun_1.filesystem.cwd, separator = gluegun_1.filesystem.separator, exists = gluegun_1.filesystem.exists, read = gluegun_1.filesystem.read;
    var sourceDir = sourceDirectory();
    var targetDir = path(cwd(), "ignite", "templates");
    // for each generator type, copy it over to the ignite/templates folder
    var changedGenerators = generators.filter(function (gen) {
        var sourceGenDir = path(sourceDir, gen);
        var targetGenDir = path(targetDir, gen);
        // ensure the directory exists
        dir(targetDir);
        // find all source files
        var files = find(sourceGenDir, { matching: "*" });
        // copy them over
        var changedFiles = files.filter(function (file) {
            var filename = file.split(separator).slice(-1)[0];
            var targetFile = path(targetGenDir, filename);
            if (!exists(targetFile) || read(targetFile) !== read(file)) {
                copy(file, targetFile, { overwrite: true });
                return true;
            }
            else {
                return false;
            }
        });
        return changedFiles.length > 0;
    });
    return changedGenerators;
}
var Platforms;
(function (Platforms) {
    Platforms["Ios"] = "ios";
    Platforms["Android"] = "android";
    Platforms["Expo"] = "expo";
})(Platforms || (Platforms = {}));
// prettier-ignore
var APP_ICON_RULESET = {
    icons: [
        { platform: Platforms.Ios, type: "universal", name: "Icon-{size}-{idiom}{scale}.png", inputFile: "ios-universal.png" },
        { platform: Platforms.Android, type: "adaptive", name: "mipmap-{dpi}/ic_launcher_background.png", inputFile: "android-adaptive-background.png" },
        { platform: Platforms.Android, type: "adaptive", name: "mipmap-{dpi}/ic_launcher_foreground.png", inputFile: "android-adaptive-foreground.png" },
        { platform: Platforms.Android, type: "legacy", name: "mipmap-{dpi}/ic_launcher.png", inputFile: "android-legacy.png", transform: { size: 812, radius: 64, padding: 106 } },
        { platform: Platforms.Android, type: "legacy", name: "mipmap-{dpi}/ic_launcher_round.png", inputFile: "android-legacy.png", transform: { size: 944, radius: 472, padding: 40 } },
        { platform: Platforms.Expo, type: "mobile", name: "app-icon-ios.png", inputFile: "ios-universal.png" },
        { platform: Platforms.Expo, type: "mobile", name: "app-icon-android-legacy.png", inputFile: "android-legacy.png" },
        { platform: Platforms.Expo, type: "mobile", name: "app-icon-android-adaptive-background.png", inputFile: "android-adaptive-background.png" },
        { platform: Platforms.Expo, type: "mobile", name: "app-icon-android-adaptive-foreground.png", inputFile: "android-adaptive-foreground.png" },
        { platform: Platforms.Expo, type: "mobile", name: "app-icon-all.png", inputFile: "ios-universal.png" },
        { platform: Platforms.Expo, type: "web", name: "app-icon-web-favicon.png", inputFile: "ios-universal.png" },
    ],
    rules: [
        { platform: Platforms.Ios, size: { universal: 1024 }, scale: 1, idiom: "ios-marketing" },
        { platform: Platforms.Ios, size: { universal: 83.5 }, scale: 2, idiom: "ipad" },
        { platform: Platforms.Ios, size: { universal: 20 }, scale: 1, idiom: "ipad" },
        { platform: Platforms.Ios, size: { universal: 20 }, scale: 2, idiom: "ipad" },
        { platform: Platforms.Ios, size: { universal: 29 }, scale: 1, idiom: "ipad" },
        { platform: Platforms.Ios, size: { universal: 29 }, scale: 2, idiom: "ipad" },
        { platform: Platforms.Ios, size: { universal: 40 }, scale: 1, idiom: "ipad" },
        { platform: Platforms.Ios, size: { universal: 40 }, scale: 2, idiom: "ipad" },
        { platform: Platforms.Ios, size: { universal: 76 }, scale: 1, idiom: "ipad" },
        { platform: Platforms.Ios, size: { universal: 76 }, scale: 2, idiom: "ipad" },
        { platform: Platforms.Ios, size: { universal: 20 }, scale: 2, idiom: "iphone" },
        { platform: Platforms.Ios, size: { universal: 20 }, scale: 3, idiom: "iphone" },
        { platform: Platforms.Ios, size: { universal: 29 }, scale: 2, idiom: "iphone" },
        { platform: Platforms.Ios, size: { universal: 29 }, scale: 3, idiom: "iphone" },
        { platform: Platforms.Ios, size: { universal: 40 }, scale: 2, idiom: "iphone" },
        { platform: Platforms.Ios, size: { universal: 40 }, scale: 3, idiom: "iphone" },
        { platform: Platforms.Ios, size: { universal: 60 }, scale: 2, idiom: "iphone" },
        { platform: Platforms.Ios, size: { universal: 60 }, scale: 3, idiom: "iphone" },
        { platform: Platforms.Android, size: { legacy: 192, adaptive: 432 }, dpi: "xxxhdpi" },
        { platform: Platforms.Android, size: { legacy: 144, adaptive: 324 }, dpi: "xxhdpi" },
        { platform: Platforms.Android, size: { legacy: 96, adaptive: 216 }, dpi: "xhdpi" },
        { platform: Platforms.Android, size: { legacy: 72, adaptive: 162 }, dpi: "hdpi" },
        { platform: Platforms.Android, size: { legacy: 48, adaptive: 108 }, dpi: "mdpi" },
        { platform: Platforms.Expo, size: { mobile: 1024, web: 48 } },
    ]
};
/**
 * Validates that all necessary app-icon input files exist in the template dir.
 * Additionally validates that they are of the correct size.
 */
function validateAppIconGenerator(option, flags) {
    return __awaiter(this, void 0, void 0, function () {
        var skipSourceEqualityValidation, path, exists, inspect, allowedOptions, optionsToValidate, inputFileNames, validationPromises, validationResults, validationMessages;
        var _this = this;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    skipSourceEqualityValidation = (flags || {}).skipSourceEqualityValidation;
                    path = gluegun_1.filesystem.path, exists = gluegun_1.filesystem.exists, inspect = gluegun_1.filesystem.inspect;
                    allowedOptions = Object.values(Platforms);
                    // check that the option is allowed
                    if (option !== "all" && !allowedOptions.includes(option)) {
                        return [2 /*return*/, {
                                isValid: false,
                                messages: ["The option \"".concat(option, "\" is not valid for generator \"app-icon\"")],
                            }];
                    }
                    optionsToValidate = option === "all" ? allowedOptions : [option];
                    inputFileNames = APP_ICON_RULESET.icons
                        .filter(function (i) { return optionsToValidate.includes(i.platform); })
                        .reduce(function (acc, i) { return Array.from(new Set(__spreadArray(__spreadArray([], acc, true), [i.inputFile], false))); }, []);
                    validationPromises = inputFileNames.map(function (fileName) { return __awaiter(_this, void 0, void 0, function () {
                        var boilerplateInputFilePath, inputFilePath, isMissing, isInvalidSize, isSameAsSource;
                        return __generator(this, function (_a) {
                            switch (_a.label) {
                                case 0:
                                    boilerplateInputFilePath = path(sourceDirectory(), "app-icon", fileName);
                                    inputFilePath = path(templatesDir(), "app-icon", fileName);
                                    isMissing = !exists(inputFilePath);
                                    return [4 /*yield*/, (function () {
                                            return __awaiter(this, void 0, void 0, function () {
                                                var metadata;
                                                return __generator(this, function (_a) {
                                                    switch (_a.label) {
                                                        case 0:
                                                            if (isMissing)
                                                                return [2 /*return*/, false];
                                                            return [4 /*yield*/, sharp(inputFilePath).metadata()];
                                                        case 1:
                                                            metadata = _a.sent();
                                                            return [2 /*return*/, metadata.width !== 1024 || metadata.height !== 1024];
                                                    }
                                                });
                                            });
                                        })()];
                                case 1:
                                    isInvalidSize = _a.sent();
                                    return [4 /*yield*/, (function () {
                                            return __awaiter(this, void 0, void 0, function () {
                                                var inputFileMd5, sourceFileMd5;
                                                return __generator(this, function (_a) {
                                                    if (skipSourceEqualityValidation)
                                                        return [2 /*return*/, false];
                                                    if (isMissing)
                                                        return [2 /*return*/, false];
                                                    inputFileMd5 = inspect(inputFilePath, { checksum: "md5" }).md5;
                                                    sourceFileMd5 = inspect(boilerplateInputFilePath, { checksum: "md5" }).md5;
                                                    return [2 /*return*/, inputFileMd5 === sourceFileMd5];
                                                });
                                            });
                                        })()];
                                case 2:
                                    isSameAsSource = _a.sent();
                                    return [2 /*return*/, { fileName: fileName, isMissing: isMissing, isInvalidSize: isInvalidSize, isSameAsSource: isSameAsSource }];
                            }
                        });
                    }); });
                    return [4 /*yield*/, Promise.all(validationPromises)
                        // accumulate error messages for any failed validations
                    ];
                case 1:
                    validationResults = _a.sent();
                    validationMessages = validationResults.reduce(function (acc, r) {
                        var messages = [
                            r.isMissing && "   • the file is missing",
                            r.isInvalidSize && "   • the file is the wrong size (expected 1024x1024px)",
                            r.isSameAsSource &&
                                "   • looks like you're using our default template; customize the file with your own icon first",
                        ].filter(Boolean);
                        if (messages.length) {
                            acc.push.apply(acc, __spreadArray(["\u26A0\uFE0F  ignite/templates/app-icon/".concat(r.fileName, ":")], messages, false));
                        }
                        return acc;
                    }, []);
                    return [2 /*return*/, {
                            isValid: !validationMessages.length,
                            messages: validationMessages,
                        }];
            }
        });
    });
}
exports.validateAppIconGenerator = validateAppIconGenerator;
/**
 * Generates app-icons for specified option.
 */
function generateAppIcons(option) {
    return __awaiter(this, void 0, void 0, function () {
        var path, exists, find, copy, write, cwd, options, optionGenerationSuccesses, _loop_1, _i, options_1, o;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    path = gluegun_1.filesystem.path, exists = gluegun_1.filesystem.exists, find = gluegun_1.filesystem.find, copy = gluegun_1.filesystem.copy, write = gluegun_1.filesystem.write;
                    cwd = process.cwd();
                    options = option === "all" ? Object.values(Platforms) : [option];
                    optionGenerationSuccesses = [];
                    _loop_1 = function (o) {
                        var optionProjectName, relativeOutputDirPath, outputDirPath, icons, _loop_2, _b, icons_1, i, boilerplateDirPath, postGenerationFn;
                        return __generator(this, function (_c) {
                            switch (_c.label) {
                                case 0:
                                    optionProjectName = { expo: "Expo" }[o];
                                    relativeOutputDirPath = {
                                        expo: "assets/images",
                                        android: "android/app/src/main/res",
                                        ios: (function () {
                                            var _a;
                                            var searchPath = path(cwd, "ios");
                                            if (!exists(searchPath))
                                                return searchPath;
                                            return (((_a = find(searchPath, {
                                                directories: true,
                                                files: false,
                                                matching: "AppIcon.appiconset",
                                            })) === null || _a === void 0 ? void 0 : _a[0]) || "ios/**/Images.xcassets/AppIcon.appiconset");
                                        })(),
                                    }[o];
                                    outputDirPath = path(cwd, relativeOutputDirPath);
                                    // if not, skip...
                                    if (exists(outputDirPath) !== "dir") {
                                        (0, pretty_1.warning)("\u26A0\uFE0F  No output directory found for \"".concat(optionProjectName, "\" at \"").concat(outputDirPath, "\". Skipping..."));
                                        return [2 /*return*/, "continue"];
                                    }
                                    (0, pretty_1.heading)("Generating ".concat(optionProjectName, " app icons..."));
                                    icons = APP_ICON_RULESET.icons.filter(function (i) { return i.platform === o; });
                                    _loop_2 = function (i) {
                                        var inputFilePath, inputFile, rules, _d, rules_1, r, outputFileName, outputFilePath, outputSize, error_1;
                                        return __generator(this, function (_e) {
                                            switch (_e.label) {
                                                case 0:
                                                    inputFilePath = path(templatesDir(), "app-icon", i.inputFile);
                                                    return [4 /*yield*/, (function () {
                                                            return __awaiter(this, void 0, void 0, function () {
                                                                var _a, size, radius, padding, cutoutMask, error_2;
                                                                return __generator(this, function (_b) {
                                                                    switch (_b.label) {
                                                                        case 0:
                                                                            if (!i.transform)
                                                                                return [2 /*return*/, inputFilePath];
                                                                            _b.label = 1;
                                                                        case 1:
                                                                            _b.trys.push([1, 3, , 4]);
                                                                            _a = i.transform, size = _a.size, radius = _a.radius, padding = _a.padding;
                                                                            cutoutMask = Buffer.from("<svg><rect x=\"0\" y=\"0\" width=\"".concat(size, "\" height=\"").concat(size, "\" rx=\"").concat(radius, "\" ry=\"").concat(radius, "\"/></svg>"));
                                                                            return [4 /*yield*/, sharp(inputFilePath)
                                                                                    .resize(size, size, { fit: "fill" })
                                                                                    .composite([{ input: cutoutMask, blend: "dest-in" }])
                                                                                    .extend({
                                                                                    top: padding,
                                                                                    bottom: padding,
                                                                                    left: padding,
                                                                                    right: padding,
                                                                                    background: { r: 0, g: 0, b: 0, alpha: 0 },
                                                                                })
                                                                                    .toBuffer()];
                                                                        case 2: return [2 /*return*/, _b.sent()];
                                                                        case 3:
                                                                            error_2 = _b.sent();
                                                                            return [3 /*break*/, 4];
                                                                        case 4: return [2 /*return*/];
                                                                    }
                                                                });
                                                            });
                                                        })()];
                                                case 1:
                                                    inputFile = _e.sent();
                                                    rules = APP_ICON_RULESET.rules.filter(function (i) { return i.platform === o; });
                                                    _d = 0, rules_1 = rules;
                                                    _e.label = 2;
                                                case 2:
                                                    if (!(_d < rules_1.length)) return [3 /*break*/, 7];
                                                    r = rules_1[_d];
                                                    outputFileName = {
                                                        expo: i.name,
                                                        android: i.name.replace("{dpi}", r.dpi),
                                                        ios: i.name
                                                            .replace("{size}", r.size[i.type])
                                                            .replace("{idiom}", r.idiom)
                                                            .replace("{scale}", r.scale > 1 ? "@".concat(r.scale, "x") : ""),
                                                    }[o];
                                                    if (!inputFile) {
                                                        (0, pretty_1.warning)("\u26A0\uFE0F  ".concat(outputFileName, ": transform failed, please file an issue on GitHub"));
                                                        return [3 /*break*/, 6];
                                                    }
                                                    outputFilePath = path(outputDirPath, outputFileName);
                                                    outputSize = r.size[i.type] * (r.scale || 1);
                                                    _e.label = 3;
                                                case 3:
                                                    _e.trys.push([3, 5, , 6]);
                                                    return [4 /*yield*/, sharp(inputFile)
                                                            .resize(outputSize, outputSize, { fit: "fill" })
                                                            .toFile(outputFilePath)];
                                                case 4:
                                                    _e.sent();
                                                    (0, pretty_1.direction)("\u2705 ".concat(outputFileName));
                                                    return [3 /*break*/, 6];
                                                case 5:
                                                    error_1 = _e.sent();
                                                    (0, pretty_1.warning)("\u26A0\uFE0F  ".concat(outputFileName, ": saving failed, check if the directory exists"));
                                                    return [3 /*break*/, 6];
                                                case 6:
                                                    _d++;
                                                    return [3 /*break*/, 2];
                                                case 7: return [2 /*return*/];
                                            }
                                        });
                                    };
                                    _b = 0, icons_1 = icons;
                                    _c.label = 1;
                                case 1:
                                    if (!(_b < icons_1.length)) return [3 /*break*/, 4];
                                    i = icons_1[_b];
                                    return [5 /*yield**/, _loop_2(i)];
                                case 2:
                                    _c.sent();
                                    _c.label = 3;
                                case 3:
                                    _b++;
                                    return [3 /*break*/, 1];
                                case 4:
                                    boilerplateDirPath = path(igniteCliRootDir(), "boilerplate");
                                    postGenerationFn = {
                                        ios: function () {
                                            var sourceContentsJsonFilePath = path(boilerplateDirPath, "ios", require(path(boilerplateDirPath, "app.json")).name, "Images.xcassets/AppIcon.appiconset/Contents.json");
                                            copy(sourceContentsJsonFilePath, path(outputDirPath, "Contents.json"), { overwrite: true });
                                            (0, pretty_1.direction)("\u2705 Contents.json");
                                        },
                                        android: function () {
                                            var sourceIcLauncherXmlFilePath = path(boilerplateDirPath, relativeOutputDirPath, "mipmap-anydpi-v26/ic_launcher.xml");
                                            copy(sourceIcLauncherXmlFilePath, path(outputDirPath, "mipmap-anydpi-v26/ic_launcher.xml"), { overwrite: true });
                                            (0, pretty_1.direction)("\u2705 mipmap-anydpi-v26/ic_launcher.xml");
                                        },
                                        expo: function () {
                                            var _a, _b, _c, _d, _e;
                                            var merge = require("deepmerge-json");
                                            var sourceExpoConfig = (_a = require(path(boilerplateDirPath, "app.json"))) === null || _a === void 0 ? void 0 : _a.expo;
                                            var outputAppConfig = path(cwd, "app.json");
                                            var iconConfig = {
                                                expo: {
                                                    icon: sourceExpoConfig === null || sourceExpoConfig === void 0 ? void 0 : sourceExpoConfig.icon,
                                                    android: {
                                                        icon: (_b = sourceExpoConfig === null || sourceExpoConfig === void 0 ? void 0 : sourceExpoConfig.android) === null || _b === void 0 ? void 0 : _b.icon,
                                                        adaptiveIcon: (_c = sourceExpoConfig === null || sourceExpoConfig === void 0 ? void 0 : sourceExpoConfig.android) === null || _c === void 0 ? void 0 : _c.adaptiveIcon,
                                                    },
                                                    ios: { icon: (_d = sourceExpoConfig === null || sourceExpoConfig === void 0 ? void 0 : sourceExpoConfig.ios) === null || _d === void 0 ? void 0 : _d.icon },
                                                    web: { favicon: (_e = sourceExpoConfig === null || sourceExpoConfig === void 0 ? void 0 : sourceExpoConfig.web) === null || _e === void 0 ? void 0 : _e.favicon },
                                                },
                                            };
                                            // Check if app.json exists - however, could also be `app.config.js` or `app.config.ts` in
                                            // which case we should output a warning of what files to update
                                            if (!exists(outputAppConfig)) {
                                                var appConfigFiles = find(cwd, { matching: "app.config.*" });
                                                if (appConfigFiles.length > 0) {
                                                    (0, pretty_1.warning)("\u26A0\uFE0F  No \"app.json\" found at \"".concat(outputAppConfig, "\". It looks like you are using a dynamic configuration! Learn more at ").concat((0, pretty_1.link)("https://docs.expo.dev/workflow/configuration/#dynamic-configuration-with-appconfigjs")));
                                                    (0, pretty_1.warning)("\u26A0\uFE0F  Please add the following to your app.config.js manually:");
                                                    JSON.stringify(iconConfig, null, 2)
                                                        .split("\n")
                                                        .map(function (line) { return (0, pretty_1.p)("  ".concat(line)); });
                                                }
                                                else {
                                                    (0, pretty_1.warning)("\u26A0\uFE0F  No \"app.json\" found at \"".concat(outputAppConfig, "\". Skipping..."));
                                                }
                                                return;
                                            }
                                            var updatedConfig = merge(require(outputAppConfig), iconConfig);
                                            write(path(cwd, "app.json"), JSON.stringify(updatedConfig, null, 2) + "\n");
                                            (0, pretty_1.direction)("\u2705 app.json");
                                        },
                                    }[o];
                                    postGenerationFn();
                                    // if we reached this point, generation for this platform was successful
                                    optionGenerationSuccesses.push(true);
                                    return [2 /*return*/];
                            }
                        });
                    };
                    _i = 0, options_1 = options;
                    _a.label = 1;
                case 1:
                    if (!(_i < options_1.length)) return [3 /*break*/, 4];
                    o = options_1[_i];
                    return [5 /*yield**/, _loop_1(o)];
                case 2:
                    _a.sent();
                    _a.label = 3;
                case 3:
                    _i++;
                    return [3 /*break*/, 1];
                case 4: return [2 /*return*/, !!optionGenerationSuccesses.length];
            }
        });
    });
}
exports.generateAppIcons = generateAppIcons;
/**
 * Validates that splash screen icon input file exists in the template dir.
 * Additionally validates the size and background parameters.
 */
function validateSplashScreenGenerator(options, flags) {
    return __awaiter(this, void 0, void 0, function () {
        var _a, androidSize, iosSize, backgroundColor, skipSourceEqualityValidation, path, exists, inspect, validationMessages, androidMessages, iosMessages, boilerplateInputFilePath, inputFilePath, isMissing, isInvalidSize, isSameAsSource, messages;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = options || {}, androidSize = _a.androidSize, iosSize = _a.iosSize, backgroundColor = _a.backgroundColor;
                    skipSourceEqualityValidation = (flags || {}).skipSourceEqualityValidation;
                    path = gluegun_1.filesystem.path, exists = gluegun_1.filesystem.exists, inspect = gluegun_1.filesystem.inspect;
                    validationMessages = [];
                    androidMessages = [
                        Number.isNaN(androidSize) && "   • a numerical value",
                        androidSize <= 0 && "   • a value greater than 0",
                        androidSize >= 288 && "   • a value less than 288",
                    ].filter(Boolean);
                    if (androidMessages.length) {
                        validationMessages.push.apply(validationMessages, __spreadArray(["\u26A0\uFE0F  \"--android-size\" option must be:"], androidMessages, false));
                    }
                    iosMessages = [
                        Number.isNaN(iosSize) && "   • a numerical value",
                        iosSize <= 0 && "   • a value greater than 0",
                    ].filter(Boolean);
                    if (iosMessages.length) {
                        validationMessages.push.apply(validationMessages, __spreadArray(["\u26A0\uFE0F  \"--ios-size\" option must be:"], iosMessages, false));
                    }
                    // check if the background option is a valid hex color
                    if (!/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/.test(backgroundColor)) {
                        validationMessages.push("\u26A0\uFE0F  background color parameter must be:");
                        validationMessages.push("   \u2022 a valid hex color");
                    }
                    boilerplateInputFilePath = path(sourceDirectory(), "splash-screen", "logo.png");
                    inputFilePath = path(templatesDir(), "splash-screen", "logo.png");
                    isMissing = !exists(inputFilePath);
                    return [4 /*yield*/, (function () {
                            return __awaiter(this, void 0, void 0, function () {
                                var metadata;
                                return __generator(this, function (_a) {
                                    switch (_a.label) {
                                        case 0:
                                            if (isMissing)
                                                return [2 /*return*/, false];
                                            return [4 /*yield*/, sharp(inputFilePath).metadata()];
                                        case 1:
                                            metadata = _a.sent();
                                            return [2 /*return*/, metadata.width !== 1024 || metadata.height !== 1024];
                                    }
                                });
                            });
                        })()];
                case 1:
                    isInvalidSize = _b.sent();
                    return [4 /*yield*/, (function () {
                            return __awaiter(this, void 0, void 0, function () {
                                var inputFileMd5, sourceFileMd5;
                                return __generator(this, function (_a) {
                                    if (skipSourceEqualityValidation)
                                        return [2 /*return*/, false];
                                    if (isMissing)
                                        return [2 /*return*/, false];
                                    inputFileMd5 = inspect(inputFilePath, { checksum: "md5" }).md5;
                                    sourceFileMd5 = inspect(boilerplateInputFilePath, { checksum: "md5" }).md5;
                                    return [2 /*return*/, inputFileMd5 === sourceFileMd5];
                                });
                            });
                        })()];
                case 2:
                    isSameAsSource = _b.sent();
                    messages = [
                        isMissing && "   • the file is missing",
                        isInvalidSize && "   • the file is the wrong size (expected 1024x1024px)",
                        isSameAsSource &&
                            "   • looks like you're using our default template; customize the file with your own icon first",
                    ].filter(Boolean);
                    if (messages.length) {
                        validationMessages.push.apply(validationMessages, __spreadArray(["\u26A0\uFE0F  ignite/templates/splash-screen/logo.png:"], messages, false));
                    }
                    return [2 /*return*/, {
                            isValid: !validationMessages.length,
                            messages: validationMessages,
                        }];
            }
        });
    });
}
exports.validateSplashScreenGenerator = validateSplashScreenGenerator;
/**
 * Generates splash screen for all platforms
 */
function generateSplashScreen(options) {
    var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
    return __awaiter(this, void 0, void 0, function () {
        function generateForExpo(type, size, expoRules) {
            return __awaiter(this, void 0, void 0, function () {
                var _i, expoRules_1, expoRule, name_1, width, height, scale, outputFileName, outputFilePath, logoSize, verticalPadding, horizontalPadding, error_3;
                return __generator(this, function (_a) {
                    switch (_a.label) {
                        case 0:
                            _i = 0, expoRules_1 = expoRules;
                            _a.label = 1;
                        case 1:
                            if (!(_i < expoRules_1.length)) return [3 /*break*/, 6];
                            expoRule = expoRules_1[_i];
                            name_1 = expoRule.name, width = expoRule.width, height = expoRule.height, scale = expoRule.scale;
                            outputFileName = ["splash-logo", type, name_1].filter(Boolean).join("-") + ".png";
                            outputFilePath = path(expoOutputDirPath, outputFileName);
                            logoSize = size * scale;
                            verticalPadding = Math.ceil((height - logoSize) / 2);
                            horizontalPadding = Math.ceil((width - logoSize) / 2);
                            _a.label = 2;
                        case 2:
                            _a.trys.push([2, 4, , 5]);
                            return [4 /*yield*/, sharp(inputFilePath)
                                    .resize(logoSize, logoSize, { fit: "fill" })
                                    .extend({
                                    top: verticalPadding,
                                    bottom: verticalPadding,
                                    left: horizontalPadding,
                                    right: horizontalPadding,
                                    background: { r: 0, g: 0, b: 0, alpha: 0 },
                                })
                                    .toFile(outputFilePath)];
                        case 3:
                            _a.sent();
                            (0, pretty_1.direction)("\u2705 assets/images/".concat(outputFileName));
                            optionGenerationSuccesses.push(true);
                            return [3 /*break*/, 5];
                        case 4:
                            error_3 = _a.sent();
                            return [3 /*break*/, 5];
                        case 5:
                            _i++;
                            return [3 /*break*/, 1];
                        case 6: return [2 /*return*/];
                    }
                });
            });
        }
        var _r, androidSize, iosSize, backgroundColor, path, exists, write, find, cwd, inputFilePath, expoOutputDirPath, isExpoOutputDirExists, optionGenerationSuccesses, boilerplateDirPath, merge, sourceExpoConfig, outputAppConfig, splashConfig, appConfigFiles, updatedConfig;
        return __generator(this, function (_s) {
            switch (_s.label) {
                case 0:
                    _r = options || {}, androidSize = _r.androidSize, iosSize = _r.iosSize, backgroundColor = _r.backgroundColor;
                    path = gluegun_1.filesystem.path, exists = gluegun_1.filesystem.exists, write = gluegun_1.filesystem.write, find = gluegun_1.filesystem.find;
                    cwd = process.cwd();
                    inputFilePath = path(templatesDir(), "splash-screen", "logo.png");
                    expoOutputDirPath = path(cwd, "assets/images");
                    isExpoOutputDirExists = exists(expoOutputDirPath) === "dir";
                    optionGenerationSuccesses = [];
                    (0, pretty_1.heading)("Generating Expo splash screens (Android, iOS, and Web)...");
                    if (!isExpoOutputDirExists) return [3 /*break*/, 5];
                    return [4 /*yield*/, generateForExpo("ios", iosSize, [
                            { name: "mobile", width: 1284, height: 2778, scale: 3 },
                            { name: "tablet", width: 2048, height: 2732, scale: 2 },
                        ])];
                case 1:
                    _s.sent();
                    return [4 /*yield*/, generateForExpo("android", androidSize, [
                            { name: "universal", width: 1440, height: 2560, scale: 4 },
                        ])];
                case 2:
                    _s.sent();
                    return [4 /*yield*/, generateForExpo("web", 300, [{ width: 1920, height: 1080, scale: 1 }])];
                case 3:
                    _s.sent();
                    return [4 /*yield*/, generateForExpo("all", 180, [{ width: 1242, height: 2436, scale: 3 }])
                        // update app.json
                    ];
                case 4:
                    _s.sent();
                    boilerplateDirPath = path(igniteCliRootDir(), "boilerplate");
                    merge = require("deepmerge-json");
                    sourceExpoConfig = (_a = require(path(boilerplateDirPath, "app.json"))) === null || _a === void 0 ? void 0 : _a.expo;
                    outputAppConfig = path(cwd, "app.json");
                    splashConfig = {
                        expo: {
                            splash: {
                                backgroundColor: backgroundColor,
                                image: (_b = sourceExpoConfig === null || sourceExpoConfig === void 0 ? void 0 : sourceExpoConfig.splash) === null || _b === void 0 ? void 0 : _b.image,
                                resizeMode: (_c = sourceExpoConfig === null || sourceExpoConfig === void 0 ? void 0 : sourceExpoConfig.splash) === null || _c === void 0 ? void 0 : _c.resizeMode,
                            },
                            android: {
                                splash: {
                                    backgroundColor: backgroundColor,
                                    image: (_e = (_d = sourceExpoConfig === null || sourceExpoConfig === void 0 ? void 0 : sourceExpoConfig.android) === null || _d === void 0 ? void 0 : _d.splash) === null || _e === void 0 ? void 0 : _e.image,
                                    resizeMode: (_g = (_f = sourceExpoConfig === null || sourceExpoConfig === void 0 ? void 0 : sourceExpoConfig.android) === null || _f === void 0 ? void 0 : _f.splash) === null || _g === void 0 ? void 0 : _g.resizeMode,
                                },
                            },
                            ios: {
                                splash: {
                                    backgroundColor: backgroundColor,
                                    image: (_j = (_h = sourceExpoConfig === null || sourceExpoConfig === void 0 ? void 0 : sourceExpoConfig.ios) === null || _h === void 0 ? void 0 : _h.splash) === null || _j === void 0 ? void 0 : _j.image,
                                    resizeMode: (_l = (_k = sourceExpoConfig === null || sourceExpoConfig === void 0 ? void 0 : sourceExpoConfig.ios) === null || _k === void 0 ? void 0 : _k.splash) === null || _l === void 0 ? void 0 : _l.resizeMode,
                                },
                            },
                            web: {
                                splash: {
                                    backgroundColor: backgroundColor,
                                    image: (_o = (_m = sourceExpoConfig === null || sourceExpoConfig === void 0 ? void 0 : sourceExpoConfig.web) === null || _m === void 0 ? void 0 : _m.splash) === null || _o === void 0 ? void 0 : _o.image,
                                    resizeMode: (_q = (_p = sourceExpoConfig === null || sourceExpoConfig === void 0 ? void 0 : sourceExpoConfig.web) === null || _p === void 0 ? void 0 : _p.splash) === null || _q === void 0 ? void 0 : _q.resizeMode,
                                },
                            },
                        },
                    };
                    // Check if app.json exists - however, could also be `app.config.js` or `app.config.ts` in
                    // which case we should output a warning of what files to update
                    if (!exists(outputAppConfig)) {
                        appConfigFiles = find(cwd, { matching: "app.config.*" });
                        if (appConfigFiles.length > 0) {
                            (0, pretty_1.warning)("\u26A0\uFE0F  No \"app.json\" found at \"".concat(outputAppConfig, "\". It looks like you are using a dynamic configuration! Learn more at ").concat((0, pretty_1.link)("https://docs.expo.dev/workflow/configuration/#dynamic-configuration-with-appconfigjs")));
                            (0, pretty_1.warning)("\u26A0\uFE0F  Please add the following to your app.config.js manually:");
                            JSON.stringify(splashConfig, null, 2)
                                .split("\n")
                                .map(function (line) { return (0, pretty_1.p)("  ".concat(line)); });
                        }
                        else {
                            (0, pretty_1.warning)("\u26A0\uFE0F  No \"app.json\" found at \"".concat(outputAppConfig, "\". Skipping..."));
                        }
                        return [2 /*return*/];
                    }
                    updatedConfig = merge(require(outputAppConfig), splashConfig);
                    write(path(cwd, "app.json"), JSON.stringify(updatedConfig, null, 2) + "\n");
                    (0, pretty_1.direction)("\u2705 app.json");
                    return [3 /*break*/, 6];
                case 5:
                    (0, pretty_1.warning)("\u26A0\uFE0F  No output directory found for \"Expo\" at \"".concat(expoOutputDirPath, "\". Skipping..."));
                    _s.label = 6;
                case 6: return [2 /*return*/, !!optionGenerationSuccesses.length];
            }
        });
    });
}
exports.generateSplashScreen = generateSplashScreen;
//# sourceMappingURL=generators.js.map