"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const command_1 = require("@oclif/command");
const creator_1 = __importDefault(require("../implements/creator"));
const account_1 = __importDefault(require("../implements/account"));
const command_2 = __importDefault(require("../extends/command"));
const login_1 = __importDefault(require("./login"));
class Create extends command_2.default {
    async run() {
        const { args, flags } = this.parse(Create);
        const creator = new creator_1.default();
        creator.eventTracker('create_start', {
            tags: Object.assign(Object.assign({}, flags), args),
        });
        const account = new account_1.default();
        const isLogin = account.isLogin();
        if (!isLogin) {
            const login = new login_1.default([], this.config);
            await login.run({ updateConfig: true });
        }
        if (args.projectPath) {
            await creator.checkProjectPath(args.projectPath || '');
        }
        else {
            args.projectPath = await creator.enterProjectPath();
        }
        await creator.checkProjectPath(args.projectPath);
        const appType = await creator.chooseAppType(flags.appType);
        const subtype = await creator.chooseSubtype({
            appType,
            subtype: flags.subtype,
        });
        const templateConfig = await creator.chooseTemplate({
            templateCate: subtype || appType,
            templateName: flags.template,
        });
        await creator.generate({
            templateCate: subtype || appType,
            templateConfig,
            projectPath: args.projectPath,
        });
    }
}
exports.default = Create;
Create.description = 'Create a project from the template';
Create.flags = {
    appType: command_1.flags.string({
        char: 'a',
        description: 'choose app type',
    }),
    subtype: command_1.flags.string({
        char: 's',
        description: 'choose app subtype',
    }),
    template: command_1.flags.string({
        char: 't',
        description: 'choose tempalte',
    }),
    help: command_1.flags.help({
        char: 'h',
    }),
};
Create.args = [
    {
        name: 'projectPath',
        required: false,
    },
];
Create.examples = [
    [
        '$ {{cli}} create ./gadget-demo -a gadget',
        'create a gadget project in the gadget-demo folder',
    ],
];
