text: "use strict";
  Object.defineProperty(exports, "__esModule", { value: true });
  const tslib_1 = require("tslib");
  const chalk_1 = require("chalk");
  const command_1 = require("@ionic/cli-utils/lib/command");
  const errors_1 = require("@ionic/cli-utils/lib/errors");
  const utils_1 = require("@ionic/cli-utils/lib/cordova/utils");
  const app_scripts_1 = require("@ionic/cli-utils/lib/ionic-angular/app-scripts");
  const base_1 = require("./base");
  let PrepareCommand = class PrepareCommand extends base_1.CordovaCommand {
      preRun(inputs, options) {
          return tslib_1.__awaiter(this, void 0, void 0, function* () {
              yield this.preRunChecks();
          });
      }
      run(inputs, options) {
          return tslib_1.__awaiter(this, void 0, void 0, function* () {
              const { getPlatforms, installPlatform } = yield Promise.resolve().then(() => require('@ionic/cli-utils/lib/cordova/project'));
              const [platform] = inputs;
              const platforms = yield getPlatforms(this.env.project.directory);
              if (platform) {
                  if (!platforms.includes(platform)) {
                      const confirm = yield this.env.prompt({
                          message: `Platform ${chalk_1.default.green(platform)} is not installed! Would you like to install it?`,
                          type: 'confirm',
                          name: 'confirm',
                      });
                      if (confirm) {
                          yield installPlatform(this.env, platform);
                      }
                      else {
                          throw new errors_1.FatalException(`Can't prepare for ${chalk_1.default.green(platform)} unless the platform is installed.\n` +
                              `Did you mean just ${chalk_1.default.green('ionic cordova prepare')}?\n`);
                      }
                  }
              }
              if (options.build) {
                  const { build } = yield Promise.resolve().then(() => require('@ionic/cli-utils/commands/build'));
                  yield build(this.env, inputs, utils_1.generateBuildOptions(this.metadata, options));
              }
              yield this.runCordova(utils_1.filterArgumentsForCordova(this.metadata, inputs, options), { showExecution: true });
          });
      }
  };
  PrepareCommand = tslib_1.__decorate([
      command_1.CommandMetadata({
          name: 'prepare',
          type: 'project',
          description: 'Copies assets to Cordova platforms, preparing them for native builds',
          longDescription: `
  ${chalk_1.default.green('ionic cordova prepare')} will do the following:
  - Copy the ${chalk_1.default.bold('www/')} directory into your Cordova platforms.
  - Transform ${chalk_1.default.bold('config.xml')} into platform-specific manifest files.
  - Copy icons and splash screens from ${chalk_1.default.bold('resources/')} to into your Cordova platforms.
  - Copy plugin files into specified platforms.
  
  You may wish to use ${chalk_1.default.green('ionic cordova prepare')} if you run your project with Android Studio or Xcode.
    `,
          exampleCommands: ['', 'ios', 'android'],
          inputs: [
              {
                  name: 'platform',
                  description: `The platform you would like to prepare (${['android', 'ios'].map(v => chalk_1.default.green(v)).join(', ')})`,
                  required: false,
              },
          ],
          options: [
              {
                  name: 'build',
                  description: 'Do not invoke an Ionic build',
                  type: Boolean,
                  default: true,
              },
              ...app_scripts_1.APP_SCRIPTS_OPTIONS,
          ]
      })
  ], PrepareCommand);
  exports.PrepareCommand = PrepareCommand;
  