remote.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. "use strict";
  2. var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
  3. if (k2 === undefined) k2 = k;
  4. var desc = Object.getOwnPropertyDescriptor(m, k);
  5. if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
  6. desc = { enumerable: true, get: function() { return m[k]; } };
  7. }
  8. Object.defineProperty(o, k2, desc);
  9. }) : (function(o, m, k, k2) {
  10. if (k2 === undefined) k2 = k;
  11. o[k2] = m[k];
  12. }));
  13. var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
  14. Object.defineProperty(o, "default", { enumerable: true, value: v });
  15. }) : function(o, v) {
  16. o["default"] = v;
  17. });
  18. var __importStar = (this && this.__importStar) || function (mod) {
  19. if (mod && mod.__esModule) return mod;
  20. var result = {};
  21. if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
  22. __setModuleDefault(result, mod);
  23. return result;
  24. };
  25. Object.defineProperty(exports, "__esModule", { value: true });
  26. exports.GitRemoteCommand = void 0;
  27. const color_1 = require("../../lib/color");
  28. const command_1 = require("../../lib/command");
  29. const errors_1 = require("../../lib/errors");
  30. class GitRemoteCommand extends command_1.Command {
  31. async getMetadata() {
  32. const dashUrl = this.env.config.getDashUrl();
  33. return {
  34. name: 'remote',
  35. type: 'project',
  36. groups: ["paid" /* MetadataGroup.PAID */],
  37. summary: 'Adds/updates the Appflow git remote to your local Ionic app',
  38. description: `
  39. This command is used by ${(0, color_1.input)('ionic link')} when Appflow is used as the git host.
  40. ${(0, color_1.input)('ionic git remote')} will check the local repository for whether or not the git remote is properly set up. This command operates on the ${(0, color_1.strong)('ionic')} remote. For advanced configuration, see ${(0, color_1.strong)('Settings')} => ${(0, color_1.strong)('Git')} in the app settings of the Dashboard[^dashboard].
  41. `,
  42. footnotes: [
  43. {
  44. id: 'dashboard',
  45. url: dashUrl,
  46. },
  47. ],
  48. };
  49. }
  50. async run(inputs, options) {
  51. const { AppClient } = await Promise.resolve().then(() => __importStar(require('../../lib/app')));
  52. const { addIonicRemote, getIonicRemote, initializeRepo, isRepoInitialized, setIonicRemote } = await Promise.resolve().then(() => __importStar(require('../../lib/git')));
  53. if (!this.project) {
  54. throw new errors_1.FatalException(`Cannot run ${(0, color_1.input)('ionic git remote')} outside a project directory.`);
  55. }
  56. const token = await this.env.session.getUserToken();
  57. const id = await this.project.requireAppflowId();
  58. const appClient = new AppClient(token, this.env);
  59. const app = await appClient.load(id);
  60. if (!app.repo_url) {
  61. throw new errors_1.FatalException(`Missing ${(0, color_1.strong)('repo_url')} property in app.`);
  62. }
  63. if (!(await isRepoInitialized(this.project.directory))) {
  64. await initializeRepo({ shell: this.env.shell }, this.project.directory);
  65. this.env.log.warn(`Initializing a git repository for your project.\n` +
  66. `Before your first ${(0, color_1.input)('git push ionic master')}, you'll want to commit all the files in your project:\n\n` +
  67. `${(0, color_1.input)('git commit -a -m "Initial commit"')}\n`);
  68. }
  69. const remote = app.repo_url;
  70. const found = await getIonicRemote({ shell: this.env.shell }, this.project.directory);
  71. if (found) {
  72. if (remote === found) {
  73. this.env.log.msg(`Existing remote ${(0, color_1.strong)('ionic')} found.`);
  74. }
  75. else {
  76. await setIonicRemote({ shell: this.env.shell }, this.project.directory, remote);
  77. this.env.log.ok(`Updated remote ${(0, color_1.strong)('ionic')}.`);
  78. }
  79. }
  80. else {
  81. await addIonicRemote({ shell: this.env.shell }, this.project.directory, remote);
  82. this.env.log.ok(`Added remote ${(0, color_1.strong)('ionic')}.`);
  83. }
  84. }
  85. }
  86. exports.GitRemoteCommand = GitRemoteCommand;