"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 install_1 = require("../Api/install");
const Logger_1 = require("../modules/Logger");
const ensureAuth_1 = require("./utils/ensureAuth");
const codeArtifactUtils_1 = require("../utils/codeArtifactUtils");
const ewizardService_types_1 = require("../interfaces/ewizardService.types");
commander
    .name('wiz install')
    .description('wiz install (with no args, in package dir)\nwiz install <component>\nwiz install <component>@<tag|branch>\n\naliases: i')
    .addOption(new commander.Option('-r, --repository <repositoryType>').hideHelp())
    .parse(process.argv);
install(commander.args, commander.opts())
    .catch((err) => Logger_1.default.logAndExit('error', err.message, 1));
function install(components = [], options) {
    return __awaiter(this, void 0, void 0, function* () {
        const ewizard = yield ensureAuth_1.default();
        const cwd = process.cwd();
        const npmRegistryParams = yield codeArtifactUtils_1.getNpmRegistryParams(options, cwd, ewizardService_types_1.ActionType.Install);
        const npmRegistryConfig = yield ewizard.getNpmRegistry(npmRegistryParams);
        const installOptions = Object.assign({ cwd }, npmRegistryConfig);
        const installAction = yield install_1.createAction(cwd);
        return installAction(components, installOptions);
    });
}
//# sourceMappingURL=wiz-install.js.map