@mexty/cli 1.0.1 → 1.1.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 (44) hide show
  1. package/README.md +5 -5
  2. package/package.json +4 -2
  3. package/src/commands/create.ts +109 -41
  4. package/src/commands/save.ts +213 -0
  5. package/src/commands/sync.ts +2 -2
  6. package/src/index.ts +98 -84
  7. package/src/utils/api.ts +241 -239
  8. package/src/utils/git.ts +28 -26
  9. package/dist/commands/create.d.ts +0 -7
  10. package/dist/commands/create.d.ts.map +0 -1
  11. package/dist/commands/create.js +0 -80
  12. package/dist/commands/create.js.map +0 -1
  13. package/dist/commands/delete.d.ts +0 -2
  14. package/dist/commands/delete.d.ts.map +0 -1
  15. package/dist/commands/delete.js +0 -54
  16. package/dist/commands/delete.js.map +0 -1
  17. package/dist/commands/fork.d.ts +0 -2
  18. package/dist/commands/fork.d.ts.map +0 -1
  19. package/dist/commands/fork.js +0 -52
  20. package/dist/commands/fork.js.map +0 -1
  21. package/dist/commands/login.d.ts +0 -2
  22. package/dist/commands/login.d.ts.map +0 -1
  23. package/dist/commands/login.js +0 -12
  24. package/dist/commands/login.js.map +0 -1
  25. package/dist/commands/publish.d.ts +0 -2
  26. package/dist/commands/publish.d.ts.map +0 -1
  27. package/dist/commands/publish.js +0 -139
  28. package/dist/commands/publish.js.map +0 -1
  29. package/dist/commands/sync.d.ts +0 -2
  30. package/dist/commands/sync.d.ts.map +0 -1
  31. package/dist/commands/sync.js +0 -140
  32. package/dist/commands/sync.js.map +0 -1
  33. package/dist/index.d.ts +0 -3
  34. package/dist/index.d.ts.map +0 -1
  35. package/dist/index.js +0 -60
  36. package/dist/index.js.map +0 -1
  37. package/dist/utils/api.d.ts +0 -55
  38. package/dist/utils/api.d.ts.map +0 -1
  39. package/dist/utils/api.js +0 -68
  40. package/dist/utils/api.js.map +0 -1
  41. package/dist/utils/git.d.ts +0 -41
  42. package/dist/utils/git.d.ts.map +0 -1
  43. package/dist/utils/git.js +0 -171
  44. package/dist/utils/git.js.map +0 -1
package/README.md CHANGED
@@ -30,7 +30,7 @@ npm install -g mexty
30
30
 
31
31
  - Node.js 16+ installed
32
32
  - Git installed and configured
33
- - MEXT server running (default: http://localhost:3001)
33
+ - MEXT server running (default: https://api.v2.mext.app)
34
34
  - GitHub access for repository operations
35
35
 
36
36
  ## Commands
@@ -193,7 +193,7 @@ After publishing or syncing, you can use components with full type safety:
193
193
 
194
194
  ```tsx
195
195
  // Full TypeScript support with IntelliSense
196
- import { MyAmazingBlock } from 'mextblock';
196
+ import { MyAmazingBlock } from '@mexty/block';
197
197
 
198
198
  // Props are fully typed - you get autocompletion and error checking
199
199
  <MyAmazingBlock
@@ -252,7 +252,7 @@ mexty publish # Automatically parses props and syncs registry locally
252
252
  mexty sync
253
253
 
254
254
  # Then use in your React app with full TypeScript support
255
- import { TeamComponent } from 'mextblock';
255
+ import { TeamComponent } from '@mexty/block';
256
256
 
257
257
  <TeamComponent
258
258
  props={{
@@ -307,7 +307,7 @@ Gets converted to JSON schema automatically for runtime validation and type gene
307
307
  For advanced use cases, you can create strongly typed components:
308
308
 
309
309
  ```tsx
310
- import { createTypedBlock } from 'mextblock';
310
+ import { createTypedBlock } from '@mexty/block';
311
311
 
312
312
  interface GameProps {
313
313
  level: number;
@@ -333,7 +333,7 @@ const TypedGame = createTypedBlock<GameProps>('VirtualGame', {
333
333
 
334
334
  The CLI uses the following default settings:
335
335
 
336
- - **Server URL**: http://localhost:3001
336
+ - **Server URL**: https://api.v2.mext.app
337
337
  - **Timeout**: 30 seconds for API requests
338
338
  - **Props Parsing**: Automatic on publish/push
339
339
  - **Type Generation**: Automatic on sync
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mexty/cli",
3
- "version": "1.0.1",
3
+ "version": "1.1.0",
4
4
  "description": "MEXT CLI for managing blocks and repositories",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -12,9 +12,11 @@
12
12
  "start": "node dist/index.js"
13
13
  },
14
14
  "dependencies": {
15
- "commander": "^11.1.0",
15
+ "@types/inquirer": "^9.0.8",
16
16
  "axios": "^1.6.0",
17
17
  "chalk": "^4.1.2",
18
+ "commander": "^11.1.0",
19
+ "inquirer": "^12.6.3",
18
20
  "simple-git": "^3.20.0"
19
21
  },
20
22
  "devDependencies": {
@@ -1,97 +1,165 @@
1
- import chalk from 'chalk';
2
- import path from 'path';
3
- import { apiClient, CreateBlockRequest } from '../utils/api';
4
- import { GitManager } from '../utils/git';
5
- import { createInterface } from 'readline';
6
- import { requireAuthentication, getAuthenticatedUser } from '../utils/auth';
1
+ import chalk from "chalk";
2
+ import path from "path";
3
+ import { apiClient, CreateBlockRequest } from "../utils/api";
4
+ import { GitManager } from "../utils/git";
5
+ import { createInterface } from "readline";
6
+ import { requireAuthentication, getAuthenticatedUser } from "../utils/auth";
7
7
 
8
8
  interface CreateOptions {
9
9
  description?: string;
10
10
  type?: string;
11
+ name?: string;
12
+ category?: string;
11
13
  }
12
14
 
13
15
  // Simple prompt function to replace inquirer
14
- async function prompt(question: string, defaultValue?: string): Promise<string> {
16
+ async function prompt(
17
+ question: string,
18
+ defaultValue?: string
19
+ ): Promise<string> {
15
20
  return new Promise((resolve) => {
16
21
  const rl = createInterface({
17
22
  input: process.stdin,
18
- output: process.stdout
23
+ output: process.stdout,
19
24
  });
20
25
 
21
- const promptText = defaultValue ? `${question} (${defaultValue}): ` : `${question}: `;
22
-
26
+ const promptText = defaultValue
27
+ ? `${question} (${defaultValue}): `
28
+ : `${question}: `;
29
+
23
30
  rl.question(promptText, (answer) => {
24
31
  rl.close();
25
- resolve(answer.trim() || defaultValue || '');
32
+ resolve(answer.trim() || defaultValue || "");
26
33
  });
27
34
  });
28
35
  }
29
36
 
30
- export async function createCommand(name: string, options: CreateOptions): Promise<void> {
37
+ export async function createCommand(
38
+ subcommand?: string,
39
+ options: CreateOptions = {}
40
+ ): Promise<void> {
31
41
  try {
32
42
  // Check authentication first
33
43
  requireAuthentication();
34
-
44
+
35
45
  const user = getAuthenticatedUser();
36
- console.log(chalk.blue(`šŸš€ Creating new block: ${name}`));
37
- console.log(chalk.gray(` User: ${user?.fullName || user?.email || 'Unknown'}`));
38
46
 
39
- // Get description if not provided
40
- let description = options.description;
41
- if (!description) {
42
- description = await prompt('Enter a description for the block', `Custom block: ${name}`);
47
+ // Handle both old and new syntax
48
+ let blockName: string;
49
+ let blockDescription: string;
50
+ let blockType: string;
51
+
52
+ if (subcommand === "block") {
53
+ // New syntax: mexty create block --name "..." --description "..." --category "..."
54
+ if (!options.name) {
55
+ console.error(
56
+ chalk.red('āŒ --name is required when using "mexty create block"')
57
+ );
58
+ console.log(
59
+ chalk.yellow(
60
+ ' Usage: mexty create block --name "Block Name" --description "Description" --category "category"'
61
+ )
62
+ );
63
+ process.exit(1);
64
+ }
65
+
66
+ blockName = options.name;
67
+ blockDescription = options.description || `Custom block: ${blockName}`;
68
+ blockType = options.category || options.type || "custom";
69
+ } else {
70
+ // Old syntax: mexty create "Block Name" --description "..." --type "..."
71
+ if (!subcommand) {
72
+ console.error(chalk.red("āŒ Block name is required"));
73
+ console.log(
74
+ chalk.yellow(' Usage: mexty create "Block Name" [options]')
75
+ );
76
+ console.log(
77
+ chalk.yellow(
78
+ ' Or: mexty create block --name "Block Name" [options]'
79
+ )
80
+ );
81
+ process.exit(1);
82
+ }
83
+
84
+ blockName = subcommand;
85
+ blockDescription = options.description || `Custom block: ${blockName}`;
86
+ blockType = options.type || "custom";
43
87
  }
44
88
 
89
+ console.log(chalk.blue(`šŸš€ Creating new block: ${blockName}`));
90
+ console.log(
91
+ chalk.gray(` User: ${user?.fullName || user?.email || "Unknown"}`)
92
+ );
93
+ console.log(chalk.gray(` Category: ${blockType}`));
94
+
45
95
  // Prepare block data
46
96
  const blockData: CreateBlockRequest = {
47
- blockType: options.type || 'custom',
48
- title: name,
49
- description: description,
50
- allowedBrickTypes: ['text', 'image', 'video', 'code', 'quiz'], // Default allowed types
51
- scope: ['user-store'], // Default scope for CLI-created blocks
52
- content: []
97
+ blockType: blockType,
98
+ title: blockName,
99
+ description: blockDescription,
100
+ allowedBrickTypes: ["text", "image", "video", "code", "quiz"], // Default allowed types
101
+ scope: ["user-store"], // Default scope for CLI-created blocks
102
+ content: [],
53
103
  };
54
104
 
55
- console.log(chalk.yellow('šŸ“” Creating block on server...'));
56
-
105
+ console.log(chalk.yellow("šŸ“” Creating block on server..."));
106
+
57
107
  // Create the block
58
108
  const block = await apiClient.createBlock(blockData);
59
-
109
+
60
110
  console.log(chalk.green(`āœ… Block created successfully!`));
61
111
  console.log(chalk.gray(` Block ID: ${block._id}`));
62
112
  console.log(chalk.gray(` Block Type: ${block.blockType}`));
63
-
113
+
64
114
  if (block.gitUrl) {
65
115
  console.log(chalk.gray(` GitHub URL: ${block.gitUrl}`));
66
-
116
+
67
117
  // Clone the repository
68
118
  const repoName = GitManager.extractRepoName(block.gitUrl);
69
119
  const targetDir = path.join(process.cwd(), repoName);
70
-
120
+
71
121
  console.log(chalk.yellow(`šŸ“¦ Cloning repository to ./${repoName}...`));
72
-
122
+
73
123
  try {
74
124
  const gitManager = new GitManager();
75
125
  await gitManager.cloneRepository(block.gitUrl, targetDir);
76
-
77
- console.log(chalk.green(`šŸŽ‰ Block created and repository cloned successfully!`));
126
+
127
+ console.log(
128
+ chalk.green(`šŸŽ‰ Block created and repository cloned successfully!`)
129
+ );
78
130
  console.log(chalk.blue(`\nNext steps:`));
79
131
  console.log(chalk.gray(` 1. cd ${repoName}`));
80
132
  console.log(chalk.gray(` 2. Make your changes`));
81
- console.log(chalk.gray(` 3. git add . && git commit -m "Your changes"`));
82
- console.log(chalk.gray(` 4. mexty publish`));
83
-
133
+ console.log(chalk.gray(` 3. mexty save`));
134
+
135
+ // Change to the cloned directory
136
+ try {
137
+ process.chdir(targetDir);
138
+ console.log(chalk.green(`šŸ“ Changed to directory: ${repoName}`));
139
+ } catch (chdirError: any) {
140
+ console.warn(
141
+ chalk.yellow(
142
+ `āš ļø Could not change to directory: ${chdirError.message}`
143
+ )
144
+ );
145
+ console.log(chalk.gray(` Please manually run: cd ${repoName}`));
146
+ }
84
147
  } catch (cloneError: any) {
85
- console.error(chalk.red(`āŒ Failed to clone repository: ${cloneError.message}`));
148
+ console.error(
149
+ chalk.red(`āŒ Failed to clone repository: ${cloneError.message}`)
150
+ );
86
151
  console.log(chalk.yellow(`You can manually clone it later:`));
87
152
  console.log(chalk.gray(` git clone ${block.gitUrl}`));
88
153
  }
89
154
  } else {
90
- console.log(chalk.yellow('āš ļø No GitHub repository was created (GitHub not configured)'));
155
+ console.log(
156
+ chalk.yellow(
157
+ "āš ļø No GitHub repository was created (GitHub not configured)"
158
+ )
159
+ );
91
160
  }
92
-
93
161
  } catch (error: any) {
94
162
  console.error(chalk.red(`āŒ Failed to create block: ${error.message}`));
95
163
  process.exit(1);
96
164
  }
97
- }
165
+ }
@@ -0,0 +1,213 @@
1
+ import chalk from "chalk";
2
+ import fs from "fs";
3
+ import path from "path";
4
+ import { apiClient } from "../utils/api";
5
+ import { GitManager } from "../utils/git";
6
+ import { createInterface } from "readline";
7
+ import { requireAuthentication, getAuthenticatedUser } from "../utils/auth";
8
+
9
+ // Simple prompt function
10
+ async function prompt(
11
+ question: string,
12
+ defaultValue?: string
13
+ ): Promise<string> {
14
+ return new Promise((resolve) => {
15
+ const rl = createInterface({
16
+ input: process.stdin,
17
+ output: process.stdout,
18
+ });
19
+
20
+ const promptText = defaultValue
21
+ ? `${question} (${defaultValue}): `
22
+ : `${question}: `;
23
+
24
+ rl.question(promptText, (answer) => {
25
+ rl.close();
26
+ resolve(answer.trim() || defaultValue || "");
27
+ });
28
+ });
29
+ }
30
+
31
+ // Extract block ID from package.json or git URL
32
+ async function findBlockId(): Promise<string | null> {
33
+ const packageJsonPath = path.join(process.cwd(), "package.json");
34
+
35
+ if (fs.existsSync(packageJsonPath)) {
36
+ try {
37
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
38
+
39
+ // Look for block ID in package.json name or description
40
+ if (packageJson.name && packageJson.name.startsWith("block-")) {
41
+ return packageJson.name.replace("block-", "");
42
+ }
43
+
44
+ // Look in description for block ID pattern
45
+ if (packageJson.description) {
46
+ const match = packageJson.description.match(
47
+ /block[:\s]+([a-f0-9]{24})/i
48
+ );
49
+ if (match) {
50
+ return match[1];
51
+ }
52
+ }
53
+ } catch (error) {
54
+ console.warn(chalk.yellow("āš ļø Could not parse package.json"));
55
+ }
56
+ }
57
+
58
+ // Try to extract from git remote URL
59
+ try {
60
+ const gitManager = new GitManager();
61
+ const remoteUrl = await gitManager.getRemoteUrl();
62
+
63
+ if (remoteUrl) {
64
+ const match = remoteUrl.match(/block-([a-f0-9]{24})/);
65
+ if (match) {
66
+ return match[1];
67
+ }
68
+ }
69
+ } catch (error) {
70
+ // Ignore git errors
71
+ }
72
+
73
+ return null;
74
+ }
75
+
76
+ export async function saveCommand(): Promise<void> {
77
+ try {
78
+ // Check authentication first
79
+ requireAuthentication();
80
+
81
+ const user = getAuthenticatedUser();
82
+ console.log(chalk.blue("šŸ’¾ Saving and publishing block..."));
83
+ console.log(
84
+ chalk.gray(` User: ${user?.fullName || user?.email || "Unknown"}`)
85
+ );
86
+
87
+ // Check if we're in a git repository
88
+ const gitManager = new GitManager();
89
+ const isGitRepo = await gitManager.isGitRepository();
90
+
91
+ if (!isGitRepo) {
92
+ console.error(
93
+ chalk.red(
94
+ "āŒ Not a git repository. Please run this command from a block repository."
95
+ )
96
+ );
97
+ process.exit(1);
98
+ }
99
+
100
+ // Get repository information
101
+ const repoInfo = await gitManager.getRepositoryInfo();
102
+ console.log(chalk.gray(` Current branch: ${repoInfo.branch}`));
103
+ console.log(chalk.gray(` Remote URL: ${repoInfo.remoteUrl}`));
104
+
105
+ // Find block ID
106
+ const blockId = await findBlockId();
107
+ if (!blockId) {
108
+ console.error(
109
+ chalk.red("āŒ Could not determine block ID from repository.")
110
+ );
111
+ console.error(
112
+ chalk.yellow(
113
+ " Make sure you are in a block repository created with mexty"
114
+ )
115
+ );
116
+ process.exit(1);
117
+ }
118
+
119
+ console.log(chalk.gray(` Block ID: ${blockId}`));
120
+
121
+ // Check if there are changes to commit
122
+ if (repoInfo.hasChanges) {
123
+ console.log(
124
+ chalk.yellow("šŸ“ Found uncommitted changes, preparing to commit...")
125
+ );
126
+
127
+ // Get commit message from user
128
+ const commitMessage = await prompt(
129
+ "Enter commit message",
130
+ "Update block content"
131
+ );
132
+
133
+ if (!commitMessage.trim()) {
134
+ console.error(chalk.red("āŒ Commit message cannot be empty"));
135
+ process.exit(1);
136
+ }
137
+
138
+ // Stage all changes
139
+ console.log(chalk.yellow("šŸ“‹ Staging changes (git add .)..."));
140
+ try {
141
+ await gitManager.git.add(".");
142
+ console.log(chalk.green("āœ… Changes staged successfully"));
143
+ } catch (addError: any) {
144
+ console.error(
145
+ chalk.red(`āŒ Failed to stage changes: ${addError.message}`)
146
+ );
147
+ process.exit(1);
148
+ }
149
+
150
+ // Commit changes
151
+ console.log(chalk.yellow(`šŸ’¬ Committing changes: "${commitMessage}"...`));
152
+ try {
153
+ await gitManager.git.commit(commitMessage);
154
+ console.log(chalk.green("āœ… Changes committed successfully"));
155
+ } catch (commitError: any) {
156
+ console.error(
157
+ chalk.red(`āŒ Failed to commit changes: ${commitError.message}`)
158
+ );
159
+ process.exit(1);
160
+ }
161
+ } else {
162
+ console.log(chalk.green("āœ… No uncommitted changes found"));
163
+ }
164
+
165
+ // Push changes to remote
166
+ console.log(
167
+ chalk.yellow(`šŸ“¤ Pushing changes to remote (${repoInfo.branch})...`)
168
+ );
169
+ try {
170
+ await gitManager.pushToRemote();
171
+ console.log(chalk.green("āœ… Changes pushed successfully"));
172
+ } catch (pushError: any) {
173
+ console.error(
174
+ chalk.red(`āŒ Failed to push changes: ${pushError.message}`)
175
+ );
176
+ console.log(
177
+ chalk.yellow(
178
+ " Please check your network connection and GitHub permissions"
179
+ )
180
+ );
181
+ process.exit(1);
182
+ }
183
+
184
+ // Trigger save and bundle
185
+ console.log(chalk.yellow("šŸ—ļø Triggering build and bundle process..."));
186
+
187
+ try {
188
+ const result = await apiClient.saveAndBundle({ blockId });
189
+
190
+ console.log(chalk.green("šŸŽ‰ Block saved and published successfully!"));
191
+ console.log(chalk.gray(` Bundle Path: ${result.bundlePath}`));
192
+ console.log(chalk.gray(` Federation URL: ${result.federationUrl}`));
193
+
194
+ if (result.message) {
195
+ console.log(chalk.blue(` ${result.message}`));
196
+ }
197
+
198
+ console.log(
199
+ chalk.blue("\nšŸ“‹ Your block is now building in the background.")
200
+ );
201
+ console.log(
202
+ chalk.gray(" You can check the build status in the web interface.")
203
+ );
204
+ } catch (buildError: any) {
205
+ console.error(chalk.red(`āŒ Build failed: ${buildError.message}`));
206
+ console.log(chalk.yellow(" Check the server logs for more details."));
207
+ process.exit(1);
208
+ }
209
+ } catch (error: any) {
210
+ console.error(chalk.red(`āŒ Failed to save block: ${error.message}`));
211
+ process.exit(1);
212
+ }
213
+ }
@@ -30,7 +30,7 @@ export async function syncCommand(): Promise<void> {
30
30
 
31
31
  // Fetch registry from server
32
32
  console.log(chalk.yellow('šŸ“” Fetching registry from server...'));
33
- const response = await fetch('http://localhost:3001/api/blocks/registry');
33
+ const response = await fetch('https://api.v2.mext.app/api/blocks/registry');
34
34
 
35
35
  if (!response.ok) {
36
36
  throw new Error(`Server responded with ${response.status}: ${response.statusText}`);
@@ -114,7 +114,7 @@ function findMextBlockPath(): string | null {
114
114
  if (fs.existsSync(path.join(possiblePath, 'package.json'))) {
115
115
  try {
116
116
  const packageJson = JSON.parse(fs.readFileSync(path.join(possiblePath, 'package.json'), 'utf8'));
117
- if (packageJson.name === '@mexty/block' || packageJson.name === 'mextblock') {
117
+ if (packageJson.name === '@mexty/block' || packageJson.name === '@mexty/block') {
118
118
  return possiblePath;
119
119
  }
120
120
  } catch (error) {