"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const command_1 = require("@oclif/command");
const fs_extra_1 = require("fs-extra");
const path_1 = require("path");
const lib_1 = require("../../lib");
function readWorkspace() {
    const configFiles = [
        lib_1.TAP_CONFIG_FILEPATH,
        lib_1.IOTIZE_STUDIO_CONFIG_FILEPATH,
        lib_1.TAP_CONFIG_FILEPATH
    ];
    if (configFiles.filter(m => fs_extra_1.existsSync(m)).length === 0) {
        throw new Error(`Cannot find one of these files ${configFiles.join(', ')} in ${process.cwd()}. Command should be run inside an IoTize app generator project directory.`);
    }
}
async function regenerateApp(options) {
    const initalDir = process.cwd();
    if (options.projectDir) {
        process.chdir(options.projectDir);
    }
    readWorkspace();
    if (options.tapConfig) {
        await lib_1.execIonicToolkitSchematics('app-config', {
            tapConfig: path_1.resolve(initalDir, options.tapConfig),
            rebuild: true
        });
    }
    await lib_1.execIonicToolkitSchematics('generate', {
        overwrite: true,
        dryRun: options.dryRun
    }, {
        dryRun: options.dryRun
    });
}
exports.regenerateApp = regenerateApp;
class UpdateCommand extends command_1.Command {
    async run() {
        const parsedInput = this.parse(UpdateCommand);
        const options = parsedInput.flags;
        await regenerateApp(options);
    }
}
exports.default = UpdateCommand;
UpdateCommand.description = 'Regenerate application according to configuration';
UpdateCommand.examples = [
    `iotize-app-gen udpate`
];
UpdateCommand.flags = {
    help: command_1.flags.help({ char: 'h' }),
    dryRun: command_1.flags.boolean(),
    tapConfig: command_1.flags.string({
        description: 'IoTize Studio configuration file (.iotz)'
    })
};
//# sourceMappingURL=regenerate.js.map