@mexty/cli 1.2.0 → 1.4.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 (52) hide show
  1. package/BLOCKS_OVERVIEW.md +229 -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 +120 -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/fork.d.ts +2 -0
  11. package/dist/commands/fork.d.ts.map +1 -0
  12. package/dist/commands/fork.js +57 -0
  13. package/dist/commands/fork.js.map +1 -0
  14. package/dist/commands/login.d.ts +2 -0
  15. package/dist/commands/login.d.ts.map +1 -0
  16. package/dist/commands/login.js +90 -0
  17. package/dist/commands/login.js.map +1 -0
  18. package/dist/commands/publish.d.ts +6 -0
  19. package/dist/commands/publish.d.ts.map +1 -0
  20. package/dist/commands/publish.js +173 -0
  21. package/dist/commands/publish.js.map +1 -0
  22. package/dist/commands/save.d.ts +2 -0
  23. package/dist/commands/save.d.ts.map +1 -0
  24. package/dist/commands/save.js +162 -0
  25. package/dist/commands/save.js.map +1 -0
  26. package/dist/commands/sync.d.ts +2 -0
  27. package/dist/commands/sync.d.ts.map +1 -0
  28. package/dist/commands/sync.js +250 -0
  29. package/dist/commands/sync.js.map +1 -0
  30. package/dist/index.d.ts +3 -0
  31. package/dist/index.d.ts.map +1 -0
  32. package/dist/index.js +76 -0
  33. package/dist/index.js.map +1 -0
  34. package/dist/utils/api.d.ts +92 -0
  35. package/dist/utils/api.d.ts.map +1 -0
  36. package/dist/utils/api.js +169 -0
  37. package/dist/utils/api.js.map +1 -0
  38. package/dist/utils/auth.d.ts +4 -0
  39. package/dist/utils/auth.d.ts.map +1 -0
  40. package/dist/utils/auth.js +27 -0
  41. package/dist/utils/auth.js.map +1 -0
  42. package/dist/utils/git.d.ts +42 -0
  43. package/dist/utils/git.d.ts.map +1 -0
  44. package/dist/utils/git.js +171 -0
  45. package/dist/utils/git.js.map +1 -0
  46. package/package.json +1 -1
  47. package/src/commands/create.ts +11 -7
  48. package/src/commands/publish.ts +146 -55
  49. package/src/index.ts +2 -13
  50. package/src/utils/api.ts +27 -0
  51. package/src/commands/fork.ts +0 -58
  52. package/src/commands/sync.ts +0 -350
@@ -1,350 +0,0 @@
1
- import chalk from "chalk";
2
- import fs from "fs";
3
- import path from "path";
4
- import { apiClient } from "../utils/api";
5
-
6
- interface BlockRegistryEntry {
7
- blockId: string;
8
- componentName: string;
9
- author?: string; // Username of the author
10
- title: string;
11
- description: string;
12
- version?: string;
13
- tags?: string[];
14
- lastUpdated: string;
15
- }
16
-
17
- interface BlockRegistry {
18
- [componentName: string]: BlockRegistryEntry;
19
- }
20
-
21
- interface AuthorNamespaceRegistry {
22
- [author: string]: {
23
- [componentName: string]: BlockRegistryEntry;
24
- };
25
- }
26
-
27
- export async function syncCommand(): Promise<void> {
28
- try {
29
- console.log(chalk.blue("🔄 Syncing block registry..."));
30
-
31
- // Fetch registry from server
32
- console.log(chalk.yellow("📡 Fetching registry from server..."));
33
- const response = await fetch("https://api.mexty.ai/api/blocks/registry");
34
-
35
- if (!response.ok) {
36
- throw new Error(
37
- `Server responded with ${response.status}: ${response.statusText}`
38
- );
39
- }
40
-
41
- const data = await response.json();
42
- const registry: BlockRegistry = data.registry;
43
- const authorRegistry: AuthorNamespaceRegistry = data.authorRegistry;
44
- const meta = data.meta;
45
-
46
- console.log(chalk.green(`✅ Registry fetched successfully!`));
47
- console.log(chalk.gray(` Total blocks: ${meta.totalBlocks}`));
48
- console.log(chalk.gray(` Total components: ${meta.totalComponents}`));
49
- console.log(chalk.gray(` Total authors: ${meta.totalAuthors || 0}`));
50
- console.log(chalk.gray(` Last updated: ${meta.lastUpdated}`));
51
-
52
- if (Object.keys(registry).length === 0) {
53
- console.log(chalk.yellow("⚠️ No components found in registry."));
54
- console.log(
55
- chalk.gray(
56
- ' Make sure you have built some blocks first using "mexty publish"'
57
- )
58
- );
59
- return;
60
- }
61
-
62
- // Display available components
63
- console.log(chalk.blue("\n📋 Available components (global namespace):"));
64
- for (const [componentName, entry] of Object.entries(registry)) {
65
- console.log(
66
- chalk.green(
67
- ` ${componentName}${
68
- entry.author ? chalk.gray(` (by ${entry.author})`) : ""
69
- }`
70
- )
71
- );
72
- console.log(chalk.gray(` Block ID: ${entry.blockId}`));
73
- console.log(chalk.gray(` Title: ${entry.title}`));
74
- console.log(
75
- chalk.gray(
76
- ` Description: ${entry.description.substring(0, 60)}${
77
- entry.description.length > 60 ? "..." : ""
78
- }`
79
- )
80
- );
81
- console.log(
82
- chalk.gray(` Tags: ${entry.tags?.join(", ") || "none"}`)
83
- );
84
- console.log("");
85
- }
86
-
87
- // Display author namespaces
88
- if (Object.keys(authorRegistry).length > 0) {
89
- console.log(chalk.blue("\n👤 Author namespaces:"));
90
- for (const [author, components] of Object.entries(authorRegistry)) {
91
- console.log(chalk.cyan(` @${author}:`));
92
- for (const [componentName, entry] of Object.entries(components)) {
93
- console.log(chalk.green(` ${componentName}`));
94
- console.log(chalk.gray(` Block ID: ${entry.blockId}`));
95
- console.log(chalk.gray(` Title: ${entry.title}`));
96
- }
97
- console.log("");
98
- }
99
- }
100
-
101
- // Generate named exports file and author entry files
102
- const mextBlockPath = findMextBlockPath();
103
- if (mextBlockPath) {
104
- console.log(chalk.blue("🔧 Updating mext-block exports..."));
105
- await generateNamedExports(mextBlockPath, registry, authorRegistry);
106
- await generateAuthorEntryFiles(mextBlockPath, authorRegistry);
107
- console.log(chalk.green(`✅ Exports updated in ${mextBlockPath}`));
108
- console.log(
109
- chalk.gray(
110
- ` Generated ${
111
- Object.keys(authorRegistry).length
112
- } author entry files`
113
- )
114
- );
115
- } else {
116
- console.log(chalk.yellow("⚠️ mext-block package not found locally."));
117
- console.log(chalk.gray(" Named exports file not generated."));
118
- }
119
-
120
- console.log(chalk.green("\n🎉 Registry sync completed!"));
121
- } catch (error: any) {
122
- console.error(chalk.red(`❌ Failed to sync registry: ${error.message}`));
123
- process.exit(1);
124
- }
125
- }
126
-
127
- /**
128
- * Find the mext-block package path
129
- */
130
- function findMextBlockPath(): string | null {
131
- // Look for mext-block in common locations
132
- const possiblePaths = [
133
- path.join(process.cwd(), "..", "mext-block"),
134
- path.join(process.cwd(), "mext-block"),
135
- path.join(process.cwd(), "..", "..", "mext-block"),
136
- ];
137
-
138
- for (const possiblePath of possiblePaths) {
139
- if (fs.existsSync(path.join(possiblePath, "package.json"))) {
140
- try {
141
- const packageJson = JSON.parse(
142
- fs.readFileSync(path.join(possiblePath, "package.json"), "utf8")
143
- );
144
- if (
145
- packageJson.name === "@mexty/block" ||
146
- packageJson.name === "@mexty/block"
147
- ) {
148
- return possiblePath;
149
- }
150
- } catch (error) {
151
- // Ignore invalid package.json files
152
- }
153
- }
154
- }
155
-
156
- return null;
157
- }
158
-
159
- /**
160
- * Generate named exports file for the mext-block package
161
- */
162
- async function generateNamedExports(
163
- mextBlockPath: string,
164
- registry: BlockRegistry,
165
- authorRegistry: AuthorNamespaceRegistry
166
- ): Promise<void> {
167
- const namedExportsPath = path.join(mextBlockPath, "src", "namedExports.ts");
168
-
169
- // Generate the file content
170
- const content = `// Auto-generated file - DO NOT EDIT MANUALLY
171
- // Generated on: ${new Date().toISOString()}
172
- // Total components: ${Object.keys(registry).length}
173
- // Total authors: ${Object.keys(authorRegistry).length}
174
-
175
- import { createNamedBlock } from './components/NamedBlock';
176
- import { createAuthorBlock } from './components/AuthorBlock';
177
-
178
- // ===== GLOBAL NAMESPACE COMPONENTS =====
179
- ${Object.entries(registry)
180
- .map(
181
- ([componentName, entry]) =>
182
- `// ${entry.title}${entry.author ? ` (by ${entry.author})` : ""}
183
- // Block ID: ${entry.blockId}
184
- // Description: ${entry.description}
185
- // Tags: ${entry.tags?.join(", ") || "none"}
186
- export const ${componentName} = createNamedBlock('${componentName}');`
187
- )
188
- .join("\n\n")}
189
-
190
- // Export all global components as an object for convenience
191
- export const NamedComponents = {
192
- ${Object.keys(registry)
193
- .map((componentName) => ` ${componentName},`)
194
- .join("\n")}
195
- };
196
-
197
- // Note: Author-specific components are now available via direct imports:
198
- // import { ComponentName } from '@mexty/block/authorname'
199
- // Available authors: ${Object.keys(authorRegistry).join(", ")}
200
-
201
- // Registry metadata
202
- export const registryMetadata = {
203
- totalComponents: ${Object.keys(registry).length},
204
- totalAuthors: ${Object.keys(authorRegistry).length},
205
- lastGenerated: '${new Date().toISOString()}',
206
- components: {
207
- ${Object.entries(registry)
208
- .map(
209
- ([componentName, entry]) =>
210
- ` ${componentName}: {
211
- blockId: '${entry.blockId}',
212
- title: '${entry.title}',
213
- description: '${entry.description.replace(/'/g, "\\'")}',
214
- author: '${entry.author || ""}',
215
- tags: [${entry.tags?.map((tag) => `'${tag}'`).join(", ") || ""}],
216
- lastUpdated: '${entry.lastUpdated}'
217
- },`
218
- )
219
- .join("\n")}
220
- },
221
- authors: {
222
- ${Object.entries(authorRegistry)
223
- .map(
224
- ([author, components]) =>
225
- ` ${author}: {
226
- ${Object.entries(components)
227
- .map(
228
- ([componentName, entry]) =>
229
- ` ${componentName}: {
230
- blockId: '${entry.blockId}',
231
- title: '${entry.title}',
232
- description: '${entry.description.replace(/'/g, "\\'")}',
233
- tags: [${entry.tags?.map((tag) => `'${tag}'`).join(", ") || ""}],
234
- lastUpdated: '${entry.lastUpdated}'
235
- },`
236
- )
237
- .join("\n")}
238
- },`
239
- )
240
- .join("\n")}
241
- }
242
- };
243
- `;
244
-
245
- // Ensure directory exists
246
- const srcDir = path.dirname(namedExportsPath);
247
- if (!fs.existsSync(srcDir)) {
248
- fs.mkdirSync(srcDir, { recursive: true });
249
- }
250
-
251
- // Write the file
252
- fs.writeFileSync(namedExportsPath, content, "utf8");
253
-
254
- // Update the main index.ts to include these exports
255
- const indexPath = path.join(mextBlockPath, "src", "index.ts");
256
- if (fs.existsSync(indexPath)) {
257
- let indexContent = fs.readFileSync(indexPath, "utf8");
258
-
259
- // Add export for named exports if not already present
260
- if (!indexContent.includes("export * from './namedExports'")) {
261
- indexContent +=
262
- "\n// Auto-generated named exports\nexport * from './namedExports';\n";
263
- fs.writeFileSync(indexPath, indexContent, "utf8");
264
- }
265
- }
266
- }
267
-
268
- /**
269
- * Generate author-specific entry files for direct imports
270
- */
271
- async function generateAuthorEntryFiles(
272
- mextBlockPath: string,
273
- authorRegistry: AuthorNamespaceRegistry
274
- ): Promise<void> {
275
- const authorsDir = path.join(mextBlockPath, "src", "authors");
276
-
277
- // Clean up existing author files
278
- if (fs.existsSync(authorsDir)) {
279
- fs.rmSync(authorsDir, { recursive: true, force: true });
280
- }
281
-
282
- // Create authors directory
283
- fs.mkdirSync(authorsDir, { recursive: true });
284
-
285
- // Generate an entry file for each author
286
- for (const [author, components] of Object.entries(authorRegistry)) {
287
- const authorDir = path.join(authorsDir, author);
288
- fs.mkdirSync(authorDir, { recursive: true });
289
-
290
- const authorEntryPath = path.join(authorDir, "index.ts");
291
-
292
- // Generate the author's entry file content
293
- const content = `// Auto-generated author entry file for ${author}
294
- // Generated on: ${new Date().toISOString()}
295
- // Total components: ${Object.keys(components).length}
296
-
297
- import { createAuthorBlock } from '../../components/AuthorBlock';
298
-
299
- ${Object.entries(components)
300
- .map(
301
- ([componentName, entry]) =>
302
- `// ${entry.title}
303
- // Block ID: ${entry.blockId}
304
- // Description: ${entry.description}
305
- // Tags: ${entry.tags?.join(", ") || "none"}
306
- export const ${componentName} = createAuthorBlock('${author}', '${componentName}');`
307
- )
308
- .join("\n\n")}
309
-
310
- // Export all components as default for convenience
311
- export default {
312
- ${Object.keys(components)
313
- .map((componentName) => ` ${componentName},`)
314
- .join("\n")}
315
- };
316
-
317
- // Author metadata
318
- export const authorMetadata = {
319
- author: '${author}',
320
- totalComponents: ${Object.keys(components).length},
321
- lastGenerated: '${new Date().toISOString()}',
322
- components: {
323
- ${Object.entries(components)
324
- .map(
325
- ([componentName, entry]) =>
326
- ` ${componentName}: {
327
- blockId: '${entry.blockId}',
328
- title: '${entry.title}',
329
- description: '${entry.description.replace(/'/g, "\\'")}',
330
- tags: [${entry.tags?.map((tag) => `'${tag}'`).join(", ") || ""}],
331
- lastUpdated: '${entry.lastUpdated}'
332
- },`
333
- )
334
- .join("\n")}
335
- }
336
- };
337
- `;
338
-
339
- // Write the author entry file
340
- fs.writeFileSync(authorEntryPath, content, "utf8");
341
-
342
- console.log(
343
- chalk.gray(
344
- ` Created entry file for ${author} (${
345
- Object.keys(components).length
346
- } components)`
347
- )
348
- );
349
- }
350
- }