@mexty/cli 1.6.0 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/GITHUB_OAUTH_SETUP.md +247 -0
  2. package/dist/commands/create.d.ts +9 -0
  3. package/dist/commands/create.d.ts.map +1 -0
  4. package/dist/commands/create.js +130 -0
  5. package/dist/commands/create.js.map +1 -0
  6. package/dist/commands/delete.d.ts +2 -0
  7. package/dist/commands/delete.d.ts.map +1 -0
  8. package/dist/commands/delete.js +59 -0
  9. package/dist/commands/delete.js.map +1 -0
  10. package/dist/commands/github-disconnect.d.ts +2 -0
  11. package/dist/commands/github-disconnect.d.ts.map +1 -0
  12. package/dist/commands/github-disconnect.js +73 -0
  13. package/dist/commands/github-disconnect.js.map +1 -0
  14. package/dist/commands/github-login.d.ts +2 -0
  15. package/dist/commands/github-login.d.ts.map +1 -0
  16. package/dist/commands/github-login.js +100 -0
  17. package/dist/commands/github-login.js.map +1 -0
  18. package/dist/commands/login.d.ts +2 -0
  19. package/dist/commands/login.d.ts.map +1 -0
  20. package/dist/commands/login.js +90 -0
  21. package/dist/commands/login.js.map +1 -0
  22. package/dist/commands/publish.d.ts +6 -0
  23. package/dist/commands/publish.d.ts.map +1 -0
  24. package/dist/commands/publish.js +176 -0
  25. package/dist/commands/publish.js.map +1 -0
  26. package/dist/commands/save.d.ts +2 -0
  27. package/dist/commands/save.d.ts.map +1 -0
  28. package/dist/commands/save.js +162 -0
  29. package/dist/commands/save.js.map +1 -0
  30. package/dist/commands/update-git-url.d.ts +2 -0
  31. package/dist/commands/update-git-url.d.ts.map +1 -0
  32. package/dist/commands/update-git-url.js +153 -0
  33. package/dist/commands/update-git-url.js.map +1 -0
  34. package/dist/index.d.ts +3 -0
  35. package/dist/index.d.ts.map +1 -0
  36. package/dist/index.js +119 -0
  37. package/dist/index.js.map +1 -0
  38. package/dist/utils/api.d.ts +117 -0
  39. package/dist/utils/api.d.ts.map +1 -0
  40. package/dist/utils/api.js +202 -0
  41. package/dist/utils/api.js.map +1 -0
  42. package/dist/utils/auth.d.ts +4 -0
  43. package/dist/utils/auth.d.ts.map +1 -0
  44. package/dist/utils/auth.js +27 -0
  45. package/dist/utils/auth.js.map +1 -0
  46. package/dist/utils/git.d.ts +47 -0
  47. package/dist/utils/git.d.ts.map +1 -0
  48. package/dist/utils/git.js +224 -0
  49. package/dist/utils/git.js.map +1 -0
  50. package/package.json +2 -1
  51. package/src/commands/github-disconnect.ts +80 -0
  52. package/src/commands/github-login.ts +107 -0
  53. package/src/index.ts +37 -0
  54. package/src/utils/api.ts +21 -0
  55. package/src/utils/git.ts +60 -2
package/src/utils/git.ts CHANGED
@@ -2,6 +2,7 @@ import simpleGit, { SimpleGit } from "simple-git";
2
2
  import path from "path";
3
3
  import fs from "fs";
4
4
  import chalk from "chalk";
5
+ import { apiClient } from "./api";
5
6
 
6
7
  // Simple spinner implementation since ora v5 has import issues
7
8
  class SimpleSpinner {
@@ -14,6 +15,11 @@ class SimpleSpinner {
14
15
  this.message = message;
15
16
  }
16
17
 
18
+ // Add setter for message text
19
+ set text(newMessage: string) {
20
+ this.message = newMessage;
21
+ }
22
+
17
23
  start(): this {
18
24
  process.stdout.write(this.message);
19
25
  this.interval = setInterval(() => {
@@ -57,6 +63,7 @@ export class GitManager {
57
63
 
58
64
  /**
59
65
  * Clone a repository to a local directory
66
+ * Supports private repositories if GitHub is connected
60
67
  */
61
68
  async cloneRepository(repoUrl: string, targetDir: string): Promise<void> {
62
69
  const spinner = ora(`Cloning repository from ${repoUrl}...`).start();
@@ -68,16 +75,67 @@ export class GitManager {
68
75
  throw new Error(`Directory ${targetDir} already exists`);
69
76
  }
70
77
 
78
+ // Check if this is a GitHub URL that might need authentication
79
+ const isGitHub = repoUrl.includes('github.com');
80
+ let authenticatedUrl = repoUrl;
81
+
82
+ if (isGitHub) {
83
+ try {
84
+ // Try to get GitHub token for private repo access
85
+ const tokenData = await apiClient.getGitHubToken();
86
+
87
+ if (tokenData.success && tokenData.token) {
88
+ // Inject token into URL for authenticated cloning
89
+ authenticatedUrl = this.injectTokenIntoUrl(repoUrl, tokenData.token);
90
+ spinner.text = `Cloning repository (authenticated)...`;
91
+ }
92
+ } catch (error: any) {
93
+ // If token retrieval fails (e.g., not connected), try without auth
94
+ // This is fine for public repositories
95
+ if (error.response?.status === 404) {
96
+ spinner.text = `Cloning repository (public)...`;
97
+ }
98
+ }
99
+ }
100
+
71
101
  // Clone the repository
72
- await this.git.clone(repoUrl, targetDir);
102
+ await this.git.clone(authenticatedUrl, targetDir);
73
103
 
74
104
  spinner.succeed(chalk.green(`Repository cloned to ${targetDir}`));
75
105
  } catch (error: any) {
76
- spinner.fail(chalk.red(`Failed to clone repository: ${error.message}`));
106
+ // Check if error is due to authentication
107
+ if (error.message.includes('Authentication failed') ||
108
+ error.message.includes('could not read Username') ||
109
+ error.message.includes('Repository not found')) {
110
+ spinner.fail(chalk.red(`Failed to clone repository: Authentication required`));
111
+ console.log(chalk.yellow('\nšŸ’” This might be a private repository.'));
112
+ console.log(chalk.blue(' Connect your GitHub account: mexty github-login\n'));
113
+ } else {
114
+ spinner.fail(chalk.red(`Failed to clone repository: ${error.message}`));
115
+ }
77
116
  throw error;
78
117
  }
79
118
  }
80
119
 
120
+ /**
121
+ * Inject GitHub token into repository URL for authenticated access
122
+ */
123
+ private injectTokenIntoUrl(repoUrl: string, token: string): string {
124
+ // Handle HTTPS URLs
125
+ if (repoUrl.startsWith('https://github.com/')) {
126
+ return repoUrl.replace('https://github.com/', `https://${token}@github.com/`);
127
+ }
128
+
129
+ // Handle SSH URLs (convert to HTTPS with token)
130
+ if (repoUrl.startsWith('git@github.com:')) {
131
+ const path = repoUrl.replace('git@github.com:', '');
132
+ return `https://${token}@github.com/${path}`;
133
+ }
134
+
135
+ // Return original URL if format not recognized
136
+ return repoUrl;
137
+ }
138
+
81
139
  /**
82
140
  * Check if current directory is a Git repository
83
141
  */