"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 commander = require("commander");
const create_1 = require("../Api/create");
const ewizardService_types_1 = require("../interfaces/ewizardService.types");
const codeArtifactUtils_1 = require("../utils/codeArtifactUtils");
const ensureAuth_1 = require("./utils/ensureAuth");
const logger_1 = require("./utils/logger");
const validateMonorepo_1 = require("./utils/validateMonorepo");
commander
    .name('wiz create ewizard-template')
    .description('Archive an email to use as a template')
    .option('--from <layoutName...>', 'Archive the email layout from <layout-name>')
    .option('--name <archiveName>', 'Set the archive name')
    .option('--target <targetClmName>', 'Set the target system. This updates settings.json')
    .option('--theme <themeName>', 'Set the email theme. This updates settings.json')
    .option('--scheme <schemeName>', 'Set the email color scheme. This updates settings.json')
    .option('--from-all', 'Create an email for every layout available')
    .option('--no-archive', 'Save email project locally without archiving')
    .parse(process.argv);
const opts = commander.opts();
createEwizardTemplate()
    .catch(logger_1.handleError)
    .finally(logger_1.closeLogger);
function createEwizardTemplate() {
    return __awaiter(this, void 0, void 0, function* () {
        (0, validateMonorepo_1.validateNameOption)(opts);
        const ewizard = yield (0, ensureAuth_1.default)();
        const npmRegistryParams = yield (0, codeArtifactUtils_1.getNpmRegistryParams)(opts, process.cwd(), ewizardService_types_1.ActionType.Install);
        const npmRegistryConfig = yield ewizard.getNpmRegistry(npmRegistryParams);
        const createOptions = Object.assign(Object.assign({}, opts), { npmRegistryConfig, command: 'ewizard-template' });
        if (!(0, validateMonorepo_1.areWorkspacesPassed)(opts)) {
            createOptions.fromMasterTemplate = true;
        }
        const baseDir = process.cwd();
        const action = yield (0, create_1.createAction)(baseDir);
        return action(baseDir, createOptions);
    });
}
//# sourceMappingURL=wiz-create-ewizard-template.js.map