"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var common_1 = require("../common");
function open(args) {
    return tslib_1.__awaiter(this, void 0, void 0, function () {
        var settings, formatPath, logRunDist, runOpen, config, platform, _a, outputDir, _b, productName, path;
        return tslib_1.__generator(this, function (_c) {
            switch (_c.label) {
                case 0:
                    settings = args.settings;
                    formatPath = function (path) { return common_1.logging.formatPath(path, true); };
                    logRunDist = function () {
                        common_1.log.info("\n\uD83D\uDC49  Run " + common_1.log.cyan('yarn ui dist') + " to build it.\n");
                    };
                    runOpen = function (path, type) {
                        common_1.log.info();
                        common_1.log.info("\uD83D\uDD90  Opening " + type + ": " + formatPath(path) + "\n");
                        return common_1.command()
                            .add("open \"" + path + "\"")
                            .run();
                    };
                    config = settings.electron.builderArgs;
                    if (!config.exists) {
                        common_1.log.warn("\uD83D\uDE29  An 'electron-builder.yml' file does not exist in the project.");
                        return [2];
                    }
                    platform = 'mac';
                    _a = config.outputDir, outputDir = _a === void 0 ? '' : _a, _b = config.productName, productName = _b === void 0 ? 'UNKNOWN' : _b;
                    return [4, common_1.fs.pathExists(outputDir)];
                case 1:
                    if (!(_c.sent())) {
                        common_1.log.info();
                        common_1.log.warn("\uD83D\uDE29  The app distribution has not been built yet.");
                        common_1.log.info("   " + formatPath(outputDir));
                        logRunDist();
                        return [2];
                    }
                    if (args.folder) {
                        return [2, runOpen(outputDir, 'folder')];
                    }
                    path = common_1.fsPath.join(outputDir, platform, productName + ".app");
                    path = "./" + path.replace(/^\\/, '');
                    path = common_1.fsPath.resolve(path);
                    return [4, common_1.fs.pathExists(path)];
                case 2:
                    if (!(_c.sent())) {
                        common_1.log.info();
                        common_1.log.warn("\uD83D\uDE29  An app named " + common_1.log.magenta(productName) + " does not exist.");
                        common_1.log.info("   " + formatPath(path));
                        logRunDist();
                        return [2];
                    }
                    return [2, runOpen(path, 'app')];
            }
        });
    });
}
exports.open = open;
//# sourceMappingURL=open.js.map