"use strict";
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());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
const cli_core_1 = require("@igniteui/cli-core");
const path = require("path");
const resolve = require("resolve");
// tslint:disable:object-literal-sort-keys
const command = {
    command: "quickstart",
    desc: "creates rich feature grid",
    builder: {
        framework: {
            alias: "f",
            default: "jquery",
            describe: "Framework to setup quickstart for",
            type: "string",
            choices: ["jquery", "react", "angular"]
        }
    },
    execute(argv) {
        return __awaiter(this, void 0, void 0, function* () {
            cli_core_1.GoogleAnalytics.post({
                t: "screenview",
                cd: "Quick Start"
            });
            cli_core_1.Util.log("Quick Start!");
            const framework = argv.framework;
            let name = "";
            let type = "";
            switch (framework) {
                case "jquery":
                    name = "jquery-quickstart";
                    type = "js";
                    break;
                case "react":
                    name = "react-quickstart";
                    type = "es6";
                    break;
                case "angular":
                    name = "angular-quickstart";
                    type = "ig-ts";
                    break;
                default:
                    cli_core_1.Util.error("The framework is not supported!", "red");
                    return;
            }
            const outDir = path.join(process.cwd(), name);
            if (cli_core_1.Util.directoryExists(path.join(__dirname, "../../templates/quickstart", argv.framework))) {
                yield cli_core_1.Util.processTemplates(path.join(__dirname, "../../templates/quickstart", argv.framework), outDir, {}, {}, false);
            }
            //change folder
            process.chdir(name);
            cli_core_1.GoogleAnalytics.post({
                t: "event",
                ec: "$ig quickstart",
                ea: `framework: ${argv.framework}`,
                cd1: framework,
                cd2: type,
                cd3: name
            });
            if (argv.framework === "react") {
                cli_core_1.Util.log("react-quickstart loaded");
                cli_core_1.Util.execSync("npm install");
                cli_core_1.Util.execSync("npm run webpack");
                // lite-server installed per project
                const liteServer = require(resolve.sync("lite-server", { basedir: process.cwd() }));
                liteServer.server();
            }
            if (argv.framework === "angular") {
                cli_core_1.Util.log("angular-quickstart loaded");
                cli_core_1.Util.execSync("npm install");
                cli_core_1.Util.execSync("npm start");
            }
            if (argv.framework === "jquery") {
                cli_core_1.Util.log("jquery-quickstart loaded");
                cli_core_1.Util.execSync("npm install");
                // lite-server installed per project
                const liteServer = require(resolve.sync("lite-server", { basedir: process.cwd() }));
                liteServer.server();
            }
        });
    }
};
exports.default = command;
