config.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.parseGlobalOptions = exports.Config = exports.DEFAULT_CONFIG_DIRECTORY = exports.CONFIG_FILE = exports.GLOBAL_OPTIONS = void 0;
  4. const tslib_1 = require("tslib");
  5. const cli_framework_1 = require("@ionic/cli-framework");
  6. const os = tslib_1.__importStar(require("os"));
  7. const path = tslib_1.__importStar(require("path"));
  8. exports.GLOBAL_OPTIONS = [
  9. {
  10. name: 'help',
  11. summary: 'Display help for commands',
  12. aliases: ['h'],
  13. type: Boolean,
  14. groups: ["hidden" /* MetadataGroup.HIDDEN */],
  15. },
  16. {
  17. name: 'verbose',
  18. summary: 'Print debug log messages',
  19. type: Boolean,
  20. },
  21. {
  22. name: 'quiet',
  23. summary: 'Only print warning and error log messages',
  24. type: Boolean,
  25. },
  26. {
  27. name: 'interactive',
  28. summary: 'Disable interactivity such as progress indicators and prompts',
  29. type: Boolean,
  30. default: true,
  31. },
  32. {
  33. name: 'color',
  34. summary: 'Disable colors in stdout',
  35. type: Boolean,
  36. default: true,
  37. },
  38. {
  39. name: 'confirm',
  40. summary: 'Automatically answer YES to confirmation prompts',
  41. type: Boolean,
  42. },
  43. {
  44. name: 'project',
  45. summary: 'The project ID to use in a multi-app configuration setup',
  46. groups: ["hidden" /* MetadataGroup.HIDDEN */],
  47. },
  48. {
  49. name: 'json',
  50. summary: 'Use JSON when operating with stdout, if possible',
  51. type: Boolean,
  52. groups: ["hidden" /* MetadataGroup.HIDDEN */],
  53. },
  54. ];
  55. exports.CONFIG_FILE = 'config.json';
  56. exports.DEFAULT_CONFIG_DIRECTORY = path.resolve(os.homedir(), '.ionic');
  57. class Config extends cli_framework_1.BaseConfig {
  58. constructor(p, options) {
  59. super(p, options);
  60. const c = this.c;
  61. // <4.0.0 config migration
  62. if (c.state) {
  63. // start fresh
  64. this.c = {
  65. 'version': '4.0.0',
  66. 'telemetry': c.telemetry,
  67. 'npmClient': c.npmClient,
  68. 'interactive': c.interactive,
  69. 'user.id': c.user && c.user.id,
  70. 'user.email': c.user && c.user.email,
  71. 'git.setup': c.git && c.git.setup,
  72. 'tokens.user': c.tokens && c.tokens.user,
  73. 'tokens.telemetry': c.tokens && c.tokens.telemetry,
  74. 'features.ssl-commands': c.features && c.features['ssl-commands'],
  75. };
  76. }
  77. }
  78. provideDefaults(config) {
  79. return {
  80. 'version': '4.0.0',
  81. 'telemetry': true,
  82. 'npmClient': 'npm',
  83. };
  84. }
  85. getAPIUrl() {
  86. return this.get('urls.api', 'https://api.ionicjs.com');
  87. }
  88. getDashUrl() {
  89. return this.get('urls.dash', 'https://dashboard.ionicframework.com');
  90. }
  91. getGitHost() {
  92. return this.get('git.host', 'git.ionicjs.com');
  93. }
  94. getGitPort() {
  95. return this.get('git.port', 22);
  96. }
  97. getHTTPConfig() {
  98. const { c } = this;
  99. return {
  100. userAgent: `node/superagent/Ionic CLI ${c.version}`,
  101. ssl: {
  102. cafile: c['ssl.cafile'],
  103. certfile: c['ssl.certfile'],
  104. keyfile: c['ssl.keyfile'],
  105. },
  106. proxy: c['proxy'],
  107. };
  108. }
  109. getOpenIDOAuthConfig() {
  110. return {
  111. authorizationUrl: this.get('oauth.openid.authorization_url', 'https://ionicframework.com/oauth/authorize'),
  112. tokenUrl: this.get('oauth.openid.token_url', 'https://api.ionicjs.com/oauth/token'),
  113. clientId: this.get('oauth.openid.client_id', 'cli'),
  114. apiAudience: this.get('oauth.openid.api_audience', 'https://api.ionicjs.com'),
  115. };
  116. }
  117. }
  118. exports.Config = Config;
  119. function parseGlobalOptions(pargv) {
  120. return (0, cli_framework_1.parseArgs)(pargv, (0, cli_framework_1.metadataOptionsToParseArgsOptions)(exports.GLOBAL_OPTIONS));
  121. }
  122. exports.parseGlobalOptions = parseGlobalOptions;