"use strict";
class BuildCommandBase {
    constructor($options, $platformsData, $platformService) {
        this.$options = $options;
        this.$platformsData = $platformsData;
        this.$platformService = $platformService;
    }
    executeCore(args) {
        return (() => {
            let platform = args[0].toLowerCase();
            this.$platformService.preparePlatform(platform).wait();
            this.$options.clean = true;
            this.$platformService.buildPlatform(platform).wait();
            if (this.$options.copyTo) {
                this.$platformService.copyLastOutput(platform, this.$options.copyTo, { isForDevice: this.$options.forDevice });
            }
        }).future()();
    }
}
exports.BuildCommandBase = BuildCommandBase;
class BuildIosCommand extends BuildCommandBase {
    constructor($options, $platformsData, $platformService) {
        super($options, $platformsData, $platformService);
        this.$options = $options;
        this.allowedParameters = [];
    }
    execute(args) {
        return this.executeCore([this.$platformsData.availablePlatforms.iOS]);
    }
    canExecute(args) {
        return this.$platformService.validateOptions(this.$platformsData.availablePlatforms.iOS);
    }
}
exports.BuildIosCommand = BuildIosCommand;
$injector.registerCommand("build|ios", BuildIosCommand);
class BuildAndroidCommand extends BuildCommandBase {
    constructor($options, $platformsData, $errors, $platformService) {
        super($options, $platformsData, $platformService);
        this.$options = $options;
        this.$errors = $errors;
        this.allowedParameters = [];
    }
    execute(args) {
        return this.executeCore([this.$platformsData.availablePlatforms.Android]);
    }
    canExecute(args) {
        return (() => {
            if (this.$options.release && (!this.$options.keyStorePath || !this.$options.keyStorePassword || !this.$options.keyStoreAlias || !this.$options.keyStoreAliasPassword)) {
                this.$errors.fail("When producing a release build, you need to specify all --key-store-* options.");
            }
            return args.length === 0 && this.$platformService.validateOptions(this.$platformsData.availablePlatforms.Android).wait();
        }).future()();
    }
}
exports.BuildAndroidCommand = BuildAndroidCommand;
$injector.registerCommand("build|android", BuildAndroidCommand);
