index.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.BaseIntegration = exports.IntegrationConfig = exports.INTEGRATION_NAMES = 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("../color");
  9. const errors_1 = require("../errors");
  10. var guards_2 = require("../../guards");
  11. Object.defineProperty(exports, "INTEGRATION_NAMES", { enumerable: true, get: function () { return guards_2.INTEGRATION_NAMES; } });
  12. class IntegrationConfig extends cli_framework_1.BaseConfig {
  13. provideDefaults(c) {
  14. return {};
  15. }
  16. }
  17. exports.IntegrationConfig = IntegrationConfig;
  18. class BaseIntegration {
  19. constructor(e) {
  20. this.e = e;
  21. }
  22. static async createFromName(deps, name) {
  23. if ((0, guards_1.isIntegrationName)(name)) {
  24. const { Integration } = await Promise.resolve().then(() => tslib_1.__importStar(require(`./${name}`)));
  25. return new Integration(deps);
  26. }
  27. throw new errors_1.IntegrationNotFoundException(`Bad integration name: ${(0, color_1.strong)(name)}`); // TODO?
  28. }
  29. async getInfo() {
  30. return [];
  31. }
  32. isAdded() {
  33. return !!this.e.project.config.get('integrations')[this.name];
  34. }
  35. isEnabled() {
  36. const integrationConfig = this.e.project.config.get('integrations')[this.name];
  37. return !!integrationConfig && integrationConfig.enabled !== false;
  38. }
  39. async enable(config) {
  40. if (config && config.root) {
  41. this.config.set('root', config.root);
  42. }
  43. this.config.unset('enabled');
  44. }
  45. async disable() {
  46. this.config.set('enabled', false);
  47. }
  48. async personalize(details) {
  49. // optionally overwritten by subclasses
  50. }
  51. async add(details) {
  52. const config = details.root !== this.e.project.directory ?
  53. { root: path.relative(this.e.project.rootDirectory, details.root) } :
  54. undefined;
  55. await this.enable(config);
  56. }
  57. }
  58. exports.BaseIntegration = BaseIntegration;