# @prolaxu/galaxy-api-tool

A powerful CLI tool for generating Galaxy API files and Vue.js CRUD components. This tool replaces bash scripts with a robust, cross-platform Node.js solution.

## 🚀 Quick Start

Use with npx (no installation required):

```bash
# Generate API files with Request validation
npx @prolaxu/galaxy-api-tool gen:api User

# Generate API files without Request (uses EmptyRequest)
npx @prolaxu/galaxy-api-tool gen:api-empty Category

# Generate Vue.js CRUD views
npx @prolaxu/galaxy-api-tool gen:views admin/User

# Generate everything (API + Views)
npx @prolaxu/galaxy-api-tool gen:all inventory/Product
```

## 📦 Installation

### Global Installation
```bash
npm install -g @prolaxu/galaxy-api-tool
```

### Local Installation
```bash
npm install @prolaxu/galaxy-api-tool
npx galaxy-api-tool --help
```

## 🛠️ Commands

### `gen:api <ModelName>`
Generates complete Galaxy API files with Request validation.

```bash
npx @prolaxu/galaxy-api-tool gen:api User
```

**Generated files:**
- `src/GalaxyAPI/Controllers/UserController.php`
- `src/GalaxyAPI/Requests/UserRequest.php`
- `src/GalaxyAPI/Resources/UserResource.php`

### `gen:api-empty <ModelName>`
Generates Galaxy API files without Request validation (uses EmptyRequest).

```bash
npx @prolaxu/galaxy-api-tool gen:api-empty Category
```

**Generated files:**
- `src/GalaxyAPI/Controllers/CategoryController.php`
- `src/GalaxyAPI/Resources/CategoryResource.php`

### `gen:views <ModelInput>`
Generates Vue.js CRUD components and Pinia store. Supports grouping.

```bash
# Simple model
npx @prolaxu/galaxy-api-tool gen:views User

# Grouped model
npx @prolaxu/galaxy-api-tool gen:views admin/User

# Nested grouping
npx @prolaxu/galaxy-api-tool gen:views inventory/Product
```

**Generated files:**
- `resources/assets/spa/stores/modules/[path]/use[Model]Store.js`
- `resources/assets/spa/modules/[path]/[Model]Form.vue`
- `resources/assets/spa/modules/[path]/[Model]ListComponent.vue`
- `resources/assets/spa/modules/[path]/[Model]Select.vue`

### `gen:all <ModelInput>`
Generates both API files and Vue.js CRUD components.

```bash
# Generate everything with Request validation
npx @prolaxu/galaxy-api-tool gen:all admin/User

# Generate everything without Request validation
npx @prolaxu/galaxy-api-tool gen:all admin/User --empty
```

## 🎯 Options

### Custom Output Path
All commands support a custom output path:

```bash
npx @prolaxu/galaxy-api-tool gen:api User --path /custom/project/path
```

### Empty Request
Use `--empty` flag with `gen:all` to generate API without Request validation:

```bash
npx @prolaxu/galaxy-api-tool gen:all User --empty
```

## 📁 Output Structure

### API Files
```
src/
└── GalaxyAPI/
    ├── Controllers/
    │   └── UserController.php
    ├── Requests/
    │   └── UserRequest.php
    └── Resources/
        └── UserResource.php
```

### Vue.js CRUD Files
```
resources/
└── assets/
    └── spa/
        ├── modules/
        │   └── admin/
        │       └── user/
        │           ├── UserForm.vue
        │           ├── UserListComponent.vue
        │           └── UserSelect.vue
        └── stores/
            └── modules/
                └── admin/
                    └── user/
                        └── useUserStore.js
```

## 🔧 Model Input Formats

The tool supports various model input formats:

| Input | Output Path | API Endpoint |
|-------|-------------|--------------|
| `User` | `user/` | `v2/tenant/user` |
| `admin/User` | `admin/user/` | `v2/tenant/admin/user` |
| `inventory/Product` | `inventory/product/` | `v2/tenant/inventory/product` |

## 📝 Examples

### Generate User Management
```bash
# Generate complete user management system
npx @prolaxu/galaxy-api-tool gen:all User

# Output:
# ✅ Generated all files:
#   API Files:
#     - Controller: src/GalaxyAPI/Controllers/UserController.php
#     - Request:    src/GalaxyAPI/Requests/UserRequest.php
#     - Resource:   src/GalaxyAPI/Resources/UserResource.php
#   CRUD Files:
#     📁 Store: resources/assets/spa/stores/modules/user/useUserStore.js
#     📝 Form: resources/assets/spa/modules/user/UserForm.vue
#     📋 List: resources/assets/spa/modules/user/UserListComponent.vue
#     🔽 Select: resources/assets/spa/modules/user/UserSelect.vue
```

### Generate Admin Panel Components
```bash
# Generate admin-specific components
npx @prolaxu/galaxy-api-tool gen:views admin/Dashboard

# Output:
# ✅ Generated CRUD files for Dashboard:
#   📁 Group: admin
#   📁 Store: resources/assets/spa/stores/modules/admin/dashboard/useDashboardStore.js
#   📝 Form: resources/assets/spa/modules/admin/dashboard/DashboardForm.vue
#   📋 List: resources/assets/spa/modules/admin/dashboard/DashboardListComponent.vue
#   🔽 Select: resources/assets/spa/modules/admin/dashboard/DashboardSelect.vue
#   
#   📝 Next steps:
#     1. Update the columns array in DashboardListComponent.vue
#     2. Add form fields to DashboardForm.vue
#     3. Import and use components in your routes/pages
#     4. API endpoint: v2/tenant/admin/dashboard
```

### Generate Inventory System
```bash
# Generate inventory management with empty request
npx @prolaxu/galaxy-api-tool gen:all inventory/Product --empty

# Output includes both API and CRUD files for inventory/product
```

## 🚦 Error Handling

The tool includes comprehensive error handling:

- **Model name validation**: Ensures valid model names
- **Path validation**: Checks for valid file paths
- **Directory creation**: Automatically creates necessary directories
- **Template validation**: Validates template syntax

```bash
# Invalid model name
npx @prolaxu/galaxy-api-tool gen:api ""
# ❌ Error: Model name