"use strict";
var _this = this;
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var path_1 = require("path");
var inquirer_1 = require("inquirer");
var node_emoji_1 = require("node-emoji");
var fs_1 = require("fs");
var lodash_1 = require("lodash");
var chalk = require("chalk");
exports.default = function (options) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
    var src, editor, dest, replaceV1, pkg, replace;
    return tslib_1.__generator(this, function (_a) {
        switch (_a.label) {
            case 0:
                src = options.get("path");
                editor = options.get("editor");
                dest = path_1.join(src, "v2", path_1.sep);
                replaceV1 = options.get("replaceV1", false);
                // Log out the `src` and `dest` paths for developer reference
                console.log(chalk.yellow("App will be migrated from: " + src));
                console.log(chalk.yellow("App will be migrated to: " + dest));
                if (!replaceV1) return [3 /*break*/, 2];
                pkg = void 0;
                try {
                    pkg = require(src + "/package.json");
                }
                catch (error) {
                    /* no-op */
                }
                if (lodash_1.get(pkg, "name") === "app_scaffold" && fs_1.existsSync(src + "/v1/")) {
                    throw new Error("It looks like you're attempting to migrate an app that has already been migrated " + node_emoji_1.emojify(":pouting_cat:"));
                }
                return [4 /*yield*/, inquirer_1.prompt([
                        {
                            type: "confirm",
                            name: "replace",
                            message: "Are you sure you want to replace v1 files?",
                            default: false
                        }
                    ])];
            case 1:
                replace = (_a.sent()).replace;
                if (!replace) {
                    throw new Error("Migration cancelled " + node_emoji_1.emojify(":crying_cat_face:"));
                }
                console.log(chalk.bold.yellow("v1 App will be backed up to: " + src + "/v1/"));
                _a.label = 2;
            case 2: return [2 /*return*/, options.merge({
                    src: src,
                    dest: dest
                })];
        }
    });
}); };
