"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
require("@iotize/device-client.js/config/iotize-studio/parser/xml");
const command_1 = require("@oclif/command");
const fs_extra_1 = require("fs-extra");
const project_1 = require("../../lib/project");
const errors_1 = require("../errors");
class GenerateCommand extends command_1.Command {
    async run() {
        const { args } = this.parse(GenerateCommand);
        let generator;
        switch (args.type) {
            case 'tapconfig':
                generator = await getConfigGenerator(args.config);
                console.log(JSON.stringify(generator.tapConfig, null, 4));
                break;
            case 'appconfig':
                generator = await getConfigGenerator(args.config);
                console.log(JSON.stringify(generator.schema, null, 4));
                break;
            default:
                throw new Error(`Illegal argument type: ${args.type}`);
        }
    }
}
exports.default = GenerateCommand;
GenerateCommand.description = 'Generate Tap or App configuration file according to IoTize Studio configuration file';
GenerateCommand.args = [
    {
        name: 'type',
        description: 'What you cant to generate',
        required: true,
        enum: [
            'tapconfig',
            'appconfig'
        ]
    },
    {
        name: 'config',
        required: true,
    }
];
async function getConfigGenerator(filepath) {
    if (!fs_extra_1.existsSync(filepath)) {
        throw errors_1.IllegalArgumentException.fileDoesNotExist(filepath);
    }
    const iotizeStudioConfig = fs_extra_1.readFileSync(filepath).toString();
    const configGenerator = project_1.createAppConfigFromIoTizeStudio(iotizeStudioConfig);
    return configGenerator;
}
//# sourceMappingURL=generate.js.map