enable.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.IntegrationsEnableCommand = void 0;
  4. const tslib_1 = require("tslib");
  5. const cli_framework_1 = require("@ionic/cli-framework");
  6. const path = tslib_1.__importStar(require("path"));
  7. const guards_1 = require("../../guards");
  8. const color_1 = require("../../lib/color");
  9. const command_1 = require("../../lib/command");
  10. const errors_1 = require("../../lib/errors");
  11. const integrations_1 = require("../../lib/integrations");
  12. class IntegrationsEnableCommand extends command_1.Command {
  13. async getMetadata() {
  14. return {
  15. name: 'enable',
  16. type: 'project',
  17. summary: 'Add & enable integrations to your app',
  18. description: `
  19. Integrations, such as Cordova, can be enabled with this command. If the integration has never been added to the project, ${(0, color_1.input)('ionic integrations enable')} will download and add the integration.
  20. Integrations can be re-added with the ${(0, color_1.input)('--add')} option.
  21. `,
  22. inputs: [
  23. {
  24. name: 'name',
  25. summary: `The integration to enable (e.g. ${integrations_1.INTEGRATION_NAMES.map(i => (0, color_1.input)(i)).join(', ')})`,
  26. validators: [cli_framework_1.validators.required, (0, cli_framework_1.contains)(integrations_1.INTEGRATION_NAMES, {})],
  27. },
  28. ],
  29. options: [
  30. {
  31. name: 'add',
  32. summary: 'Download and add the integration even if enabled',
  33. type: Boolean,
  34. },
  35. {
  36. name: 'root',
  37. summary: 'Specify an alternative destination to download into when adding',
  38. spec: { value: 'path' },
  39. },
  40. {
  41. name: 'quiet',
  42. summary: 'Less verbose output, ignore integration errors',
  43. type: Boolean,
  44. },
  45. ],
  46. };
  47. }
  48. async run(inputs, options) {
  49. const [name] = inputs;
  50. const { add, quiet } = options;
  51. if (!this.project) {
  52. throw new errors_1.FatalException(`Cannot run ${(0, color_1.input)('ionic integrations enable')} outside a project directory.`);
  53. }
  54. const root = options['root']
  55. ? path.resolve(this.project.rootDirectory, String(options['root']))
  56. : this.project.rootDirectory;
  57. if (!(0, guards_1.isIntegrationName)(name)) {
  58. throw new errors_1.FatalException(`Don't know about ${(0, color_1.input)(name)} integration!`);
  59. }
  60. const integration = await this.project.createIntegration(name);
  61. try {
  62. if (!integration.isAdded() || add) {
  63. await integration.add({
  64. root,
  65. enableArgs: options['--'] ? options['--'] : undefined,
  66. quiet: Boolean(quiet),
  67. });
  68. this.env.log.ok(`Integration ${(0, color_1.input)(integration.name)} added!`);
  69. }
  70. else {
  71. const wasEnabled = integration.config.get('enabled') !== false;
  72. // We still need to run this whenever this command is run to make sure
  73. // everything is good with the integration.
  74. await integration.enable();
  75. if (wasEnabled) {
  76. this.env.log.info(`Integration ${(0, color_1.input)(integration.name)} already enabled.`);
  77. }
  78. else {
  79. this.env.log.ok(`Integration ${(0, color_1.input)(integration.name)} enabled!`);
  80. }
  81. }
  82. }
  83. catch (e) {
  84. if (e instanceof cli_framework_1.BaseError) {
  85. if (quiet) {
  86. this.env.log.error(e.message);
  87. }
  88. else {
  89. throw new errors_1.FatalException(e.message);
  90. }
  91. }
  92. else {
  93. throw e;
  94. }
  95. }
  96. }
  97. }
  98. exports.IntegrationsEnableCommand = IntegrationsEnableCommand;