"use strict";
var _this = this;
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var shelljs_1 = require("shelljs");
var lodash_1 = require("lodash");
var chalk = require("chalk");
var runShellScript = function (cmd, cwd, options) {
    if (cwd === void 0) { cwd = __dirname; }
    if (options === void 0) { options = {}; }
    return new Promise(function (res, rej) {
        shelljs_1.exec(cmd, lodash_1.merge({
            silent: false,
            cwd: cwd
        }, options), function (code, stdout, stderr) {
            if (code === 0) {
                res(stdout);
            }
            else {
                rej(stderr);
            }
        });
    });
};
exports.default = function (options) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
    var dest;
    return tslib_1.__generator(this, function (_a) {
        switch (_a.label) {
            case 0:
                dest = options.get("dest");
                console.log(chalk.bold.green("Installing dependencies"));
                return [4 /*yield*/, runShellScript("yarn install --prefer-offline", dest)];
            case 1:
                _a.sent();
                console.log(chalk.bold.green("Building v2 app"));
                return [4 /*yield*/, runShellScript("yarn run build", dest)];
            case 2:
                _a.sent();
                console.log(chalk.bold.green("Validating v2 app"));
                return [4 /*yield*/, runShellScript("zat validate --path " + dest + "/dist/")];
            case 3:
                _a.sent();
                return [2 /*return*/];
        }
    });
}); };
