"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 fs = require("fs-extra");
const path = require("path");
let command;
command = {
    command: "build",
    desc: "builds the project",
    builder: {},
    templateManager: null,
    execute(argv) {
        return __awaiter(this, void 0, void 0, function* () {
            cli_core_1.GoogleAnalytics.post({
                t: "screenview",
                cd: "Build"
            });
            command.build(argv);
        });
    },
    build(argv) {
        return __awaiter(this, void 0, void 0, function* () {
            cli_core_1.Util.log("Build started.");
            yield cli_core_1.PackageManager.ensureIgniteUISource(true, command.templateManager);
            if (!cli_core_1.ProjectConfig.hasLocalConfig()) {
                cli_core_1.Util.error("Add command is supported only on existing project created with igniteui-cli", "red");
                return;
            }
            const config = cli_core_1.ProjectConfig.getConfig();
            cli_core_1.GoogleAnalytics.post({
                t: "event",
                ec: "$ig build",
                cd1: config.project.framework,
                cd2: config.project.projectType,
                cd11: !!config.skipGit,
                cd14: config.project.theme
            });
            yield cli_core_1.PackageManager.installPackages();
            if (config.project.projectType === "es6") {
                return;
            }
            if (config.project.theme.includes(".less") || config.project.theme.includes(".sass")) {
                fs.mkdirSync("./themes");
                const source = path.join(config.project.igniteuiSource, "/css/themes/", config.project.theme.split(".")[0]);
                const destination = path.join(config.project.sourceRoot, "themes");
                fs.copySync(source, destination, { recursive: true });
            }
        });
    }
};
exports.default = command;
