@myop/cli 0.1.4 → 0.1.6

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.
package/README.md ADDED
@@ -0,0 +1,335 @@
1
+ # @myop/cli
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@myop/cli.svg)](https://www.npmjs.com/package/@myop/cli)
4
+ [![License](https://img.shields.io/npm/l/@myop/cli.svg)](https://github.com/myop/cli/blob/main/LICENSE)
5
+
6
+ > Command-line interface for building, developing, and managing Myop components
7
+
8
+ Myop CLI is a powerful developer tool for creating and managing remote UI components. Build once, deploy anywhere - components built with Myop can be consumed across different frameworks and platforms.
9
+
10
+ ## Features
11
+
12
+ - 🚀 **Development Server** - Hot-reload enabled dev server with visual network monitoring
13
+ - 📊 **Visual Dashboard** - Real-time request tracking and architecture visualization
14
+ - 🔄 **Auto-sync** - Automatic component synchronization across multiple dev instances
15
+ - 🌐 **Proxy Fallback** - Seamless fallback to cloud-hosted components
16
+ - 📦 **Component Management** - Easy component registration and discovery
17
+ - 🎨 **Professional UI** - Chrome DevTools-inspired interface with zoom/pan capabilities
18
+
19
+ ## Installation
20
+
21
+ ```bash
22
+ npm install -g @myop/cli
23
+ ```
24
+
25
+ Or use locally in your project:
26
+
27
+ ```bash
28
+ npm install --save-dev @myop/cli
29
+ ```
30
+
31
+ ## Quick Start
32
+
33
+ ### Initialize a New Component
34
+
35
+ ```bash
36
+ # Create a new component
37
+ myop add
38
+
39
+ # Start development server
40
+ myop dev
41
+ ```
42
+
43
+ ### Development Workflow
44
+
45
+ 1. **Start the dev server** in your component directory:
46
+ ```bash
47
+ myop dev
48
+ ```
49
+
50
+ 2. **Access the dashboard** at `http://localhost:9292`
51
+
52
+ 3. **View your component** at `http://localhost:9292/view/<componentId>/`
53
+
54
+ 4. **Make changes** - the server watches `.js` and `.css` files and rebuilds automatically
55
+
56
+ ## Commands
57
+
58
+ ### `myop dev`
59
+
60
+ Start the development server with file watching and hot-reload.
61
+
62
+ ```bash
63
+ myop dev [options]
64
+ ```
65
+
66
+ **Features:**
67
+ - Runs on ports `9292` (main) and `9293` (management)
68
+ - Watches `.js` and `.css` files for changes
69
+ - Automatic builds on file changes
70
+ - Visual dashboard with network architecture diagram
71
+ - Multiple instances can register with the same server
72
+ - Health monitoring with automatic failover
73
+
74
+ **Options:**
75
+ - `-c, --config <path>` - Path to myop.config.json (default: `./myop.config.json`)
76
+ - `-v, --verbose` - Enable verbose logging
77
+
78
+ ### `myop add`
79
+
80
+ Add a new flow or component to your project.
81
+
82
+ ```bash
83
+ myop add
84
+ ```
85
+
86
+ Interactive prompt to add new components to your Myop configuration.
87
+
88
+ ### `myop remove`
89
+
90
+ Remove a flow or component from your project.
91
+
92
+ ```bash
93
+ myop remove
94
+ ```
95
+
96
+ Interactive prompt to remove components from your configuration.
97
+
98
+ ### `myop install`
99
+
100
+ Install dependencies and set up your Myop project.
101
+
102
+ ```bash
103
+ myop install
104
+ ```
105
+
106
+ ### `myop sync`
107
+
108
+ Synchronize your components with the Myop cloud.
109
+
110
+ ```bash
111
+ myop sync
112
+ ```
113
+
114
+ ## Configuration
115
+
116
+ Create a `myop.config.json` in your project root:
117
+
118
+ ```json
119
+ {
120
+ "componentId": "your-component-id",
121
+ "componentName": "My Component"
122
+ }
123
+ ```
124
+
125
+ **Fields:**
126
+ - `componentId` (required) - Unique identifier for your component
127
+ - `componentName` (optional) - Human-readable name displayed in the dashboard
128
+
129
+ ## Development Dashboard
130
+
131
+ The dev server includes a professional visual dashboard accessible at `http://localhost:9292`:
132
+
133
+ ### Features
134
+
135
+ - **Network Architecture View**
136
+ - Visual diagram showing request flow from origins → local server → cloud
137
+ - Interactive nodes (drag to reposition)
138
+ - Zoom and pan controls
139
+ - Curved connection lines for better readability
140
+
141
+ - **Real-time Monitoring**
142
+ - Live request tracking via Server-Sent Events (SSE)
143
+ - Origin detection and grouping
144
+ - Component request counts
145
+ - Local vs. proxied request statistics
146
+
147
+ - **Component Registry**
148
+ - All registered components with IDs and names
149
+ - Direct links to component views
150
+ - File paths for easy navigation
151
+
152
+ - **Activity Log**
153
+ - Recent request history
154
+ - Origin information
155
+ - Timestamp tracking
156
+
157
+ ## Architecture
158
+
159
+ ### Multi-Instance Support
160
+
161
+ The dev server supports running multiple component instances simultaneously:
162
+
163
+ 1. **First Instance** - Starts both main and management servers
164
+ 2. **Additional Instances** - Register with the existing server
165
+ 3. **Auto-Failover** - If the main server dies, another instance takes over
166
+
167
+ ### Request Flow
168
+
169
+ ```
170
+ Origin Request
171
+
172
+ Local Dev Server (port 9292)
173
+
174
+ Component Registered?
175
+ ├─ Yes → Serve from local dist/
176
+ └─ No → Proxy to cloud.myop.dev
177
+ ```
178
+
179
+ ### File Structure
180
+
181
+ ```
182
+ myop-cli/
183
+ ├── src/
184
+ │ ├── myop-cli.js # Main CLI entry point
185
+ │ ├── commands/
186
+ │ │ └── dev/ # Dev command
187
+ │ │ ├── index.js # Server logic
188
+ │ │ ├── README.md # Dev command docs
189
+ │ │ └── management-website/
190
+ │ │ ├── index.js # HTML generator
191
+ │ │ ├── styles.css # Dashboard styles
192
+ │ │ └── app.js # Client-side code
193
+ │ ├── operations/ # CLI operations
194
+ │ └── common/ # Shared utilities
195
+ └── dist/ # Built files (npm publish)
196
+ ```
197
+
198
+ ## API
199
+
200
+ ### Consume Endpoint
201
+
202
+ ```
203
+ GET /consume?id=<componentId>
204
+ ```
205
+
206
+ Returns the component's HTML loader configuration. Serves from local dist if registered, otherwise proxies to cloud.
207
+
208
+ **Response:**
209
+ ```json
210
+ {
211
+ "item": {
212
+ "id": "component-id",
213
+ "name": "component-id",
214
+ "consume_variant": [{
215
+ "id": "variant-id",
216
+ "name": "dev version",
217
+ "loader": {
218
+ "type": "HTMLLoader",
219
+ "shadowRootMode": "localFrame",
220
+ "HTML": "<html>...</html>"
221
+ }
222
+ }]
223
+ }
224
+ }
225
+ ```
226
+
227
+ ### Management API (port 9293)
228
+
229
+ #### Register Component
230
+ ```
231
+ POST /_register
232
+ Body: { "componentId": "id", "distPath": "/path", "componentName": "name" }
233
+ ```
234
+
235
+ #### Unregister Component
236
+ ```
237
+ POST /_unregister
238
+ Body: { "componentId": "id" }
239
+ ```
240
+
241
+ #### List Components
242
+ ```
243
+ GET /_list
244
+ Response: { "components": [[id, {path, name}], ...] }
245
+ ```
246
+
247
+ ## Development
248
+
249
+ ### Building from Source
250
+
251
+ ```bash
252
+ # Clone the repository
253
+ git clone https://github.com/myop/cli.git
254
+ cd cli
255
+
256
+ # Install dependencies
257
+ npm install
258
+
259
+ # Build
260
+ npm run build
261
+
262
+ # Test locally
263
+ ./dist/myop-cli.js dev
264
+ ```
265
+
266
+ ### Project Structure
267
+
268
+ The CLI is built with Vite and uses ES modules. Key technologies:
269
+
270
+ - **Commander.js** - CLI framework
271
+ - **Inquirer** - Interactive prompts
272
+ - **Ora** - Terminal spinners
273
+ - **Native Node.js APIs** - HTTP server, file watching, child processes
274
+
275
+ ## Contributing
276
+
277
+ Contributions are welcome! Please read our [Contributing Guide](CONTRIBUTING.md) for details on:
278
+
279
+ - Code of Conduct
280
+ - Development workflow
281
+ - Submitting pull requests
282
+ - Coding standards
283
+
284
+ ## Troubleshooting
285
+
286
+ ### Port Already in Use
287
+
288
+ If ports 9292 or 9293 are already in use:
289
+
290
+ ```bash
291
+ # Find process using the port
292
+ lsof -i :9292
293
+
294
+ # Kill the process
295
+ kill -9 <PID>
296
+ ```
297
+
298
+ ### Component Not Found
299
+
300
+ Ensure your `myop.config.json` exists and contains a valid `componentId`:
301
+
302
+ ```bash
303
+ cat myop.config.json
304
+ ```
305
+
306
+ ### Build Errors
307
+
308
+ Clear the dist folder and rebuild:
309
+
310
+ ```bash
311
+ rm -rf dist node_modules
312
+ npm install
313
+ npm run build
314
+ ```
315
+
316
+ ## License
317
+
318
+ [LICENSE](LICENSE)
319
+
320
+ ## Links
321
+
322
+ - [Homepage](https://myop.dev)
323
+ - [Documentation](https://docs.myop.dev)
324
+ - [GitHub Issues](https://github.com/myop/cli/issues)
325
+ - [NPM Package](https://www.npmjs.com/package/@myop/cli)
326
+
327
+ ## Support
328
+
329
+ - 📧 Email: support@myop.dev
330
+ - 💬 Discord: [Join our community](https://myop.dev/discord)
331
+ - 🐛 Issues: [GitHub Issues](https://github.com/myop/cli/issues)
332
+
333
+ ---
334
+
335
+ Made with ❤️ by the Myop team