0
# CLI Commands
1
2
Command-line interface for building, developing, and bundling the admin dashboard and extensions. Provides tools for both development and production workflows.
3
4
## Capabilities
5
6
### Build Command
7
8
Builds the admin dashboard for production deployment with optimization and asset compilation.
9
10
```typescript { .api }
11
/**
12
* Build the admin dashboard for production
13
* @param options - Build configuration options
14
*/
15
function build(options: BuildOptions): Promise<void>;
16
17
interface BuildOptions extends AdminOptions {
18
/** Build for deployment to external host */
19
deployment?: boolean;
20
}
21
```
22
23
**Usage:**
24
25
```bash
26
# Basic build
27
medusa-admin build
28
29
# Build with custom path
30
medusa-admin build --path /admin
31
32
# Build with custom backend URL
33
medusa-admin build --backend http://localhost:9000
34
35
# Build for external deployment
36
medusa-admin build --deployment --backend https://api.mystore.com
37
```
38
39
### Develop Command
40
41
Starts the admin dashboard in development mode with hot-reload and webpack dev server integration.
42
43
```typescript { .api }
44
/**
45
* Start admin dashboard in development mode
46
* @param options - Development server options
47
*/
48
function develop(options: DevelopArgs): Promise<void>;
49
50
interface DevelopArgs extends AdminOptions {
51
/** Port for development server */
52
port: number;
53
}
54
```
55
56
**Usage:**
57
58
```bash
59
# Start development server
60
medusa-admin develop
61
62
# Start with custom port
63
medusa-admin develop --port 3000
64
65
# Start with custom backend and path
66
medusa-admin develop --port 3000 --backend http://localhost:9000 --path /admin
67
```
68
69
### Bundle Command
70
71
Bundles admin extensions (routes, widgets, settings) for plugins using Rollup with TypeScript compilation.
72
73
```typescript { .api }
74
/**
75
* Bundle extensions to the admin dashboard
76
*/
77
function bundle(): Promise<void>;
78
```
79
80
**Usage:**
81
82
```bash
83
# Bundle admin extensions
84
medusa-admin bundle
85
```
86
87
**Requirements for bundling:**
88
- `src/admin` directory with extensions
89
- `package.json` with valid package name
90
- Extension files following Medusa admin conventions
91
92
### CLI Creation
93
94
Creates the main CLI program with all available commands.
95
96
```typescript { .api }
97
/**
98
* Creates the main CLI program with all available commands
99
* @returns Commander.js program instance
100
*/
101
function createCli(): Promise<Command>;
102
```
103
104
## Build Process
105
106
The build process involves several steps:
107
108
1. **Configuration Loading**: Loads Medusa config and plugin options
109
2. **Plugin Discovery**: Finds enabled admin UI plugins
110
3. **Asset Compilation**: Compiles TypeScript and processes assets
111
4. **Bundle Generation**: Creates optimized production bundles
112
5. **Manifest Creation**: Generates build manifest for change detection
113
114
## Development Workflow
115
116
Development mode provides:
117
118
- **Hot Reload**: Automatic recompilation on file changes
119
- **Source Maps**: Enhanced debugging experience
120
- **Proxy Integration**: Seamless backend API integration
121
- **Extension Loading**: Dynamic loading of custom extensions
122
123
## Extension Bundling
124
125
The bundle command processes admin extensions:
126
127
1. **Discovery**: Scans `src/admin` for routes, widgets, and settings
128
2. **Virtual Entry**: Creates virtual entry point for Rollup
129
3. **Compilation**: Transpiles TypeScript with ESBuild
130
4. **Output**: Generates ESM bundles in `dist/admin`
131
132
**Supported Extension Types:**
133
- **Routes**: Custom admin pages at specific paths
134
- **Widgets**: Components embedded in existing admin pages
135
- **Settings**: Configuration pages in admin settings section
136
137
## Error Handling
138
139
CLI commands provide detailed error reporting:
140
141
- **Configuration Errors**: Invalid plugin configurations
142
- **Build Failures**: TypeScript compilation or bundling errors
143
- **Missing Dependencies**: Required packages not installed
144
- **File System Errors**: Permission or disk space issues