"use strict";
var _this = this;
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var globby_1 = require("globby");
var shelljs_1 = require("shelljs");
exports.default = function (options) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
    var src, editor, replaceV1, v1Files;
    return tslib_1.__generator(this, function (_a) {
        switch (_a.label) {
            case 0:
                src = options.get("src");
                editor = options.get("editor");
                replaceV1 = options.get("replaceV1");
                return [4 /*yield*/, new Promise(function (res) { return editor.commit(res); })];
            case 1:
                _a.sent();
                if (replaceV1) {
                    v1Files = globby_1.sync("/*", {
                        dot: true,
                        root: "" + src,
                        ignore: [src + "/v2/**", src + "/v2", src + "/**/.git*/**"]
                    });
                    // Create the v1 directory
                    shelljs_1.mkdir("-p", src + "/v1");
                    // Move all the v1 files across to the backup directory
                    shelljs_1.mv(v1Files, src + "/v1/");
                    // Move the v2 files to the root directory
                    shelljs_1.mv("-n", src + "/v2/*", src + "/");
                    // Remove the old v2 directory
                    shelljs_1.rm("-fR", src + "/v2");
                    // Set the new dest on to options so that scripts will
                    // invoke at the new path for the migration output
                    return [2 /*return*/, options.set("dest", src)];
                }
                return [2 /*return*/];
        }
    });
}); };
